通过对标签的重命名进行重整操作,便于统一化管理或者服务升级前后管理。
原始数据:
cat targets/node-exporter.yml
targets"172.20.31.195:9100" labels __os__"linux" __release__"redhat"targets"172.20.31.196:9100" labels __os__"linux" __release__"centos"targets"172.20.31.197:9100" labels __os__"linux" __release__"centos"
replace: 对原有的标签进行更名
scrape_configsjob_name'node-exporter' file_sd_configsfiles targets/node-exporter.yml refresh_interval 1m relabel_configssource_labels"__os__" regex"(.*)" target_label"os" action replace replacement"$1"
replace-separator: 对字段进行合并处理
scrape_configsjob_name'node-exporter' file_sd_configsfiles targets/node-exporter.yml refresh_interval 1m relabel_configssource_labels"__os__""__release__" separator"-" regex"(.*)" target_label"os_release" action replace replacement"$1"
keep: 满足特定条件的实例进行采集,其他的不采集。
scrape_configsjob_name'node-exporter' file_sd_configsfiles targets/node-exporter.yml refresh_interval 1m relabel_configssource_labels"__release__" regex"redhat" action keep
drop: 满足特定条件的实例不采集,其他的采集。
scrape_configsjob_name'node-exporter' file_sd_configsfiles targets/node-exporter.yml refresh_interval 1m relabel_configssource_labels"__release__" regex"redhat" action drop
labelkeep: 对抓取的实例特定标签进行保留,其他标签删除。
scrape_configsjob_name'node-exporter' file_sd_configsfiles targets/node-exporter.yml refresh_interval 1m relabel_configssource_labels"__os__" regex"(.*)" target_label"os" action replace replacement"$1"source_labels"__release__" regex"(.*)" target_label"release" action replace replacement"$1"regex"jobs" action labelkeep
labeldrop: 对抓取的实例特定标签进行删除。
scrape_configsjob_name'node-exporter' file_sd_configsfiles targets/node-exporter.yml refresh_interval 1m relabel_configssource_labels"__os__" regex"(.*)" target_label"os" action replace replacement"$1"source_labels"__release__" regex"(.*)" target_label"release" action replace replacement"$1"regex"os" action labeldrop
hashmod:将target_label设置成source_label的modulus配置的hash值;
labelmap:将regex匹配到的所有标签的名称配置成新的标签,值配置成新标签的值;