Prometheus endpoints support in InfluxDB

Prometheus remote read and write API support

Note: The Prometheus API Stability Guaranteesstates that remote read and remote write endpoints are features listed as experimentalor subject to change, and thus considered unstable for 2.x. Any breaking changeswill be included in the InfluxDB release notes.

InfluxDB support for the Prometheus remote read and write API adds the followingHTTP endpoints to InfluxDB:

  • /api/v1/prom/read
  • /api/v1/prom/write

Additionally, there is a /metrics endpoint configured to produce default Go metrics in Prometheus metrics format.

Create a target database

Create a database in your InfluxDB instance to house data sent from Prometheus.In the examples provided below, prometheus is used as the database name, butyou’re welcome to use the whatever database name you like.

  1. CREATE DATABASE "prometheus"

Configuration

To enable the use of the Prometheus remote read and write APIs with InfluxDB, add URLvalues to the following settings in the Prometheus configuration file:

The URLs must be resolvable from your running Prometheus server and use the porton which InfluxDB is running (8086 by default).Also include the database name using the db= query parameter.

Example: Endpoints in Prometheus configuration file

  1. remote_write:
  2. - url: "http://localhost:8086/api/v1/prom/write?db=prometheus"
  3. remote_read:
  4. - url: "http://localhost:8086/api/v1/prom/read?db=prometheus"

Read and write URLs with authentication

If authentication is enabled on InfluxDB,pass the username and password of an InfluxDB user with read and write privilegesusing the u= and p= query parameters respectively.

Examples of endpoints with authentication enabled**_
  1. remote_write:
  2. - url: "http://localhost:8086/api/v1/prom/write?db=prometheus&u=username&p=password"
  3. remote_read:
  4. - url: "http://localhost:8086/api/v1/prom/read?db=prometheus&u=username&p=password"

Including plain text passwords in your Prometheus configuration file is not ideal.Unfortunately, environment variables and secrets are not supported in Prometheus configuration files.See this Prometheus issue for more information:

Support for environment variable substitution in configuration file

How Prometheus metrics are parsed in InfluxDB

As Prometheus data is brought into InfluxDB, the following transformations aremade to match the InfluxDB data structure:

  • The Prometheus metric name becomes the InfluxDB measurement name.
  • The Prometheus sample (value) becomes an InfluxDB field using the value field key. It is always a float.
  • Prometheus labels become InfluxDB tags.
  • All # HELP and # TYPE lines are ignored.
  • [v1.7.6 and later] Prometheus remote write endpoint drops unsupported Prometheus values (NaN,-Inf, and +Inf) rather than reject the entire batch.

Example: Parse Prometheus to InfluxDB

  1. # Prometheus metric
  2. example_metric{queue="0:http://example:8086/api/v1/prom/write?db=prometheus",le="0.005"} 308
  3. # Same metric parsed into InfluxDB
  4. measurement
  5. example_metric
  6. tags
  7. queue = "0:http://example:8086/api/v1/prom/write?db=prometheus"
  8. le = "0.005"
  9. job = "prometheus"
  10. instance = "localhost:9090"
  11. __name__ = "example_metric"
  12. fields
  13. value = 308

In InfluxDB v1.5 and earlier, all Prometheus data goes into a single measurementnamed and the Prometheus measurement name is stored in the _name label.In InfluxDB v1.6 or later, every Prometheus measurement gets its own InfluxDB measurement.

This format is different than the format used by the Telegraf Prometheus input plugin.