/[sysadmin-cookbook]/recepies/acct/lastcomm-duration.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /recepies/acct/lastcomm-duration.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 39 - (show annotations)
Sat May 2 14:44:31 2009 UTC (11 years, 2 months ago) by dpavlin
File MIME type: text/plain
File size: 729 byte(s)
display statistics just for long running commands

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use YAML;
7
8 my $too_long = 0.5; # s
9 my $stats;
10
11 open(my $lastcomm, '-|', 'lastcomm');
12 while(<$lastcomm>) {
13 chomp;
14 if ( m{^(\S+).+?(\S+)\s+(\S+)\s+(\d+\.\d+) secs} ) {
15 my ( $command, $user, $tty, $duration ) = ( $1, $2, $3, $4 );
16 $stats->{command}->{$command} += $duration;
17 $stats->{user}->{$user} += $duration;
18 $stats->{tty}->{$tty} += $duration;
19 print "$_\n" if $duration > $too_long;
20 } else {
21 warn "# $_";
22 }
23 }
24
25 foreach my $stat ( keys %$stats ) {
26 print "\n$stat:\n";
27 my $counter = $stats->{$stat};
28 foreach my $name ( sort { $counter->{$b} <=> $counter->{$a} } keys %$counter ) {
29 my $d = $counter->{$name};
30 printf "%8.2f %s\n", $d, $name if $d > $too_long;
31 }
32 }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26