/[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 8 - (show annotations)
Thu Jul 16 19:20:07 2009 UTC (14 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 2228 byte(s)
speedup column extractor from 8.57s to 5.45s for 549413 iterations

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 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 $veid =~ s/^0$/hw/;
62
63 my $s = c('VSZ');
64 if ( $s < $too_small ) {
65 $vsz->{$t}->{$veid}+= $s * 1024;
66 } else {
67 my $cmd = c('COMMAND');
68 $cmd =~ s{-.+$}{};
69 $cmd =~ s{^/\S+/(\w+?)}{$1};
70 $cmd =~ s{^\w+ /\S+/(\w+?)}{$1};
71 $cmd =~ s{:?\s+.*$}{};
72 $cmd =~ s{\W+}{_}g;
73 $veid .= '-' . $cmd;
74 $veid = substr($veid,0,16);
75 $vsz->{$t}->{$veid}+= $s * 1024;
76 }
77 $veids->{$veid}++;
78 }
79
80 }
81
82 print STDERR "reading ps dumps";
83
84 count $_ foreach @ARGV;
85
86 #print "VSZ: ",dump( $vsz );
87
88 my @veids = keys %$veids;
89 warn "# veids = ",dump( sort @veids );
90
91 my $rrd_file = 'ps.rrd';
92 unlink $rrd_file if -e $rrd_file;
93
94 my $rrd = RRD::Simple->new( file => $rrd_file );
95 $rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids );
96
97 foreach my $t ( sort keys %$vsz ) {
98 print STDERR ".";
99 # warn "## ",dump( %{ $vsz->{$t} } );
100
101 eval {
102 $rrd->update($t, map {
103 ( $_ => $vsz->{$t}->{$_} )
104 } @veids );
105 };
106 warn "SKIP $t: $@\n" if $@;
107 }
108
109 $rrd->graph(
110 sources => [ sort @veids ],
111 source_drawtypes => [ map { $_ ? 'STACK' : 'AREA' } 0 .. $#veids ],
112 periods => [ qw/hour 6hour 12hour day week month year 3years/ ],
113 extended_legend => 1,
114 title => "memory > $too_small K",
115 width => 500 * $zoom,
116 height => 200 * $zoom,
117 );
118

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26