在promtheus+grafana監(jiān)控棧斥杜,blackbox是一款出鏡率比較高的exporter。blackbox支持使用HTTP、HTTPS, DNS, TCP, ICMP和gRPC對目標(biāo)進(jìn)行請求,根據(jù)響應(yīng)結(jié)果來偵測目標(biāo)的健康狀況。實際使用可以選擇不同的探測器戒洼,常用的blackbox探測器有http、tcp允华、icmp和dns圈浇。不同的偵測器,有不同的配置參數(shù)靴寂。
本文以常用的http探測器為例磷蜀,探測的URL為百度主頁:https://www.baidu.com。
1. blackbox
使用docker-compose來管理blackbox容器的運行百炬。創(chuàng)建一個目錄blackbox用來存放相關(guān)文件褐隆,
docker-compose.yaml
version: '3.3'
services:
blackbox_exporter:
image: prom/blackbox-exporter:v0.19.0
ports:
- "9115:9115"
restart: always
volumes:
- "./config:/config"
command: "--config.file=/config/blackbox.yaml"
config/blackbox.yaml
[root@a blackbox]# cat config/blackbox.yaml
modules:
http_get:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2.0"]
valid_status_codes: [200]
no_follow_redirects: false
tls_config:
insecure_skip_verify: true
配置文件很好理解, 其中配置項”no_follow_redirects:false“主要是防止誤判剖踊,很多站點會配置http到https的跳轉(zhuǎn)庶弃,這時http的返回狀態(tài)碼不是200衫贬,但站點是正常的,加這個選項讓請求根據(jù)響應(yīng)頭”Location“的值再發(fā)起新的請求歇攻,以最終的響應(yīng)狀態(tài)碼為準(zhǔn)固惯。
2. prometheus
prometheus的安裝和運行比較簡單。prometheus配置文件如下缴守,
prometheus.yaml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["localhost:9090"]
- job_name: 'blackbox-access-baidu'
scrape_interval: 1m
metrics_path: /probe
params:
module: [http_get]
static_configs:
- targets:
- https://www.baidu.com
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 10.0.1.5:9115 # The blackbox exporter's real hostname:port.
有一處不要寫錯了葬毫,
params:
module: [http_get]
3. grafana
grafana官網(wǎng)“
https://grafana.com/grafana/dashboards/”有專門針對blackbox exporter的dashboard,根據(jù)需要選擇屡穗,選定后直接通過ID在grafana上導(dǎo)入贴捡。效果圖,
歡迎評論村砂、交流烂斋!