使用 blackbox_exporter 监控 post 路由资源
配置 blackbox.yml
modules:
post_two_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
valid_status_codes: []
method: POST
headers:
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: 'application/x-www-form-urlencoded; charset=UTF-8'
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-origin
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36
X-Requested-With: XMLHttpRequest
body: 'code=200&type=0'
preferred_ip_protocol: "ip4"
ip_protocol_fallback: false
fail_if_body_not_matches_regexp: [".*success.*"]
Prometheus 配置
- job_name: blackbox-http-post
metrics_path: /probe
scrape_interval: 10s
params:
module: [post_two_2xx]
static_configs:
- targets:
- http://192.168.1.120:8080/v1/
- https:// 监控站点
重启 Prometheus 和 blackbox_exporter 就可以了
如果从 probe_http_status_code 获取到的状态码为 500,则是提交的 body 参数可能出现了问题,如果 Content-Type 是 application/json,body 直接为 ‘{“code”:200}’ 即可,如果 Content-Type 为 application/x-www-form-urlencoded,参数格式为 ‘code=2000&type=11’ , 必要时可进行 url 编码