Documentation

Scrape Prometheus metrics

Use Telegraf, InfluxDB scrapers, or the prometheus.scrape Flux function to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and store them in InfluxDB.

Use Telegraf

To use Telegraf to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and write them to InfluxDB, follow these steps:

  1. Add the Prometheus input plugin to your Telegraf configuration file.
    1. Set the urls to scrape metrics from.
    2. Set the metric_version configuration option to specify which metric parsing version to use (version 2 is recommended).
  2. Add the InfluxDB v2 output plugin to your Telegraf configuration file and configure it to write to InfluxDB.
Example telegraf.conf
# ...

## Collect Prometheus formatted metrics
[[inputs.prometheus]]
  urls = ["http://example.com/metrics"]
  metric_version = 2

## Write Prometheus formatted metrics to InfluxDB
[[outputs.influxdb_v2]]
  urls = ["http://localhost:8086"]
  token = "$INFLUX_TOKEN"
  organization = "example-org"
  bucket = "example-bucket"

# ...
  • Copy
  • Fill window

Use an InfluxDB scraper

InfluxDB scrapers automatically scrape Prometheus-formatted metrics from an HTTP-accessible endpoint at a regular interval. For information about setting up an InfluxDB scraper, see Scrape data using InfluxDB scrapers.

Use prometheus.scrape()

To use the prometheus.scrape() Flux function to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and write them to InfluxDB, do the following in your Flux script:

  1. Import the experimental/prometheus package.
  2. Use prometheus.scrape() and provide the URL to scrape metrics from.
  3. Use to() and specify the InfluxDB bucket to write the scraped metrics to.
Example Flux script
import "experimental/prometheus"

prometheus.scrape(url: "http://example.com/metrics")
    |> to(bucket: "example-bucket")
  • Copy
  • Fill window
  1. (Optional) To scrape Prometheus metrics at regular intervals using Flux, add your Flux scraping script as an InfluxDB task.

For information about scraping Prometheus-formatted metrics with prometheus.scrape(), see Scrape Prometheus metrics with Flux.


Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: