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

全部博文(534)

文章存档

2015年(4)

2014年(27)

2013年(15)

2012年(38)

2011年(36)

2010年(85)

2009年(63)

2008年(142)

2007年(124)

分类:

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