Prometheus 启用筛选的收集器

Prometheus 启用筛选的收集器,prometheus,prometheus-node-exporter,Prometheus,Prometheus Node Exporter,Prometheus节点导出器没有一种简单的方法可以在不向流程传递20个标志的情况下禁用所有默认度量。在这种情况下,似乎有一种更简单的方法可以仅获取相关指标: 启用筛选的收集器 对于高级使用,可以向node_导出器传递一个可选的收集器列表以筛选度量。collect[]参数可以多次使用。在Prometheus配置中,您可以在scrape配置下使用此语法 params: collect[]: - foo - bar 这对于让不同的Prometheus服务器从节点收集特定的度量

Prometheus节点导出器没有一种简单的方法可以在不向流程传递20个标志的情况下禁用所有默认度量。在这种情况下,似乎有一种更简单的方法可以仅获取相关指标:

启用筛选的收集器

对于高级使用,可以向node_导出器传递一个可选的收集器列表以筛选度量。collect[]参数可以多次使用。在Prometheus配置中,您可以在scrape配置下使用此语法

params:
  collect[]:
    - foo
    - bar
这对于让不同的Prometheus服务器从节点收集特定的度量非常有用

我的假设是你把参数直接放在你的下,因为有一个匹配的参数字段。然而,究竟什么应该归入collect[]项下?foo和bar的例子描述得再清楚不过了。是命令行参数(例如“--collector.cpu”)、收集器名称(例如“cpu”)、收集器度量名称(例如“node\u cpu”)、实际度量(例如“node\u cpu\u seconds\u total”)还是其他什么?

测试节点收集器时,collect[]参数必须是收集器名称。例如,
--collector.cpu
中的名称是
cpu

如果指定无效的收集器,如
foo
,则将收到以下HTTP“400错误请求”消息:


还有另一个通用的解决方案,可以与所有出口商合作。是一个可在prometheus配置文件中设置的配置选项。按照文件规定:

这样做的一个用途是将过于昂贵的时间序列列入黑名单 摄入

因此,您可以删除或保留与正则表达式匹配的度量。例如,要仅存储节点导出器收集的cpu度量,可以在
prometheus.yml
文件中使用以下内容:

scrape_configs:
 - job_name: node
   static_configs:
    - targets:
       - localhost:9100
   metric_relabel_configs:
    - source_labels: [__name__]
      regex: node_cpu_.*
      action: keep
如上所述,
collect[]
参数中预期的参数是收集器的名称

作为对答案的补充,您可以在下面找到节点导出器配置的工作示例,它只过滤
cpu
meminfo
文件系统
收集器:

scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  # Node exporter
  - job_name: 'node_exporter'

    static_configs:
    - targets: ['localhost:9100']
    params:
      collect[]:
        - cpu
        - meminfo
        - filesystem
scrape\u配置:
#作业名称作为标签“job=”添加到此配置中的任何时间序列。
-工作名称:“普罗米修斯”
#metrics\u路径默认为“/metrics”
#方案默认为“http”。
静态\u配置:
-目标:['localhost:9090']
#节点导出器
-作业\u名称:“节点\u导出器”
静态\u配置:
-目标:['localhost:9100']
参数:
收集[]:
-中央处理器
-meminfo
-文件系统

请记住,旧收集的度量仍然可以访问,但是一旦重新启动了
prometheus
服务,只有过滤后的度量(
cpu
meminfo
文件系统
)可用。

该功能看起来更有用。
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'prometheus'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
    - targets: ['localhost:9090']

  # Node exporter
  - job_name: 'node_exporter'

    static_configs:
    - targets: ['localhost:9100']
    params:
      collect[]:
        - cpu
        - meminfo
        - filesystem