API-BlackBox-exporter监控服务接口API
一、安装BlackBox-exporter
1、下载安装
各个版本的blackbox_exporter https://github.com/prometheus/blackbox_exporter/releases
以linux系统为例,下载编译好的二进制包,解压使用:
也可以在linux系统上wget命令下载
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.14.0/blackbox_exporter-0.14.0.linux-amd64.tar.gz # 下载blackbox-exporter
tar -zxvf blackbox_exporter-0.14.0.linux-amd64.tar.gz # 解压并安装blackbox-exporter
2、验证是否安装成功
cd blackbox_exporter-0.14.0.linux-amd64 # 进入blackbox-exporter安装包
./blackbox_exporter --version # 查看版本号(验证是否安装成功)
二、配置blackbox_exporter
1、看一下blackbox_exporter原生提供的module
vi blackbox.yml
进入blackbox.yml文件:
2、根据需求自定义module
3、启动blackbox_exporter
nohup ./blackbox_exporter &
三、在prometheus中配置要检查的API
1、在prometheus中加入Job_name
- job_name: 'prometheus_200_status'
metrics_path: /probe
params:
module: [http_get_200]
static_configs:
- targets: ['http://10.8.132.108:8080/test/user/list']
labels:
instance: 'port_status'
group: 'tcp'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.8.132.141:9115
2、重启prometheus服务
ps -ef|grep prometheus
kill -9 15995 # 杀死prometheus对应进程
./prometheus & # 启动prometheus
3、查看prometheus的UI界面
4、监控服务API常用的指标
我用到的指标:
#是否探测成功 (是我们想要的,如果探测成功说明返回体中有"code":200)
probe_success 1
#返回的http状态码 (不是我们想要的)
probe_http_status_code 200
#探测从开始到结束的时间,单位 s,请求这个页面响应时间
probe_duration_seconds 0.010889113
其他监控指标:
# DNS解析时间,单位 s
probe_dns_lookup_time_seconds 0.000199105
# 探测从开始到结束的时间,单位 s,请求这个页面响应时间
probe_duration_seconds 0.010889113
# HELP probe_failed_due_to_regex Indicates if probe failed due to regex
# TYPE probe_failed_due_to_regex gauge
probe_failed_due_to_regex 0
# HTTP 内容响应的长度
probe_http_content_length -1
# 按照阶段统计每阶段的时间
probe_http_duration_seconds{phase="connect"} 0.001083728 #连接时间
probe_http_duration_seconds{phase="processing"} 0.008365885 #处理请求的时间
probe_http_duration_seconds{phase="resolve"} 0.000199105 #响应时间
probe_http_duration_seconds{phase="tls"} 0 #校验证书的时间
probe_http_duration_seconds{phase="transfer"} 0.000446424 #传输时间
# 重定向的次数
probe_http_redirects 0
# ssl 指示是否将 SSL 用于最终重定向
probe_http_ssl 0
# 返回的状态码
probe_http_status_code 200
# 未压缩的响应主体长度
probe_http_uncompressed_body_length 1766
# http 协议的版本
probe_http_version 1.1
# HELP probe_ip_addr_hash Specifies the hash of IP address. It's useful to detect if the IP address changes.
probe_ip_addr_hash 3.24030434e+09
# 使用的 ip 协议的版本号
probe_ip_protocol 4
# 是否探测成功
probe_success 1