本文主要是介绍Prometheus+blackbox_exporter监控url(get、post)及ssl证书,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载
prometheus、blackbox_exporter:https://prometheus.io/download/
解压后可以看到prometheus.yml、blackbox.yml
启动
nohub ./prometheus --config.file=prometheus.yml &
nohub ./blackbox_exporter–config.file=blackbox.yml &
配置
vim prometheus.yml
- job_name: 'blackbox' #自定义job_namescrape_interval: 10s #监测时间默认15smetrics_path: /probe #指标,默认为metrics,这边采用probeparams:module: [http_2xx] #blackbox.yml中的模块(get)static_configs:- targets:- https://baidu.com #监听地址relabel_configs:- source_labels: [__address__]target_label: __param_target- source_labels: [__param_target]target_label: instance- target_label: __address__replacement: 192.168.223.146:9115 #blackbox服务地址- job_name: 'blackbox-post'scrape_interval: 30smetrics_path: /probeparams:module: [http_post_2xx] #此模块用于监听post请求static_configs:- targets:- https://test.com/labels:url_name: "POST 用户查询" #标签用于区分relabel_configs:- source_labels: [__address__]target_label: __param_target- source_labels: [__param_target]target_label: instance- target_label: __address__replacement: 192.168.223.146:9115
vim blackbox.yml
需要修改该模块监听post请求 http_post_2xx
http_post_2xx:prober: httptimeout: 30shttp:method: POSTheaders:Content-Type: application/jsontoken: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2Nzk4OTYzMTEsImV4cCI6MTY3OTk4MjcxMSwicGlkIjoxLCJwbmFtZSI6Iui_kOiQpeaAu-mDqCIsImVpZCI6MSwidWlkIjoxLCJyaWQiOjEsInV0eXBlIjoiMSIsIm5hbWUiOiLov5DokKXmgLvpg6giLCJjbGllbnQiOjF9.4ev-OoYsfW5DZ9xaDFMyfQw6qTbuah99yNgoo26FKMgbody: "isnew=1" #body: {"isnew":"1"}
配置告警规则
下面是两个告警规则,因为有的url接口就是慢,也不影响业务,所以统一配置成超过1秒告警,会导致某些时间频繁报警,所以可以根据 =~ 和 = 的方法配置某一个规则大于1.5秒才告警;
vim /prometheus/rules/http_export-alert-rules.yml
groups:- name: nginx状态-监控告警rules:- alert: 状态码检测expr: probe_http_status_code{job="blackbox"} != 200for: 0mlabels:serverity: warningstatus: 非常严重annotations:summary: "请求URL状态码非200"description: "请求{{$.Labels.instance}}状态码非200"- alert: 证书过期时间检测expr: probe_ssl_earliest_cert_expiry {job="blackbox"} -time() < 86400 * 30for: 5mlabels:serverity: warningstatus: 警告annotations:summary: "证书过期时间不足30天"description: "{{$.Labels.instance}}证书还有30天到期,请及时更换"- alert: 页面响应时间检测expr: probe_duration_seconds{job="blackbox"} >= 1for: 1mlabels:serverity: warningstatus: 警告annotations:summary: "页面响应时间超过1秒"description: "{{$.Labels.instance}}页面响应时间超过1秒"- alert: post页面响应时间检测expr: probe_duration_seconds{job="blackbox-post"} >= 1for: 1mlabels:serverity: warningstatus: 警告annotations:summary: "{{$.Labels.instance}}页面响应时间超过1秒"description: "服务:{{$.Labels.url_name}}---响应时间>=1s,(当前:{{$value}})"
监控模板
模板直通车
Grafana模板编码 8587
这篇关于Prometheus+blackbox_exporter监控url(get、post)及ssl证书的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!