[collectd] [PATCH] collection3: add module Uptime

Wolfgang Kroener wk at azog.de
Wed Jun 9 11:26:53 CEST 2010


Create a nice graph from the uptime-plugin.

Heavily based on an example by Marco Chiappero on the
collectd-mailinglist:
http://mailman.verplant.org/pipermail/collectd/2009-August/003028.html
---
 contrib/collection3/etc/collection.conf            |    3 +
 .../collection3/lib/Collectd/Graph/Type/Uptime.pm  |  141 ++++++++++++++++++++
 2 files changed, 144 insertions(+), 0 deletions(-)
 create mode 100644 contrib/collection3/lib/Collectd/Graph/Type/Uptime.pm

diff --git a/contrib/collection3/etc/collection.conf b/contrib/collection3/etc/collection.conf
index e56017e..46314c5 100644
--- a/contrib/collection3/etc/collection.conf
+++ b/contrib/collection3/etc/collection.conf
@@ -669,4 +669,7 @@ GraphWidth 400
   RRDVerticalLabel "W"
   RRDFormat "%4.1lfW"
 </Type>
+<Type uptime>
+  Module Uptime
+</Type>
 # vim: set sw=2 sts=2 et syntax=apache fileencoding=utf-8 :
diff --git a/contrib/collection3/lib/Collectd/Graph/Type/Uptime.pm b/contrib/collection3/lib/Collectd/Graph/Type/Uptime.pm
new file mode 100644
index 0000000..cc46059
--- /dev/null
+++ b/contrib/collection3/lib/Collectd/Graph/Type/Uptime.pm
@@ -0,0 +1,141 @@
+package Collectd::Graph::Type::Uptime;
+
+# Heavily based on an example by Marco Chiappero on the collectd-mailinglist:
+# http://mailman.verplant.org/pipermail/collectd/2009-August/003028.html
+
+use strict;
+use warnings;
+use base ('Collectd::Graph::Type');
+
+use Collectd::Graph::Common (qw($ColorCanvas ident_to_filename));
+
+return (1);
+
+sub new
+{
+  my $pkg = shift;
+  my $obj = Collectd::Graph::Type->new (@_);
+  $obj->{'data_sources'} = [qw(value)];
+  $obj->{'rrd_opts'} = ['-v', 'Days'];
+  $obj->{'rrd_title'} = 'System Uptime';
+  $obj->{'rrd_format'} = '%.2lf';
+  $obj->{'colors'} = [qw(00ff00 0000ff ff0000)];
+
+  return (bless ($obj, $pkg));
+} # new
+
+
+sub getRRDArgs
+{
+  my $obj = shift;
+  my $index = shift;
+
+  my $ident = $obj->{'files'}[$index];
+  if (!$ident)
+  {
+    cluck ("Invalid index: $index");
+    return;
+  }
+  my $filename = ident_to_filename ($ident);
+  $filename =~ s#:#\\:#g;
+
+  my $red = 'DA1F3D';
+  my $yellow = 'F17742';
+  my $orange = 'FCE053';
+  my $blue = '6CABE7';
+  my $grey = '66666640';
+
+  return (['-t', 'System Uptime', '-v', 'Days',
+    "DEF:uptime_sec_avg=${filename}:value:AVERAGE",
+    "DEF:uptime_sec_max=${filename}:value:MAX",
+    'CDEF:uptime_no_unkn=uptime_sec_max,UN,0,uptime_sec_max,IF',
+    'CDEF:uptime_peaks=uptime_no_unkn,PREV(uptime_no_unkn),LT,PREV(uptime_no_unkn),UNKN,IF',
+    'VDEF:minimum_uptime_secs=uptime_peaks,MINIMUM',
+    'CDEF:minimum_uptime_graph=uptime_sec_max,minimum_uptime_secs,EQ,uptime_sec_max,86400,/,0,IF',
+    'CDEF:minimum_uptime_days=uptime_sec_max,minimum_uptime_secs,EQ,uptime_sec_max,86400,/,FLOOR,0,IF',
+    'CDEF:minimum_uptime_hours=uptime_sec_max,minimum_uptime_secs,EQ,uptime_sec_max,86400,%,3600,/,FLOOR,0,IF',
+    'CDEF:minimum_uptime_mins=uptime_sec_max,minimum_uptime_secs,EQ,uptime_sec_max,86400,%,3600,%,60,/,FLOOR,0,IF',
+    'VDEF:min_uptime_graph=minimum_uptime_graph,MAXIMUM',
+    'VDEF:min_uptime_days=minimum_uptime_days,MAXIMUM',
+    'VDEF:min_uptime_hours=minimum_uptime_hours,MAXIMUM',
+    'VDEF:min_uptime_mins=minimum_uptime_mins,MAXIMUM',
+    'VDEF:maximum_uptime_secs=uptime_sec_max,MAXIMUM',
+    'CDEF:maximum_uptime_graph=uptime_sec_max,maximum_uptime_secs,EQ,uptime_sec_max,86400,/,0,IF',
+    'CDEF:maximum_uptime_days=uptime_sec_max,maximum_uptime_secs,EQ,uptime_sec_max,86400,/,FLOOR,0,IF',
+    'CDEF:maximum_uptime_hours=uptime_sec_max,maximum_uptime_secs,EQ,uptime_sec_max,86400,%,3600,/,FLOOR,0,IF',
+    'CDEF:maximum_uptime_mins=uptime_sec_max,maximum_uptime_secs,EQ,uptime_sec_max,86400,%,3600,%,60,/,FLOOR,0,IF',
+    'VDEF:max_uptime_graph=maximum_uptime_graph,MAXIMUM',
+    'VDEF:max_uptime_days=maximum_uptime_days,MAXIMUM',
+    'VDEF:max_uptime_hours=maximum_uptime_hours,MAXIMUM',
+    'VDEF:max_uptime_mins=maximum_uptime_mins,MAXIMUM',
+    'VDEF:average_uptime_secs=uptime_sec_max,AVERAGE',
+    'CDEF:average_uptime_graph=uptime_sec_max,POP,average_uptime_secs,86400,/',
+    'CDEF:average_uptime_days=uptime_sec_max,POP,average_uptime_secs,86400,/,FLOOR',
+    'CDEF:average_uptime_hours=uptime_sec_max,POP,average_uptime_secs,86400,%,3600,/,FLOOR',
+    'CDEF:average_uptime_mins=uptime_sec_max,POP,average_uptime_secs,86400,%,3600,%,60,/,FLOOR',
+    'VDEF:avg_uptime_days=average_uptime_days,LAST',
+    'VDEF:avg_uptime_hours=average_uptime_hours,LAST',
+    'VDEF:avg_uptime_mins=average_uptime_mins,LAST',
+    'CDEF:current_uptime_graph=uptime_sec_max,86400,/',
+    'CDEF:current_uptime_days=uptime_sec_max,86400,/,FLOOR',
+    'CDEF:current_uptime_hours=uptime_sec_max,86400,%,3600,/,FLOOR',
+    'CDEF:current_uptime_mins=uptime_sec_max,86400,%,3600,%,60,/,FLOOR',
+    'VDEF:curr_uptime_days=current_uptime_days,LAST',
+    'VDEF:curr_uptime_hours=current_uptime_hours,LAST',
+    'VDEF:curr_uptime_mins=current_uptime_mins,LAST',
+    'CDEF:time=uptime_sec_max,POP,TIME',
+    'VDEF:start=time,FIRST',
+    'VDEF:last=time,LAST',
+    'CDEF:time_window=uptime_sec_max,UN,0,uptime_sec_max,IF,POP,TIME',
+    'CDEF:time_window2=PREV(time_window)',
+    'VDEF:window_start=time_window,FIRST',
+    'VDEF:window_last=time_window,LAST',
+    'CDEF:delta=uptime_sec_max,POP,window_last,window_start,-',
+    'CDEF:system_on_un=uptime_sec_avg,UN,UNKN,1,IF',
+    'CDEF:system_on=PREV(system_on_un),1,EQ,system_on_un,POP,TIME,window_last,EQ,*,1,system_on_un,IF',
+    'VDEF:new_average_on=system_on,AVERAGE',
+    'VDEF:total_uptime_secs=system_on_un,TOTAL',
+    'CDEF:total_uptime_days=uptime_sec_max,POP,total_uptime_secs,86400,/,FLOOR',
+    'CDEF:total_uptime_hours=uptime_sec_max,POP,total_uptime_secs,86400,%,3600,/,FLOOR',
+    'CDEF:total_uptime_mins=uptime_sec_max,POP,total_uptime_secs,86400,%,3600,%,60,/,FLOOR',
+    'VDEF:tot_uptime_days=total_uptime_days,LAST',
+    'VDEF:tot_uptime_hours=total_uptime_hours,LAST',
+    'VDEF:tot_uptime_mins=total_uptime_mins,LAST',
+    'CDEF:temp_perc_on=uptime_sec_max,POP,total_uptime_secs,delta,/,100,*',
+    'VDEF:new_perc_on=temp_perc_on,LAST',
+    'COMMENT:\s',
+    "AREA:current_uptime_graph#${grey}",
+    "LINE1:current_uptime_graph#${yellow}:Current",
+    'GPRINT:curr_uptime_days:%5.0lf days',
+    'GPRINT:curr_uptime_hours:%3.0lf hours',
+    'GPRINT:curr_uptime_mins:%3.0lf mins \tdate\:',
+    'GPRINT:curr_uptime_mins:%x:strftime',
+    'COMMENT:\n',
+    "LINE1:max_uptime_graph#${red}:Maximum",
+    'GPRINT:max_uptime_days:%5.0lf days',
+    'GPRINT:max_uptime_hours:%3.0lf hours',
+    'GPRINT:max_uptime_mins:%3.0lf mins \tdate\:',
+    'GPRINT:max_uptime_mins:%x:strftime',
+    'COMMENT:\n',
+    "HRULE:min_uptime_graph#${orange}:Minimum",
+    'GPRINT:min_uptime_days:%5.0lf days',
+    'GPRINT:min_uptime_hours:%3.0lf hours',
+    'GPRINT:min_uptime_mins:%3.0lf mins \tdate\:',
+    'GPRINT:min_uptime_mins:%x:strftime',
+    'COMMENT:\n',
+    "LINE1:average_uptime_graph#${blue}:Average",
+    'GPRINT:avg_uptime_days:%5.0lf days',
+    'GPRINT:avg_uptime_hours:%3.0lf hours',
+    'GPRINT:avg_uptime_mins:%3.0lf mins',
+    'COMMENT:\n',
+    "COMMENT:Total    ",
+    'GPRINT:tot_uptime_days:%5.0lf days',
+    'GPRINT:tot_uptime_hours:%3.0lf hours',
+    'GPRINT:tot_uptime_mins:%3.0lf mins  ',
+    'GPRINT:new_perc_on:%3.2lf%% up',
+    'COMMENT:\n',
+    'COMMENT:\s']);
+
+} # sub getRRDArgs
+
+# vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
-- 
1.7.1




More information about the collectd mailing list