/[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 10 - (show annotations)
Fri Jul 17 12:37:29 2009 UTC (10 years ago) by dpavlin
File MIME type: text/plain
File size: 2169 byte(s)
dump first letter of process or dot

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26