/[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

Annotation of /ps2rrd.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (hide annotations)
Fri Jul 17 13:25:34 2009 UTC (10 years, 4 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 dpavlin 2 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     use Data::Dump qw/dump/;
7     use RRD::Simple;
8 dpavlin 9 use POSIX qw/mktime/;
9 dpavlin 11 use Getopt::Long;
10 dpavlin 2
11 dpavlin 6 my $debug = 0;
12     my $zoom = 2;
13    
14 dpavlin 11 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 dpavlin 2 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 dpavlin 9 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 dpavlin 6
36     warn "# $file ", -s $file, " bytes [$t]\n" if $debug;
37    
38 dpavlin 2 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 dpavlin 8 return $r[ $cp->{$_[0]} ]; # XXX speedup
47    
48 dpavlin 2 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 dpavlin 11 next if defined $only_veid && $only_veid != $veid;
62     $veid =~ s/^0$/0-hw/;
63 dpavlin 2
64     my $s = c('VSZ');
65     if ( $s < $too_small ) {
66 dpavlin 6 $vsz->{$t}->{$veid}+= $s * 1024;
67 dpavlin 10 print STDERR ".";
68 dpavlin 2 } 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 dpavlin 6 $vsz->{$t}->{$veid}+= $s * 1024;
78 dpavlin 10 print STDERR substr($cmd,0,1);
79 dpavlin 2 }
80     $veids->{$veid}++;
81     }
82    
83     }
84    
85 dpavlin 11 print STDERR "parsing ps with grouping < $too_small k";
86 dpavlin 6
87 dpavlin 2 count $_ foreach @ARGV;
88    
89 dpavlin 6 #print "VSZ: ",dump( $vsz );
90 dpavlin 2
91 dpavlin 11 my @veids = sort keys %$veids;
92     warn "# veids = ",dump( @veids );
93 dpavlin 2
94 dpavlin 6 my $rrd_file = 'ps.rrd';
95     unlink $rrd_file if -e $rrd_file;
96    
97 dpavlin 11 my @t = sort keys %$vsz;
98    
99     print "\ndrawing $#t intervals ", $t[0], " - ", $t[$#t];
100    
101 dpavlin 6 my $rrd = RRD::Simple->new( file => $rrd_file );
102 dpavlin 2 $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );
103    
104 dpavlin 11 foreach my $t ( @t ) {
105 dpavlin 6 print STDERR ".";
106     # warn "## ",dump( %{ $vsz->{$t} } );
107 dpavlin 2
108     eval {
109 dpavlin 6 $rrd->update($t, map {
110     ( $_ => $vsz->{$t}->{$_} )
111 dpavlin 2 } @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 dpavlin 6 width => 500 * $zoom,
123     height => 200 * $zoom,
124 dpavlin 2 );
125    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26