监控你的机场链路质量(Windows)

hehe

Smokeping 作为链路质量监控是非常完美的选择,但是因为我只有一台 Windows 所以选择了 Grafana + prometheus + blackbox exporter 来监控 VPS 的链路质量,发现也可以用来监控机场各个节点的链路状态。

下载 Grafana (本教程使用9.1.0 的 OSS Windows版本) https://grafana.com/grafana/download?edition=oss&pg=get&platform=windows&plcmt=selfmanaged-box1-cta1

下载 Prometheus(本教程使用 2.36.2.windows-amd64) 和 Blackbox_exporter (本教程使用 0.21.1.windows.amd64) https://prometheus.io/download/

配置 Clash:

本人使用 Clash for Windows,所以需要先在 Settings 里面关闭 Random Controller Port,然后在 General 里 Home Directory 点击 Open Folder 打开目录,修改 config.yaml:

external-controller: 127.0.0.1:3703 #监听地址和端口
secret: 41e42810-0958-4132-980f-15c97f1313bd #密钥,没有可以在 clash for windows 里的Settings 里 Core Secret 点击 Update

在 blackbox.yml 里添加:

  http_clash_speedtest:
    prober: http
    timeout: 5s
    http:
      method: GET
      headers:
        Authorization: Bearer 41e42810-0958-4132-980f-15c97f1313bd

创建 prometheus-clash-nodelist.yml , targets 填写所有节点的 clash 测速 api:

- targets:
  - 'http://127.0.0.1:3703/proxies/🇭🇰 IEPL-SS香港1/delay?timeout=5000&url=https://www.gstatic.com/generate_204'
  labels:
    instance: 'SS香港1'
    module: http_clash_speedtest

- targets:
  - 'http://127.0.0.1:3703/proxies/🇭🇰 IEPL-SS香港2/delay?timeout=5000&url=https://www.gstatic.com/generate_204'
  labels:
    instance: 'SS香港2'
    module: http_clash_speedtest

修改 prometheus.yml:

scrape_configs:
  - job_name: 'Clash'
    metrics_path: /probe
    scrape_interval: 5s
    file_sd_configs:
      - files:
          - 'prometheus-clash-nodelist.yml' 
    relabel_configs:
      - source_labels: [module]
        target_label: __param_module
      - source_labels: [__address__]
        target_label: __param_target
      - target_label: __address__
        replacement: 127.0.0.1:9115  

可以通过 CMD 运行 Blackbox_exporter 和 Prometheus,如正常运行则可以在浏览器进入 localhost:9090 点击 Status → Target 看到我们刚才添加的节点运行状况。Prometheus 默认保留 15 天的数据,可以添加 --storage.tsdb.retention.time=365d 来进行更长时间的监控,配合 WINSW 创建服务以持久化的运行。

Grafana 默认使用端口 3000,可以在 conf 目录下复制 defaults.ini 重命名为 custom.ini 并修改自定义端口:

# The http port to use
http_port = 3001

启动完成后浏览器进入 localhost:3001,默认账户密码 admin,登录后在左下角进入Configuration, 点击 Add data source 添加 Prometheus 数据库, HTTP 的 URL 栏填写 http://localhost:9090 即可,Prometheus 可以通过 --web.listen-address=:9091 修改默认端口

添加好数据库后在 Dashboard 里导入 这个面板 就可以了,默认使用中位数测量延迟,显示丢包(只代表时间内有丢包情况,详细的丢包率可以看下面的 packet loss)。

Report abuse