Prometheus 监控服务端口、网站状态等(黑盒监测)
1、blackbox_exporter介绍
blackbox_exporter是Prometheus 官方提供的 exporter 之一,可以提供 http、dns、tcp、icmp 的监控数据采集。
blackbox_exporter 应用场景:
HTTP 测试: 定义 Request Header 信息,判断 Http status / Http Respones Header / Http Body 内容
TCP 测试:业务组件端口状态监听, 应用层协议定义与监听
ICMP 测试:主机探活机制
POST 测试:接口联通性
SSL 证书过期时间
2、安装blackbox_exporter
# wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.16.0/blackbox_exporter-0.16.0.linux-amd64.tar.gz
# tar xf blackbox_exporter-0.16.0.linux-amd64.tar.gz -C /usr/local/
# ln -s /usr/local/blackbox_exporter-0.16.0.linux-amd64/ /usr/local/blackbox_exporter
# 使用systemd管理blackbox_exporter服务
# vim /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
User=root
Type=simple
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter --config.file=/usr/local/blackbox_exporter/blackbox.yml
Restart=on-failure
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start blackbox_exporter
# systemctl enable blackbox_exporter
3、配置Prometheus采集数据
# cd /usr/local/prometheus
# vim prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# 网站监控
- job_name: 'http_status'
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets: ['http://www.baidu.com']
labels:
instance: http_status
group: web
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.31.63:9115
# ping 检测
- job_name: 'ping_status'
metrics_path: /probe
params:
module: [icmp]
static_configs:
- targets: ['192.168.31.62']
labels:
instance: 'ping_status'
group: 'icmp'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.31.63:9115
# 端口监控
- job_name: 'port_status'
metrics_path: /probe
params:
module: [tcp_connect]
static_configs:
- targets: ['192.168.31.62:80']
labels:
instance: 'port_status'
group: 'port'
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- target_label: __address__
replacement: 192.168.31.63:9115
# systemctl restart prometheus
4、Grafana可视化展示
需要安装饼状态图插件,安装后重启grafana。
grafana-cli plugins install grafana-piechart-panel
systemctl restart grafana-server.service
此模板ID为9965,数据源选择Prometheus:
- END -
推荐阅读 kubevirt在360的探索之路(K8s接管虚拟化),涨姿势~ 超详细!Kubernetes 学习笔记总结 基于 Nginx+lua+Memcache 实现灰度发布 Kubernetes生产环境最佳实践 一文搞懂蓝绿发布、灰度发布和滚动发布 高性能 Nginx HTTPS 调优 - 如何为 HTTPS 提速 30% 记一次 Linux服务器被入侵后的排查思路
点亮,服务器三年不宕机
评论