我有Prometheus在几台配置计算机上从节点导出程序中获取度量标准,配置如下:
scrape_configs:
- job_name: node_exporter
static_configs:
- targets:
- 1.2.3.4:9100
- 2.3.4.5:9100
- 3.4.5.6:9100
当在Grafana中查看时,这些实例被分配了相当无意义的IP地址;相反,我更希望看到它们的主机名。我认为您应该能够重新命名instance
标签以匹配节点的主机名,所以我尝试使用这样的重新标记规则,但没有任何效果:
relabel_configs:
- source_labels: ['nodename']
target_label: 'instance'
我可以手动重命名每个目标,但这需要将每个主机名硬编码到Prometheus中,这并不好。我看到节点导出程序提供了包含主机名的度量node_uname_info
,但是如何从其中提取它呢?
node_uname_info{domainname="(none)",machine="x86_64",nodename="myhostname",release="4.13.0-32-generic",sysname="Linux",version="..."} 1
发布于 2018-06-25 12:26:03
我刚刚遇到了这个问题,解决方案是使用group_left来解决这个问题。您不能用请求中不存在的值重新命名,您只限于提供给Prometheus的不同参数或用于请求的模块中存在的参数(gcp、aws.)。
因此,我使用的解决方案是将包含我们想要的内容( hostnmame
)的现有值与节点导出者的度量相结合。我们的答案存在于包含node_uname_info
值的nodename
度量中。
我用这个帖子的答案作为我的请求的模型:https://stackoverflow.com/a/50357418。
解决办法是:
node_memory_Active_bytes
* on(instance) group_left(nodename)
node_uname_info
这样,默认情况下只包含instance
和job
标签的instance
度量将获得一个额外的nodename
标签,您可以在Grafana的description字段中使用该标签。
希望这会对其他人有所帮助。
发布于 2020-08-14 14:17:08
这一解决方案存储数据在刮刮时间与所需的标签,不需要有趣的PromQL查询或硬编码的黑客。它这样做的方法是用relabel_configs
替换用regexes抓取的数据的标签。
默认情况下,instance
设置为__address__
,$host:$port
。
第一次尝试:为了将instance
标签设置为$host
,可以使用relabel_configs
来消除替罪羊目标的端口:
- job_name: 'whatever'
static_configs:
- targets: [
'yourhost.lol:9001'
]
relabel_configs:
- source_labels: [__address__]
target_label: instance
regex: '([^:]+)(:[0-9]+)?'
replacement: '${1}'
但是上面的也会覆盖您想要设置的标签,例如在file_sd_configs
中
[
{
"targets": ['yourhost.lol:9001'],
"labels": {
"instance": 'node42'
}
}
]
解决方案:如果您想保留这些标签,relabel_configs
可以多次重写标签,方法如下:
- job_name: 'whatever'
metrics_path: /metric/rolf
file_sd_configs:
- files:
- rolf_exporter_targets.yml
relabel_configs:
- source_labels: [instance]
target_label: __tmp_instance
regex: '(.+)'
replacement: '${1};'
- source_labels: [__tmp_instance, __address__]
separator: ''
target_label: instance
regex: '([^:;]+)((:[0-9]+)?|;(.*))'
replacement: '${1}'
这样做,手动设置的instance
在sd_configs
优先,但如果它没有设置,端口仍然被剥夺。
发布于 2020-10-31 16:10:33
您可以在prometheus的工作描述中使用类似于此的重新命名规则:
- job_name: node-exporter
....
relabel_configs:
.....
# relable the label 'instance' with your pod_node_name
- source_labels: [__meta_kubernetes_pod_node_name]
target_label: instance
在prometheus服务发现中,您可以首先检查标签的正确名称。标签将以“....pod_node_name”结尾
https://stackoverflow.com/questions/49896956
复制相似问题