summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-06-15 20:17:51 +0200
committerDaniel Friesel <derf@finalrewind.org>2017-06-15 20:17:51 +0200
commitac05cd28d02947bb99ff02dd680a2d0e6b848c67 (patch)
treea23a465242921e131ccddd1da3a58e1958dcefc1
parent061d6b06cb4f6a784ed17469608bd9dad94c0b6b (diff)
Add a memory column to the host overview
-rw-r--r--index.pl29
-rw-r--r--templates/main.html.ep7
2 files changed, 36 insertions, 0 deletions
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 @@
<tr>
<th>Hostname</th>
<th>Load</th>
+ <th>Memory</th>
<th>OS</th>
</tr>
% for my $host (@{$active_hosts}) {
<tr>
<td><%= $host->{hostname} %></td>
<td><%= $host->{load15} %></td>
+ % if (exists $host->{mem_used_ratio}) {
+ <td><%= sprintf('%.1f%%', $host->{mem_used_ratio} * 100) %></td>
+ % }
+ % else {
+ <td><%= sprintf('%d MB', $host->{mem_total} / 1024) %></td>
+ % }
<td>Debian <%= $host->{debian_version} %></td>
</tr>
% }