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:
- Add the Prometheus input plugin to your Telegraf configuration file.
- Set the
urlsto scrape metrics from. - Set the
metric_versionconfiguration option to specify which metric parsing version to use (version2is recommended). - Add the InfluxDB v2 output plugin to your Telegraf configuration file and configure it to write to InfluxDB.
Example telegraf.conf
1. # ...
3. ## Collect Prometheus formatted metrics
4. [[inputs.prometheus]]
5. urls = ["http://example.com/metrics"]
6. metric_version = 2
8. ## Write Prometheus formatted metrics to InfluxDB
9. [[outputs.influxdb_v2]]
10. urls = ["http://localhost:8086"]
11. token = "$INFLUX_TOKEN"
12. organization = "example-org"
13. bucket = "example-bucket"
15. # ...
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:
- Import the experimental/prometheus package.
- Use
prometheus.scrape()and provide the URL to scrape metrics from. - Use to() and specify the InfluxDB bucket to write the scraped metrics to.
Example Flux script
1. import "experimental/prometheus"
3. prometheus.scrape(url: "http://example.com/metrics")
4. |> to(bucket: "example-bucket")
- (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.
Related
- Telegraf Prometheus input plugin
- Scrape Prometheus metrics with Flux
- prometheus.scrape() function
- Work with Prometheus metric types
- Prometheus metric parsing formats
- Scrape data using InfluxDB scrapers
