监控域名与证书过期

部署Black Exporter

这里使用二进制部署Black Exporter

  1. # 下载安装
  2. wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz
  3. tar -xvf blackbox_exporter-0.16.0.linux-amd64.tar.gz
  4. mv blackbox_exporter-0.16.0.linux-amd64/ /data/redis_exporter
  5. # 创建配置文件
  6. cat > /data/black_exporter/black_exporter.yml << EOF
  7. modules:
  8. http_2xx:
  9. prober: http
  10. timeout: 20s
  11. http:
  12. preferred_ip_protocol: "ip4"
  13. http_post_2xx_query:
  14. prober: http
  15. timeout: 20s
  16. http:
  17. preferred_ip_protocol: "ip4" ##使用ipv4
  18. method: POST
  19. headers:
  20. Content-Type: application/json ##header头
  21. body: '{"hmac":"","params":{"publicFundsKeyWords":"xxx"}}' ##传参
  22. tls_connect_tls:
  23. prober: tcp
  24. timeout: 5s
  25. tcp:
  26. tls: true
  27. tcp_connect:
  28. prober: tcp
  29. timeout: 5s
  30. #
  31. pop3s_banner:
  32. prober: tcp
  33. tcp:
  34. query_response:
  35. - expect: "^+OK"
  36. tls: true
  37. tls_config:
  38. insecure_skip_verify: false
  39. ssh_banner:
  40. prober: tcp
  41. tcp:
  42. query_response:
  43. - expect: "^SSH-2.0-"
  44. irc_banner:
  45. prober: tcp
  46. tcp:
  47. query_response:
  48. - send: "NICK prober"
  49. - send: "USER prober prober prober :prober"
  50. - expect: "PING :([^ ]+)"
  51. send: "PONG ${1}"
  52. - expect: "^:[^ ]+ 001"
  53. icmp:
  54. prober: icmp
  55. timeout: 20s
  56. EOF
  57. # 配置systemd
  58. cat > /etc/systemd/system/blackbox_exporter.service <<EOF
  59. [Unit]
  60. Description=blackbox_exporter
  61. Documentation=https://prometheus.io/
  62. After=network.target
  63. [Service]
  64. Type=simple
  65. User=prometheus
  66. ExecStart=/data/blackbox_exporter/blackbox_exporter --config.file=/data/blackbox_exporter/blackbox.yml
  67. Restart=on-failure
  68. [Install]
  69. WantedBy=multi-user.target
  70. EOF
  71. # 启动服务
  72. systemctl enable blackbox_exporter.service
  73. systemctl start blackbox_exporter.service
  74. systemctl status blackbox_exporter.service
  75. # 配置Consul自动发现
  76. cat > /data/consul/server1/config/blackbox-exporter.json <<EOF
  77. {
  78. "service":{
  79. "name":"blackbox-exporter",
  80. "tags":[
  81. "prod",
  82. "blackbox-exporter"
  83. ],
  84. "address": "172.26.42.229",
  85. "port":9115,
  86. "check":{
  87. "http":"http://172.26.42.229:9115",
  88. "interval":"10s"
  89. },
  90. "token":"your_token"
  91. }
  92. }
  93. EOF
  94. # 热加载Consul配置
  95. consul reload
  96. # Grafana导入Dashboard-ID:7587