给我一个blackbox_exporter的监控示例
时间: 2023-02-24 19:22:12 浏览: 279
blackbox_exporter-0.20.0-rc.0.linux-amd64.tar.gz
blackbox_exporter 是一个 Prometheus 监控工具,专门用于对黑盒系统进行监控。以下是一个使用 blackbox_exporter 监控 HTTP 服务的示例:
1. 安装 blackbox_exporter:
```
$ wget https://github.com/prometheus/blackbox_exporter/releases/download/v0.18.0/blackbox_exporter-0.18.0.linux-amd64.tar.gz
$ tar xvfz blackbox_exporter-0.18.0.linux-amd64.tar.gz
$ cd blackbox_exporter-0.18.0.linux-amd64
$ sudo mv blackbox_exporter /usr/local/bin/
```
2. 配置 blackbox_exporter:
创建一个配置文件,例如 `blackbox.yml`:
```
modules:
http_2xx:
prober: http
timeout: 5s
http:
valid_http_versions: ["HTTP/1.1", "HTTP/2"]
method: GET
no_follow_redirects: false
fail_if_ssl: false
scrape_configs:
- job_name: http
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- http://www.example.com
- https://www.example.com
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_target]
target_label: instance
- target_label: __address__
replacement: localhost:9115
```
3. 启动 blackbox_exporter:
```
$ blackbox_exporter --config.file=blackbox.yml
```
4. 配置 Prometheus:
在 Prometheus 的配置文件中添加如下内容:
```
scrape_configs:
- job_name: blackbox
metrics_path: /probe
params:
module: [http_2xx]
static_configs:
- targets:
- http://localhost:9115
relabel_configs:
- source_labels: [__address__]
target_label: __param_target
- source_labels: [__param_module]
target_label: __metrics_path__
replacement: /probe
```
这样,Prometheus 就可以定期从 blackbox_exporter 获取监控
阅读全文