{"id":1325,"date":"2020-07-27T03:02:43","date_gmt":"2020-07-27T03:02:43","guid":{"rendered":"https:\/\/www.ipcpu.com\/?p=1325"},"modified":"2020-11-27T06:03:22","modified_gmt":"2020-11-27T06:03:22","slug":"prometheus-relabel","status":"publish","type":"post","link":"https:\/\/c.ipcpu.com\/2020\/07\/prometheus-relabel\/","title":{"rendered":"prometheus\u4e2d\u7684relabel"},"content":{"rendered":"

prometheus\u4e2d\u7684relabel.md
\n<\/p>\n

relabel\u987e\u540d\u601d\u4e49\uff0c\u5c31\u662f\u6807\u7b7e\u91cd\u5199\uff0c\u53ef\u4ee5\u5141\u8bb8\u7528\u6237\u91cd\u5199\u6807\u7b7e\u6216\u8005\u9488\u5bf9\u6807\u7b7e\u505a\u4e00\u4e9b\u8fc7\u6ee4\u64cd\u4f5c\uff0cPrometheus\u4e2d\u7684relabel\u6709\u4e09\u79cd\uff0c\u5e94\u7528\u8303\u56f4\u548c\u5de5\u4f5c\u65f6\u6bb5\u4e0d\u4e00\u6837\uff0c\u4e00\u5b9a\u8981\u533a\u5206<\/p>\n

\n

relabel_config<\/strong>
\n Relabeling is a powerful tool to dynamically rewrite the label set of a target before it gets scraped.
\n \u5728\u88abprometheus\u6293\u53d6\u4e4b\u524d\u4fee\u6539\uff0c\u9488\u5bf9\u7684\u662ftarget<\/p>\n

metric_relabel_configs<\/strong>
\n Metric relabeling is applied to samples as the last step before ingestion.
\n \u5728\u88abprometheus\u5b58\u50a8\u4e4b\u524d\u4fee\u6539\uff0c\u9488\u5bf9\u7684\u662fMetric<\/p>\n

alert_relabel_configs<\/strong>
\n Alert relabeling is applied to alerts before they are sent to the Alertmanager.
\n \u5728\u88ab\u53d1\u9001\u5230alertmanager\u4e4b\u524d\uff0c\u9488\u5bf9\u7684\u662falert<\/p>\n<\/blockquote>\n

\u63a5\u4e0b\u6765\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u524d\u4e24\u79cd\uff0c\u7b2c\u4e09\u79cd\u6211\u8fd8\u6ca1\u6709\u7528\u5230\u3002<\/p>\n

1. relabel_config<\/h2>\n

\u7b2c\u4e00\u79cd\u7684relabel\u53ea\u9488\u5bf9targets\u9875\u9762\u51fa\u73b0\u7684label\uff0c\u5982\u4e0b\u56fe
\n
\nrelabel_config\u7684action\u7c7b\u578b<\/p>\n

\n

replace: \u5bf9\u6807\u7b7e\u548c\u6807\u7b7e\u503c\u8fdb\u884c\u66ff\u6362\u3002\u9ed8\u8ba4action\u3002
\n keep: \u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5b9e\u4f8b\u8fdb\u884c\u91c7\u96c6\uff0c\u5176\u4ed6\u7684\u4e0d\u91c7\u96c6\u3002
\n drop\uff1a \u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5b9e\u4f8b\u4e0d\u91c7\u96c6\uff0c\u5176\u4ed6\u7684\u91c7\u96c6\u3002
\n hashmod\uff1a \u8fd9\u4e2a\u6211\u4e5f\u6ca1\u770b\u61c2\u5565\u610f\u601d\uff0c\u56e7\u3002
\n labelmap\uff1a \u8fd9\u4e2a\u6211\u4e5f\u6ca1\u770b\u61c2\u5565\u610f\u601d\uff0c\u56e7\u3002
\n labeldrop\uff1a \u5bf9\u6293\u53d6\u7684\u5b9e\u4f8b\u7279\u5b9a\u6807\u7b7e\u8fdb\u884c\u5220\u9664\u3002
\n labelkeep\uff1a \u5bf9\u6293\u53d6\u7684\u5b9e\u4f8b\u7279\u5b9a\u6807\u7b7e\u8fdb\u884c\u4fdd\u7559\uff0c\u5176\u4ed6\u6807\u7b7e\u5220\u9664\u3002<\/p>\n<\/blockquote>\n

\u6700\u5e38\u7528\u7684\u662f\u5f53\u5c5eBlackbox exporter.\u7684\u66ff\u6362\u4e86<\/p>\n

\n
 scrape_configs:\n  - job_name: 'blackbox'\n    metrics_path: \/probe\n    params:\n      module: [http_2xx]  # Look for a HTTP 200 response.\n    static_configs:\n      - targets:\n        - http:\/\/prometheus.io    # Target to probe with http.\n        - https:\/\/prometheus.io   # Target to probe with https.\n        - http:\/\/example.com:8080 # Target to probe with http on port 8080.\n    relabel_configs:\n      - source_labels: [__address__]\n        target_label: __param_target\n      - source_labels: [__param_target]\n        target_label: instance\n      - target_label: __address__\n        replacement: 127.0.0.1:9115  # The blackbox exporter's real hostname:port.<\/code><\/pre>\n<\/div>\n

\u8fd8\u6709drop\u67d0\u4e9blabel\u7684target<\/p>\n

\n
    relabel_configs:\n      - action: drop\n        source_labels: ['buniess']\n        regex: \"MT\"<\/code><\/pre>\n<\/div>\n

2. metric_relabel_configs<\/h2>\n

\u8fd9\u4e2a\u9488\u5bf9\u7684\u662fmetric\u4e2d\u7684label\uff0c\u5982\u4e0b\u56fe
\n
\n\u6bd4\u5982\u6211\u8981\u8fc7\u6ee4\u6389{code=\"404\"}\u7684metric<\/p>\n

\n
    metric_relabel_configs:\n      - action: drop\n        source_labels: ['code']\n        regex: \"404\"\n<\/code><\/pre>\n<\/div>\n

\u53c2\u8003\u8d44\u6599<\/h2>\n

https:\/\/prometheus.io\/docs\/prometheus\/latest\/configuration\/configuration\/<\/a><\/p>\n

\u6765\u81ea\u4e3a\u77e5\u7b14\u8bb0(Wiz)<\/a><\/div>\n

\u8f6c\u8f7d\u8bf7\u6ce8\u660e\uff1aIPCPU-\u7f51\u7edc\u4e4b\u8def<\/a> » prometheus\u4e2d\u7684relabel<\/a><\/p>","protected":false},"excerpt":{"rendered":"

prometheus\u4e2d\u7684relabel.md relabel\u987e\u540d\u601d\u4e49\uff0c\u5c31\u662f\u6807\u7b7e\u91cd\u5199\uff0c\u53ef\u4ee5\u5141\u8bb8\u7528\u6237\u91cd\u5199\u6807\u7b7e\u6216\u8005\u9488\u5bf9\u6807\u7b7e\u505a\u4e00\u4e9b\u8fc7\u6ee4\u64cd\u4f5c\uff0cPrometheus\u4e2d\u7684relabel\u6709\u4e09\u79cd\uff0c\u5e94\u7528\u8303\u56f4\u548c\u5de5\u4f5c\u65f6\u6bb5\u4e0d\u4e00\u6837\uff0c\u4e00\u5b9a\u8981\u533a\u5206 relabel_config Relabeling is a powerful tool to dynamically rewrite the label set of a target before it gets scraped. \u5728\u88abprometheus\u6293\u53d6\u4e4b\u524d\u4fee\u6539\uff0c\u9488\u5bf9\u7684\u662ftarget metric_relabel_configs Metric relabeling is applied to samples as the last step before ingestion. \u5728\u88abprometheus\u5b58\u50a8\u4e4b\u524d\u4fee\u6539\uff0c\u9488\u5bf9\u7684\u662fMetric alert_relabel_configs Alert relabeling is applied to alerts before they are sent to the Alertmanager. \u5728\u88ab\u53d1\u9001\u5230alertmanager\u4e4b\u524d\uff0c\u9488\u5bf9\u7684\u662falert \u63a5\u4e0b\u6765\u6211\u4eec\u8be6\u7ec6\u4ecb\u7ecd\u524d\u4e24\u79cd\uff0c\u7b2c\u4e09\u79cd\u6211\u8fd8\u6ca1\u6709\u7528\u5230\u3002 1. relabel_config \u7b2c\u4e00\u79cd\u7684relabel\u53ea\u9488\u5bf9targets\u9875\u9762\u51fa\u73b0\u7684label\uff0c\u5982\u4e0b\u56fe […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[13],"tags":[190],"_links":{"self":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1325"}],"collection":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/comments?post=1325"}],"version-history":[{"count":1,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1325\/revisions"}],"predecessor-version":[{"id":1326,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/posts\/1325\/revisions\/1326"}],"wp:attachment":[{"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/media?parent=1325"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/categories?post=1325"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c.ipcpu.com\/wp-json\/wp\/v2\/tags?post=1325"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}