#!/bin/awk -f
BEGIN {
t=0;
FS="[ %]+";
printf("%s max:\n\n",ENVIRON["MYVAR"]);
}
{
if(FNR==1 && NR==1)
printf("filename=%s\n",FILENAME);
if($0~ENVIRON["MYVAR"]) {
n++;
if($0~" \\.")
sub(".")
$6=$6;
if(t<$6)
t=$6;
if(n%4==0) {
printf("%.2f\n",t);
t=0;
}
}
if(FNR==1 && NR!=1)
printf("\nfilename=%s\n",FILENAME);
}
脚本使用:
1.统计cpu
MYVAR=cpu ./t1.awk 0705.txt
2.统计cpu,mem,swap
for i in cpu mem swap ; do MYVAR="$i" ./t1.awk 0705.txt-bak ; done
每15分钟产生一条,awk分析每小时最大使用率
07-05 00:00
the usage of cpu is 2.2%
the usage of mem is 16.678800%
the usage of swap is .411200%
07-05 00:15
the usage of cpu is .9%
the usage of mem is 16.378300%
the usage of swap is .394600%
07-05 00:30
the usage of cpu is 12.2%
the usage of mem is 17.535100%
the usage of swap is .394700%
07-05 00:45
the usage of cpu is 12.4%
the usage of mem is 17.657800%
the usage of swap is .406600%
阅读(478) | 评论(0) | 转发(0) |