Skip to content

Commit

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

diskstats ver 2.0.22 and later gives weird numbers on some entries after system reboot

 - how I fix
  - check /proc/uptime to detect system reboot
  - use uptime second instead of interval if uptime < interval
  - reset all previous status values to zero if uptime < interval

fundamental solution should be as munin-monitoring#426 (comment)
but it might be significant rewrite
  • Loading branch information
mittyorz committed Apr 26, 2015
2 parents 1a8185e + dc35c68 commit 9c11743
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions plugins/node.d.linux/diskstats.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ do_autoconf() if ( $ARGV[0] && $ARGV[0] eq 'autoconf' );
# 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 Down Expand Up @@ -67,6 +70,20 @@ 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 @@ -181,6 +198,17 @@ sub calculate_values {

my $interval = time() - $prev_time;

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;
}
}

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 9c11743

Please sign in to comment.