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
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

coderzpw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值