{"id":1690,"date":"2024-11-09T20:10:32","date_gmt":"2024-11-09T12:10:32","guid":{"rendered":"http:\/\/blue.yn.cn\/?p=1690"},"modified":"2024-11-10T18:58:55","modified_gmt":"2024-11-10T10:58:55","slug":"%e7%9b%91%e6%8e%a7%e6%a1%88%e4%be%8b","status":"publish","type":"post","link":"http:\/\/blue.yn.cn\/?p=1690","title":{"rendered":"\u76d1\u63a7\u6848\u4f8b"},"content":{"rendered":"<h3>\u76d1\u63a7\u6848\u4f8b\u4ecb\u7ecd<\/h3>\n<h4>\u76d1\u63a7\u573a\u666f\u63cf\u8ff0<\/h4>\n<p>\u524d\u9762\u5df2\u7ecf\u5b66\u4e9b\u4e86\u5982\u4f55\u4f7f\u7528<code>prometheus<\/code>\u7ed3\u5408<code>node_exporter<\/code>\u6765\u76d1\u63a7\u7cfb\u7edf\u8d44\u6e90\u7684<code>cpu<\/code>\u3001\u5185\u5b58\u3001\u78c1\u76d8\u3001\u7f51\u7edc\u7b49\uff0c\u540c\u65f6\u6211\u4eec\u8fd8\u901a\u8fc7\u76d1\u63a7\u7684\u65b9\u6cd5\u8bba\u627e\u51fa\u4e86\u4e0d\u540c\u8d44\u6e90\u7684\u91cd\u8981\u7684\u6307\u6807\uff0c\u5e76\u7f16\u5199<code>PromQL<\/code>\u67e5\u8be2\u8868\u8fbe\u5f0f\u548c\u544a\u8b66\u89c4\u5219\u3002<\/p>\n<p>\u4f46\u662f\uff0c\u7cfb\u7edf\u8d44\u6e90\u7684\u76d1\u63a7\u53ea\u662f\u76d1\u63a7\u7684\u4e00\u90e8\u5206\u3002\u56e0\u6b64\u6211\u4eec\u8fd8\u9700\u8981\u5173\u6ce8\u8fd0\u884c\u5728\u8fd9\u4e9b\u8282\u70b9\u4e0a\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<br \/>\n\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8\u5982\u4f55\u901a\u8fc7<strong>\u5e94\u7528\u7a0b\u5e8f\u66b4\u9732\u7684\u6307\u6807\u6765\u76f4\u63a5\u76d1\u63a7\u5b83\u4eec\uff0c\u6216\u8005\u901a\u8fc7<code>exporter<\/code>\u6765\u95f4\u63a5\u6536\u96c6\u4e0d\u540c\u5e94\u7528\u7684\u6307\u6807\u6570\u636e<\/strong>\u3002<\/p>\n<p>\u540c\u65f6\u6211\u4eec\u8fd8\u4f1a\u9010\u4e00\u4ecb\u7ecd\u6bcf\u4e2a\u5e94\u7528\u7684\u5173\u952e\u6027\u80fd\u6307\u6807\uff0c\u5e76\u8bb2\u89e3\u5982\u4f55\u5229\u7528<code>PromQL<\/code>\u5bf9\u8fd9\u4e9b\u6307\u6807\u8fdb\u884c\u67e5\u8be2\u3002\u6b64\u5916\uff0c\u6211\u4eec\u5236\u4f5c\u5bf9\u5e94\u7684<code>PromQL<\/code>\u4f5c\u4e3a\u544a\u8b66\u89c4\u5219\uff0c\u4ee5\u4fbf\u5728\u7cfb\u7edf\u51fa\u73b0\u5f02\u5e38\u65f6\uff0c\u80fd\u7b2c\u4e00\u65f6\u95f4\u8fdb\u884c\u901a\u77e5\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731154229276.png\" alt=\"file\" \/><\/p>\n<h3>blackbox_exporter\u9ed1\u76d2\u76d1\u63a7<\/h3>\n<h4>blackbox_exporter\u4ecb\u7ecd<\/h4>\n<p><code>blackbox_exporter<\/code>\u662f\u4e00\u4e2a\u4e13\u95e8\u7528\u4e8e\u9ed1\u76d2\u76d1\u63a7\u7684\u5de5\u5177\uff0c\u5b83\u652f\u6301\u591a\u79cd\u7f51\u7edc\u534f\u8bae\u5bf9\u76ee\u6807\u5bf9\u8c61\u8fdb\u884c\u68c0\u6d4b\uff0c\u6bd4\u5982<code>http<\/code>\u3001<code>https<\/code>\u3001<code>tcp<\/code>\u548c<code>icmp<\/code>\u3002<br \/>\n\u8fd9\u610f\u5473\u7740\u6211\u4eec\u53ef\u4ee5\u7528\u5b83\u6765\u76d1\u63a7\u7f51\u7ad9\u54cd\u5e94\u72b6\u6001\u548c\u54cd\u5e94\u65f6\u95f4\uff0c\u4ee5\u53ca\u901a\u8fc7\u7aef\u53e3\u6765\u5224\u65ad\u670d\u52a1\u662f\u5426\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>\u6b64\u5916\u7528\u6237\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4e0d\u540c\u7684\u68c0\u67e5\u6a21\u5757\u6765\u5b9a\u5236<code>blackbox_exporter<\/code>\uff0c\u4ee5\u4fbf\u5b83\u80fd\u591f\u9002\u5e94\u4e0d\u540c\u7684\u68c0\u6d4b\u9700\u6c42\u3002<\/p>\n<p>\u8981\u4f7f\u7528<code>blackbox_exporter<\/code>\u76d1\u63a7\u4e00\u4e2a\u670d\u52a1\uff0c\u4f60\u53ea\u9700\u8981\u544a\u8bc9\u5b83\u670d\u52a1\u7684\u5730\u5740\u548c\u60f3\u8981\u68c0\u67e5\u7684\u7c7b\u578b\u3002<code>blackbox_exporter<\/code>\u5c06\u6267\u884c\u68c0\u67e5\uff0c\u7136\u540e\u5c06\u7ed3\u679c\u5b58\u50a8\u5728<code>\/probe<\/code>\u63a5\u53e3\u4e2d\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731154669669.png\" alt=\"file\" \/><\/p>\n<p>\u5982\u679c\u60f3\u8981\u4f7f<code>Prometheus<\/code>\u901a\u8fc7<code>blackbox_exporter<\/code>\u76d1\u63a7\u670d\u52a1\uff0c\u5219\u9700\u8981\u7531<code>Prometheus<\/code>\u544a\u8bc9<code>blackbox_exporter<\/code>\u9700\u8981\u76d1\u63a7\u7684\u76ee\u6807\uff08\u5373<code>target<\/code>\uff09\uff0c\u4ee5\u53ca\u76d1\u63a7\u68c0\u6d4b\u7684\u65b9\u6cd5\uff08\u5373<code>module<\/code>\uff09\uff0c\u5b8c\u6210\u8bbe\u5b9a\u540e\uff0c<code>prometheus<\/code>\u5c31\u53ef\u4ee5\u5b9a\u671f\u4ece<code>blackbox_exporter<\/code>\u63d0\u4f9b\u7684<code>\/probe<\/code>\u7aef\u70b9\u6293\u53d6\u6307\u6807\u6570\u636e\uff0c\u4ece\u800c\u5bf9\u76ee\u6807\u670d\u52a1\u7684\u5065\u5eb7\u72b6\u6001\u8fdb\u884c\u5206\u6790\u548c\u8bc4\u4f30\u3002<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731154879352.png\" alt=\"file\" \/><\/p>\n<h4>\u5b89\u88c5blackbox_exporter<\/h4>\n<ol>\n<li>\u8bbf\u95ee<code>blackbox_exporter<\/code>\u7684<code>github<\/code>\u5730\u5740\uff0c<code>https:\/\/github.com\/prometheus\/blackbox_exporter\/releases\/download\/v0.25.0\/blackbox_exporter-0.25.0.linux-amd64.tar.gz<\/code>\uff0c\u4e0b\u8f7d<code>blackbox_exporter<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-bash\"># \u52a0\u901f\u5730\u5740\nwget https:\/\/mirror.ghproxy.com\/https:\/\/github.com\/prometheus\/blackbox_exporter\/releases\/download\/v0.25.0\/blackbox_exporter-0.25.0.linux-amd64.tar.gz<\/code><\/pre>\n<ol start=\"2\">\n<li>\u89e3\u538b<code>blackbox_exporter<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-bash\">tar xf blackbox_exporter-0.25.0.linux-amd64.tar.gz -C \/etc\nln -s \/etc\/blackbox_exporter-0.25.0.linux-amd64\/ \/etc\/blackbox_exporter<\/code><\/pre>\n<ol start=\"3\">\n<li>\u7f16\u8f91<code>\/etc\/blackbox_exporter\/blackbox.yml<\/code>\u9ed8\u8ba4\u7f16\u8f91\u6587\u4ef6\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5bf9\u5e94\u7684\u6a21\u5757\uff0c<br \/>\n<a href=\"https:\/\/github.com\/prometheus\/blackbox_exporter\/blob\/master\/example.yml\">https:\/\/github.com\/prometheus\/blackbox_exporter\/blob\/master\/example.yml<\/a><\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/etc\/blackbox_exporter\/blackbox.yml\nmodules:\n  http_2xx:\n    prober: http\n    http:\n      preferred_ip_protocol: &quot;ip4&quot;\n      valid_http_versions: [ &quot;HTTP\/1.1&quot;, &quot;HTTP\/2.0&quot; ]\n\n  http_post_2xx:\n    prober: http\n    http:\n      method: POST\n      preferred_ip_protocol: &quot;ip4&quot;\n      valid_http_versions: [ &quot;HTTP\/1.1&quot;, &quot;HTTP\/2.0&quot; ]\n\n  tcp_connect:\n    prober: tcp\n    timeout: 5s\n\n  icmp:\n    prober: icmp\n    timeout: 5s\n    icmp:\n      preferred_ip_protocol: &quot;ip4&quot;\n\n  dns_tcp:\n    prober: dns\n    dns:\n      transport_protocol: &quot;tcp&quot;\n      preferred_ip_protocol: &quot;ip4&quot;\n      query_name: &quot;www.blue.yn.cn&quot;\n\n  ssh_banner:\n    prober: tcp\n    tcp:\n      query_response:\n      - expect: &quot;^SSH-2.0-&quot;\n      - send: &quot;SSH-2.0-blackbox-ssh-check&quot;<\/code><\/pre>\n<ol start=\"4\">\n<li>\u914d\u7f6e<code>blackbox_exporter<\/code>\u542f\u52a8\u6587\u4ef6<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/usr\/lib\/systemd\/system\/blackbox_exporter.service\n[Unit]\nDescription=blackbox_exporter\nDocumentation=https:\/\/prometheus.io\/\nAfter=network.target\n\n[Service]\nExecStart=\/etc\/blackbox_exporter\/blackbox_exporter \\\n        --config.file=\/etc\/blackbox_exporter\/blackbox.yml \\\n        --web.listen-address=:9115\nExecReload=\/bin\/kill -HUP $MAINPID\nTimeoutStopSec=20s\nRestart=always\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<ol start=\"5\">\n<li>\u542f\u52a8<code>blackbox_exporter<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-bash\">systemctl daemon-reload\nsystemctl enable blackbox_exporter.service\nsystemctl start blackbox_exporter.service\n\nnetstat -lntp\nActive Internet connections (only servers)\nProto Recv-Q Send-Q Local Address           Foreign Address         State       PID\/Program name\ntcp6       0      0 :::9115                 :::*                    LISTEN      26220\/blackbox_expo<\/code><\/pre>\n<h4>\u8bbf\u95eeblack_exporter<\/h4>\n<ol>\n<li>\u8bbf\u95ee<code>blackbox_exporter<\/code>\uff0c\u901a\u8fc7<code>http:\/\/ip:9115<\/code><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731203607138.png\" alt=\"file\" \/><\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528<code>blackbox_exporter<\/code>\u76d1\u63a7\u7ad9\u70b9\uff0c\u9700\u8981\u4f20\u9012\u76ee\u6807<code>target<\/code>\uff0c\u4ee5\u53ca\u68c0\u6d4b\u65b9\u6cd5<code>module<\/code><br \/>\n\u5177\u4f53\u7684<code>url<\/code>\u5730\u5740\uff1a<code>http:\/\/prometheus.dot.com:9115\/probe?target=prometheus.io&amp;module=http_2xx&amp;debug=true<\/code><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731203768273.png\" alt=\"file\" \/><\/p>\n<ol start=\"3\">\n<li>\u9488\u5bf9<code>blackbox_exporter<\/code>\u7684\u63a2\u6d4b\u8fc7\u7a0b\u8fdb\u884c\u89e3\u8bfb<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">Logs for the probe:\nts=2023-12-14T09:36:24.705068763Z caller=main.go:181 module=http_2xx target=https:\/\/www.xuliangwei.com level=info msg=&quot;Beginning probe&quot; probe=http timeout_seconds=119.5\nts=2023-12-14T09:36:24.705236167Z caller=http.go:328 module=http_2xx target=https:\/\/www.xuliangwei.com level=info msg=&quot;Resolving target address&quot; target=www.xuliangwei.com ip_protocol=ip4\nts=2023-12-14T09:36:24.730574694Z caller=http.go:328 module=http_2xx target=https:\/\/www.xuliangwei.com level=info msg=&quot;Resolved target address&quot; target=www.xuliangwei.com ip=61.241.151.57\nts=2023-12-14T09:36:24.730712818Z caller=client.go:252 module=http_2xx target=https:\/\/www.xuliangwei.com level=info msg=&quot;Making HTTP request&quot; url=https:\/\/61.241.151.57 host=www.xuliangwei.com\nts=2023-12-14T09:36:24.882298995Z caller=handler.go:120 module=http_2xx target=https:\/\/www.xuliangwei.com level=info msg=&quot;Received HTTP response&quot; status_code=200\nts=2023-12-14T09:36:25.060161001Z caller=handler.go:120 module=http_2xx target=https:\/\/www.xuliangwei.com level=info msg=&quot;Response timings for roundtrip&quot; roundtrip=0 start=2023-12-14T17:36:24.730819996+08:00 dnsDone=2023-12-14T17:36:24.730819996+08:00 connectDone=2023-12-14T17:36:24.749386743+08:00 gotConn=2023-12-14T17:36:24.776091161+08:00 responseStart=2023-12-14T17:36:24.882150293+08:00 tlsStart=2023-12-14T17:36:24.749480744+08:00 tlsDone=2023-12-14T17:36:24.77581621+08:00 end=2023-12-14T17:36:25.060139851+08:00\nts=2023-12-14T09:36:25.060440526Z caller=main.go:181 module=http_2xx target=https:\/\/www.xuliangwei.com level=info msg=&quot;Probe succeeded&quot; duration_seconds=0.355298304\n\n# 1\u3001\u5f00\u59cb\u63a2\u6d4b\uff08msg=&quot;Beginning probe&quot;\uff09 \u4f7f\u2f64\u7684\u662f http_2xx \u6a21\u5757\uff0c\u8d85\u65f6\u8bbe\u7f6e\u4e3a119.5\u79d2\u3002\n# 2\u3001\u89e3\u6790\u2f6c\u6807\u5730\u5740\uff08msg=&quot;Resolving target address&quot;\uff09 \u6b63\u5728\u5c1d\u8bd5\u89e3\u6790\u2f6c\u6807 www.xuliangwei.com \u7684IP\u5730\u5740\uff0c\u4f7f\u2f64\u7684\u662fIPv4\u534f\u8bae\u3002\n# 3\u3001\u5df2\u89e3\u6790\u2f6c\u6807\u5730\u5740\uff08msg=&quot;Resolved target address&quot;\uff09 \u6210\u529f\u89e3\u6790\u4e3a61.241.151.57\u3002\n# 4\u3001\u53d1\u51fa HTTP \u8bf7\u6c42\uff08msg=&quot;Making HTTP request&quot;\uff09 \u5411 http:\/\/61.241.151.57 \u53d1\u51faHTTP\u8bf7\u6c42\uff0c\u8bf7\u6c42\u4e2d\u7684 host \u5934\u8bbe\u7f6e\u4e3a www.xuliangwei.com\u3002\n# 5\u3001\u6536\u5230 HTTP \u54cd\u5e94\uff08msg=&quot;Received HTTP response&quot;\uff09 \u5df2\u6536\u5230\u72b6\u6001\u7801\u4e3a200\u7684HTTP\u54cd\u5e94\uff0c\u8fd9\u610f\u5473\u7740\u7f51\u9875\u6b63\u5e38\uff0c\u670d\u52a1\u5668\u6210\u529f\u5904\u7406\u4e86\u8bf7\u6c42\u3002\n# 6\u3001\u54cd\u5e94\u65f6\u95f4\uff08msg=&quot;Response timings for roundtrip&quot;\uff09 \u63d0\u4f9b\u4e86\u5bf9\u4e8e\u6574\u4e2a\u8bf7\u6c42-\u54cd\u5e94\u5468\u671f\u4e2d\u6bcf\u4e2a\u6b65\u9aa4\u7684\u5177\u4f53\u65f6\u95f4\u70b9\uff0c\u5305\u62ecDNS\u89e3\u6790\u5b8c\u6210\u3001TLS\u63e1\u2f3f\u5f00\u59cb\u548c\u5b8c\u6210\u3001\u8fde\u63a5\u5efa\u2f74\u3001\u83b7\u5f97\u8fde\u63a5\u3001\u54cd\u5e94\u5f00\u59cb\u7b49\u65f6\u95f4\u70b9\u3002\n# 7\u3001\u63a2\u6d4b\u6210\u529f\uff08msg=&quot;Probe succeeded&quot;\uff09 \u63a2\u6d4b\u64cd\u4f5c\u6210\u529f\u5b8c\u6210\uff0c\u603b\u8017\u65f6\u4e3a0.355298304\u79d2\u3002<\/code><\/pre>\n<h4>\u914d\u7f6eprometheus<\/h4>\n<ol>\n<li>\u4fee\u6539<code>prometheus<\/code>\u914d\u7f6e\uff0c\u7531\u4e8e<code>blackbox_exporter<\/code>\u9700\u8981\u4f20\u5165<code>taget<\/code>\u548c<code>module<\/code>\u53c2\u6570\uff0c\u56e0\u6b64\u91c7\u7528\u5982\u4e0b\u65b9\u5f0f\uff1a<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">vim \/etc\/prometheus\/prometheus.yml\nscrape_configs:\n  - job_name: &#039;blackbox_http&#039;\n    metrics_path: \/probe # metrics\u7684path\u8fd9\u6b21\u4e0d\u662f\/metrics\uff0c\u2f7d\u662f\/probe\n    params: # \u4f20\u9012\u53c2\u6570\n      module: [http_2xx] # \u8c03\u2f64\u54ea\u4e2a\u6a21\u5757\u8fdb\u2f8f\u63a2\u6d4b\n      target: [&quot;https:\/\/www.xuliangwei.com&quot;,&quot;http:\/www.oldxu.net&quot;,&quot;https:\/\/www.baidu.com&quot;] # \u63a2\u6d4b\u7684\u7ad9\u70b9\u662f\u54ea\u4e9b\n    static_configs:\n      - targets: [&quot;prom-node04.oldxu.net:9115&quot;]<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u91cd\u65b0\u52a0\u8f7d<code>prometheus<\/code>\u914d\u7f6e\u6587\u4ef6<br \/>\n<code>curl -X POST http:\/\/localhost:9090\/-\/reload<\/code><\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5<code>prometheus<\/code>\u7684<code>status--&gt;target<\/code>\u9875\u9762\uff0c\u9a8c\u8bc1<code>blackbox_exporter<\/code>\u662f\u5426\u5df2\u7ecf\u6210\u529f\u7eb3\u5165\u76d1\u63a7<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731204307589.png\" alt=\"file\" \/><\/p>\n<ol start=\"4\">\n<li>\u9a8c\u8bc1\u6293\u53d6\u7684<code>metrics<\/code>\u662f\u5426\u6b63\u786e<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731204340837.png\" alt=\"file\" \/><\/p>\n<h4>\u91cd\u65b0\u914d\u7f6eprometheus<\/h4>\n<ol>\n<li>\u4fee\u6539<code>prometheus<\/code>\u914d\u7f6e\uff0c\u4f7f\u7528<code>relabel_configs<\/code>\u505a\u6807\u7b7e\u66ff\u6362<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/etc\/prometheus\/prometheus.yml\nscrape_configs:\n  - job_name: &quot;blackbox_http&quot;\n    metrics_path: &quot;\/probe&quot;\n    static_configs:\n    - targets: [&quot;blue.yn.cn&quot;]\n    params:\n      module: [http_2xx]\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: 192.168.99.51:9115\n\n# relabel_configs\u662f\u6807\u7b7e\u91cd\u5199\u7684\u914d\u7f6e\uff0c\u8fd9\u2fa5\u8fdb\u2f8f\u4e86\u4e09\u6b21\u64cd\u4f5c\uff1a\n# 1\u3001\u5c06\u76ee\u6807\u5730\u5740\uff08__address__\uff09\u8d4b\u4e88\u7ed9__param_target\uff0c\u8fd9\u662fBlackbox Exporter\u9700\u8981\u7684\u2f6c\u6807target\u53c2\u6570\u3002\n# 2\u3001\u5c06__param_target\u7684\u5185\u5bb9\u590d\u5236\u5230instance\u6807\u7b7e\uff0c\u8fd9\u6837Prometheus UI\u4e2d\u663e\u793a\u7684instance\u5b9e\u4f8b\u540d\u79f0\u4f1a\u662f\u76ee\u6807\u7ad9\u70b9\u5730\u5740\uff0c\u2f7d\u4e0d\u662fBlackbox\u7684\u5730\u5740\u3002\n# 3\u3001\u6700\u540e\uff0c\u5c06\u5b9e\u9645\u53d1\u9001\u63a2\u6d4b\u8bf7\u6c42\u7684\u5730\u5740\uff08__address__\uff09\u8bbe\u7f6e\u4e3a\u8fd0\u2f8fBlackbox Exporter\u7684\u8282\u70b9\u5730\u5740\u548c\u7aef\u53e3\uff08192.168.99.51:9115\uff09\uff0c\u8fd9\u6837Prometheus\u5c31\u4f1a\u5411\u8fd9\u4e2a\u5730\u5740\u53d1\u9001\u63a2\u6d4b\u8bf7\u6c42\u3002<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u91cd\u65b0\u52a0\u8f7d<code>prometheus<\/code>\u914d\u7f6e\u6587\u4ef6<br \/>\n<code>curl -X POST http:\/\/localhost:9090\/-\/reload<\/code><\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5<code>prometheus<\/code>\u7684<code>status--&gt;target<\/code>\u9875\u9762\uff0c\u9a8c\u8bc1<code>blackbox_http<\/code>\u662f\u5426\u5df2\u7ecf\u6210\u529f\u7eb3\u5165\u76d1\u63a7<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731204680647.png\" alt=\"file\" \/><\/p>\n<ol start=\"4\">\n<li>\u518d\u6b21\u68c0\u67e5<code>metrics<\/code>\u6307\u6807<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731204704304.png\" alt=\"file\" \/><\/p>\n<h4>\u914d\u7f6etcp\u3001ssh\u3001icmp\u76d1\u63a7<\/h4>\n<ol>\n<li>\u4fee\u6539<code>prometheus<\/code>\u914d\u7f6e<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/etc\/prometheus\/prometheus.yml\nscrape_configs:\n  - job_name: &quot;blackbox_tcp&quot;\n    metrics_path: &quot;\/probe&quot;\n    static_configs:\n    - targets: [&quot;blue.yn.cn:873&quot;,&quot;blue.yn.cn:10050&quot;,&quot;blue.yn.cn:3306&quot;]\n    params:\n      module: [tcp_connect]\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: 192.168.99.51:9115\n\n  - job_name: &quot;blackbox_icmp&quot;\n    metrics_path: &quot;\/probe&quot;\n    static_configs:\n    - targets: [&quot;blue.yn.cn&quot;]\n    params:\n      module: [icmp]\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: 192.168.99.51:9115\n\n  - job_name: &quot;blackbox_ssh&quot;\n    metrics_path: &quot;\/probe&quot;\n    static_configs:\n    - targets: [&quot;blue.yn.cn:22&quot;]\n    params:\n      module: [ssh_banner]\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: 192.168.99.51:9115<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u91cd\u65b0\u52a0\u8f7d<code>prometheus<\/code>\u914d\u7f6e\u6587\u4ef6<br \/>\n<code>curl -X POST http:\/\/localhost:9090\/-\/reload<\/code><\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5<code>prometheus<\/code>\u7684<code>status--&gt;target<\/code>\u9875\u9762\uff0c\u9a8c\u8bc1<code>blackbox_tcp\u3001blackbox_ssh\u3001blackbox_icmp<\/code>\u662f\u5426\u5df2\u7ecf\u6210\u529f\u7eb3\u5165\u76d1\u63a7<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731206366278.png\" alt=\"file\" \/><\/p>\n<h4>blackbox\u5e38\u7528\u6307\u6807\u4e0e\u793a\u4f8b<\/h4>\n<ol>\n<li><code>blackbox<\/code>\u63a2\u6d4b\u76f8\u5173\u6307\u6807<\/li>\n<\/ol>\n<table>\n<thead>\n<tr>\n<th>\u6307\u6807\u540d\u79f0<\/th>\n<th>\u6307\u6807\u7c7b\u578b<\/th>\n<th>\u6307\u6807\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>probe_success<\/td>\n<td>gauge<\/td>\n<td>\u63a2\u6d4b\u76ee\u6807\u662f\u5426\u6210\u529f\uff081\u8868\u793a\u63a2\u6d4b\u6d4b\u529f\uff0c0\u8868\u793a\u63a2\u6d4b\u5931\u8d25\uff09<\/td>\n<\/tr>\n<tr>\n<td>probe_dns_lookup_time_seconds<\/td>\n<td>gauge<\/td>\n<td>dns\u67e5\u8be2\u6240\u6d88\u8017\u7684\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\uff08\u63a2\u6d4b\u76ee\u6807\u4e3a\u57df\u540d\u65f6\u624d\u6709\u610f\u4e49\uff09<\/td>\n<\/tr>\n<tr>\n<td>probe_duration_seconds<\/td>\n<td>gauge<\/td>\n<td>\u63a2\u6d4b\u76ee\u6807\u603b\u8017\u65f6\uff0c\u5355\u4f4d\u79d2\uff08\u5305\u62ec\u4e86dns\u89e3\u6790\u65f6\u95f4\u3001tcp\u8fde\u63a5\u5efa\u7acb\u65f6\u95f4\u3001\u53d1\u9001\u8bf7\u6c42\u4ee5\u53ca\u63a5\u6536\u54cd\u5e94\u7684\u5168\u90e8\u65f6\u95f4\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6848\u4f8b1\uff1a\u67e5\u8be2<code>blackbox<\/code>\u63a2\u6d4b\u5931\u8d25\u7684\u76ee\u6807\uff0c\u4ee5\u53ca\u4f7f\u7528\u7684\u63a2\u6d4b\u65b9\u5f0f\u3002<br \/>\n<code>probe_success<\/code><\/p>\n<p>\u6848\u4f8b2\uff1a\u67e5\u8be2<code>dns<\/code>\u89e3\u6790\u54cd\u5e94\u65f6\u95f4\u8d85\u8fc7500\u6beb\u79d2\u7684\u76ee\u6807<br \/>\n<code>probe_dns_lookup_time_seconds &gt; 0.500<\/code><\/p>\n<p>\u6848\u4f8b3\uff1a\u67e5\u8be2\u6700\u8fd11\u5206\u949f\uff0c\u5e73\u5747\u63a2\u6d4b\u76ee\u6807\u603b\u8017\u65f6\u8d85\u8fc70.1\u79d2\u7684\u76ee\u6807<br \/>\n<code>avg_over_time(probe_duration_seconds[1m]) &gt; 0.1<\/code><\/p>\n<ol start=\"2\">\n<li><code>blackbox<\/code>\u63a2\u6d4b<code>http<\/code>\u76f8\u5173\u6307\u6807<\/li>\n<\/ol>\n<table>\n<thead>\n<tr>\n<th>\u6307\u6807\u540d\u79f0<\/th>\n<th>\u6307\u6807\u7c7b\u578b<\/th>\n<th>\u6307\u6807\u542b\u4e49<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>probe_http_version<\/td>\n<td>gauge<\/td>\n<td>\u63a2\u6d4b\u76ee\u6807\u4f7f\u7528\u7684http\u534f\u8bae\u7248\u672c<\/td>\n<\/tr>\n<tr>\n<td>probe_http_ssl<\/td>\n<td>gauge<\/td>\n<td>\u63a2\u6d4b\u7684\u8bf7\u6c42\u662f\u5426\u901a\u8fc7https\u534f\u8bae\u8fdb\u884c\u30021\u8868\u793a\u4f7f\u7528https\uff0c0\u8868\u793a\u4e0d\u4f7f\u7528<\/td>\n<\/tr>\n<tr>\n<td>probe_http_redirects<\/td>\n<td>gauge<\/td>\n<td>\u7edf\u8ba1\u5728\u5b8c\u6210http\u8bf7\u6c42\u8fc7\u7a0b\u4e2d\u53d1\u751f\u7684\u91cd\u5b9a\u5411\u6b21\u6570<\/td>\n<\/tr>\n<tr>\n<td>probe_http_status_code<\/td>\n<td>gauge<\/td>\n<td>http\u54cd\u5e94\u7684http\u72b6\u6001\u7801<\/td>\n<\/tr>\n<tr>\n<td>probe_http_duration_seconds<\/td>\n<td>gauge<\/td>\n<td>http\u8bb0\u5f55http\u8bf7\u6c42\u7684\u5404\u4e2a\u9636\u6bb5\u7684\u6301\u7eed\u65f6\u95f4\u3002\u5305\u62ec\u8fde\u63a5\u5efa\u7acb\uff08connect\uff09\u3001\u57df\u540d\u89e3\u6790\uff08resolve\uff09\u3001tls\u63e1\u624b\uff08tls\uff09\u3001\u670d\u52a1\u5668\u5904\u7406\uff08processing\uff09\u4ee5\u53ca\u6570\u636e\u4f20\u8f93\uff08transfer\uff09\u9636\u6bb5<\/td>\n<\/tr>\n<tr>\n<td>probe_ssl_earliest_cert_expiry<\/td>\n<td>gauge<\/td>\n<td>ssl\u8bc1\u4e66\u8fc7\u671f\u7684\u65f6\u95f4\u6233\u3002\uff08\u672a\u6765\u65f6\u95f4\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6848\u4f8b1\uff1a\u67e5\u8be2\u76ee\u6807\u7ad9\u70b9\u91cd\u5b9a\u5411\u8d85\u8fc75\u6b21\u4ee5\u4e0a<br \/>\n<code>probe_http_redirects &gt; 5<\/code><\/p>\n<p>\u6848\u4f8b2\uff1a\u67e5\u8be2\u76ee\u6807\u7ad9\u70b9\u4e0d\u540c\u9636\u6bb5\u8017\u65f6\u8d85\u8fc7500\u6beb\u79d2<\/p>\n<pre><code class=\"language-bash\">(\nprobe_http_duration_seconds{phase=&quot;resolve&quot;} &gt; 0.5 or\nprobe_http_duration_seconds{phase=&quot;connect&quot;} &gt; 0.5 or\nprobe_http_duration_seconds{phase=&quot;tls&quot;} &gt; 0.5 or\nprobe_http_duration_seconds{phase=&quot;processing&quot;} &gt; 0.5 or\nprobe_http_duration_seconds{phase=&quot;transfer&quot;} &gt; 0.5\n)<\/code><\/pre>\n<p>\u6848\u4f8b3\uff1a\u67e5\u8be2\u76ee\u6807\u7ad9\u70b9\u54cd\u5e94\u72b6\u6001\u7801\u5f02\u5e38\u7684\uff0c\u4f8b\u5982\uff1a\u5c0f\u4e8e\u7b49\u4e8e199\uff0c\u6216\u8005\u5927\u4e8e\u7b49\u4e8e400\u4ee5\u4e0a\u7684<br \/>\n<code>probe_http_status_code &lt;= 199 or probe_http_status_code &gt;= 400<\/code><\/p>\n<p>\u6848\u4f8b4\uff1a\u8ba1\u7b97\u7f51\u7ad9\u8bc1\u4e66\u8fc7\u671f\u65f6\u95f4\uff0c\u8ba1\u7b97\u516c\u5f0f\uff1a\uff08<code>ssl<\/code>\u8fc7\u671f\u65f6\u95f4-\u5f53\u524d\u65f6\u95f4\uff09\/86400<br \/>\n<code>(probe_ssl_earliset_cert_expiry - time()) \/ 86400<\/code><\/p>\n<h4>blackbox\u544a\u8b66\u89c4\u5219\u6587\u4ef6<\/h4>\n<ol>\n<li>\u7f16\u5199\u544a\u8b66\u89c4\u5219\u6587\u4ef6<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/etc\/prometheus\/rules\/blackbox_rules.yml\ngroups:\n  - name: Blackbox\u544a\u8b66\u89c4\u5219\u6587\u4ef6\n    rules:\n    - alert: \u63a2\u6d4b\u5931\u8d25\n      expr: sum(probe_success == 0) by (instance, job)\n      for: 5m\n      labels:\n        severity: critical\n      annotations:\n        summary: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u63a2\u6d4b\u5931\u8d25&quot;\n        description: &quot;\u63a2\u6d4b\u76ee\u6807 {{ $labels.instance }} \u5728 job {{ $labels.job}} \u4e2d\u5931\u8d25\u3002&quot;\n\n    - alert: \u7ad9\u70b9\u6574\u4f53\u5e73\u5747\u8bf7\u6c42\u65f6\u95f4\u8fc7\u957f\n      expr: sum(avg_over_time(probe_http_duration_seconds[1m])) by (instance,job) &gt; 3\n      for: 1m\n      labels:\n        severity: warning\n      annotations:\n        summary: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u8bf7\u6c42\u65f6\u95f4\u8fc7\u957f&quot;\n        description: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u6700\u8fd11\u5206\u949f\u7684\u5e73\u5747\u8bf7\u6c42\u65f6\u95f4\u8d85\u8fc73\u79d2\u3002\u5f53\u524d\u5e73\u5747\u8bf7\u6c42\u65f6\u95f4\uff1a{{ $value }}\u79d2\u3002&quot;\n\n    - alert: \u91cd\u5b9a\u5411\u6b21\u6570\u8fc7\u591a\n      expr: probe_http_redirects &gt; 5\n      for: 5m\n      labels:\n        severity: warning\n      annotations:\n        summary: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u91cd\u5b9a\u5411\u6b21\u6570\u8fc7\u591a&quot;\n        description: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u5728\u6700\u8fd1\u7684\u63a2\u6d4b\u4e2d\u91cd\u5b9a\u5411\u6b21\u6570\u8d85\u8fc75\u6b21\u3002\u5f53\u524d\u6b21\u6570\uff1a{{ $value }}\u6b21\u3002&quot;\n\n    - alert: \u7ad9\u70b9\u9636\u6bb5\u8017\u65f6\u8fc7\u957f\n      expr:\n        (\n          probe_http_duration_seconds{phase=&quot;connect&quot;} &gt; 0.5 or\n          probe_http_duration_seconds{phase=&quot;processing&quot;} &gt; 0.5 or\n          probe_http_duration_seconds{phase=&quot;resolve&quot;} &gt; 0.5 or\n          probe_http_duration_seconds{phase=&quot;tls&quot;} &gt; 0.5 or\n          probe_http_duration_seconds{phase=&quot;transfer&quot;} &gt; 0.5\n        )\n      for: 1m\n      labels:\n        severity: warning\n      annotations:\n        summary: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u9636\u6bb5 &#039;{{ $labels.phase }}&#039; \u8017\u65f6\u8fc7\u957f&quot;\n        description: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u5728\u9636\u6bb5 &#039;{{ $labels.phase}}&#039; \u7684\u8017\u65f6\u8d85\u8fc70.5\u79d2\u3002\u5f53\u524d\u8017\u65f6\uff1a{{ $value }}\u79d2\u3002                                                                 &quot;\n\n    - alert: \u7ad9\u70b9\u54cd\u5e94\u72b6\u6001\u7801\u5f02\u5e38\n      expr: probe_http_status_code &lt;= 199 or probe_http_status_code &gt;= 400\n      for: 5m\n      labels:\n        severity: critical\n      annotations:\n        summary: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u8fd4\u56de\u5f02\u5e38\u72b6\u6001\u7801&quot;\n        description: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u8fd4\u56de\u7684\u72b6\u6001\u7801\u4e3a {{ $value }}\uff0c\u8868\u660e\u8bf7\u6c42\u53ef\u80fd\u5b58\u5728\u95ee\u9898\u3002&quot;\n\n    - alert: \u8bc1\u4e66\u5373\u5c06\u8fc7\u671f&lt;7\n      expr: (probe_ssl_earliest_cert_expiry - time()) \/86400 &lt; 7\n      for: 24h\n      labels:\n        severity: critical\n      annotations:\n        summary: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u7684 SSL \u8bc1\u4e66\u5373\u5c06\u8fc7\u671f&quot;\n        description: &quot;\u5b9e\u4f8b {{ $labels.instance }} \u7684 SSL \u8bc1\u4e66\u5c06\u5728 {{ $value}} \u5929\u5185\u8fc7\u671f\u3002&quot;<\/code><\/pre>\n<ol start=\"2\">\n<li>\u68c0\u67e5\u544a\u8b66\u89c4\u5219\u4fe1\u606f<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731226738084.png\" alt=\"file\" \/><\/p>\n<h4>\u5bfc\u5165blackbox\u56fe\u5f62<\/h4>\n<ol>\n<li>\u4e13\u7528\u9488\u5bf9<code>http<\/code>\u7684\u56fe\u5f62\uff0c\u5bfc\u5165<code>id13569<\/code><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731226786200.png\" alt=\"file\" \/><\/p>\n<ol start=\"2\">\n<li>\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>id7587<\/code>\u7684\u56fe\u5f62<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731226836903.png\" alt=\"file\" \/><\/p>\n<ol start=\"3\">\n<li>\u4ee5\u53ca<code>id9965<\/code>\u7684\u56fe\u5f62<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731227207337.png\" alt=\"file\" \/><\/p>\n<h3>snmp_exporter\u7f51\u7edc\u8bbe\u5907\u76d1\u63a7<\/h3>\n<h4>snmp_exporter\u4ecb\u7ecd<\/h4>\n<p><code>snmp_exporter<\/code>\u7684\u4f5c\u7528\u662f\u5c06<code>snmp<\/code>\u83b7\u53d6\u5230\u7684\u6570\u636e\u8f6c\u6362\u4e3a<code>prometheus<\/code>\u53ef\u4ee5\u517c\u5bb9\u7684\u683c\u5f0f\u3002\u901a\u8fc7<code>snmp_exporter<\/code>\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u76d1\u63a7\u90a3\u4e9b\u652f\u6301<code>snmp<\/code>\u534f\u8bae\u7684\u8bbe\u5907\uff0c\u5982\u4ea4\u6362\u673a\u3001\u8def\u7531\u5668\u3001\u9632\u706b\u5899\u7b49<\/p>\n<p><code>prometheus<\/code>\u501f\u52a9<code>snmp_exporter<\/code>\u76d1\u63a7\u7f51\u7edc\u8bbe\u5907\u9700\u8981\u4f20\u9012\u5982\u4e0b\u51e0\u4e2a\u53c2\u6570\uff1a<\/p>\n<ul>\n<li>1.<code>target<\/code>\uff08\u76ee\u6807\u8bbe\u5907\u7684\u5730\u5740\uff09\uff1a\u9700\u8981\u76d1\u63a7\u7684\u8bbe\u5907\u5730\u5740<\/li>\n<li>2.<code>module<\/code>\uff08\u4f7f\u7528\u7684\u6a21\u5757\uff09\uff1a\u4e0d\u540c\u7684\u6a21\u5757\uff0c\u5b58\u50a8\u4e86\u4e0d\u540c\u8bbe\u5907\u7684\u6307\u6807\u3002\uff08\u5982\u679c\u6ca1\u6709\u63d0\u4f9b\u8bbe\u5907\u5bf9\u5e94\u7684\u6307\u6807\uff0c\u5219\u9700\u8981\u5b9a\u5236\uff09<\/li>\n<li>3.<code>auth<\/code>\uff08\u8ba4\u8bc1\u4fe1\u606f\uff09\uff1a\u63d0\u4f9b<code>snmp<\/code>\u8ba4\u8bc1\u4fe1\u606f\uff0c\u5982\u56e2\u4f53\u540d\u79f0\uff08<code>community<\/code>\uff09<\/li>\n<\/ul>\n<h4>\u5b89\u88c5snmp_exporter<\/h4>\n<ol>\n<li>\u8bbf\u95ee<code>snmp_exporter<\/code>\u7684<code>github<\/code>\u5730\u5740\uff0c<code>https:\/\/github.com\/prometheus\/snmp_exporter\/releases<\/code>\uff0c\u4e0b\u8f7d<code>snmp_exporter<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-bash\"># \u52a0\u901f\u5730\u5740\nwget https:\/\/mirror.ghproxy.com\/https:\/\/github.com\/prometheus\/snmp_exporter\/releases\/download\/v0.26.0\/snmp_exporter-0.26.0.linux-amd64.tar.gz<\/code><\/pre>\n<ol start=\"2\">\n<li>\u89e3\u538b<code>snmp_exporter<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-bash\">tar xf snmp_exporter-0.26.0.linux-amd64.tar.gz -C \/etc\/\nln -s \/etc\/snmp_exporter-0.26.0.linux-amd64\/ \/etc\/snmp_exporter<\/code><\/pre>\n<ol start=\"3\">\n<li>\u4fee\u6539<code>snmp.yml<\/code>\u914d\u7f6e\u6587\u4ef6\u7684\u56e2\u4f53\u540d\u79f0\u548c\u8ba4\u8bc1\u65b9\u5f0f\uff08\u9ed8\u8ba4\u7684<code>snmp.yml<\/code>\u63d0\u4f9b\u7684<code>if_mib<\/code>\u6a21\u5757\u8db3\u591f\u4f7f\u7528\uff0c\u7279\u6b8a\u7684\u6307\u6807\u9700\u8981\u5148\u83b7\u53d6<code>oid<\/code>\uff0c\u7136\u540e\u901a\u8fc7<code>generator<\/code>\u7a0b\u5e8f\u6765\u751f\u6210\u5bf9\u5e94\u7684\u6307\u6807\uff0c\u6700\u540e\u5408\u5e76\u5230<code>snmp.yml<\/code>\u7684\u6a21\u5757\u4e2d\uff09<br \/>\n<a href=\"https:\/\/github.com\/prometheus\/snmp_exporter\/tree\/main\/generator\" title=\"generator\">generator<\/a><\/li>\n<\/ol>\n<pre><code class=\"language-bash\">vim \/etc\/snmp_exporter\/snmp.yml\nauths:\npublic_v1:\ncommunity: public\nsecurity_level: noAuthNoPriv\nauth_protocol: MD5\npriv_protocol: DES\nversion: 1\npublic_v2:\ncommunity: 123456\nsecurity_level: noAuthNoPriv\nauth_protocol: MD5\npriv_protocol: DES\nversion: 2<\/code><\/pre>\n<ol start=\"3\">\n<li>\u914d\u7f6e<code>snmp_exporter<\/code>\u542f\u52a8\u6587\u4ef6<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/usr\/lib\/systemd\/system\/snmp_exporter.service\n[Unit]\nDescription=snmp_exporter\nDocumentation=https:\/\/prometheus.io\/\nAfter=network.target\n\n[Service]\nExecStart=\/etc\/snmp_exporter\/snmp_exporter --web.listen-address=:9116 --config.file=\/etc\/snmp_exporter\/snmp.yml\nExecReload=\/bin\/kill -HUP $MAINPID\nTimeoutStopSec=20s\nRestart=always\n\n[Install]\nWantedBy=multi-user.target<\/code><\/pre>\n<ol start=\"4\">\n<li>\u542f\u52a8<code>snmp_exporter<\/code><\/li>\n<\/ol>\n<pre><code class=\"language-bash\">systemctl daemon-reload\nsystemctl enable snmp_exporter.service\nsystemctl start snmp_exporter.service\nnetstat -lntp\nActive Internet connections (only servers)\nProto Recv-Q Send-Q Local Address           Foreign Address         State       PID\/Program name\ntcp6       0      0 :::9116                 :::*                    LISTEN      108458\/snmp_exporte<\/code><\/pre>\n<ol start=\"5\">\n<li>\u8bbf\u95ee<code>metrics<\/code><\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731235967682.png\" alt=\"file\" \/><\/p>\n<h4>\u914d\u7f6eprometheus<\/h4>\n<ol>\n<li>\u4fee\u6539<code>prometheus<\/code>\u914d\u7f6e\uff0c\u4f7f\u7528<code>relabel_configs<\/code>\u505a\u6807\u7b7e\u66ff\u6362\u3002<\/li>\n<\/ol>\n<pre><code class=\"language-bash\">cat \/etc\/prometheus\/prometheus.yml\nscrape_configs:\n  - job_name: &#039;snmp_exporter&#039;\n    scrape_interval: 60s\n    scrape_timeout: 30s\n    metrics_path: \/snmp\n    params:\n      auth: [public_v2]\n      module: [if_mib]\n    static_configs:\n      - targets: [&quot;x.x.x.x&quot;]\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: 192.168.99.4:9116<\/code><\/pre>\n<ol start=\"2\">\n<li>\n<p>\u91cd\u65b0\u52a0\u8f7d<code>prometheus<\/code>\u914d\u7f6e\u6587\u4ef6<br \/>\n<code>curl  -X POST http:\/\/localhost:9090\/-\/reload<\/code><\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5<code>prometheus<\/code>\u7684<code>status--&gt;targets<\/code>\u9875\u9762\uff0c\u9a8c\u8bc1<code>snmp_exporter<\/code>\u662f\u5426\u5df2\u6210\u529f\u7eb3\u5165\u76d1\u63a7<\/p>\n<\/li>\n<\/ol>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/2024\/11\/image-1731236244039.png\" alt=\"file\" \/><\/p>\n<h4>\u5bfc\u5165snmp_exporter\u56fe\u5f62<\/h4>\n<p>\u5bfc\u5165<code>id12489\u3001id12492<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u76d1\u63a7\u6848\u4f8b\u4ecb\u7ecd \u76d1\u63a7\u573a\u666f\u63cf\u8ff0 \u524d\u9762\u5df2\u7ecf\u5b66\u4e9b\u4e86\u5982\u4f55\u4f7f\u7528prometheus\u7ed3\u5408node_exporter\u6765\u76d1\u63a7\u7cfb\u7edf&#8230; &raquo; <a class=\"read-more-link\" href=\"http:\/\/blue.yn.cn\/?p=1690\">\u9605\u8bfb\u5168\u6587<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-1690","post","type-post","status-publish","format-standard","hentry","category-prometheus"],"_links":{"self":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1690"}],"version-history":[{"count":9,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1690\/revisions"}],"predecessor-version":[{"id":1716,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=\/wp\/v2\/posts\/1690\/revisions\/1716"}],"wp:attachment":[{"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1690"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blue.yn.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}