{"id":3079,"date":"2024-09-03T14:43:36","date_gmt":"2024-09-03T06:43:36","guid":{"rendered":"https:\/\/199604.com\/?p=3079"},"modified":"2024-09-03T14:43:36","modified_gmt":"2024-09-03T06:43:36","slug":"kube-prometheus-%e4%bd%bf%e7%94%a8-blackbox-exporter-%e8%bf%9b%e8%a1%8ctcp%e7%9b%91%e6%8e%a7%e4%b8%8e-http-%e7%9b%91%e6%8e%a7","status":"publish","type":"post","link":"https:\/\/199604.com\/3079","title":{"rendered":"kube-prometheus \u4f7f\u7528 blackbox-exporter \u8fdb\u884cTCP\u76d1\u63a7\u4e0e http \u76d1\u63a7"},"content":{"rendered":"<h1>kube-prometheus \u4f7f\u7528 blackbox-exporter \u8fdb\u884cTCP\u76d1\u63a7\u4e0e http \u76d1\u63a7<\/h1>\n<h2>\u524d\u8a00<\/h2>\n<p>\u5b89\u88c5<code>kube-prometheus<\/code> \u540e\u9ed8\u8ba4\u5728namespace\u7684<code>monitoring<\/code>\u4e2d\u6709\u521b\u5efa <code>blackbox-exporter<\/code>\u7684deployment\u3002\u56e0\u6b64k8s\u4e2d\u65e0\u9700\u518d\u90e8\u7f72<code>blackbox-exporter<\/code>\u3002<\/p>\n<h2>\u521b\u5efaProbe\u8d44\u6e90<\/h2>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efaProbe\u8d44\u6e90\u6765\u5b9a\u4e49TCP\u548cHTTP\u63a2\u6d4b\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bYAML\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-yaml \">kind: Probe\napiVersion: monitoring.coreos.com\/v1\nmetadata:\n  name: tcp_example\n  namespace: monitoring\nspec:\n  interval: 60s\n  module: tcp_connect\n  jobLabel: tcp_example\n  prober:\n    url: blackbox-exporter.monitoring.svc.cluster.local:19115\n  targets:\n    staticConfig:\n      static:\n        - ip:8443\n\n---\nkind: Probe\napiVersion: monitoring.coreos.com\/v1\nmetadata:\n  name: example-http\n  namespace: monitoring\nspec:\n  interval: 60s\n  module: http_2xx\n  jobLabel: example-http\n  prober:\n    url: blackbox-exporter.monitoring.svc.cluster.local:19115\n  targets:\n    staticConfig:\n      static:\n        - http:\/\/ip:8443\/test\n\n\n<\/code><\/pre>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5e94\u7528Probe\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-shell \">kubectl apply -f probe.yaml\n<\/code><\/pre>\n<h2>\u68c0\u67e5Prometheus\u914d\u7f6e<\/h2>\n<p>\u786e\u4fddPrometheus\u80fd\u591f\u6293\u53d6\u5230Probe\u7684\u7ed3\u679c\u3002\u53ef\u4ee5\u5728Prometheus\u7684Web\u754c\u9762\u4e2d\u67e5\u8be2<code>probe_success<\/code>\u6307\u6807\uff0c\u503c\u4e3a1\u8868\u793a\u63a2\u6d4b\u6210\u529f\uff0c0\u8868\u793a\u5931\u8d25\u3002<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/qn.199604.com\/typoraImg\/image-20240903143559886.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/qn.199604.com\/typoraImg\/image-20240903143559886.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20240903143559886\" \/><\/div><\/p>\n<h2>\u76d1\u63a7\u9879<\/h2>\n<pre><code class=\"language-shell \">probe_\n\nprobe_success  #\u662f\u5426\u63a2\u6d4b\u6210\u529f(\u53d6\u503c1\u30010\uff0c\u5206\u522b\u8868\u793a\u6210\u529f\u3001\u5931\u8d25)\nprobe_duration_seconds #\u63a2\u6d4b\u7684\u8017\u65f6\n#\u5173\u4e8eDNS\nprobe_dns_lookup_time_seconds #DNS\u89e3\u6790\u7684\u8017\u65f6\nprobe_ip_protocol #IP\u534f\u8bae\u53d6\u503c\u4e3a4\u30016\nprobe_ip_addr_hash #IP\u5730\u5740\u7684\u54c8\u5e0c\u503c\uff0c\u7528\u4e8e\u5224\u65adIP\u662f\u5426\u53d8\u5316\n#\u5173\u4e8eHTTP\nprobe_http_status_code #HTTP\u54cd\u5e94\u7684\u72b6\u6001\u7801\uff0c\u5982\u679c\u53d1\u751f\u91cd\u5b9a\u5411\uff0c\u5219\u53d6\u51b3\u4e8e\u6700\u540e\u4e00\u6b21\u54cd\u5e94\nprobe_http_content_length #HTTP\u54cd\u5e94\u7684body\u957f\u5ea6\uff0c\u5355\u4f4dbytes\nprobe_http_version #HTTP\u54cd\u5e94\u7684\u534f\u8bae\u7248\u672c\uff0c\u6bd4\u59821.1\nprobe_http_ssl #HTTP\u54cd\u5e94\u662f\u5426\u91c7\u7528SSL\uff0c\u53d6\u503c 1\u30010\nprobe_ssl_earliest_cert_expiry #SSL\u8bc1\u4e66\u8fc7\u671f\u65f6\u95f4\uff0c\u4e3aUnix\u65f6\u95f4\u6233\n<\/code><\/pre>\n<h2>\u521b\u5efa\u89e6\u53d1\u544a\u8b66\u89c4\u5219<\/h2>\n<pre><code class=\"language-yaml \">groups:\n- name: Blackbox\n  rules:\n  - alert: \u9ed1\u76d2\u5b50\u63a2\u6d4b\u5931\u8d25\u62a5\u8b66\n    expr: probe_success == 0\n    for: 1m\n    labels:\n      severity: critical\n    annotations:\n      summary: '\u9ed1\u76d2\u5b50\u63a2\u6d4b\u5931\u8d25 {{ $labels.instance }}'\n      description: \"\u9ed1\u76d2\u5b50\u63a2\u6d4b\u5931\u8d25,\u5f53\u524d\u503c{{ $value }}\"\n  - alert: \u8bf7\u6c42\u6162\u544a\u8b66\n    expr: avg_over_time(probe_duration_seconds[1m]) &gt; 1\n    for: 1m\n    labels:\n      severity: warning\n    annotations:\n      summary: '\u8bf7\u6c42\u6162 {{ $labels.instance }}'\n      description: \"\u8bf7\u6c42\u65f6\u95f4\u64cd\u8fc71\u79d2\uff0c\u503c{{ $value }}\"\n  - alert: http\u72b6\u6001\u7801\u68c0\u6d4b\u5931\u8d25\n    expr: probe_http_status_code &lt;= 199 OR probe_http_status_code &gt;= 400\n    for: 1m\n    labels:\n      severity: critical\n    annotations:\n      summary: 'http\u72b6\u6001\u7801\u68c0\u6d4b\u5931\u8d25{{ $labels.instance }}'\n      description: \"HTTP\u72b6\u6001\u7801\u975e200-399,\u5f53\u524d\u72b6\u6001\u7801\u4e3a{{ $value }}\"\n  - alert: ssl\u8bc1\u4e66\u5373\u5c06\u5230\u671f\n    expr: probe_ssl_earliest_cert_expiry - time() &lt; 86400 *30\n    for: 1m\n    labels:\n      severity: warning\n    annotations:\n      summary: '\u8bc1\u4e66\u5373\u5c06\u5230\u671f {{ $labels.instance }}'\n      description: \"SSL \u8bc1\u4e66\u572830\u5929\u540e\u5230\u671f,\u503c{{ $value }}\"    \n<\/code><\/pre>\n<h2>\u53c2\u8003<\/h2>\n<p>1.<code>https:\/\/github.com\/prometheus-operator\/kube-prometheus\/blob\/release-0.9\/docs\/blackbox-exporter.md<\/code><\/p>\n<p>2.<code>https:\/\/blog.csdn.net\/qq_31977125\/article\/details\/132164695<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>kube-prometheus \u4f7f\u7528 blackbox-exporter \u8fdb\u884cTCP\u76d1\u63a7\u4e0e http \u76d1\u63a7 \u524d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[353,403],"tags":[351,369],"class_list":["post-3079","post","type-post","status-publish","format-standard","hentry","category-kubernetes","category-prometheus","tag-kubernetes","tag-prometheus"],"_links":{"self":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/3079","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/comments?post=3079"}],"version-history":[{"count":1,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/3079\/revisions"}],"predecessor-version":[{"id":3080,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/3079\/revisions\/3080"}],"wp:attachment":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/media?parent=3079"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/categories?post=3079"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/tags?post=3079"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}