From ac05cd28d02947bb99ff02dd680a2d0e6b848c67 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 15 Jun 2017 20:17:51 +0200 Subject: Add a memory column to the host overview --- index.pl | 29 +++++++++++++++++++++++++++++ templates/main.html.ep | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/index.pl b/index.pl index b36f6a7..f72c38c 100644 --- a/index.pl +++ b/index.pl @@ -67,6 +67,26 @@ sub update_db { app->defaults( layout => 'default' ); app->attr( dbh => sub { return $dbh } ); +sub parse_df { + my ($df_raw) = @_; + + my %ret; + + for my $line ( split( /\n/, $df_raw ) ) { + my ( $fs, $size, $used, $available, $usepct, $mountpoint ) + = split( /\s+/, $line ); + $ret{$mountpoint} = { + filesystem => $fs, + size => $size, + used => $used, + available => $available, + use_percent => $usepct, + }; + } + + return \%ret; +} + get '/' => sub { my ($self) = @_; my $epoch = DateTime->now( time_zone => 'Europe/Berlin' )->epoch; @@ -81,6 +101,15 @@ get '/' => sub { for my $host ( @{$hostdata_raw} ) { my $hostref = { map { ( $fields[$_], $host->[$_] ) } ( 0 .. $#fields ) }; + + $hostref->{disks} = parse_df( $hostref->{df_raw} ); + delete $hostref->{df_raw}; + + if ( $hostref->{mem_available} and $hostref->{mem_total} ) { + $hostref->{mem_used_ratio} + = 1 - ( $hostref->{mem_available} / $hostref->{mem_total} ); + } + push( @hostdata, $hostref ); if ( $epoch - $hostref->{last_contact} < ( 31 * 60 ) ) { push( @curdata, $hostref ); diff --git a/templates/main.html.ep b/templates/main.html.ep index 6f786dc..d23644c 100644 --- a/templates/main.html.ep +++ b/templates/main.html.ep @@ -4,12 +4,19 @@ Hostname Load + Memory OS % for my $host (@{$active_hosts}) { <%= $host->{hostname} %> <%= $host->{load15} %> + % if (exists $host->{mem_used_ratio}) { + <%= sprintf('%.1f%%', $host->{mem_used_ratio} * 100) %> + % } + % else { + <%= sprintf('%d MB', $host->{mem_total} / 1024) %> + % } Debian <%= $host->{debian_version} %> % } -- cgit v1.2.3