Scrape Prometheus metrics
Use Telegraf
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 Cloud, follow these steps:
- Add the Prometheus input plugin to your Telegraf configuration file.
- Set the
urls
to scrape metrics from. - Set the
metric_version
configuration option to specify which metric parsing version to use (version2
is recommended).
- Set the
- Add the InfluxDB v2 output plugin to your Telegraf configuration file and configure it to to write to InfluxDB Cloud.
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"
# ...
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 Cloud, 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 Cloud bucket to write the scraped metrics to.
Example Flux script
import "experimental/prometheus"
prometheus.scrape(url: "http://example.com/metrics")
|> 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.
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for InfluxDB and this documentation. To find support, the following resources are available:
InfluxDB Cloud and InfluxDB Enterprise customers can contact InfluxData Support.