平均值:
cat 192.168.101.* | grep load | awk '{sum+=$4} END {print "average=", sum/NR}'
cat 192.168.101.* | grep Memory | awk '{sum+=$3} END {print "average=", sum/NR}'
cat 192.168.101.* | grep os-root | awk '{sum+=$5} END {print "average=", sum/NR}'
峰值:
方法一:
cat 192.168.101.* | grep load | sort -k 4 -n | tail -n 1 | cut -d " " -f 4
cat 192.168.101.* | grep Memory | sort -k 3 -n | tail -n 1 | cut -d " " -f 2 | cut -d : -f 2
cat 192.168.101.* | grep os-root | sort -k 5 -n | tail -n 1 | cut -d " " -f 12
标橙色cut命令和文本格式还有些理不清
方法二:
cat 192.168.101.* | grep load | awk 'BEGIN {max = 0} {if ($4-max>0) max=$4 fi} END {print "max=", max}'
cat 192.168.101.* | grep Memory | awk 'BEGIN {max = 0} {if ($3-max>0) max=$3 fi} END {print "max=", max}'
cat 192.168.101.* | grep os-root | awk 'BEGIN {max = 0} {if ($5-max>0) max=$5 fi} END {print "max=", max}'
方法三:有误
cat 192.168.101.* | grep load | awk 'BEGIN {max = 0} {if ($4>max) max=$4 fi} END {print "max=", max}'
cat 192.168.101.* | grep Memory | awk 'BEGIN {max = 0} {if ($3>max) max=$3 fi} END {print "max=", max}'
cat 192.168.101.* | grep os-root | awk 'BEGIN {max = 0} {if ($5>max) max=$5 fi} END {print "max=", max}'
标橙色一条有错误,如下:
[root@XXXX]# cat 192.168.101.* | grep load
system load average: 0.73
system load average: 1.32
system load average: 0.59
system load average: 1.55
system load average: 1.92
system load average: 1.28
system load average: 1.00
system load average: 0.29
system load average: 2.42
system load average: 1.14
system load average: 0.45
system load average: 0.10
system load average: 2.01
system load average: 1.40
system load average: 1.21
system load average: 0.82
system load average: 14.61
system load average: 3.40
system load average: 0.17
system load average: 2.39
system load average: 0.16
system load average: 3.25
system load average: 1.15
system load average: 0.26
system load average: 0.17
[root@XXXX]# cat 192.168.101.* | grep load | awk 'BEGIN {max = 0} {if ($4>max) max=$4 fi} END {print "max=", max}'
max= 3.40
结果竟然是3.40而不是14.61
这是因为数值的比较不是按照数值大小,而是按照字母的ASCII进行排序。
因而,改为方法一sort,加-n
或改为方法二,做差同0比较