/[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 6 - (hide annotations)
Thu Jul 16 19:13:01 2009 UTC (14 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 2184 byte(s)
create DateTime just once and record timestamps

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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26