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
git clone https://github.com/githubflyideas/host-dns-perf.git /home/host-dns-perf
cd /home/host-dns-perfbash install.shinstall.sh 做的事:
- 创建
data/run/web/目录 - 把
host-dns-perf.sh设为可执行 - 复制
host-dns-perf.conf(已存在则跳过) - 复制
index.html到web/ - 安装 cron 到
/etc/cron.d/host-dns-perf - 创建软链接
/usr/local/bin/host-dns-perf -> /home/host-dns-perf/host-dns-perf.sh - 立即采集一次
方案 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 &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)可用