{"id":1057,"date":"2021-04-28T10:08:06","date_gmt":"2021-04-28T02:08:06","guid":{"rendered":"https:\/\/www.linuxdevops.cn\/?p=1057"},"modified":"2021-04-28T10:08:06","modified_gmt":"2021-04-28T02:08:06","slug":"p-h-h-j-c","status":"publish","type":"post","link":"https:\/\/www.linuxdevops.cn\/2021\/04\/p-h-h-j-c\/","title":{"rendered":"Prometheus Operator blackbox_exporter \u9ed1\u76d2\u76d1\u6d4b"},"content":{"rendered":"
\u767d\u76d2\u76d1\u63a7<\/p>\n<\/li>\n
\u58a8\u76d2\u76d1\u63a7<\/p>\n<\/li>\n<\/ul>\n
\u767d\u76d2\u76d1\u63a7<\/strong>\uff1a\u662f\u6307\u6211\u4eec\u65e5\u5e38\u76d1\u63a7\u4e3b\u673a\u7684\u8d44\u6e90\u7528\u91cf\u3001\u5bb9\u5668\u7684\u8fd0\u884c\u72b6\u6001\u3001\u6570\u636e\u5e93\u4e2d\u95f4\u4ef6\u7b49\u8fd0\u884c\u6570\u636e\u3002\u8fd9\u4e9b\u90fd\u662f\u652f\u6301\u4e1a\u52a1\u548c\u670d\u52a1\u7684\u57fa\u7840\u8bbe\u65bd\uff0c\u901a\u8fc7\u767d\u76d2\u80fd\u591f\u4e86\u89e3\u5176\u5185\u90e8\u7684\u5b9e\u9645\u8fd0\u884c\u72b6\u6001\uff0c\u901a\u8fc7\u5bf9\u76d1\u63a7\u6307\u6807\u7684\u89c2\u5bdf\u80fd\u591f\u9884\u5224\u53ef\u80fd\u51fa\u73b0\u7684\u95ee\u9898\uff0c\u4ece\u800c\u5bf9\u6f5c\u5728\u7684\u4e0d\u786e\u5b9a\u56e0\u7d20\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n \u58a8\u76d2\u76d1\u63a7<\/strong>\uff1a\u5373\u4ee5\u7528\u6237\u7684\u8eab\u4efd\u6d4b\u8bd5\u670d\u52a1\u7684\u5916\u90e8\u53ef\u89c1\u6027\uff0c\u5e38\u89c1\u7684\u9ed1\u76d2\u76d1\u63a7\u5305\u62ec HTTP\u63a2\u9488\u3001TCP\u63a2\u9488\u3001Dns\u3001icmp\u7b49\u7528\u4e8e\u68c0\u6d4b\u7ad9\u70b9\u3001\u670d\u52a1\u7684\u53ef\u8bbf\u95ee\u6027\u3001\u670d\u52a1\u7684\u8fde\u901a\u6027\u3001\u8bc1\u4e66\u8fc7\u671f\u65f6\u95f4\u4ee5\u53ca\u8bbf\u95ee\u6548\u7387\u7b49\u3002<\/p>\n \u4e24\u8005\u6bd4\u8f83\uff1a\u9ed1\u76d2\u76d1\u63a7\u76f8\u8f83\u4e8e\u767d\u76d2\u76d1\u63a7\u6700\u5927\u7684\u4e0d\u540c\u5728\u4e8e\u9ed1\u76d2\u76d1\u63a7\u662f\u4ee5\u6545\u969c\u4e3a\u5bfc\u5411\u5f53\u6545\u969c\u53d1\u751f\u65f6\uff0c\u9ed1\u76d2\u76d1\u63a7\u80fd\u5feb\u901f\u53d1\u73b0\u6545\u969c\uff0c\u800c\u767d\u76d2\u76d1\u63a7\u5219\u4fa7\u91cd\u4e8e\u4e3b\u52a8\u53d1\u73b0\u6216\u8005\u9884\u6d4b\u6f5c\u5728\u7684\u95ee\u9898\u3002\u4e00\u4e2a\u5b8c\u5584\u7684\u76d1\u63a7\u76ee\u6807\u662f\u8981\u80fd\u591f\u4ece\u767d\u76d2\u7684\u89d2\u5ea6\u53d1\u73b0\u6f5c\u5728\u95ee\u9898\uff0c\u80fd\u591f\u5728\u9ed1\u76d2\u7684\u89d2\u5ea6\u5feb\u901f\u53d1\u73b0\u5df2\u7ecf\u53d1\u751f\u7684\u95ee\u9898\u3002<\/p>\n \u5b98\u65b9\u4ed3\u5e93\u5730\u5740\uff1a \u6dfb\u52a0\u4ed3\u5e93<\/p>\n \u4e0b\u8f7d&\u89e3\u538b<\/p>\n \u4fee\u6539values.yaml \u4fee\u6539blackbox_exporter\u914d\u7f6e<\/p>\n <\/p>\n \u90e8\u7f72 Blackbox-Exporter<\/p>\n \u5728\u5185\u7f51\u53ef\u4ee5\u901a\u8fc7ping (icmp)\u68c0\u6d4b\u670d\u52a1\u5668\u7684\u5b58\u6d3b\uff0c\u4ee5\u524d\u9762\u7684\u6700\u57fa\u672c\u7684module\u914d\u7f6e\u4e3a\u4f8b\uff0c\u5728Prometheus\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6e\u4f7f\u7528ping module\uff1a<\/p>\n Helm \u90e8\u7f72\u7684Prometheus Operator \u76f4\u63a5\u4fee\u6539values.yaml \u6587\u4ef6\u5728prometheus.additionalScrapeConfigs \u4e0b\u6dfb\u52a0\u914d\u7f6e\u7136\u540e\u66f4\u65b0\u5373\u53ef\u3002<\/strong><\/p>\n <\/p>\n \u66f4\u65b0<\/p>\n \u6253\u5f00Prometheus Dashboard\u7684 Target \u9875\u9762\uff0c\u5c31\u4f1a\u770b\u5230 \u4e0a\u9762\u5b9a\u4e49\u7684\u4efb\u52a1<\/p>\n<\/li>\n<\/ul>\n <\/p>\n \u540c\u6837\u7684\u64cd\u4f5c\u8fd8\u53ef\u4ee5\u6dfb\u52a0\u66f4\u591a\u4e0d\u901a\u7c7b\u578b\u7684\u9ed1\u76d2\u76d1\u6d4b<\/p>\n<\/blockquote>\n ssl_expiry.rules<\/p>\n Blackbox prober exporter<\/strong><\/a><\/p>\n prometheus-community\/helm-charts<\/strong><\/a><\/p>\n\u5728Kubernetes \u4e2d\u4f7f\u7528Helm \u90e8\u7f72 Blackbox-Exporter<\/h2>\n
https:\/\/github.com\/prometheus-community\/helm-charts<\/code> \u8fd9\u91cc\u9762\u5305\u542bprometheus \u76f8\u5173\u7ec4\u4ef6\u51e0\u4e4e\u6240\u6709\u7684helm chert\u3002<\/p>\n
\n
$ helm repo add prometheus-community https:\/\/prometheus-community.github.io\/helm-charts\n$ helm repo update<\/code><\/pre>\n<\/li>\n
$ helm pull prometheus-community\/prometheus-blackbox-exporter\n$ tar -zxvf prometheus-blackbox-exporter.tar.gz<\/code><\/pre>\n<\/li>\n
modules:\n http_2xx: # http \u68c0\u6d4b\u6a21\u5757 Blockbox-Exporter \u4e2d\u6240\u6709\u7684\u63a2\u9488\u5747\u662f\u4ee5 Module \u7684\u4fe1\u606f\u8fdb\u884c\u914d\u7f6e\n prober: http\n timeout: 10s\n http:\n valid_http_versions: [\"HTTP\/1.1\", \"HTTP\/2\"]\n valid_status_codes: [200] # \u9ed8\u8ba4 2xx\uff0c\u8fd9\u91cc\u5b9a\u4e49\u4e00\u4e2a\u8fd4\u56de\u72b6\u6001\u7801\uff0c\u5728grafana\u4f5c\u56fe\u65f6\uff0c\u6709\u660e\u793a\u3002\n method: GET\n headers:\n Host: prometheus.example.com\n Accept-Language: en-US\n Origin: example.com\n preferred_ip_protocol: \"ip4\" # \u9996\u9009IP\u534f\u8bae\n no_follow_redirects: false # \u5173\u95ed\u8ddf\u968f\u91cd\u5b9a\u5411\n http_post_2xx: # http post \u76d1\u6d4b\u6a21\u5757\n prober: http\n timeout: 10s\n http:\n valid_http_versions: [\"HTTP\/1.1\", \"HTTP\/2\"]\n method: POST\n # post \u8bf7\u6c42headers, body \u8fd9\u91cc\u53ef\u4ee5\u4e0d\u58f0\u660e\n headers: # \u4f7f\u7528 json \u683c\u5f0f\n Content-Type: application\/json\n body: '{\"text\": \"hello\"}'\n preferred_ip_protocol: \"ip4\"\n tcp_connect: # TCP \u68c0\u6d4b\u6a21\u5757\n prober: tcp\n timeout: 10s\n dns_tcp: # DNS \u901a\u8fc7TCP\u68c0\u6d4b\u6a21\u5757\n prober: dns\n dns:\n transport_protocol: \"tcp\" # \u9ed8\u8ba4\u662f udp\n preferred_ip_protocol: \"ip4\" # \u9ed8\u8ba4\u662f ip6\n query_name: \"kubernetes.default.svc.cluster.local\" # \u5229\u7528\u8fd9\u4e2a\u57df\u540d\u6765\u68c0\u67e5 dns \u670d\u52a1\u5668\n # query_type: \"A\" # \u5982\u679c\u662f kube-dns \uff0c\u4e00\u5b9a\u8981\u52a0\u5165\u8fd9\u4e2a\uff0c\u56e0\u4e3a\u4e0d\u652f\u6301Ipv6<\/code><\/pre>\n<\/li>\n<\/ul>\n
\n
$ helm install blackbox-exporter -n monitor .<\/code><\/pre>\n<\/li>\n<\/ul>\n
Prometheus Operator \u914d\u7f6e<\/h2>\n
\n
HTTP \u76d1\u63a7\uff08\u76d1\u63a7\u5916\u90e8\u57df\u540d\uff09<\/h4>\n
- job_name: 'blackbox_http_2xx'\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 - https:\/\/www.baidu.com # 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: prometheus-blackbox-exporter.monitor:9115 # The blackbox exporter's real hostname:port.<\/code><\/pre>\n<\/li>\n
ping \u76d1\u6d4b\u914d\u7f6e<\/h3>\n
- job_name: 'blackbox_ping_all'\n scrape_interval: 1m\n metrics_path: \/probe\n params:\n module: [ping]\n static_configs:\n - targets:\n - 64.115.3.100\n labels:\n instance: test\n relabel_configs:\n - source_labels: [__address__]\n target_label: __param_target\n - target_label: __address__\n replacement: prometheus-blackbox-exporter.monitor:9115 # blackbox-exporter Sevice \u5730\u5740\u7aef\u53e3<\/code><\/pre>\n<\/li>\n<\/ul>\n
\n
$ vim values.yaml\n$ helm upgrade prometheus -n monitor .<\/code><\/pre>\n<\/li>\n
\n
\n
DNS \u76d1\u63a7<\/h3>\n
- job_name: \"blackbox-k8s-service-dns\"\n scrape_interval: 30s\n scrape_timeout: 10s\n metrics_path: \/probe # \u4e0d\u662f metrics\uff0c\u662f probe\n params:\n module: [dns_tcp] # \u4f7f\u7528 DNS TCP \u6a21\u5757\n static_configs:\n - targets:\n - kube-dns.kube-system:53 # \u4e0d\u8981\u7701\u7565\u7aef\u53e3\u53f7\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: prometheus-blackbox-exporter.monitor:9115 # blackbox-exporter Sevice \u5730\u5740\u7aef\u53e3<\/code><\/pre>\n<\/li>\n
ICMP\u76d1\u6d4b<\/h3>\n
- job_name: node_status\n metrics_path: \/probe\n params:\n module: [icmp]\n static_configs:\n - targets: ['10.165.94.31']\n labels:\n instance: node_status\n group: 'node'\n relabel_configs:\n - source_labels: [__address__]\n target_label: __param_target\n - target_label: __address__\n replacement: prometheus-blackbox-exporter.monitor:9115 # blackbox-exporter Sevice \u5730\u5740\u7aef\u53e3<\/code><\/pre>\n<\/li>\n
TCP\u76d1\u6d4b<\/h3>\n
- job_name: 'prometheus_port_status'\n metrics_path: \/probe\n params:\n module: [tcp_connect]\n static_configs:\n - targets: ['172.19.155.133:8765']\n labels:\n instance: 'port_status'\n group: 'tcp'\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: prometheus-blackbox-exporter.monitor:9115 # blackbox-exporter Sevice \u5730\u5740\u7aef\u53e3<\/code><\/pre>\n<\/li>\n
SSL \u8bc1\u4e66\u8fc7\u671f\u65f6\u95f4\u76d1\u6d4b<\/h3>\n
rule_files:\n - ssl_expiry.rules\nscrape_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 - example.com # Target to probe\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: prometheus-blackbox-exporter.monitor:9115 # blackbox-exporter Sevice \u5730\u5740\u7aef\u53e3<\/code><\/pre>\n
groups: \n - name: ssl_expiry.rules \n rules: \n - alert: SSLCertExpiringSoon \n expr: probe_ssl_earliest_cert_expiry{job=\"blackbox\"} - time() < 86400 * 30 \n for: 10m<\/code><\/pre>\n<\/li>\n<\/ul>\n
\u53c2\u8003\uff1a<\/h2>\n
\n