Merge branch 'collectd-4.4'
authorFlorian Forster <octo@huhu.verplant.org>
Tue, 19 Aug 2008 07:27:14 +0000 (09:27 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 19 Aug 2008 07:27:14 +0000 (09:27 +0200)
Conflicts:

src/tcpconns.c

configure.in
contrib/collection3/etc/collection.conf
contrib/collection3/lib/Collectd/Graph/Config.pm [new file with mode: 0644]
src/Makefile.am
src/snmp.c
src/swap.c
src/tcpconns.c

index 2b85a2b..4a7fdfb 100644 (file)
@@ -1232,12 +1232,13 @@ then
   AC_SUBST(BUILD_WITH_LIBSTATGRAB_LDFLAGS)
 fi
 
-AC_CHECK_LIB(kvm, kvm_getswapinfo, [with_libkvm="yes"], [with_libkvm="no"])
-if test "x$with_libkvm" = "xyes"
+AC_CHECK_LIB(kvm, kvm_getswapinfo, [with_kvm_getswapinfo="yes"], [with_kvm_getswapinfo="no"])
+if test "x$with_kvm_getswapinfo" = "xyes"
 then
-       AC_DEFINE(HAVE_LIBKVM, 1, [Define to 1 if you have the 'kvm' library (-lkvm)])
+       AC_DEFINE(HAVE_LIBKVM_GETSWAPINFO, 1,
+                 [Define to 1 if you have the 'kvm' library with the 'kvm_getswapinfo' symbol (-lkvm)])
 fi
-AM_CONDITIONAL(BUILD_WITH_LIBKVM, test "x$with_libkvm" = "xyes")
+AM_CONDITIONAL(BUILD_WITH_LIBKVM_GETSWAPINFO, test "x$with_kvm_getswapinfo" = "xyes")
 
 with_sensors_cflags=""
 with_sensors_ldflags=""
index e60316f..37ea64b 100644 (file)
@@ -53,6 +53,14 @@ GraphWidth 400
   Color interrupt a000a0
   Color steal     000000
 </Type>
+<Type current>
+  DataSources value
+  DSName value Current
+  RRDTitle "Current ({type_instance})"
+  RRDVerticalLabel "Ampere"
+  RRDFormat "%4.1lfA"
+  Color value ffb000
+</Type>
 <Type df>
   Module Df
   DataSources free used
@@ -113,6 +121,22 @@ GraphWidth 400
   RRDFormat "%6.1lf"
   Color value 00b000
 </Type>
+<Type frequency>
+  DataSources frequency
+  DSName frequency Frequency
+  RRDTitle "Frequency ({type_instance})"
+  RRDVerticalLabel "Hertz"
+  RRDFormat "%4.1lfHz"
+  Color frequency a000a0
+</Type>
+<Type humidity>
+  DataSources value
+  DSName value Humitidy
+  RRDTitle "Humitidy ({instance})"
+  RRDVerticalLabel "Percent"
+  RRDFormat "%4.1lf%%"
+  Color value 00e000
+</Type>
 <Type if_errors>
   Module GenericIO
   DataSources rx tx
@@ -213,6 +237,14 @@ GraphWidth 400
   Color buffered  ffb000
   Color used      ff0000
 </Type>
+<Type percent>
+  DataSources percent
+  DSName percent Percent
+  RRDTitle "Percent ({type_instance})"
+  RRDVerticalLabel "Percent"
+  RRDFormat "%4.1lf%%"
+  Color percent 0000ff
+</Type>
 <Type ping>
   DataSources ping
   DSName "ping Latency"
@@ -220,6 +252,14 @@ GraphWidth 400
   RRDVerticalLabel "Milliseconds"
   RRDFormat "%5.2lfms"
 </Type>
+<Type power>
+  DataSources value
+  DSName value Watts
+  RRDTitle "Power ({type_instance})"
+  RRDVerticalLabel "Watts"
+  RRDFormat "%6.2lf%sW"
+  Color value 008080
+</Type>
 <Type ps_state>
   Module GenericStacked
   DataSources value
@@ -240,6 +280,22 @@ GraphWidth 400
   Color blocked  ff00ff
   Color stopped  a000a0
 </Type>
+<Type swap>
+  Module GenericStacked
+  DataSources value
+  RRDTitle "Swap utilization on {hostname}"
+  RRDVerticalLabel "Bytes"
+  RRDFormat "%5.1lf%s"
+  RRDOptions -b 1024 -l 0
+  DSName     "free Free    "
+  DSName   "cached Cached  "
+  DSName     "used Used    "
+  #Order used cached free
+  Order free cached used
+  Color free      00e000
+  Color cached    0000ff
+  Color used      ff0000
+</Type>
 <Type tcp_connections>
   Module GenericStacked
   DataSources value
diff --git a/contrib/collection3/lib/Collectd/Graph/Config.pm b/contrib/collection3/lib/Collectd/Graph/Config.pm
new file mode 100644 (file)
index 0000000..d20be35
--- /dev/null
@@ -0,0 +1,144 @@
+package Collectd::Graph::Config;
+
+=head1 NAME
+
+Collectd::Graph::Config - Parse the collection3 config file.
+
+=cut
+
+# Copyright (C) 2008  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 Carp (qw(cluck confess));
+use Exporter ();
+use Config::General ('ParseConfig');
+use Collectd::Graph::Type ();
+
+@Collectd::Graph::Config::ISA = ('Exporter');
+@Collectd::Graph::Config::EXPORT_OK = (qw(gc_read_config gc_get_config
+  gc_get_scalar));
+
+our $Configuration = undef;
+
+return (1);
+
+=head1 EXPORTED FUNCTIONS
+
+=over 4
+
+=item B<gc_read_config> (I<$file>)
+
+Reads the configuration from the file located at I<$file>. Returns B<true> when
+successfull and B<false> otherwise.
+
+=cut
+
+sub gc_read_config
+{
+  my $file = shift;
+  my %conf;
+
+  if ($Configuration)
+  {
+    return (1);
+  }
+
+  $file ||= "etc/collection.conf";
+
+  %conf = ParseConfig (-ConfigFile => $file,
+    -LowerCaseNames => 1,
+    -UseApacheInclude => 1,
+    -IncludeDirectories => 1,
+    ($Config::General::VERSION >= 2.38) ? (-IncludeAgain => 0) : (),
+    -MergeDuplicateBlocks => 1,
+    -CComments => 0);
+  if (!%conf)
+  {
+    return;
+  }
+
+  $Configuration = \%conf;
+  return (1);
+} # gc_read_config
+
+=item B<gc_get_config> ()
+
+Returns the hash as provided by L<Config::General>. The hash is returned as a
+hash reference. Don't change it!
+
+=cut
+
+sub gc_get_config
+{
+  return ($Configuration);
+} # gc_get_config
+
+=item B<gc_get_config> (I<$key>, [I<$default>])
+
+Returns the scalar value I<$key> from the config file. If the key does not
+exist, I<$default> will be returned. If no default is given, B<undef> will be
+used in this case.
+
+=cut
+
+sub gc_get_scalar
+{
+  my $key = shift;
+  my $default = (@_ != 0) ? shift : undef;
+  my $value;
+
+  if (!$Configuration)
+  {
+    return ($default);
+  }
+
+  $value = $Configuration->{lc ($key)};
+  if (!defined ($value))
+  {
+    return ($default);
+  }
+
+  if (ref ($value) ne '')
+  {
+    cluck ("Value for `$key' should be scalar, but actually is "
+      . ref ($value));
+    return ($default);
+  }
+
+  return ($value);
+} # gc_get_config
+
+=back
+
+=head1 DEPENDS ON
+
+L<Config::General>
+
+=head1 SEE ALSO
+
+L<Collectd::Graph::Type>
+
+=head1 AUTHOR AND LICENSE
+
+Copyright (c) 2008 by Florian Forster
+E<lt>octoE<nbsp>atE<nbsp>verplant.orgE<gt>. Licensed under the terms of the GNU
+General Public License, VersionE<nbsp>2 (GPLv2).
+
+=cut
+
+# vim: set shiftwidth=2 softtabstop=2 tabstop=8 et fdm=marker :
index 3c5c87b..8d8845e 100644 (file)
@@ -642,7 +642,7 @@ endif
 if BUILD_WITH_LIBDEVINFO
 swap_la_LIBADD += -ldevinfo
 endif
-if BUILD_WITH_LIBKVM
+if BUILD_WITH_LIBKVM_GETSWAPINFO
 swap_la_LIBADD += -lkvm
 endif
 if BUILD_WITH_LIBSTATGRAB
index 2026e8b..0dad67c 100644 (file)
@@ -1153,10 +1153,6 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
     vb = res->variables;
     if (vb == NULL)
     {
-      if (res != NULL)
-       snmp_free_pdu (res);
-      res = NULL;
-
       status = -1;
       break;
     }
@@ -1165,10 +1161,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
      * subtree */
     if (csnmp_check_res_left_subtree (host, data, res) != 0)
     {
-      if (res != NULL)
-       snmp_free_pdu (res);
-      res = NULL;
-
+      status = 0;
       break;
     }
 
@@ -1190,11 +1183,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
          (vb != NULL) && (vb->next_variable != NULL);
          vb = vb->next_variable)
        /* do nothing */;
-      if (vb == NULL)
-      {
-       status = -1;
-       break;
-      }
+      assert (vb != NULL);
 
       /* Copy OID to oid_list[data->values_len] */
       memcpy (oid_list[data->values_len].oid, vb->name,
@@ -1257,6 +1246,10 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data)
     res = NULL;
   } /* while (status == 0) */
 
+  if (res != NULL)
+    snmp_free_pdu (res);
+  res = NULL;
+
   if (status == 0)
     csnmp_dispatch_table (host, data, instance_list, value_table);
 
index f9debc1..8c09e35 100644 (file)
@@ -56,10 +56,10 @@ static kstat_t *ksp;
 /* No global variables */
 /* #endif defined(VM_SWAPUSAGE) */
 
-#elif HAVE_LIBKVM
+#elif HAVE_LIBKVM_GETSWAPINFO
 static kvm_t *kvm_obj = NULL;
 int kvm_pagesize;
-/* #endif HAVE_LIBKVM */
+/* #endif HAVE_LIBKVM_GETSWAPINFO */
 
 #elif HAVE_LIBSTATGRAB
 /* No global variables */
@@ -86,7 +86,7 @@ static int swap_init (void)
        /* No init stuff */
 /* #endif defined(VM_SWAPUSAGE) */
 
-#elif HAVE_LIBKVM
+#elif HAVE_LIBKVM_GETSWAPINFO
        if (kvm_obj != NULL)
        {
                kvm_close (kvm_obj);
@@ -105,7 +105,7 @@ static int swap_init (void)
                ERROR ("swap plugin: kvm_open failed.");
                return (-1);
        }
-/* #endif HAVE_LIBKVM */
+/* #endif HAVE_LIBKVM_GETSWAPINFO */
 
 #elif HAVE_LIBSTATGRAB
        /* No init stuff */
@@ -260,7 +260,7 @@ static int swap_read (void)
        swap_submit ("free", sw_usage.xsu_avail);
 /* #endif VM_SWAPUSAGE */
 
-#elif HAVE_LIBKVM
+#elif HAVE_LIBKVM_GETSWAPINFO
        struct kvm_swap data_s;
        int             status;
 
@@ -286,7 +286,7 @@ static int swap_read (void)
 
        swap_submit ("used", used);
        swap_submit ("free", free);
-/* #endif HAVE_LIBKVM */
+/* #endif HAVE_LIBKVM_GETSWAPINFO */
 
 #elif HAVE_LIBSTATGRAB
        sg_swap_stats *swap;
index 655c53e..fac6a18 100644 (file)
@@ -143,7 +143,7 @@ static void conn_submit_port_entry (port_entry_t *pe)
       || (pe->flags & PORT_COLLECT_LOCAL))
   {
     ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
-       "%hu-local", pe->port);
+       "%"PRIu16"-local", pe->port);
 
     for (i = 1; i <= TCP_STATE_MAX; i++)
     {
@@ -158,7 +158,7 @@ static void conn_submit_port_entry (port_entry_t *pe)
   if (pe->flags & PORT_COLLECT_REMOTE)
   {
     ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
-       "%hu-remote", pe->port);
+       "%"PRIu16"-remote", pe->port);
 
     for (i = 1; i <= TCP_STATE_MAX; i++)
     {
@@ -224,7 +224,7 @@ static void conn_reset_port_entry (void)
       port_entry_t *next = pe->next;
 
       DEBUG ("tcpconns plugin: Removing temporary entry "
-         "for listening port %hu", pe->port);
+         "for listening port %"PRIu16, pe->port);
 
       if (prev == NULL)
        port_list_head = next;
@@ -255,8 +255,8 @@ static int conn_handle_ports (uint16_t port_local, uint16_t port_remote, uint8_t
 #endif
      )
   {
-    NOTICE ("tcpconns plugin: Ignoring connection with unknown state 0x%02x.",
-       state);
+    NOTICE ("tcpconns plugin: Ignoring connection with "
+       "unknown state 0x%02"PRIx8".", state);
     return (-1);
   }
 
@@ -268,7 +268,7 @@ static int conn_handle_ports (uint16_t port_local, uint16_t port_remote, uint8_t
       pe->flags |= PORT_IS_LISTENING;
   }
 
-  DEBUG ("tcpconns plugin: Connection %hu <-> %hu (%s)",
+  DEBUG ("tcpconns plugin: Connection %"PRIu16" <-> %"PRIu16" (%s)",
       port_local, port_remote, tcp_state[state]);
 
   pe = conn_get_port_entry (port_local, 0 /* no create */);