Prometheus 监控之 Blackbox_exporter黑盒监测
Prometheus 监控之 Blackbox_exporter黑盒监测
相关内容原文地址:
CSDN:GeekXuShuo:Prometheus 监控之 Blackbox_exporter黑盒监测 [icmp、tcp、http(get\post)、dns、ssl证书过期时间]
.Anoxia:blackbox_exporter+grafana+prometheus监控主机存活,端口存活及网站状态
51CTO:铁血军人:网络探测:Blackbox Exporter
1、blackbox_exporter概述
blackbox_exporter是Prometheus 官方提供的 exporter 之一,可以提供 http、dns、tcp、icmp 的监控数据采集。
1.1 Blackbox_exporter 应用场景
- HTTP 测试
- 定义 Request Header 信息
- 判断 Http status / Http Respones Header / Http Body 内容
- TCP 测试
- 业务组件端口状态监听
- 应用层协议定义与监听
- ICMP 测试
- 主机探活机制
- POST 测试
- 接口联通性
- SSL 证书过期时间
2、blackbox_exporter安装
2.1 Docker方式安装
docker pull prom/blackbox-exporter
docker run -d -p 9115:9115 --name blackbox-exporter prom/blackbox-exporter
2.2 宿主机安装
各个版本的blackbox_exporter https://github.com/prometheus/blackbox_exporter/releases
以linux系统为例,下载编译好的二进制包,解压使用:
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz
tar -zxvf blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /data
mv /data/blackbox_exporter-0.16.0.linux-amd64 /data/blackbox_exporter
验证是否安装成功:
# cd /data/blackbox_exporter/
# ./blackbox_exporter --version
启动:
nohup ./blackbox_exporter &
blackbox_exporter --web.listen-address=:9115 --config.file=blackbox.yml
默认监听端口为9115:
# ss -tunlp|grep 9115
tcp LISTEN 0 32768 *:9115 *:* users:(("blackbox_export",29880,3))
3、blackbox_exporter配置
基本的配置:
modules:
http_2xx: # http 监测模块
prober: http
http:
http_post_2xx: # http post 监测模块
prober: http
http:
method: POST
tcp_connect: # tcp 监测模块
prober: tcp
ping: # icmp 检测模块
prober: icmp
timeout: 5s
icmp:
preferred_ip_protocol: "ip4"
四、prometheus配置
4.1 ping检测
在内网可以通过ping (icmp)检测服务器的存活,以前面的最基本的module配置为例,在Prometheus的配置文件中配置使用ping module:
- job_name: 'ping_all'
scrape_interval: 1m
metrics_path: /probe
params:
module: [ping]
static_configs:
- targets:
- 192.168.1.2
labels:
instance: node2
- targets:
- 192.168.1.3
labels:
instance: node3
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 127.0.0.1:9115 # black_exporter 这里和Prometheus在一台机器上
通过配置文件可以很直接的看出Prometheus使用black_exporter作为代理使用black_exporter配置的module检测各个target的状态。 下面是一个http://127.0.0.1:9115/probe?module=ping&target=192.168.1.2返回的是192.168.1.2这个target的metrics。
#DNS解析时间,单位 s
probe_dns_lookup_time_seconds 0.039431355
#探测从开始到结束的时间,单位 s,请求这个页面响应时间
probe_duration_seconds 0.651619323
probe_failed_due_to_regex 0
#HTTP 内容响应的长度
probe_http_content_length -1
#按照阶段统计每阶段的时间
probe_http_duration_seconds{phase="connect"} 0.050388884 #连接时间
probe_http_duration_seconds{phase="processing"} 0.45868667 #处理请求的时间
probe_http_duration_seconds{phase="resolve"} 0.040037612 #响应时间
probe_http_duration_seconds{phase="tls"} 0.145433254 #校验证书的时间
probe_http_duration_seconds{phase="transfer"} 0.000566269
#重定向的次数
probe_http_redirects 1
#ssl 指示是否将 SSL 用于最终重定向
probe_http_ssl 1
#返回的状态码
probe_http_status_code 200
#未压缩的响应主体长度
probe_http_uncompressed_body_length 40339
#http 协议的版本
probe_http_version 1.1
#使用的 ip 协议的版本号
probe_ip_protocol 4
probe_ssl_earliest_cert_expiry 1.59732e+09
#是否探测成功
probe_success 1
#TLS 的版本号
probe_tls_version_info{version="TLS 1.2"} 1
4.2 http监测
以前面的最基本的module配置为例,在Prometheus的配置文件中配置使用http_2xx module:
- job_name: 'http_get_all' # blackbox_export module
scrape_interval: 30s
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- https://frognew.com
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9115 #blackbox-exporter 所在的机器和端口
http检测除了可以探测http服务的存活外,还可以根据指标probe_ssl_earliest_cert_expiry进行ssl证书有效期预警。
4.3 监控主机存活状态
- job_name: node_status
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets: ['10.165.94.31']
labels:
instance: node_status
group: 'node'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 172.19.155.133:9115
10.165.94.31是被监控端ip,172.19.155.133是Blackbox_exporter
4.4 监控主机端口存活状态
- job_name: 'prometheus_port_status'
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['172.19.155.133:8765']
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: 172.19.155.133:9115
4.5 监控网站状态
- job_name: web_status
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['http://www.baidu.com']
labels:
instance: user_status
group: 'web'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 172.19.155.133:9115
5、prometheus告警规则
groups:
- name: example
rules:
- alert: curlHttpStatus
expr: probe_http_status_code{job="blackbox-http"}>=400 and probe_success{job="blackbox-http"}==0
#for: 1m
labels:
docker: number
annotations:
summary: '业务报警: 网站不可访问'
description: '{{$labels.instance}} 不可访问,请及时查看,当前状态码为{{$value}}'
6、Grafana
grafana模板号:9965。
此模板需要安装饼状图插件 下载地址 https://grafana.com/grafana/plugins/grafana-piechart-panel
安装插件,重启grafana生效。
grafana-cli plugins install grafana-piechart-panel
service grafana-server restart
6.1 访问grafana
Prometheus 监控之 Blackbox_exporter黑盒监测的更多相关文章
- Blackbox_exporter黑盒监测
一.概述 blackbox_exporter是Prometheus 官方提供的 exporter 之一,可以提供 http.dns.tcp.icmp 的监控数据采集.Blackbox_exporter ...
- 03 . Prometheus监控容器和HTTP探针应用
Eeporter是什么及来源? 是什么? 广义上讲所有可以向Prometheus提供监控样本数据的程序都可以被称为一个Exporter.而Exporter的一个实例称为target,如下所示,Prom ...
- Prometheus 监控K8S Node监控
Prometheus 监控K8S Node监控 Prometheus社区提供的NodeExporter项目可以对主机的关键度量指标进行监控,通过Kubernetes的DeamonSet可以在各个主机节 ...
- Prometheus监控k8s企业级应用
Prometheus架构图 常见的镜像 pod 备注 kube-state-metric 用来收集K8S基本状态信息的监控代理 node-exporter 专门用来收集K8S运算节点基础信息,需要部署 ...
- Prometheus监控实战应用
目录 1.Prometheus的主要特征及概述 2.普罗米修斯原理架构图 3.下载安装启动Prometheus 4.web客户端操作 5.默认图像 6.目录解释 7.配置文件 8.监控指标 8.1.监 ...
- Prometheus 监控报警系统 AlertManager 之邮件告警
转载自:https://cloud.tencent.com/developer/article/1486483 文章目录1.Prometheus & AlertManager 介绍2.环境.软 ...
- prometheus监控系统
关于Prometheus Prometheus是一套开源的监控系统,它将所有信息都存储为时间序列数据:因此实现一种Profiling监控方式,实时分析系统运行的状态.执行时间.调用次数等,以找到系统的 ...
- Kubernetes集群部署史上最详细(二)Prometheus监控Kubernetes集群
使用Prometheus监控Kubernetes集群 监控方面Grafana采用YUM安装通过服务形式运行,部署在Master上,而Prometheus则通过POD运行,Grafana通过使用Prom ...
- SpringCloud使用Prometheus监控(基于Eureka)
本文介绍SpringCloud使用Prometheus,基于Eureka服务发现. 1.Prometheus介绍 在之前写过两篇有关Prometheus使用的文章,如下: <SpringBoot ...
随机推荐
- Servlet+JSP+JDBC综合案例
层级关系: 一.Util包 包里面写一个JDBCTools.java文件 功能:实现数据库连接返回一个Connection对象,并且可以实现数据库相应资源的关闭! 注意事项: 1.定义成员变量 1 p ...
- FSMC全称“静态存储器控制器”。
FSMC全称"静态存储器控制器". 使用FSMC控制器后,可以把FSMC提供的FSMC_A[25:0]作为地址线,而把FSMC提供的FSMC_D[15:0]作为数据总线. (1)当 ...
- Linux 时间同步 01 简介
Linux 时间同步 01 简介 目录 Linux 时间同步 01 简介 时间同步 公共NTP服务器地址及IP 系统时间相关文件 时间同步 大数据产生与处理系统是各种计算设备集群的,计算设备将统一.同 ...
- ConcurrentHashMap 并发之美
一.前言 她如暴风雨中的一叶扁舟,在高并发的大风大浪下疾驰而过,眼看就要被湮灭,却又在绝境中绝处逢生 编写一套即稳定.高效.且支持并发的代码,不说难如登天,却也绝非易事. 一直有小伙伴向我咨询关于Co ...
- istio kiali 亲和性调度
一.节点调度 在开始 kiali 亲和性调度之前,先演示一个简单的例子介绍 pod 选择调度到指定 node: 节点打标 使用命令查看当前所有 k8s 节点: [root@k8s-master ~]# ...
- Lock锁 精讲
1.为什么需要Lock 为什么synchronized不够用,还需要Lock Lock和synchronized这两个最常见的锁都可以达到线程安全的目的,但是功能上有很大不同. Lock并不是用来代替 ...
- [C#] 老古董的 Microsoft Chart Controls 也可以进行数据预测
我要先声明,这篇文章介绍到的内容虽说不是不能用,但玩乐成分居多,大家看看就好,不要太认真. 1. Microsoft Chart Controls 中的 FinancialFormula 在上一篇文章 ...
- JavaScript 内存详解 & 分析指南
前言 JavaScript 诞生于 1995 年,最初被设计用于网页内的表单验证. 这些年来 JavaScript 成长飞速,生态圈日益壮大,成为了最受程序员欢迎的开发语言之一.并且现在的 JavaS ...
- vue中选中弹出框内的表格
一:可多选情况且对应勾选 由于是弹出框形式,所以会出现新增DOM与数据的改变问题,因此要使用$nextTick,不然一开始弹出得时候DOM还没有生成,却要获取DOM会报错:这种多选情况会出现一个bug ...
- 基于B/S架构的在线考试系统的设计与实现
前言 这个是我的Web课程设计,用到的主要是JSP技术并使用了大量JSTL标签,所有代码已经上传到了我的Github仓库里,地址:https://github.com/quanbisen/online ...