Skip to content

Commit

Permalink
fix issue:426 (Numbers are crazy in diskstats plugin after reboot)
Browse files Browse the repository at this point in the history
 * munin-monitoring#426

 * check /proc/uptime to detect system reboot
 * use uptime second instead of interval if uptime < interval
 * reset all previous status values to zero on reboot
  • Loading branch information
mittyorz committed Apr 26, 2015
1 parent 2540951 commit b966eb3
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions plugins/node.d.linux/diskstats.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use Munin::Plugin;
use MIME::Base64;
use Storable qw(nfreeze thaw);

use Data::Dumper;

# Hardcoded pollinterval of 300 seconds
my $poll_interval = 300;

Expand All @@ -30,10 +32,14 @@ need_multigraph();

# Handle munin 'autoconf' command
do_autoconf() if ( $ARGV[0] && $ARGV[0] eq 'autoconf' );
my ($debug) = 1 if ( $ARGV[0] && $ARGV[0] eq 'debug' );

# Fetch current counter values
my %cur_diskstats = fetch_device_counters();

# Fetch uptime to detect system reboot
my ($uptime) = fetch_uptime();

# Weed out unwanted devices
filter_device_list( \%cur_diskstats );

Expand All @@ -54,6 +60,10 @@ eval {
# Persist state from current run
add_new_state( time(), %cur_diskstats );

print "uptime => $uptime \n",
"prev_time => $prev_time \n",
if ($debug);

# Probably the first run for the given device, we need state to do our job,
# so let's wait for the next run.
exit if ( not defined $prev_time or not %prev_diskstats );
Expand All @@ -67,6 +77,21 @@ exit 0;
# SUBS #
########


# fetch_uptime
#
# read /proc/uptime and return it

sub fetch_uptime {
open my $FH, "<", '/proc/uptime' or return undef;
my $line = <$FH>;
chomp($line);
my @row = split(/\s+/, $line);
close $FH;

return @row;
}

# generate_multigraph_data
#
# Creates the data which is needed by munin's fetch command
Expand Down Expand Up @@ -180,6 +205,23 @@ sub calculate_values {
my $bytes_per_sector = 512;

my $interval = time() - $prev_time;

print "interval => $interval \n",
"prev_stats => ", Dumper( $prev_stats ),
if ($debug);
if ($uptime < $interval) {
# system has rebooted

$interval = $uptime;

# all values will be zero at system reboot
for my $entry ( keys %$prev_stats ) {
$prev_stats->{$entry} = 0;
}
}
print "interval => $interval \n",
"prev_stats => ", Dumper( $prev_stats ),
if ($debug);

my $read_ios = subtract_wrapping_numbers($cur_stats->{'rd_ios'}, $prev_stats->{'rd_ios'});
my $write_ios = subtract_wrapping_numbers($cur_stats->{'wr_ios'}, $prev_stats->{'wr_ios'});
Expand Down

0 comments on commit b966eb3

Please sign in to comment.