问题
The Prometheus node exporter does not have a simple way to disable all default metrics without passing 20 flags to the process. In the documentation it looks like there might be an easier way to fetch only the relevant metrics:
Filtering enabled collectors
...
For advanced use the node_exporter can be passed an optional list of collectors to filter metrics. The collect[] parameter may be used multiple times. In Prometheus configuration you can use this syntax under the scrape config.
params: collect[]: - foo - bar
This can be useful for having different Prometheus servers collect specific metrics from nodes.
My assumption is you put the params directly under your scrape_config because there's a matching params field. However, what exactly is supposed to go under collect[]? The examples foo and bar couldn't be any less descriptive. Is it the command-line argument (e.g., "--collector.cpu"), the collector name (e.g., "cpu"), the collector metric name (e.g., "node_cpu"), the actual metric (e.g., "node_cpu_seconds_total"), or something else?
回答1:
There is another solution that is generic and can work with all exporters. relabel_map_config is a configuration option that can be set inside the prometheus config file. As specified in the documentation:
One use for this is to blacklist time series that are too expensive to ingest.
Thus you can drop or keep metrics that match a regex. For instance, to only store the cpu metrics collected by the node exporter, you can use the following inside the prometheus.yml
file:
scrape_configs:
- job_name: node
static_configs:
- targets:
- localhost:9100
metric_relabel_configs:
- source_labels: [__name__]
regex: node_cpu_.*
action: keep
回答2:
From testing the node collector the collect[] parameter must be the collector name. E.g., the name from --collector.cpu
is cpu
.
If you specify an invalid collector such as foo
, you'll receive the following HTTP "400 Bad Request" message:
Couldn't create missing collector: foo
来源:https://stackoverflow.com/questions/53325478/filtering-enabled-collectors