初始环境:

    1. scrape_configs:
    2. - job_name: 'avalon-inner'
    3. static_configs:
    4. - targets: ['10.172.188.212:8083']
    5. labels:
    6. project: devops
    7. app: jenkins/master
    1. [root@k8s-node02 server]# curl http://192.168.200.147:9090/api/v1/targets?state=active | jq
    2. {
    3. "status": "success",
    4. "data": {
    5. "activeTargets": [
    6. {
    7. "discoveredLabels": {
    8. "__address__": "10.172.188.212:8083",
    9. "__metrics_path__": "/metrics",
    10. "__scheme__": "http",
    11. "app": "jenkins/master",
    12. "job": "avalon-inner", //定义标签
    13. "project": "devops" //定义标签
    14. },
    15. "labels": {
    16. "app": "jenkins/master",
    17. "instance": "10.172.188.212:8083",
    18. "job": "avalon-inner", //定义标签
    19. "project": "devops" //定义标签
    20. },
    21. "scrapePool": "avalon-inner",
    22. "scrapeUrl": "http://10.172.188.212:8083/metrics",
    23. "globalUrl": "http://10.172.188.212:8083/metrics",
    24. "lastError": "",
    25. "lastScrape": "2021-03-18T17:57:44.732036509+08:00",
    26. "lastScrapeDuration": 0.026422222,
    27. "health": "up"
    28. }
    29. ],
    30. "droppedTargets": []
    31. }
    32. }

    将标签project的值 复制给 app

    1. scrape_configs:
    2. # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
    3. - job_name: 'avalon-inner'
    4. static_configs:
    5. - targets: ['10.172.188.212:8083']
    6. #- targets: ['192.168.200.147:8083','10.172.188.212:8083']
    7. labels:
    8. project: devops
    9. app: jenkins/master
    10. relabel_configs:
    11. - source_labels: [project]
    12. regex: (.+)
    13. target_label: project
    14. action: replace
    1. [root@k8s-node02 server]# curl http://192.168.200.147:9090/api/v1/targets?state=active | jq
    2. % Total % Received % Xferd Average Speed Time Time Time Current
    3. Dload Upload Total Spent Left Speed
    4. 100 557 100 557 0 0 330k 0 --:--:-- --:--:-- --:--:-- 543k
    5. {
    6. "status": "success",
    7. "data": {
    8. "activeTargets": [
    9. {
    10. "discoveredLabels": {
    11. "__address__": "10.172.188.212:8083",
    12. "__metrics_path__": "/metrics",
    13. "__scheme__": "http",
    14. "app": "jenkins/master",
    15. "job": "avalon-inner", //定义标签(不变)
    16. "project": "devops" //定义标签(不变)
    17. },
    18. "labels": {
    19. "app": "devops", //app值 被修改
    20. "instance": "10.172.188.212:8083",
    21. "job": "avalon-inner",
    22. "project": "devops" //定义标签 未操作
    23. },
    24. "scrapePool": "avalon-inner",
    25. "scrapeUrl": "http://10.172.188.212:8083/metrics",
    26. "globalUrl": "http://10.172.188.212:8083/metrics",
    27. "lastError": "",
    28. "lastScrape": "0001-01-01T00:00:00Z",
    29. "lastScrapeDuration": 0,
    30. "health": "unknown"
    31. }
    32. ],
    33. "droppedTargets": []
    34. }
    35. }