Merge branch 'collectd-4.5' into collectd-4.6
authorFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 14 Mar 2009 17:52:19 +0000 (18:52 +0100)
committerFlorian Forster <octo@leeloo.lan.home.verplant.org>
Sat, 14 Mar 2009 17:52:19 +0000 (18:52 +0100)
contrib/collection3/bin/graph.cgi
contrib/collection3/bin/index.cgi
contrib/collection3/bin/json.cgi
contrib/collection3/etc/collection.conf
contrib/collection3/lib/Collectd/Graph/Common.pm
contrib/collection3/lib/Collectd/Graph/Type/PsCputime.pm [new file with mode: 0644]
contrib/collection3/lib/Collectd/Graph/Type/TableSize.pm [new file with mode: 0644]
contrib/collection3/lib/Collectd/Graph/Type/Wirkleistung.pm [new file with mode: 0644]
src/common.c
src/liboping/test_liboping.c [deleted file]
src/memory.c

index 7fe2087..c096dc9 100755 (executable)
@@ -20,6 +20,8 @@ our $Debug = param ('debug');
 our $Begin = param ('begin');
 our $End = param ('end');
 our $GraphWidth = param ('width');
+our $GraphHeight = param ('height');
+our $Index = param ('index') || 0;
 our $OutputFormat = 'PNG';
 our $ContentType = 'image/png';
 
@@ -58,6 +60,16 @@ if (!$GraphWidth)
   $GraphWidth = gc_get_scalar ('GraphWidth', 400);
 }
 
+if ($GraphHeight)
+{
+  $GraphHeight =~ s/\D//g;
+}
+
+if (!$GraphHeight)
+{
+  $GraphHeight = gc_get_scalar ('GraphHeight', 100);
+}
+
 { # Sanitize begin and end times
   $End ||= 0;
   $Begin ||= 0;
@@ -167,7 +179,7 @@ if ($Debug)
   print "\$expires = $expires;\n";
 }
 
-my $args = $obj->getRRDArgs (0);
+my $args = $obj->getRRDArgs (0 + $Index);
 
 if ($Debug)
 {
@@ -190,7 +202,7 @@ else
   }
 
   $| = 1;
-  RRDs::graph ('-', '-a', $OutputFormat, '--width', $GraphWidth, @timesel, @$args);
+  RRDs::graph ('-', '-a', $OutputFormat, '--width', $GraphWidth, '--height', $GraphHeight, @timesel, @$args);
   if (my $err = RRDs::error ())
   {
     print STDERR "RRDs::graph failed: $err\n";
index be20928..ba5b48a 100755 (executable)
@@ -20,6 +20,7 @@ use warnings;
 use lib ('../lib');
 use utf8;
 
+use Carp (qw(cluck confess));
 use FindBin ('$RealBin');
 use CGI (':cgi');
 use CGI::Carp ('fatalsToBrowser');
@@ -145,7 +146,7 @@ HTML
     <title>collection.cgi, Version 3</title>
     <link rel="icon" href="../share/shortcut-icon.png" type="image/png" />
     <link rel="stylesheet" href="../share/style.css" type="text/css" />
-    <script type="text/javascript" src="../share/navigate.js" />
+    <script type="text/javascript" src="../share/navigate.js"></script>
   </head>
   <body onload="nav_init ($begin, $end);">
 HTML
index c2af61c..99e2703 100755 (executable)
@@ -24,6 +24,7 @@ use FindBin ('$RealBin');
 use CGI (':cgi');
 use CGI::Carp ('fatalsToBrowser');
 use URI::Escape ('uri_escape');
+use JSON ('objToJson');
 
 use Data::Dumper;
 
@@ -33,6 +34,7 @@ use Collectd::Graph::Common (qw(get_all_hosts get_files_for_host type_to_module_
 use Collectd::Graph::Type ();
 
 our $Debug = param ('debug') ? 1 : 0;
+our $ServerName = 'collect.noris.net';
 
 gc_read_config ("$RealBin/../etc/collection.conf");
 
@@ -45,11 +47,11 @@ else
   print "Content-Type: application/json; charset=utf-8\n\n";
 }
 
-print "{\n";
-
+my $obj = {};
 my @hosts = get_all_hosts ();
 for (my $i = 0; $i < @hosts; $i++)
 {
+  my $host_obj = {};
   my $host = $hosts[$i];
   my $files = get_files_for_host ($host);
   my %graphs = ();
@@ -75,46 +77,31 @@ for (my $i = 0; $i < @hosts; $i++)
     $graphs{$type}->addFiles ($file);
   } # for (@$files)
 
-  print qq(  "$host":\n  {\n);
+  #print qq(  ") . objToJson ({ foo => 123 }) . qq(":\n  {\n);
 
   @graphs = keys %graphs;
   for (my $j = 0; $j < @graphs; $j++)
   {
     my $type = $graphs[$j];
     my $graphs_num = $graphs{$type}->getGraphsNum ();
-    my @args = ();
 
-    for (my $k = 0; $k < $graphs_num; $k++)
+    if (!defined ($host_obj->{$type}))
     {
-      my $args = $graphs{$type}->getGraphArgs ($k);
-      my $url = 'http://' . $ENV{'SERVER_NAME'} . "/cgi-bin/graph.cgi?" . $args;
-      push (@args, $url);
+      $host_obj->{$type} = [];
     }
 
-    print qq(    "$type": [ )
-    . join (', ', map { qq("$_") } (@args));
-
-    if ($j == (@graphs - 1))
-    {
-      print qq( ]\n);
-    }
-    else
+    for (my $k = 0; $k < $graphs_num; $k++)
     {
-      print qq( ],\n);
+      my $args = $graphs{$type}->getGraphArgs ($k);
+      my $url = "http://$ServerName/cgi-bin/collection3/bin/graph.cgi?" . $args;
+      push (@{$host_obj->{$type}}, $url);
     }
   } # for (keys %graphs)
 
-  if ($i == (@hosts - 1))
-  {
-    print qq(  }\n);
-  }
-  else
-  {
-    print qq(  },\n\n);
-  }
+  $obj->{$host} = $host_obj;
 } # for (my $i = 0; $i < @hosts; $i++)
 
-print "}\n";
+print STDOUT objToJson ($obj, { pretty => 1, indent => 2 });
 
 exit (0);
 
index b7e76b2..9497d8e 100644 (file)
@@ -124,6 +124,13 @@ GraphWidth 400
   RRDFormat "%5.1lf%ss"
   Scale 0.001
 </Type>
+<Type dns_opcode>
+  DataSources value
+  DSName "value Queries/s"
+  RRDTitle "DNS Opcode {type_instance}"
+  RRDVerticalLabel "Queries/s"
+  RRDFormat "%6.1lf"
+</Type>
 <Type entropy>
   DataSources entropy
   DSName entropy Entropy bits
@@ -195,7 +202,7 @@ GraphWidth 400
   DataSources rx tx
   DSName rx RX
   DSName tx TX
-  RRDTitle "Interface Traffic ({type_instance})"
+  RRDTitle "Interface Traffic ({instance})"
   RRDVerticalLabel "Bits per second"
 # RRDOptions ...
   RRDFormat "%5.1lf%s"
@@ -211,6 +218,16 @@ GraphWidth 400
 # RRDOptions ...
   RRDFormat "%5.1lf%s"
 </Type>
+<Type io_octets>
+  Module GenericIO
+  DataSources rx tx
+  DSName "rx Read   "
+  DSName "tx Written"
+  RRDTitle "IO Traffic ({instance})"
+  RRDVerticalLabel "Bytes per second"
+# RRDOptions ...
+  RRDFormat "%5.1lf%s"
+</Type>
 <Type ipt_bytes>
   DataSources value
   DSName value Bytes/s
@@ -247,12 +264,14 @@ GraphWidth 400
   DSName     "free Free    "
   DSName   "cached Cached  "
   DSName "buffered Buffered"
+  DSName   "locked Locked  "
   DSName     "used Used    "
   #Order used buffered cached free
   Order free cached buffered used
   Color free      00e000
   Color cached    0000ff
   Color buffered  ffb000
+  Color locked    ff00ff
   Color used      ff0000
 </Type>
 <Type mysql_commands>
@@ -262,6 +281,7 @@ GraphWidth 400
   RRDVerticalLabel "Invocations"
   RRDFormat "%6.2lf"
 
+
   DSName admin_commands admin_commands
   DSName alter_table alter_table
   DSName begin begin
@@ -399,6 +419,9 @@ GraphWidth 400
   RRDFormat "%6.2lf%sW"
   Color value 008080
 </Type>
+<Type ps_cputime>
+  Module PsCputime
+</Type>
 <Type ps_rss>
   DataSources value
   DSName value RSS
@@ -442,6 +465,15 @@ GraphWidth 400
   Color cached    0000ff
   Color used      ff0000
 </Type>
+<Type table_size>
+  Module TableSize
+  DataSources value
+  DSName value Bytes
+  RRDTitle "Table size ({instance})"
+  RRDVerticalLabel "Size [Bytes]"
+# RRDOptions ...
+  RRDFormat "%5.1lf%s"
+</Type>
 <Type tcp_connections>
   Module GenericStacked
   DataSources value
@@ -485,4 +517,12 @@ GraphWidth 400
   RRDFormat "%4.1lfV"
   Color value f00000
 </Type>
+<Type wirkleistung>
+  Module Wirkleistung
+  DataSources kWh
+  DSName value Wh
+  RRDTitle "Watt"
+  RRDVerticalLabel "W"
+  RRDFormat "%4.1lfW"
+</Type>
 # vim: set sw=2 sts=2 et syntax=apache fileencoding=latin-1 :
index 0deefd6..b445c8e 100644 (file)
@@ -36,6 +36,7 @@ $ColorHalfBlue = 'B7B7F7';
   get_timespan_selection
   get_host_selection
   get_plugin_selection
+  get_random_color
   get_faded_color
   sort_idents_by_type_instance
   type_to_module_name
@@ -516,6 +517,26 @@ sub _color_to_string
   return (sprintf ('%02hx%02hx%02hx', map { int (255.0 * $_) } @{$_[0]}));
 } # _color_to_string
 
+sub get_random_color
+{
+  my ($r, $g, $b) = (rand (), rand ());
+  my $min = 0.0;
+  my $max = 1.0;
+
+  if (($r + $g) < 1.0)
+  {
+    $min = 1.0 - ($r + $g);
+  }
+  else
+  {
+    $max = 2.0 - ($r + $g);
+  }
+
+  $b = $min + (rand () * ($max - $min));
+
+  return (_color_to_string ([$r, $g, $b]));
+} # get_random_color
+
 sub get_faded_color
 {
   my $fg = shift;
diff --git a/contrib/collection3/lib/Collectd/Graph/Type/PsCputime.pm b/contrib/collection3/lib/Collectd/Graph/Type/PsCputime.pm
new file mode 100644 (file)
index 0000000..b0a8f9a
--- /dev/null
@@ -0,0 +1,97 @@
+package Collectd::Graph::Type::PsCputime;
+
+# Copyright (C) 2008,2009  Florian octo Forster <octo at verplant.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; only version 2 of the License is applicable.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+use strict;
+use warnings;
+use base ('Collectd::Graph::Type');
+
+use Collectd::Graph::Common (qw(ident_to_filename get_faded_color));
+
+return (1);
+
+sub getDataSources
+{
+  return ([qw(syst user)]);
+} # getDataSources
+
+sub new
+{
+  my $pkg = shift;
+  my $obj = Collectd::Graph::Type->new (@_);
+  $obj->{'data_sources'} = [qw(syst user)];
+  $obj->{'rrd_opts'} = ['-v', 'CPU time [s]', '-l', '0'];
+  $obj->{'rrd_title'} = 'CPU time used by {plugin_instance}';
+  $obj->{'rrd_format'} = '%5.1lf';
+  $obj->{'colors'} = [qw(00b000 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 $faded_blue = get_faded_color ('0000ff');
+  my $faded_red = get_faded_color ('ff0000');
+
+  return (['-t', $obj->getTitle (), @{$obj->{'rrd_opts'}},
+    "DEF:user_min_raw=${filename}:user:MIN",
+    "DEF:user_avg_raw=${filename}:user:AVERAGE",
+    "DEF:user_max_raw=${filename}:user:MAX",
+    "DEF:syst_min_raw=${filename}:syst:MIN",
+    "DEF:syst_avg_raw=${filename}:syst:AVERAGE",
+    "DEF:syst_max_raw=${filename}:syst:MAX",
+    "CDEF:user_min=0.000001,user_min_raw,*",
+    "CDEF:user_avg=0.000001,user_avg_raw,*",
+    "CDEF:user_max=0.000001,user_max_raw,*",
+    "CDEF:syst_min=0.000001,syst_min_raw,*",
+    "CDEF:syst_avg=0.000001,syst_avg_raw,*",
+    "CDEF:syst_max=0.000001,syst_max_raw,*",
+    "VDEF:v_user_min=user_min,MINIMUM",
+    "VDEF:v_user_avg=user_avg,AVERAGE",
+    "VDEF:v_user_max=user_max,MAXIMUM",
+    "VDEF:v_user_lst=syst_avg,LAST",
+    "VDEF:v_syst_min=syst_min,MINIMUM",
+    "VDEF:v_syst_avg=syst_avg,AVERAGE",
+    "VDEF:v_syst_max=syst_max,MAXIMUM",
+    "VDEF:v_syst_lst=syst_avg,LAST",
+    "CDEF:user_stack=syst_avg,user_avg,+",
+    "AREA:user_stack#${faded_blue}",
+    'LINE1:user_stack#0000ff:User  ',
+    'GPRINT:v_user_min:%5.1lf%ss Min,',
+    'GPRINT:v_user_avg:%5.1lf%ss Avg,',
+    'GPRINT:v_user_max:%5.1lf%ss Max,',
+    'GPRINT:v_user_lst:%5.1lf%ss Last\l',
+    "AREA:syst_avg#${faded_red}",
+    'LINE1:syst_avg#ff0000:System',
+    'GPRINT:v_syst_min:%5.1lf%ss Min,',
+    'GPRINT:v_syst_avg:%5.1lf%ss Avg,',
+    'GPRINT:v_syst_max:%5.1lf%ss Max,',
+    'GPRINT:v_syst_lst:%5.1lf%ss Last\l']);
+} # getRRDArgs
+
+# vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
diff --git a/contrib/collection3/lib/Collectd/Graph/Type/TableSize.pm b/contrib/collection3/lib/Collectd/Graph/Type/TableSize.pm
new file mode 100644 (file)
index 0000000..5ad8ae0
--- /dev/null
@@ -0,0 +1,236 @@
+package Collectd::Graph::Type::TableSize;
+
+# Copyright (C) 2008,2009  Florian octo Forster <octo at verplant.org>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; only version 2 of the License is applicable.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+use strict;
+use warnings;
+use base ('Collectd::Graph::Type');
+
+use Collectd::Graph::Common (qw($ColorCanvas $ColorFullBlue $ColorHalfBlue
+  ident_to_filename sanitize_type_instance
+  get_random_color sort_idents_by_type_instance));
+
+use RRDs ();
+
+return (1);
+
+sub _get_last_value
+{
+  my $ident = shift;
+  my $value = undef;
+  my $filename = ident_to_filename ($ident);
+  my ($start ,$step ,$names ,$data) = RRDs::fetch ($filename, 'AVERAGE', '-s', '-3600');
+  if (my $errmsg = RRDs::error ())
+  {
+    print STDERR "RRDs::fetch ($filename) failed: $errmsg\n";
+    return;
+  }
+
+  for (@$data)
+  {
+    my $line = $_;
+
+    for (@$line)
+    {
+      my $ds = $_;
+
+      if (defined ($ds))
+      {
+       $value = $ds;
+      }
+    }
+  } # for (@$data)
+
+  return ($value);
+} # _get_last_value
+
+sub getLastValues
+{
+  my $obj = shift;
+  my $last_value = {};
+
+  if (exists ($obj->{'last_value'}))
+  {
+    return ($obj->{'last_value'});
+  }
+
+  for (@{$obj->{'files'}})
+  {
+    my $file = $_;
+
+    $last_value->{$file} = _get_last_value ($file);
+  }
+  $obj->{'last_value'} = $last_value;
+  return ($obj->{'last_value'});
+} # getLastValues
+
+sub _group_files
+{
+  my $obj = shift;
+  my $data = [];
+  my @files;
+  my $last_values;
+
+  $last_values = $obj->getLastValues ();
+
+  @files = sort
+  { 
+    if (!defined ($last_values->{$a}) && !defined ($last_values->{$b}))
+    {
+      return (0);
+    }
+    elsif (!defined ($last_values->{$a}))
+    {
+      return (1);
+    }
+    elsif (!defined ($last_values->{$b}))
+    {
+      return (-1);
+    }
+    else
+    {
+      return ($last_values->{$a} <=> $last_values->{$b});
+    }
+  } (@{$obj->{'files'}});
+
+  for (my $i = 0; $i < @files; $i++)
+  {
+    my $file = $files[$i];
+    my $j = int ($i / 10);
+
+    $data->[$j] ||= [];
+    push (@{$data->[$j]}, $file);
+  }
+
+  return ($data);
+} # _group_files
+
+sub getGraphsNum
+{
+  my $obj = shift;
+  my $group = _group_files ($obj);
+
+  return (0 + @$group);
+}
+
+sub getRRDArgs
+{
+  my $obj = shift;
+  my $index = shift;
+
+  my $group = _group_files ($obj);
+
+  my $rrd_opts = $obj->{'rrd_opts'} || [];
+  my $format = $obj->{'rrd_format'} || '%5.1lf';
+
+  my $idents = $group->[$index];
+  my $ds_name_len = 0;
+
+  my $ds = $obj->getDataSources ();
+  if (!$ds)
+  {
+    confess ("obj->getDataSources failed.");
+  }
+  if (@$ds != 1)
+  {
+    confess ("I can only work with RRD files that have "
+      . "exactly one data source!");
+  }
+  my $data_source = $ds->[0];
+
+  my $rrd_title = $obj->getTitle ($idents->[0]);
+
+  my $colors = $obj->{'rrd_colors'} || {};
+  my @ret = ('-t', $rrd_title, @$rrd_opts);
+
+  if (defined $obj->{'rrd_vertical'})
+  {
+    push (@ret, '-v', $obj->{'rrd_vertical'});
+  }
+
+  if ($obj->{'custom_order'})
+  {
+    sort_idents_by_type_instance ($idents, $obj->{'custom_order'});
+  }
+
+  $obj->{'ds_names'} ||= {};
+  my @names = map { $obj->{'ds_names'}{$_->{'type_instance'}} || $_->{'type_instance'} } (@$idents);
+
+  for (my $i = 0; $i < @$idents; $i++)
+  {
+    my $ident = $idents->[$i];
+    my $filename = ident_to_filename ($ident);
+
+    if ($ds_name_len < length ($names[$i]))
+    {
+      $ds_name_len = length ($names[$i]);
+    }
+    
+    # Escape colons _after_ the length has been checked.
+    $names[$i] =~ s/:/\\:/g;
+
+    push (@ret,
+      "DEF:min${i}=${filename}:${data_source}:MIN",
+      "DEF:avg${i}=${filename}:${data_source}:AVERAGE",
+      "DEF:max${i}=${filename}:${data_source}:MAX");
+  }
+
+  for (my $i = 0; $i < @$idents; $i++)
+  {
+    my $type_instance = $idents->[$i]{'type_instance'};
+    my $ds_name = sprintf ("%-*s", $ds_name_len, $names[$i]);
+    my $color = '000000';
+    if (exists $colors->{$type_instance})
+    {
+      $color = $colors->{$type_instance};
+    }
+    else
+    {
+      $color = get_random_color ();
+    }
+    push (@ret,
+      "LINE1:avg${i}#${color}:${ds_name}",
+      "GPRINT:min${i}:MIN:${format} Min,",
+      "GPRINT:avg${i}:AVERAGE:${format} Avg,",
+      "GPRINT:max${i}:MAX:${format} Max,",
+      "GPRINT:avg${i}:LAST:${format} Last\\l");
+  }
+
+  return (\@ret);
+}
+
+sub getGraphArgs
+{
+  my $obj = shift;
+  my $index = shift;
+
+  my $group = _group_files ($obj);
+  my $idents = $group->[$index];
+
+  my @args = ();
+  for (qw(hostname plugin plugin_instance type))
+  {
+    if (defined ($idents->[0]{$_}))
+    {
+      push (@args, $_ . '=' . $idents->[0]{$_});
+    }
+  }
+  push (@args, "index=$index");
+
+  return (join (';', @args));
+} # getGraphArgs
+
+# vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
diff --git a/contrib/collection3/lib/Collectd/Graph/Type/Wirkleistung.pm b/contrib/collection3/lib/Collectd/Graph/Type/Wirkleistung.pm
new file mode 100644 (file)
index 0000000..6d5234f
--- /dev/null
@@ -0,0 +1,90 @@
+package Collectd::Graph::Type::Wirkleistung;
+
+# Copyright (C) 2009  Stefan Pfab <spfab at noris.net>
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation; only version 2 of the License is applicable.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+use strict;
+use warnings;
+use base ('Collectd::Graph::Type');
+
+use Collectd::Graph::Common (qw(ident_to_filename get_faded_color));
+
+return (1);
+
+sub getDataSources
+{
+  return ([qw(wirkleistung)]);
+} # getDataSources
+
+sub new
+{
+  my $pkg = shift;
+  my $obj = Collectd::Graph::Type->new (@_);
+  $obj->{'data_sources'} = [qw(wirkleistung)];
+  $obj->{'rrd_opts'} = ['-v', 'Watt'];
+  $obj->{'rrd_title'} = 'Wirkleistung ({type_instance})';
+  $obj->{'rrd_format'} = '%5.1lf%s W';
+  $obj->{'colors'} = [qw(000000 f00000)];
+
+  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 $faded_green = get_faded_color ('00ff00');
+  my $faded_red = get_faded_color ('ff0000');
+
+  return (['-t', 'Wirkleistung (' . $ident->{'type_instance'} . ')', '-v', 'Watt', '-l', '0',
+    "DEF:min0=${filename}:kWh:MIN",
+    "DEF:avg0=${filename}:kWh:AVERAGE",
+    "DEF:max0=${filename}:kWh:MAX",
+    'AREA:max0#bfbfbf',
+    'AREA:min0#FFFFFF',
+    'CDEF:watt_avg0=avg0,36000,*,',
+    'CDEF:watt_min0=min0,36000,*,',
+    'CDEF:watt_max0=max0,36000,*,',
+    'CDEF:watt_total=avg0,10,*,',
+    'VDEF:total=watt_total,TOTAL',
+    'VDEF:first=watt_total,FIRST',
+    'VDEF:last=watt_total,LAST',
+    #'CDEF:first_value=first,POP',
+    #'CDEF:first_time=first,POP',
+    'LINE1:watt_avg0#000000:W',
+    'HRULE:190#ff0000',
+    'GPRINT:watt_min0:MIN:%4.1lfW Min,',
+    'GPRINT:watt_avg0:AVERAGE:%4.1lfW Avg,',
+    'GPRINT:watt_max0:MAX:%4.1lfW Max,',
+    'GPRINT:watt_avg0:LAST:%4.1lfW Last\l',
+    'GPRINT:total:%4.1lf%sWh Gesamtverbrauch im angezeigten Zeitraum\l',
+    'GPRINT:first:erster Wert %c:strftime',
+    'GPRINT:last:letzter Wert %c:strftime']);
+
+    # HRULE:190\ ff0000    
+
+} # getRRDArgs
+
+# vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
index b654719..1af2f14 100644 (file)
@@ -531,26 +531,26 @@ int check_create_dir (const char *file_orig)
 int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
 {
        char ident[128];
+
+       *ksp_ptr = NULL;
        
        if (kc == NULL)
                return (-1);
 
        ssnprintf (ident, sizeof (ident), "%s,%i,%s", module, instance, name);
 
+       *ksp_ptr = kstat_lookup (kc, module, instance, name);
        if (*ksp_ptr == NULL)
        {
-               if ((*ksp_ptr = kstat_lookup (kc, module, instance, name)) == NULL)
-               {
-                       ERROR ("Cound not find kstat %s", ident);
-                       return (-1);
-               }
+               ERROR ("get_kstat: Cound not find kstat %s", ident);
+               return (-1);
+       }
 
-               if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
-               {
-                       WARNING ("kstat %s has wrong type", ident);
-                       *ksp_ptr = NULL;
-                       return (-1);
-               }
+       if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
+       {
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
+               *ksp_ptr = NULL;
+               return (-1);
        }
 
 #ifdef assert
@@ -560,13 +560,13 @@ int get_kstat (kstat_t **ksp_ptr, char *module, int instance, char *name)
 
        if (kstat_read (kc, *ksp_ptr, NULL) == -1)
        {
-               WARNING ("kstat %s could not be read", ident);
+               ERROR ("get_kstat: kstat %s could not be read", ident);
                return (-1);
        }
 
        if ((*ksp_ptr)->ks_type != KSTAT_TYPE_NAMED)
        {
-               WARNING ("kstat %s has wrong type", ident);
+               ERROR ("get_kstat: kstat %s has wrong type", ident);
                return (-1);
        }
 
diff --git a/src/liboping/test_liboping.c b/src/liboping/test_liboping.c
deleted file mode 100644 (file)
index cd7a781..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "liboping.h"
-
-int main (int argc, char **argv)
-{
-       pingobj_t      *ping;
-       pingobj_iter_t *iter;
-
-       int i;
-
-       if (argc < 2)
-       {
-               printf ("Usage: %s <host> [host [host [...]]]\n", argv[0]);
-               return (1);
-       }
-
-       if ((ping = ping_construct ()) == NULL)
-       {
-               fprintf (stderr, "ping_construct failed\n");
-               return (-1);
-       }
-
-       for (i = 1; i < argc; i++)
-       {
-               printf ("Adding host `%s'..\n", argv[i]);
-
-               if (ping_host_add (ping, argv[i]) > 0)
-               {
-                       fprintf (stderr, "ping_host_add (verplant.org) failed\n");
-                       return (-1);
-               }
-       }
-
-       while (1)
-       {
-               if (ping_send (ping) < 0)
-               {
-                       fprintf (stderr, "ping_send failed\n");
-                       return (-1);
-               }
-
-               for (iter = ping_iterator_get (ping); iter != NULL; iter = ping_iterator_next (iter))
-               {
-                       const char *host;
-                       double      latency;
-
-                       host    = ping_iterator_get_host (iter);
-                       latency = ping_iterator_get_latency (iter);
-
-                       printf ("host = %s, latency = %f\n", host, latency);
-               }
-
-               sleep (5);
-       }
-
-       return (0);
-}
index ebaa8f2..7e4e754 100644 (file)
@@ -92,8 +92,11 @@ static int memory_init (void)
 #elif defined(HAVE_LIBKSTAT)
        /* getpagesize(3C) tells me this does not fail.. */
        pagesize = getpagesize ();
-       if (get_kstat (&ksp, "unix", 0, "system_pages"))
+       if (get_kstat (&ksp, "unix", 0, "system_pages") != 0)
+       {
                ksp = NULL;
+               return (-1);
+       }
 #endif /* HAVE_LIBKSTAT */
 
        return (0);