Filtering Enabled Collectors

限于喜欢 提交于 2020-02-25 13:15:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!