#prometheus-metrics #home #exporting #consumption #io #ad-guard

bin+lib agh-exporter-rs

一个小型HTTP服务器,用于导出AdGuard Home指标以在Prometheus中消费

3个版本

0.1.4 2024年1月17日
0.1.2 2024年1月3日
0.1.0 2024年1月2日

#387 in HTTP服务器

每月 27次下载

Apache-2.0

25KB
264

agh-exporter-rs

agh-exporter-rs是一个小型HTTP服务器,用于导出AdGuard Home指标以在Prometheus中消费,基于tokio-rsserde-rsreqwestaxum构建。导出的指标名称与AdGuard Home指标输出相同;有关详细信息,请参阅AdGuard Home openapi规范。

示例指标

$ curl http://agh-exporter:9100/metrics
num_dns_queries 47578
num_blocked_filtering 8447
num_replaced_safebrowsing 0
num_replaced_safesearch 0
num_replaced_parental 0
avg_processing_time 0.031464
top_clients{client = "192.168.1.28"} 10321
top_clients{client = "192.168.1.32"} 6308
top_clients{client = "192.168.1.16"} 6266
...
top_upstreams_responses{upstream = "1.1.1.1:53"} 15264
top_upstreams_responses{upstream = "1.0.0.1:53"} 14659
top_upstreams_avg_time{upstream = "1.1.1.1:53"} 0.0497817546514675
top_upstreams_avg_time{upstream = "1.0.0.1:53"} 0.04927965318234532
top_queried_domains{domain = "www.baidu.com"} 4120
top_queried_domains{domain = "raw.githubusercontent.com"} 3064
top_queried_domains{domain = "1.0.168.192.in-addr.arpa"} 2181
...
top_blocked_domains{domain = "os-12-5-alpha.logs.roku.com"} 2353
top_blocked_domains{domain = "scribe.logs.roku.com"} 2208
top_blocked_domains{domain = "dit.whatsapp.net"} 862
...

安装和运行crate

crates.io

使用cargo安装

$ cargo install agh-exporter-rs

$ agh-exporter-rs -h           
A small HTTP server exporting AdGuard Home metrics for consumption in Prometheus.

Usage: agh-exporter-rs [OPTIONS]

Options:
  -a, --agh-host <AGH_HOST>
          Base AGH API URL. Note the trailing slash! [env: AGH_HOST=] [default: http://localhost/control/]
  -s, --serve-addr <SERVE_ADDR>
          Address to bind to and serve metrics from, including metrics URL [env: AGH_SERVE_ADDR=] [default: http://0.0.0.0:9100/metrics]
  -u, --agh-username <AGH_USERNAME>
          AGH username [env: AGH_USERNAME=]
  -p, --agh-password <AGH_PASSWORD>
          AGH password [env: AGH_PASSWORD=]
  -i, --scrape-interval <SCRAPE_INTERVAL>
          Scrape interval, in seconds. Should ideally be less than half the Prometheus server scrape interval [env: AGH_SCRAPE_INTERVAL=] [default: 5]
  -h, --help
          Print help
  -V, --version
          Print version

使用Docker

从GitHub容器注册库中拉取镜像

$ docker pull ghcr.io/molguin92/agh-exporter-rs:latest

您还可以将镜像包含在以下docker-compose.yml

version: '3'
services:
  agh-exporter:
    image: ghcr.io/molguin92/agh-exporter-rs:latest
    environment:
      AGH_HOST: http://localhost/adguard/control/
      AGH_SERVE_ADDR: http://localhost:9100/metrics
      AGH_USERNAME: foo
      AGH_PASSWORD: bar
      AGH_SCRAPE_INTERVAL: 5
    ports:
      - "9100:9100"
    restart: on-failure

确保更新环境变量以匹配您的AdGuard Home部署。

本地构建

克隆存储库并使用cargo构建

$ git clone [email protected]:molguin92/agh-exporter-rs.git

$ cd agh-exporter-rs

$ cargo build

许可证

在Apache 2.0许可证下授权。有关详细信息,请参阅LICENSE

依赖项

~10–25MB
~362K SLoC