Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

collect the system data

by jackhhc (Initiate)
on Aug 24, 2003 at 07:31 UTC ( [id://286162]=perlquestion: print w/replies, xml ) Need Help??

jackhhc has asked for the wisdom of the Perl Monks concerning the following question:

Dear Sir:
I want to collect some system data.
I got a report from my server.
I will got the two blocks data echo time.
How can I get the second block data and get the bigger 2 value of util field. I have some script do from shell. But I do't how to do it from perl. thanks
Jack Hu
Data examplt:

-------- device %util queue r+w/s blks/s secs-avs +erv 09:47:09 10/0/15/1.6.0 45.33 0.00 77 897 5 +.88 09:47:09 10/0/15/1.5.0 16.00 0.00 59 806 2 +.74 -------- device %util queue r+w/s blks/s secs-avs +erv 09:47:14 10/0/15/1.6.0 6.50 0.00 21 166 3 +.17 09:47:14 10/0/15/1.5.0 3.44 0.00 18 157 1 +.89 09:47:14 10/2/2/0.3.0 2.48 0.00 4 134 6 +.20 09:47:14 10/2/2/0.13.0 2.29 0.00 4 133 6 +.03 09:47:14 10/1/5/0.2.0 8.22 0.02 15 60 5 +.48

20030823 Edit by Corion: Fixed formatting

Replies are listed 'Best First'.
Re: collect the system data
by liz (Monsignor) on Aug 24, 2003 at 08:12 UTC
    Not quite sure what you're doing here, but assuming the log is in a file and you want to find out the highest %util value, this would do the trick (I think).
    open LOG,'logfile' or die "Can't open 'logfile': $!\n"; my $max = 0; while (<LOG>) { $_ = substr( $_,27,6 ); # make sure the position and length are ok $max = $_ if $_ > $max; # if it's not numeric, it's 0 and never mo +re than $max } print "max = $max\n";

    Liz

Re: collect the system data
by CombatSquirrel (Hermit) on Aug 24, 2003 at 10:24 UTC
    Give this a shot:
    #!perl use strict; use warnings; my $section = 0; my ($time, $device, $util, $queue, $rws, $blks, $secs); my @results; open (LOG, '<', 'data.log') or die "Cannot open file data.log for inpu +t: $!\n"; while (<LOG>) { if (/^-+\s+/) { ++$section; next; } if ($section == 2) { next if (/^\s*$/); @results = split; next if (@results != 7); if (!$util or $util < $results[2]) { ($time, $device, $util, $queue, $rws, $blks, $secs) = @result +s; } } } print "Time: $time; device: $device; %util: $util\n"; print "r+w/s: $rws; blks/s: $blks; secs-avserv: $secs\n";
    It selects the data with the highest %util value from the second part of the file.
    Hope this helps, CombatSquirrel.
Re: collect the system data
by asarih (Hermit) on Aug 24, 2003 at 12:27 UTC
    I know this is perl monks, but I have to ask: What's wrong with sort -rnk3 logfile? If you want just the top 2, then: sort -rnk3 logfile | head -2 should do what you want. Do you want the rest unsorted?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://286162]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-19 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found