使用 df -h 如何创建自定义警报条件
With df -h how to create custom alert-conditions
使用 df -h
、awk
、tail
、tr
,如何创建应显示以下指示之一的自定义 "alert" 列/mnt/hgfs :
- 警告:如果入住率在75%到80%之间
- 严重:如果入住率在81%到95%之间
- 报警:如果速率大于96%
编辑:它在熬夜。
df |awk -v threshold="75 81 96" -v message="Warning Critical Alarm" -v mnt="/mnt/hgfs" '
BEGIN {n=split(threshold, T); split(message, M)}
$NF == mnt {
for(i=n; i>0; i--)
if(int() > T[i]) {print M[i] ":", mnt, "usage:", ; exit}
print mnt, "usage normal"
}'
- 将您的任意值导入为 space-separated 字符串。
split
列表成数组;获取具有 n=split()
的元素数
- 在最后一列为“/mnt/hgfs”的任何行上,
i
在 T(hreshold) 数组上向后迭代,将第五列 (Use%) 与每个值进行比较。如果它更大,则使用 M(essage) 数组的相同值打印一条警告消息,然后在执行其他比较之前退出。
新需求的解决方案:
df |awk '
NR == 1 {alert="Alert"}
int() < 75 {alert=""}
int() > 75 {alert="Warning"}
int() > 81 {alert="Critical"}
int() > 96 {alert="Alarm"}
{printf("%-10s%s\n", alert, [=11=])}'
使用 df -h
、awk
、tail
、tr
,如何创建应显示以下指示之一的自定义 "alert" 列/mnt/hgfs :
- 警告:如果入住率在75%到80%之间
- 严重:如果入住率在81%到95%之间
- 报警:如果速率大于96%
编辑:它在熬夜。
df |awk -v threshold="75 81 96" -v message="Warning Critical Alarm" -v mnt="/mnt/hgfs" '
BEGIN {n=split(threshold, T); split(message, M)}
$NF == mnt {
for(i=n; i>0; i--)
if(int() > T[i]) {print M[i] ":", mnt, "usage:", ; exit}
print mnt, "usage normal"
}'
- 将您的任意值导入为 space-separated 字符串。
split
列表成数组;获取具有n=split()
的元素数
- 在最后一列为“/mnt/hgfs”的任何行上,
i
在 T(hreshold) 数组上向后迭代,将第五列 (Use%) 与每个值进行比较。如果它更大,则使用 M(essage) 数组的相同值打印一条警告消息,然后在执行其他比较之前退出。
新需求的解决方案:
df |awk '
NR == 1 {alert="Alert"}
int() < 75 {alert=""}
int() > 75 {alert="Warning"}
int() > 81 {alert="Critical"}
int() > 96 {alert="Alarm"}
{printf("%-10s%s\n", alert, [=11=])}'