/[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 11 - (show annotations)
Fri Jul 17 13:25:34 2009 UTC (14 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 2472 byte(s)
added command-line options

--debug
--zoom 2
--veid 42
--size 64

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26