7 |
use RRD::Simple; |
use RRD::Simple; |
8 |
use DateTime; |
use DateTime; |
9 |
|
|
10 |
|
my $debug = 0; |
11 |
|
my $zoom = 2; |
12 |
|
|
13 |
my $veids; |
my $veids; |
14 |
my $vsz; |
my $vsz; |
15 |
|
|
16 |
my $too_small = 64; # M |
my $too_small = 16; # M |
17 |
$too_small *= 1024; # k |
$too_small *= 1024; # k |
18 |
|
|
19 |
sub count { |
sub count { |
20 |
my $file = shift; |
my $file = shift; |
21 |
open(my $fh, '<', $file) || die "$file: $!"; |
open(my $fh, '<', $file) || die "$file: $!"; |
22 |
warn "# $file ", -s $file, $/; |
|
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>; |
my $cols = <$fh>; |
39 |
$cols =~ s/^\s+//; |
$cols =~ s/^\s+//; |
43 |
$cp->{$c[$_]} = $_ foreach 0 .. $#c; |
$cp->{$c[$_]} = $_ foreach 0 .. $#c; |
44 |
our @r; |
our @r; |
45 |
sub c { |
sub c { |
46 |
|
return $r[ $cp->{$_[0]} ]; # XXX speedup |
47 |
|
|
48 |
my $name = shift; |
my $name = shift; |
49 |
my $n = $cp->{$name}; |
my $n = $cp->{$name}; |
50 |
die "no column $name in ",dump( $cp ) unless defined $n; |
die "no column $name in ",dump( $cp ) unless defined $n; |
62 |
|
|
63 |
my $s = c('VSZ'); |
my $s = c('VSZ'); |
64 |
if ( $s < $too_small ) { |
if ( $s < $too_small ) { |
65 |
$vsz->{$file}->{$veid}+= $s * 1024; |
$vsz->{$t}->{$veid}+= $s * 1024; |
66 |
} else { |
} else { |
67 |
my $cmd = c('COMMAND'); |
my $cmd = c('COMMAND'); |
68 |
$cmd =~ s{-.+$}{}; |
$cmd =~ s{-.+$}{}; |
72 |
$cmd =~ s{\W+}{_}g; |
$cmd =~ s{\W+}{_}g; |
73 |
$veid .= '-' . $cmd; |
$veid .= '-' . $cmd; |
74 |
$veid = substr($veid,0,16); |
$veid = substr($veid,0,16); |
75 |
$vsz->{$file}->{$veid}+= $s * 1024; |
$vsz->{$t}->{$veid}+= $s * 1024; |
76 |
} |
} |
77 |
$veids->{$veid}++; |
$veids->{$veid}++; |
78 |
} |
} |
79 |
|
|
80 |
} |
} |
81 |
|
|
82 |
|
print STDERR "reading ps dumps"; |
83 |
|
|
84 |
count $_ foreach @ARGV; |
count $_ foreach @ARGV; |
85 |
|
|
86 |
print "VSZ: ",dump( $vsz ); |
#print "VSZ: ",dump( $vsz ); |
87 |
|
|
88 |
my @veids = keys %$veids; |
my @veids = keys %$veids; |
89 |
warn "# veids = ",dump( sort @veids ); |
warn "# veids = ",dump( sort @veids ); |
90 |
|
|
91 |
my $rrd = RRD::Simple->new( file => "ps.rrd" ); |
my $rrd_file = 'ps.rrd'; |
92 |
$rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids ); |
unlink $rrd_file if -e $rrd_file; |
93 |
|
|
94 |
foreach my $file ( sort keys %$vsz ) { |
my $rrd = RRD::Simple->new( file => $rrd_file ); |
95 |
my $t = (stat($file))[9]; |
$rrd->create( 'hour', map { ( $_ => 'GAUGE' ) } @veids ); |
|
if ( $file =~ m{(\d\d\d\d)-(\d\d)-(\d\d)/(\d\d)(\d\d)} ) { |
|
|
$t = new DateTime( |
|
|
year => $1, |
|
|
month => $2, |
|
|
day => $3, |
|
|
hour => $4, |
|
|
minute => $5, |
|
|
); |
|
|
warn "+ $t\n"; |
|
|
} |
|
96 |
|
|
97 |
#warn "## ",dump( %{ $vsz->{$file} } ); |
foreach my $t ( sort keys %$vsz ) { |
98 |
|
print STDERR "."; |
99 |
|
# warn "## ",dump( %{ $vsz->{$t} } ); |
100 |
|
|
101 |
eval { |
eval { |
102 |
$rrd->update($t->epoch, map { |
$rrd->update($t, map { |
103 |
( $_ => $vsz->{$file}->{$_} ) |
( $_ => $vsz->{$t}->{$_} ) |
104 |
} @veids ); |
} @veids ); |
105 |
}; |
}; |
106 |
warn "SKIP $t: $@\n" if $@; |
warn "SKIP $t: $@\n" if $@; |
112 |
periods => [ qw/hour 6hour 12hour day week month year 3years/ ], |
periods => [ qw/hour 6hour 12hour day week month year 3years/ ], |
113 |
extended_legend => 1, |
extended_legend => 1, |
114 |
title => "memory > $too_small K", |
title => "memory > $too_small K", |
115 |
width => 500, |
width => 500 * $zoom, |
116 |
height => 200, |
height => 200 * $zoom, |
117 |
); |
); |
118 |
|
|