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

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 $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 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 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 $vsz->{$t}->{$veid}+= $s * 1024;
64 } 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 $vsz->{$t}->{$veid}+= $s * 1024;
74 }
75 $veids->{$veid}++;
76 }
77
78 }
79
80 print STDERR "reading ps dumps";
81
82 count $_ foreach @ARGV;
83
84 #print "VSZ: ",dump( $vsz );
85
86 my @veids = keys %$veids;
87 warn "# veids = ",dump( sort @veids );
88
89 my $rrd_file = 'ps.rrd';
90 unlink $rrd_file if -e $rrd_file;
91
92 my $rrd = RRD::Simple->new( file => $rrd_file );
93 $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );
94
95 foreach my $t ( sort keys %$vsz ) {
96 print STDERR ".";
97 # warn "## ",dump( %{ $vsz->{$t} } );
98
99 eval {
100 $rrd->update($t, map {
101 ( $_ => $vsz->{$t}->{$_} )
102 } @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 width => 500 * $zoom,
114 height => 200 * $zoom,
115 );
116

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26