/[ps-trend]/ps2rrd.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 /ps2rrd.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Tue Jul 14 22:41:33 2009 UTC (14 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 2010 byte(s)
parse (vz)ps output and create rrd graphs

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use Data::Dump qw/dump/;
7 use RRD::Simple;
8 use DateTime;
9
10 my $veids;
11 my $vsz;
12
13 my $too_small = 64; # M
14 $too_small *= 1024; # k
15
16 sub count {
17 my $file = shift;
18 open(my $fh, '<', $file) || die "$file: $!";
19 warn "# $file ", -s $file, $/;
20
21 my $cols = <$fh>;
22 $cols =~ s/^\s+//;
23 my @c = split(/\s+/,$cols);
24 # warn "# c = ",dump( @c );
25 our $cp;
26 $cp->{$c[$_]} = $_ foreach 0 .. $#c;
27 our @r;
28 sub c {
29 my $name = shift;
30 my $n = $cp->{$name};
31 die "no column $name in ",dump( $cp ) unless defined $n;
32 return $r[$n];
33 }
34
35 while(<$fh>) {
36 chomp;
37 s/^\s+//g;
38 s/\s+$//g;
39 @r = split(/\s+/, $_, $#c + 1 );
40
41 my $veid = c('VEID');
42 $veid =~ s/^0$/hw/;
43
44 my $s = c('VSZ');
45 if ( $s < $too_small ) {
46 $vsz->{$file}->{$veid}+= $s * 1024;
47 } else {
48 my $cmd = c('COMMAND');
49 $cmd =~ s{-.+$}{};
50 $cmd =~ s{^/\S+/(\w+?)}{$1};
51 $cmd =~ s{^\w+ /\S+/(\w+?)}{$1};
52 $cmd =~ s{:?\s+.*$}{};
53 $cmd =~ s{\W+}{_}g;
54 $veid .= '-' . $cmd;
55 $veid = substr($veid,0,16);
56 $vsz->{$file}->{$veid}+= $s * 1024;
57 }
58 $veids->{$veid}++;
59 }
60
61 }
62
63 count $_ foreach @ARGV;
64
65 print "VSZ: ",dump( $vsz );
66
67 my @veids = keys %$veids;
68 warn "# veids = ",dump( sort @veids );
69
70 my $rrd = RRD::Simple->new( file => "ps.rrd" );
71 $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );
72
73 foreach my $file ( sort keys %$vsz ) {
74 my $t = (stat($file))[9];
75 if ( $file =~ m{(\d\d\d\d)-(\d\d)-(\d\d)/(\d\d)(\d\d)} ) {
76 $t = new DateTime(
77 year => $1,
78 month => $2,
79 day => $3,
80 hour => $4,
81 minute => $5,
82 );
83 warn "+ $t\n";
84 }
85
86 #warn "## ",dump( %{ $vsz->{$file} } );
87
88 eval {
89 $rrd->update($t->epoch, map {
90 ( $_ => $vsz->{$file}->{$_} )
91 } @veids );
92 };
93 warn "SKIP $t: $@\n" if $@;
94 }
95
96 $rrd->graph(
97 sources => [ sort @veids ],
98 source_drawtypes => [ map { $_ ? 'STACK' : 'AREA' } 0 .. $#veids ],
99 periods => [ qw/hour 6hour 12hour day week month year 3years/ ],
100 extended_legend => 1,
101 title => "memory > $too_small K",
102 width => 500,
103 height => 200,
104 );
105

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26