- 论坛徽章:
- 0
|
这个是画cpu占用情况的图,我测试集群用的,perl不怎么会,临时拼凑的,其中的画图功能网络上找的,脚本不太完善,但满足我的需求了
我的数据来自sar 可以根据自己需要检测的指标灵活改动,另外我还会经常来吃饺子的~~~~
- #!/usr/bin/perl
- #
- # read from file cpud1(data which produce by sar -u)
- # by justlooks
- ############################################################
- use strict;
- use GD::Graph::lines;
- my @tmp1;
- my @cpud=();
- my @timed=();
- open(FH,"cpud1") or die "nnnnnn!\n";
- while(<FH>){
- @tmp1=split;
- if($tmp1[8]=~m/\d+/){
- push @cpud,$tmp1[8];
- }
- if(m/(?<=:)\d{2}:\d{2}/){
- push @timed,$&;
- }
- }
- my $arrlen=@cpud;
- my $i;
- for $i (0..$arrlen-1){
- $cpud[$i]=100-$cpud[$i]; #把图转个180度
- }
- close(FH);
-
- my @data=(
- [@timed],
- [@cpud],);
- my $my_graph=new GD::Graph::lines(1000,600);
- $my_graph->set(
- x_label => 'time',
- y_label => 'cpu use(%)',
- y_max_value => '100',
- y_min_value => '0',
- title => 'just draw',
- transparent => 0,
- );
- $my_graph->plot(\@data);
- save_chart($my_graph,'edit2');
- sub save_chart
- {
- my $chart = shift or die "Need a chart";
- my $name = shift or die "Need a name";
- local(*OUT);
- my $ext = $chart->export_format;
- open(OUT,">$name.$ext") or
- die "Can not open $name.$ext for write: $!";
- binmode OUT;
- print OUT $chart->gd->$ext();
- close OUT;
- }
复制代码 |
|