Skip to content

Repository files navigation

host-dns-perf

DNS 主机状态盘 —— 一分钟一采集,多时间槽对比,纯静态页面,无额外依赖。

支持 Unbound 和 BIND,自动识别 chronyd / ntpd。

效果

  • 页面显示当前值 + 与 1h / 6h / 12h / 1d / 3d / 7d 前的对比箭头
  • 覆盖 Unbound/BIND、CPU、内存、网络、磁盘、conntrack、NTP
  • 一行 health.txt 供监控系统 grep

目录结构

/home/host-dns-perf/
├── host-dns-perf.sh      采集脚本(主程序)
├── host-dns-perf.conf    配置文件
├── host-dns-perf.cron    cron 任务文件(安装到 /etc/cron.d/)
├── Caddyfile             Web 服务配置
├── caddy                 Caddy 二进制(自行下载放这里)
├── install.sh            一键安装脚本
├── data/                 快照(持久,跨重启保留 7 天对比)
├── run/                  prev 状态(重启清空可接受)
└── web/
    ├── index.html
    ├── current.json
    ├── slots.json
    ├── base-1h.json ... base-7d.json
    └── health.txt

快速部署(5 分钟)

1. 克隆到目标目录

git clone https://github.com/githubflyideas/host-dns-perf.git /home/host-dns-perf
cd /home/host-dns-perf

2. 一键安装

bash install.sh

install.sh 做的事:

  • 创建 data/ run/ web/ 目录
  • host-dns-perf.sh 设为可执行
  • 复制 host-dns-perf.conf(已存在则跳过)
  • 复制 index.htmlweb/
  • 安装 cron 到 /etc/cron.d/host-dns-perf
  • 创建软链接 /usr/local/bin/host-dns-perf -> /home/host-dns-perf/host-dns-perf.sh
  • 立即采集一次

3. 启动 Web 服务

方案 A — Caddy(推荐,自带 Basic Auth)

下载 Caddy 单二进制放到 /home/host-dns-perf/

# https://github.com/caddyserver/caddy/releases 下载 linux_amd64 版本
cd /home/host-dns-perf
chmod +x caddy

生成真实密码哈希(替换 Caddyfile 里的占位哈希):

./caddy hash-password --plaintext admin
# 把输出粘贴到 Caddyfile 中 admin 后面

启动:

./caddy start --config Caddyfile

方案 B — Python 3.7+

nohup python3 -m http.server 8081 --bind 0.0.0.0 --directory /home/host-dns-perf/web &

4. 打开页面

http://本机IP:8081/

配置说明

编辑 /home/host-dns-perf/host-dns-perf.conf

变量 默认值 说明
MODULES unbound cpu mem net sock disk conntrack ntp 去掉不需要的模块
PROBE_NAME www.baidu.com 探测域名
PROBE_SERVER 127.0.0.1 DNS 监听地址
NTP_OFFSET_WARN 50 NTP 偏移告警阈值(毫秒)
NTP_OFFSET_DOWN 1000 NTP 偏移故障阈值(毫秒)
IFACE (空) 空=汇总所有非 lo 网卡,或指定如 eth0
DISK_MOUNT / 监控哪个挂载点的磁盘占用

监控系统对接

curl -s http://主机:8081/health.txt | grep -q 'DNSHEALTH.*status=NORMAL' || 告警

health.txt 示例:

DNSHEALTH host=dns-01 status=NORMAL qps=1240 cache_hit=87% mem=41% ts=2026-09-05T01:00:00Z

临时只跑部分模块

host-dns-perf --modules "unbound cpu ntp"
host-dns-perf --no-rotate    # 只更新 current.json,不动历史快照

已知限制

  • PSI(/proc/pressure)需 4.20+ 内核,CentOS 7 不支持,不采集
  • 首次运行速率类指标显示 0,第二次起正常
  • Unbound 模块需 unbound-control 且已开启 remote-control
  • NTP 模块需 chronyc(chronyd)或 ntpq(ntpd)可用

About

DNS host monitor: Unbound/BIND + NTP, multi-slot diff, static page, zero dependencies

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages