---
title: Scrape Prometheus metrics
description: 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.
url: https://docs.influxdata.com/influxdb/v2/write-data/developer-tools/scrape-prometheus-metrics/
estimated_tokens: 1851
product: InfluxDB OSS v2
version: v2
---

# Scrape Prometheus metrics

This page documents an earlier version of InfluxDB OSS. [InfluxDB 3 Core](/influxdb3/core/) is the latest stable version.

#### API token hashing is enabled by default in InfluxDB OSS 2.9.0

Stronger token security: tokens are stored as hashes on disk, so a copy of the database file doesn’t expose usable tokens. Existing tokens are hashed on first startup and the original strings can’t be recovered afterward — **capture any plaintext tokens you still need before you upgrade**.

For more information, see [Token hashing](/influxdb/v2/admin/tokens/#token-hashing).

Use [Telegraf](/telegraf/v1/), [InfluxDB scrapers](/influxdb/v2/write-data/no-code/scrape-data/),

or the [`prometheus.scrape` Flux function](/flux/v0/stdlib/experimental/prometheus/scrape/) to scrape Prometheus-formatted metrics from an HTTP-accessible endpoint and store them in InfluxDB.

-   [Use Telegraf](#use-telegraf)
-   [Use an InfluxDB scraper](#use-an-influxdb-scraper)
-   [Use prometheus.scrape()](#use-prometheusscrape)

## 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](/telegraf/v1/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](/influxdb/v2/reference/prometheus-metrics/) to use *(version `2` is recommended)*.
2. Add the [InfluxDB v2 output plugin](/telegraf/v1/plugins/#output-influxdb_v2) to your Telegraf configuration file and configure it to write to InfluxDB .

##### Example telegraf.conf

```toml
# ...

## 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 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](/influxdb/v2/write-data/no-code/scrape-data/).

## Use prometheus.scrape()

To use the [`prometheus.scrape()` Flux function](/flux/v0/stdlib/experimental/prometheus/scrape/) 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](/flux/v0/stdlib/experimental/prometheus/).
2. Use `prometheus.scrape()` and provide the URL to scrape metrics from.
3. Use [`to()`](/flux/v0/stdlib/influxdata/influxdb/to/) and specify the InfluxDB bucket to write the scraped metrics to.

##### Example Flux script

```js
import "experimental/prometheus"

prometheus.scrape(url: "http://example.com/metrics")
    |> to(bucket: "example-bucket")
```

4. (Optional) To scrape Prometheus metrics at regular intervals using Flux, add your Flux scraping script as an [InfluxDB task](/influxdb/v2/process-data/).

*For information about scraping Prometheus-formatted metrics with `prometheus.scrape()`, see [Scrape Prometheus metrics with Flux](/flux/v0/prometheus/scrape-prometheus/).*

#### Related

-   [Telegraf Prometheus input plugin](/telegraf/v1/plugins/#input-prometheus)
-   [Scrape Prometheus metrics with Flux](/flux/v0/prometheus/scrape-prometheus/)
-   [prometheus.scrape() function](/flux/v0/stdlib/experimental/prometheus/scrape/)
-   [Work with Prometheus metric types](/flux/v0/prometheus/metric-types/)
-   [Prometheus metric parsing formats](/influxdb/v2/reference/prometheus-metrics/)
-   [Scrape data using InfluxDB scrapers](/influxdb/v2/write-data/no-code/scrape-data/)

[prometheus](/influxdb/v2/tags/prometheus/) [scraper](/influxdb/v2/tags/scraper/)
