下载地址:https://prometheus.io/download/
官方文档地址:https://github.com/prometheus/blackbox_exporter
配置文件用法:https://github.com/prometheus/blackbox_exporter/blob/master/CONFIGURATION.md
配置文件举例: https://github.com/prometheus/blackbox_exporter/blob/master/example.yml
The blackbox exporter allows blackbox probing of endpoints over HTTP, HTTPS, DNS, TCP, ICMP and gRPC.
Checking the results
Visiting http://localhost:9115/probe?target=google.com&module=http_2xx will return metrics for a HTTP probe against google.com.
The probe_success metric indicates if the probe succeeded.
Adding a debug=true parameter will return debug information for that probe.
用法示例:
1.docker方式
docker run --rm \
-p 9115/tcp \
--name blackbox_exporter \
-v $(pwd):/config \
quay.io/prometheus/blackbox-exporter:latest --config.file=/config/blackbox.yml
2.二进制方式
./blackbox_exporter <flags>
Prometheus Configuration:
scrape_configs:
- job_name: 'blackbox'
metrics_path: /probe
params:
module: [http_2xx] # Look for a HTTP 200 response.
static_configs:
- targets:
- http://prometheus.io # Target to probe with http.
- https://prometheus.io # Target to probe with https.
- http://example.com:8080 # Target to probe with http on port 8080.
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 # The blackbox exporter's real hostname:port.
scrape_configs:
- job_name: blackbox_all
metrics_path: /probe
params:
module: [ http_2xx ] # Look for a HTTP 200 response.
dns_sd_configs:
- names:
- example.com
- prometheus.io
type: A
port: 443
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
replacement: https://$1/ # Make probe URL be like https://1.2.3.4:443/
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 127.0.0.1:9115 # The blackbox exporter's real hostname:port.
- source_labels: [__meta_dns_name]
target_label: __param_hostname # Make domain name become 'Host' header for probe requests
- source_labels: [__meta_dns_name]
target_label: vhost # and store it in 'vhost' label
具体安装步骤:
1.下载软件
wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.24.0/blackbox_exporter-0.24.0.linux-amd64.tar.gz
2.解压缩
tar -zxv -f blackbox_exporter-0.24.0.linux-amd64.tar.gz -C /usr/local
3.配置为系统服务
# vim /usr/lib/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/blackbox_exporter/blackbox_exporter \
--config.file=/usr/local/blackbox_exporter/blackbox.yml \
--web.listen-address=:9115
Restart=on-failure
[Install]
WantedBy=multi-user.target
另一种写法:
cat <<EOF > /etc/systemd/system/blackbox_exporter.service
[Unit]
Description=blackbox_exporter
After=network.target
[Service]
Type=simple
User=os2uat
Group=os2uat
ExecStart=/usr/local/bin/blackbox_exporter \
--config.file=/app/software/blackbox_exporter-0.22.0.linux-amd64/blackbox.yml \
--web.listen-address=:9115
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
4.重载系统systemd配置,启动服务并且设置服务自启,查看服务运行状态
# systemctl daemon-reload
# systemctl enable --now blackbox_exporter
# systemctl restart blackbox_exporter
# systemctl status blackbox_exporter
5.测试接口
curl -s {{节点IP}}:9115/metrics
ps -ef|grep "server.port"
ps -ef|grep "mall-server"
mall-server
服务及其所在主机:
重新加载配置文件
curl -X POST http://172.31.128.1:9079/-/reload
probe_success{name="huanma-activity"}
probe_success{app="huanma-activity", environment="prod", instance="172.31.115.18:8067", job="http"}
probe_success{module=~"$module",company=~"$company",project=~"$project",env=~"$env",name=~"$name",instance=~"$instance",instance=~".*$sname.*"} - 0
probe_success{module=~"$module",company=~"$company",project=~"$project",env=~"$env",name=~"$name",instance=~"$instance",instance=~".*$sname.*"} - 0
__scheme__="tcp"
modules:
http_2xx:
prober: http
tcp_connect:
prober: tcp
pop3s_banner:
prober: tcp
tcp:
query_response:
- expect: "^+OK"
tls: true
tls_config:
insecure_skip_verify: false
modules:
http_2xx:
prober: http
timeout: 5s
http:
method: GET
preferred_ip_protocol: "ip4"
valid_status_codes: [200]
tcp_connect:
prober: tcp
timeout: 5s
- job_name: "tcp"
metrics_path: /probe
params:
module: [tcp_connect]
file_sd_configs:
- files:
- targets/tcp.yaml
refresh_interval: 2m
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: 172.31.128.1:9115
label_values(probe_success{module=~"$module",company=~"$company",project=~"$project",env=~"$env",name=~"$name",app=~"$app"},app)
label_values(probe_success{module=~"$module",company=~"$company",project=~"$project",env=~"$env"},name)
probe_success{app=~"$app"}