使用 df -h 如何创建自定义警报条件

With df -h how to create custom alert-conditions

使用 df -hawktailtr,如何创建应显示以下指示之一的自定义 "alert" 列/mnt/hgfs :

编辑:它在熬夜。

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"                                                                                                                                               
  }'
  1. 将您的任意值导入为 space-separated 字符串。
  2. split 列表成数组;获取具有 n=split()
  3. 的元素数
  4. 在最后一列为“/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=])}'