content/shared/influxdb-v2/write-data/developer-tools/scrape-prometheus-metrics.md
Use Telegraf{{% show-in "v2" %}}, InfluxDB scrapers,{{% /show-in %}}
or the prometheus.scrape Flux function
to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and store them in InfluxDB.
{{% show-in "v2" %}}
{{% /show-in %}} {{% show-in "cloud,cloud-serverless" %}}
{{% /show-in %}}
To use Telegraf to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and write them to InfluxDB{{% show-in "cloud,cloud-serverless" %}} Cloud{{% /show-in %}}, follow these steps:
urls to scrape metrics from.metric_version configuration option to specify which
metric parsing version to use
(version 2 is recommended).# ...
## 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"
# ...
{{% show-in "v2" %}}
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.
{{% /show-in %}}
To use the prometheus.scrape() Flux function
to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and write
them to InfluxDB{{% show-in "cloud,cloud-serverless" %}} Cloud{{% /show-in %}}, do the following in your Flux script:
experimental/prometheus package.prometheus.scrape() and provide the URL to scrape metrics from.to() and specify the InfluxDB{{% show-in "cloud,cloud-serverless" %}} Cloud{{% /show-in %}} bucket to write
the scraped metrics to.import "experimental/prometheus"
prometheus.scrape(url: "http://example.com/metrics")
|> to(bucket: "example-bucket")
For information about scraping Prometheus-formatted metrics with prometheus.scrape(),
see Scrape Prometheus metrics with Flux.