Scrape Prometheus endpoints
Scrape applications and exporters that expose Prometheus /metrics
endpoints, and write the metrics to InfluxDB 3.
This example scrapes a node_exporter
instance and an application endpoint.
Configuration
[[inputs.prometheus]]
## Endpoints to scrape on each collection interval.
urls = [
"http://node1.example.com:9100/metrics",
"http://app1.example.com:8080/metrics"
]
## Metric layout. The plugin default is 1. Version 2 is recommended.
metric_version = 2
## Tag metrics with the scraped URL.
url_tag = "url"
[[outputs.influxdb_v3]]
urls = ["http://localhost:8181"]
token = "AUTH_TOKEN"
database = "DATABASE_NAME"Replace the following:
AUTH_TOKEN: your InfluxDB authorization tokenDATABASE_NAME: the database to write to
How it works
urlslists the endpoints to scrape. The plugin requests each one on the collection interval and parses the exposition-format response.metric_version = 2stores each Prometheus sample as a metric namedprometheus, with labels as tags and the Prometheus metric name as the field key. This layout is sparse, works well with column-oriented destinations like InfluxDB 3, and round-trips cleanly if you later re-serialize metrics with the Prometheus output data format. The plugin’s default is1(dense layout: metric name as measurement,counter/gaugefield names), kept for backward compatibility.url_tagrecords which endpoint each metric came from.
Example output
prometheus,cpu=cpu0,mode=idle,url=http://node1.example.com:9100/metrics node_cpu_seconds_total=18472.1 1709572230000000000
prometheus,url=http://node1.example.com:9100/metrics node_memory_MemAvailable_bytes=5836500992 1709572230000000000
prometheus,method=GET,path=/api/orders,status=200,url=http://app1.example.com:8080/metrics http_requests_total=84721 1709572230000000000Extend this example
- In Kubernetes, scrape dynamically instead of listing URLs: set
monitor_kubernetes_pods = trueto discover pods by annotation, orkubernetes_servicesfor service endpoints. See the plugin documentation. - To accept pushed Prometheus data instead of scraping, pair http_listener_v2 with the Prometheus input data format or the Prometheus Remote Write input data format.
- Histogram and summary metrics accumulate state. If you re-expose scraped metrics for Prometheus to collect, use the prometheus_client output plugin.
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community! We welcome and encourage your feedback and bug reports for Telegraf and this documentation. To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.