关于Prometheus Exporters采集与聚合指标间隔的技术咨询
Great question—this is a key detail that trips up a lot of folks getting deep into Prometheus! Let’s break this down with the official guidelines and node_exporter example you referenced.
Core Rule: Exporters Don’t Schedule Their Own Collection
First, let’s reinforce the official best practice: exporters should never run their own timers to collect metrics in the background. Instead, all metric collection and aggregation happens only when Prometheus sends a scrape request to the exporter’s /metrics endpoint.
This design keeps exporters lightweight and puts full control of the monitoring cadence in Prometheus’s hands—no need for exporters to manage state or sync schedules with the server.
How Node Exporter (and Most Exporters) Work in Practice
Looking at the node_exporter CPU collector code you mentioned: when Prometheus hits /metrics, the exporter triggers the collector’s Collect function. At that exact moment:
- It reads the latest raw CPU data (from
/proc/staton Linux) - It compares this raw data to the previous scrape’s cached values
- It calculates aggregated metrics like CPU usage percentages for each core/state
- It returns these computed metrics to Prometheus, and updates the cached raw data for the next scrape
There’s no background timer ticking every X seconds to precompute metrics. All work happens on-demand, when Prometheus asks for it.
So What’s the Actual Frequency?
The collection and aggregation frequency directly matches the scrape_interval configured for the exporter’s job in Prometheus.
For example:
- If you set
scrape_interval: 15sfor your node_exporter job, Prometheus will send a request every 15 seconds. - Each request triggers a full round of data collection and aggregation from the exporter.
- The metrics returned reflect the state of the system at the time of the scrape (or, for rate-based metrics like CPU usage, the delta between the current and previous scrape).
Why This Design Matters
- Consistency: Prometheus aligns all scrapes to its internal schedule, ensuring metrics are collected at predictable intervals across all targets.
- Resource Efficiency: Exporters don’t waste cycles collecting metrics when no one’s asking for them.
- Simplicity: No need to configure and sync timers between exporters and Prometheus—just set the scrape interval once in your Prometheus config.
内容的提问来源于stack exchange,提问作者AZ-

