Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1757084
  • 博文数量: 293
  • 博客积分: 10574
  • 博客等级: 上将
  • 技术积分: 5085
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-22 17:00
文章分类

全部博文(293)

文章存档

2011年(27)

2010年(84)

2009年(62)

2008年(120)

我的朋友

分类:

2011-07-21 01:43:15

#!/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%
阅读(475) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~