在机器上部署 blackbox_exporter

  1. - 项目地址 https://github.com/prometheus/blackbox_exporter


使用ansible部署 blackbox_exporter

  1. ansible-playbook -i host_file service_deploy.yaml -e "tgz=blackbox_exporter-0.18.0.linux-amd64.tar.gz" -e "app=blackbox_exporter"

访问页面

  1. http://ip:9115/

image.png

http trace中对于http各个状态的描述

  1. - dns解析时间: DNSDone-DNSStart
  2. - tls握手时间: gotConn - DNSDone
  3. - tls connect连接时间: connectDone - DNSDone
  4. - tls connect连接时间: gotConn - DNSDone
  5. - processing 服务端处理时间: responseStart - gotConn
  6. - transfer 数据传输时间: end - responseStart
  1. trace := &httptrace.ClientTrace{
  2. DNSStart: tt.DNSStart,
  3. DNSDone: tt.DNSDone,
  4. ConnectStart: tt.ConnectStart,
  5. ConnectDone: tt.ConnectDone,
  6. GotConn: tt.GotConn,
  7. GotFirstResponseByte: tt.GotFirstResponseByte,
  8. }


blackbox_exporter 需要传入target 和 module 参数,采用下列方式加入的采集池中

  1. - job_name: 'blackbox-http'
  2. metrics_path: /probe
  3. params:
  4. module: [http_2xx] # Look for a HTTP 200 response.
  5. static_configs:
  6. - targets:
  7. - http://prometheus.io # Target to probe with http.
  8. - https://www.baidu.com # Target to probe with https.
  9. - http://172.16.58.78:3000 # Target to probe with http on port 3000.
  10. relabel_configs:
  11. - source_labels: [__address__]
  12. target_label: __param_target
  13. - source_labels: [__param_target]
  14. target_label: instance
  15. - target_label: __address__
  16. replacement: 172.16.58.78:9115 # The blackbox exporter's real hostname:port.

会发现如此配置之后 实例数据只有blackbox_exporter的地址 而没有target的地址

  1. probe_duration_seconds{instance="172.20.70.205:9115", job="blackbox-http"}

blackbox_exporter 采集加入的采集池中

  1. - job_name: 'blackbox-ssh'
  2. metrics_path: /probe
  3. params:
  4. module: [ssh_banner] # Look for a HTTP 200 response.
  5. static_configs:
  6. - targets:
  7. - 172.16.58.78:22 # Target to probe with http.
  8. - 172.16.58.79:22 # Target to probe with https.
  9. relabel_configs:
  10. - source_labels: [__address__]
  11. target_label: __param_target
  12. - source_labels: [__param_target]
  13. target_label: instance
  14. - target_label: __address__
  15. replacement: 172.16.58.78:9115 # The blackbox exporter's real hostname:port.
  16. - job_name: 'blackbox-ping'
  17. metrics_path: /probe
  18. params:
  19. module: [icmp] # Look for a HTTP 200 response.
  20. static_configs:
  21. - targets:
  22. - 172.16.58.78 # Target to probe with http.
  23. - 172.16.58.79 # Target to probe with https.
  24. - 8.8.8.8
  25. relabel_configs:
  26. - source_labels: [__address__]
  27. target_label: __param_target
  28. - source_labels: [__param_target]
  29. target_label: instance
  30. - target_label: __address__
  31. replacement: 172.16.58.78:9115 # The blackbox exporter's real hostname:port.

grafana 上导入 blackbox_exporter dashboard

  1. # 模块使用 ssh_banner 探测172.20.70.215:22
  2. http://172.20.70.205:9115/probe?module=ssh_banner&target=172.20.70.215:22
  3. # 结果解读
  4. # HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds
  5. # TYPE probe_dns_lookup_time_seconds gauge
  6. probe_dns_lookup_time_seconds 2.5331e-05
  7. # HELP probe_duration_seconds Returns how long the probe took to complete in seconds
  8. # TYPE probe_duration_seconds gauge
  9. probe_duration_seconds 0.02228226
  10. # HELP probe_failed_due_to_regex Indicates if probe failed due to regex
  11. # TYPE probe_failed_due_to_regex gauge
  12. probe_failed_due_to_regex 0
  13. # HELP probe_ip_addr_hash Specifies the hash of IP address. It's useful to detect if the IP address changes.
  14. # TYPE probe_ip_addr_hash gauge
  15. probe_ip_addr_hash 9.51584696e+08
  16. # HELP probe_ip_protocol Specifies whether probe ip protocol is IP4 or IP6
  17. # TYPE probe_ip_protocol gauge
  18. probe_ip_protocol 4
  19. # HELP probe_success Displays whether or not the probe was a success
  20. # TYPE probe_success gauge
  21. probe_success 1
  22. # ssh_banner 模块解读
  23. # 使用tcp进行探测,并且 期望得到 SSH-2.0-的响应
  24. ssh_banner:
  25. prober: tcp
  26. tcp:
  27. query_response:
  28. - expect: "^SSH-2.0-"
  29. # 和telnet结果一致
  30. [root@prome_master_01 blackbox_exporter]# telnet 172.20.70.215 22
  31. Trying 172.20.70.215...
  32. Connected to 172.20.70.215.
  33. Escape character is '^]'.
  34. SSH-2.0-OpenSSH_7.4
  35. Protocol mismatch.
  36. Connection closed by foreign host.
  1. - job_name: 'blackbox-ssh'
  2. metrics_path: /probe
  3. params:
  4. module: [ssh_banner] # Look for a HTTP 200 response.
  5. static_configs:
  6. - targets:
  7. - 172.16.58.78:22 # Target to probe with http.
  8. - 172.16.58.79:22 # Target to probe with https.
  9. relabel_configs:
  10. - source_labels: [__address__]
  11. target_label: __param_target
  12. - source_labels: [__param_target]
  13. target_label: instance
  14. - target_label: __address__
  15. replacement: 172.16.58.78:9115 # The blackbox exporter's real hostname:port.

进行ping探测

  1. http://172.20.70.205:9115/probe?module=icmp&target=www.baidu.com
  2. # 结果解读
  3. # HELP probe_dns_lookup_time_seconds Returns the time taken for probe dns lookup in seconds
  4. # TYPE probe_dns_lookup_time_seconds gauge
  5. probe_dns_lookup_time_seconds 0.195704171
  6. # HELP probe_duration_seconds Returns how long the probe took to complete in seconds
  7. # TYPE probe_duration_seconds gauge
  8. probe_duration_seconds 0.378563375
  9. # HELP probe_icmp_duration_seconds Duration of icmp request by phase
  10. # TYPE probe_icmp_duration_seconds gauge
  11. probe_icmp_duration_seconds{phase="resolve"} 0.195704171
  12. probe_icmp_duration_seconds{phase="rtt"} 0.182456226
  13. probe_icmp_duration_seconds{phase="setup"} 0.000145827
  14. # HELP probe_icmp_reply_hop_limit Replied packet hop limit (TTL for ipv4)
  15. # TYPE probe_icmp_reply_hop_limit gauge
  16. probe_icmp_reply_hop_limit 49
  17. # HELP probe_ip_addr_hash Specifies the hash of IP address. It's useful to detect if the IP address changes.
  18. # TYPE probe_ip_addr_hash gauge
  19. probe_ip_addr_hash 2.282787449e+09
  20. # HELP probe_ip_protocol Specifies whether probe ip protocol is IP4 or IP6
  21. # TYPE probe_ip_protocol gauge
  22. probe_ip_protocol 4
  23. # HELP probe_success Displays whether or not the probe was a success
  24. # TYPE probe_success gauge
  25. probe_success 1
  26. - job_name: 'blackbox-ping'
  27. metrics_path: /probe
  28. params:
  29. module: [icmp] # Look for a HTTP 200 response.
  30. static_configs:
  31. - targets:
  32. - 172.16.58.78 # Target to probe with http.
  33. - 172.16.58.79 # Target to probe with https.
  34. - 8.8.8.8
  35. relabel_configs:
  36. - source_labels: [__address__]
  37. target_label: __param_target
  38. - source_labels: [__param_target]
  39. target_label: instance
  40. - target_label: __address__
  41. replacement: 172.16.58.78:9115 # The blackbox exporter's real hostname:port.
  42. ssh探测过程说明
  43. prometheus --> blackbox_exporter 使用配置 http://192.168.0.112:9115/probe?module=ssh_banner&target=192.168.0.127%3A22 --> 192.168.0.127:22