docs-v2/content/influxdb/v2.0/write-data/developer-tools/scrape-prometheus-metrics.md

4.1 KiB

title seotitle weight description menu related influxdb/v2.0/tags
Scrape Prometheus metrics Scape Prometheus metrics into InfluxDB 205 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.
influxdb_2_0
name parent
Scrape Prometheus metrics Developer tools
/{{< latest "telegraf" >}}/plugins/#input-prometheus, Telegraf Prometheus input plugin
/{{< latest "flux" >}}/prometheus/scrape-prometheus/, Scrape Prometheus metrics with Flux
/{{< latest "flux" >}}/stdlib/experimental/prometheus/scrape/
/{{< latest "flux" >}}/prometheus/metric-types/
/influxdb/v2.0/reference/prometheus-metrics/
/influxdb/v2.0/write-data/no-code/scrape-data/
prometheus
scraper

Use [Telegraf](/{{< latest "telegraf" >}}/){{% oss-only %}}, InfluxDB scrapers,{{% /oss-only %}} or the [prometheus.scrape Flux function](/{{< latest "flux" >}}/stdlib/experimental/prometheus/scrape/) to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and store them in InfluxDB.

{{% oss-only %}}

{{% /oss-only %}} {{% cloud-only %}}

{{% /cloud-only %}}

Use Telegraf

To use Telegraf to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and write them to InfluxDB{{% cloud-only %}} Cloud{{% /cloud-only %}}, follow these steps:

  1. Add the [Prometheus input plugin](/{{< latest "telegraf" >}}/plugins/#input-prometheus) 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](/{{< latest "telegraf" >}}/plugins/#output-influxdb_v2) to your Telegraf configuration file and configure it to to write to InfluxDB{{% cloud-only %}} Cloud{{% /cloud-only %}}.
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"

# ...

{{% oss-only %}}

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.

{{% /oss-only %}}

Use prometheus.scrape()

To use the [prometheus.scrape() Flux function](/{{< latest "flux" >}}/stdlib/experimental/prometheus/scrape/) to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and write them to InfluxDB{{% cloud-only %}} Cloud{{% /cloud-only %}}, do the following in your Flux script:

  1. Import the [experimental/prometheus package](/{{< latest "flux" >}}/stdlib/experimental/prometheus/).
  2. Use prometheus.scrape() and provide the URL to scrape metrics from.
  3. Use [to()](/{{< latest "flux" >}}/stdlib/influxdata/influxdb/to/) and specify the InfluxDB{{% cloud-only %}} Cloud{{% /cloud-only %}} bucket to write the scraped metrics to.
Example Flux script
import "experimental/prometheus"

prometheus.scrape(url: "http://example.com/metrics")
  |> to(bucket: "example-bucket")
  1. (Optional) To scrape Prometheus metrics at regular intervals using Flux, add your Flux scraping script as an [InfluxDB task](/{{< latest "influxdb" >}}/process-data/).

For information about scraping Prometheus-formatted metrics with prometheus.scrape(), see [Scrape Prometheus metrics with Flux](/{{< latest "flux" >}}/prometheus/scrape-prometheus/).