将 `nfsiostat` 添加到 SystemPerformance
已包含在 SystemPerformance 中
SystemPerformance 已内置 NFS 磁盘命令(包括 nfsiostat),但默认处于禁用状态。通过以下命令启用:
$$Enablenfs^SystemPerformance()
启用后,系统将添加以下 NFS 命令(以 Linux 为例):
/usr/sbin/nfsstat -cn/usr/sbin/nfsiostat [间隔] [次数]
请确保这些命令已安装且可通过操作系统运行
如需重新禁用,可执行:
$$Disablenfs^SystemPerformance()
向 SystemPerformance 添加通用命令
添加任意操作系统工具时,会在 ^IRIS.SystemPerformance("cmds","user")下创建一个"用户"命令。
示例:
%SYS>set ^IRIS.SystemPerformance("cmds","user",$i(^IRIS.SystemPerformance("cmds","user")))=$lb("nfsiostat","/usr/sbin/nfsiostat ","间隔"," ","次数"," > ")
操作建议:
添加前建议先查看现有命令结构,选择合适的配置文件名称:
zwrite ^IRIS.SystemPerformance("cmds")
为 SystemPerformance 添加带时间戳的 nfsiostat
通过脚本可简化实现流程。
包装脚本
保存为 /usr/local/bin/nfsiostat_ts.sh:
#!/bin/bash
# 用法:nfsiostat_ts.sh <间隔> <次数>
INTERVAL=${1:-5}
COUNT=${2:-12}
nfsiostat "$INTERVAL" "$COUNT" | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush() }'
赋予执行权限:
chmod +x /usr/local/bin/nfsiostat_ts.sh
添加到 SystemPerformance
set ^IRIS.SystemPerformance("cmds","30mins",$i(^IRIS.SystemPerformance("cmds","30mins"))) = $lb("nfsiostat","/usr/local/bin/nfsiostat_ts.sh ","间隔"," ","次数","")
此时 $lb()结构会将间隔和次数作为 $1和 $2传递给脚本,例如实际执行的命令为:
/usr/local/bin/nfsiostat_ts.sh 1 1800
验证配置:
zwrite ^IRIS.SystemPerformance("cmds","30mins")
手动测试脚本
在完整配置文件运行前,建议先用短时间测试:
/usr/local/bin/nfsiostat_ts.sh 5 3
预期输出:
2026-03-12 14:30:00 nfs-server:/export 挂载于 /data:
2026-03-12 14:30:00 操作/秒 rpc 积压
2026-03-12 14:30:00 19.40 0.00
2026-03-12 14:30:05 nfs-server:/export 挂载于 /data:
...
此时时间戳将直接嵌入 SystemPerformance HTML 输出的对应章节,且间隔/次数始终与当前运行的配置文件保持同步。
注:目前尚未为 YASPE 添加时间戳格式支持,后续将另行通知。
非 IRIS 服务器环境
命令行运行增强版 nfsiostat
适用于未安装 IRIS 的 Web 服务器(例如需与 SystemPerformance 中的 mgstat和 vmstat数据匹配的场景)。
更新包装脚本(日志文件名包含日期)
#!/bin/bash
# 用法:nfsiostat_ts.sh <间隔> <次数>
INTERVAL=${1:-5}
COUNT=${2:-17268}
nfsiostat "$INTERVAL" "$COUNT" | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush() }'
日志文件名中的日期通过 cron 传递(避免硬编码路径):
Cron 任务配置
crontab -e
添加以下条目(每天午夜运行,生成如 nfsiostat_20260312.log的日志文件):
0 0 * * * /usr/local/bin/nfsiostat_ts.sh 5 17268 > /path/to/logs/nfsiostat_$(date +\%Y\%m\%d).log 2>&1
注意:cron 中
%符号需转义为\%,否则会被视为换行符。
验证任务调度:
crontab -l
检查日志生成:
tail -f /path/to/logs/nfsiostat_$(date +%Y%m%d).log
可选:日志轮转
若每日运行且仅需保留最近 7 天日志,可添加清理任务(在日志生成 5 分钟后执行):
0 0 * * * /usr/local/bin/nfsiostat_ts.sh 5 17268 > /path/to/logs/nfsiostat_$(date +\%Y\%m\%d).log 2>&1
5 0 * * * find /path/to/logs -name "nfsiostat_*.log" -mtime +7 -delete