Merge branch 'collectd-4.4'
authorFlorian Forster <octo@huhu.verplant.org>
Wed, 20 Aug 2008 07:21:37 +0000 (09:21 +0200)
committerFlorian Forster <octo@huhu.verplant.org>
Wed, 20 Aug 2008 07:21:37 +0000 (09:21 +0200)
Conflicts:

src/collectd.conf.pod

1  2 
src/collectd.conf.pod
src/common.h
src/memcached.c

diff --combined src/collectd.conf.pod
@@@ -30,11 -30,7 +30,11 @@@ section-start or -end. Empty lines and 
  ignored. Values are either string, enclosed in double-quotes,
  (floating-point-)numbers or a boolean expression, i.E<nbsp>e. either B<true> or
  B<false>. String containing of only alphanumeric characters and underscores do
 -not need to be quoted.
 +not need to be quoted. Lines may be wrapped by using `\' as the last character
 +before the newline. This allows long lines to be split into multiple lines.
 +Quoted strings may be wrapped as well. However, those are treated special in
 +that whitespace at the beginning of the following lines will be ignored, which
 +allows for nicely indenting the wrapped lines.
  
  The configuration is read and processed in order, i.E<nbsp>e. from top to
  bottom. So the plugins are loaded in the order listed in this config file. It
@@@ -236,19 -232,6 +236,19 @@@ Optional user name needed for authentic
  
  Optional password needed for authentication.
  
 +=item B<VerifyPeer> B<true|false>
 +
 +Enable or disable peer SSL certificate verification. See
 +L<http://curl.haxx.se/docs/sslcerts.html> for details. Enabled by default.
 +
 +=item B<VerifyHost> B<true|false>
 +
 +Enable or disable peer host name verification. If enabled, the plugin checks
 +if the C<Common Name> or a C<Subject Alternate Name> field of the SSL
 +certificate matches the host name provided by the B<URL> option. If this
 +identity check fails, the connection is aborted. Obviously, only works when
 +connecting to a SSL enabled server. Enabled by default.
 +
  =item B<CACert> I<File>
  
  File that holds one or more SSL certificates. If you want to use HTTPS you will
@@@ -467,7 -450,7 +467,7 @@@ similar interfaces. Thus, you can use t
  interfaces you're interested in. Sometimes, however, it's easier/preferred
  to collect all interfaces I<except> a few ones. This option enables you to
  do that: By setting B<IgnoreSelected> to I<true> the effect of
 -B<Interface> is inversed: All selected interfaces are ignored and all
 +B<Interface> is inverted: All selected interfaces are ignored and all
  other interfaces are collected.
  
  =back
@@@ -488,20 -471,6 +488,20 @@@ This option enables you to do that: By 
  the effect of B<Sensor> is inverted: All selected sensors are ignored and
  all other sensors are collected.
  
 +=item B<NotifySensorAdd> I<true>|I<false>
 +
 +If a sensor appears after initialization time of a minute a notification
 +is sent.
 +
 +=item B<NotifySensorRemove> I<true>|I<false>
 +
 +If a sensor disappears a notification is sent.
 +
 +=item B<NotifySensorNotPresent> I<true>|I<false>
 +
 +If you have for example dual power supply and one of them is (un)plugged then
 +a notification is sent.
 +
  =back
  
  =head2 Plugin C<iptables>
@@@ -539,7 -508,7 +539,7 @@@ irqs. This may not be practical, especi
  can use the B<Irq>-option to pick the interrupt you're interested in.
  Sometimes, however, it's easier/preferred to collect all interrupts I<except> a
  few ones. This option enables you to do that: By setting B<IgnoreSelected> to
 -I<true> the effect of B<Irq> is inversed: All selected interrupts are ignored
 +I<true> the effect of B<Irq> is inverted: All selected interrupts are ignored
  and all other interrupts are collected.
  
  =back
@@@ -798,7 -767,7 +798,7 @@@ Here are some examples to help you unde
  The behaviour is the same as with all other similar plugins: If nothing is
  selected at all, everything is collected. If some things are selected using the
  options described above, only these statistics are collected. If you set
 -B<IgnoreSelected> to B<true>, this behavior is inversed, i.E<nbsp>e. the
 +B<IgnoreSelected> to B<true>, this behavior is inverted, i.E<nbsp>e. the
  specified statistics will not be collected.
  
  =back
@@@ -906,32 -875,6 +906,32 @@@ and are checked by default depends on t
  
  =back
  
 +=head2 Plugin C<notify_desktop>
 +
 +This plugin sends a desktop notification to a notification daemon, as defined
 +in the Desktop Notification Specification. To actually display the
 +notifications, B<notification-daemon> is required and B<collectd> has to be
 +able to access the X server.
 +
 +The Desktop Notification Specification can be found at
 +L<http://www.galago-project.org/specs/notification/>.
 +
 +=over 4
 +
 +=item B<OkayTimeout> I<timeout>
 +
 +=item B<WarningTimeout> I<timeout>
 +
 +=item B<FailureTimeout> I<timeout>
 +
 +Set the I<timeout>, in milliseconds, after which to expire the notification
 +for C<OKAY>, C<WARNING> and C<FAILURE> severities respectively. If zero has
 +been specified, the displayed notification will not be closed at all - the
 +user has to do so herself. These options default to 5000. If a negative number
 +has been specified, the default is used as well.
 +
 +=back
 +
  =head2 Plugin C<ntpd>
  
  =over 4
@@@ -964,46 -907,6 +964,46 @@@ L<upsc(8)>
  
  =back
  
 +=head2 Plugin C<onewire>
 +
 +The C<onewire> plugin uses the B<owcapi> library from the B<owfs> project
 +L<http://owfs.org/> to read sensors connected via the onewire bus.
 +
 +=over 4
 +
 +=item B<Device> I<Device>
 +
 +Sets the device to read the values from. This can either be a "real" hardware
 +device, such as a serial port or an USB port, or the address of the
 +L<owserver(1)> socket, usually B<localhost:4304>.
 +
 +Though the documentation claims to automatically recognize the given address
 +format, with versionE<nbsp>2.7p4 we had to specify the type explicitly. So
 +with that version, the following configuration worked for us:
 +
 +  <Plugin onewire>
 +    Device "-s localhost:4304"
 +  </Plugin>
 +
 +=item B<Sensor> I<Sensor>
 +
 +Selects sensors to collect or to ignore, depending on B<IgnoreSelected>, see
 +below. Sensors are specified without the family byte at the beginning, to you'd
 +use C<F10FCA000800>, and B<not> include the leading C<10.> family byte and
 +point.
 +
 +=item B<IgnoreSelected> I<true>|I<false>
 +
 +If no configuration if given, the B<onewire> plugin will collect data from all
 +sensors found. This may not be practical, especially if sensors are added and
 +removed regularly. Sometimes, however, it's easier/preferred to collect only
 +specific sensors or all sensors I<except> a few specified ones. This option
 +enables you to do that: By setting B<IgnoreSelected> to I<true> the effect of
 +B<Sensor> is inverted: All selected interfaces are ignored and all other
 +interfaces are collected.
 +
 +=back
 +
  =head2 Plugin C<perl>
  
  This plugin embeds a Perl-interpreter into collectd and provides an interface
@@@ -1024,227 -927,6 +1024,227 @@@ Sets the Time-To-Live of generated ICM
  
  =back
  
 +=head2 Plugin C<postgresql>
 +
 +The C<postgresql> plugin queries statistics from PostgreSQL databases. It
 +keeps a persistent connection to all configured databases and tries to
 +reconnect if the connection has been interrupted. A database is configured by
 +specifying a B<Database> block as described below. The default statistics are
 +collected from PostgreSQL's B<statistics collector> which thus has to be
 +enabled for this plugin to work correctly. This should usually be the case by
 +default. See the section "The Statistics Collector" of the B<PostgreSQL
 +Documentation> for details.
 +
 +By specifying custom database queries using a B<Query> block as described
 +below, you may collect any data that is available from some PostgreSQL
 +database. This way, you are able to access statistics of external daemons
 +which are available in a PostgreSQL database or use future or special
 +statistics provided by PostgreSQL without the need to upgrade your collectd
 +installation.
 +
 +The B<PostgreSQL Documentation> manual can be found at
 +L<http://www.postgresql.org/docs/manuals/>.
 +
 +  <Plugin postgresql>
 +    <Query magic>
 +      Query "SELECT magic, spells FROM wizard WHERE host = $1;"
 +      Param hostname
 +      Column gauge magic
 +      Column counter spells
 +    </Query>
 +
 +    <Database foo>
 +      Host "hostname"
 +      Port "5432"
 +      User "username"
 +      Password "secret"
 +      SSLMode "prefer"
 +      KRBSrvName "kerberos_service_name"
 +      Query magic
 +    </Database>
 +    <Database bar>
 +      Service "service_name"
 +    </Database>
 +  </Plugin>
 +
 +The B<Query> block defines one database query which may later be used by a
 +database definition. It accepts a single mandatory argument which specifies
 +the name of the query. The names of all queries have to be unique. The
 +following configuration options are available to define the query:
 +
 +=over 4
 +
 +=item B<Query> I<sql query>
 +
 +Specify the I<sql query> which the plugin should execute. The string may
 +contain the tokens B<$1>, B<$2>, etc. which are used to reference the first,
 +second, etc. parameter. The value of the parameters is specified by the
 +B<Param> configuration option - see below for details. To include a literal
 +B<$> character followed by a number, surround it with single quotes (B<'>).
 +
 +Any SQL command which may return data (such as C<SELECT> or C<SHOW>) is
 +allowed. Note, however, that only a single command may be used. Semicolons are
 +allowed as long as a single non-empty command has been specified only.
 +
 +=item B<Param> I<hostname>|I<database>|I<username>
 +
 +Specify the parameters which should be passed to the SQL query. The parameters
 +are referred to in the SQL query as B<$1>, B<$2>, etc. in the same order as
 +they appear in the configuration file. The value of the parameter is
 +determined depending on the value of the B<Param> option as follows:
 +
 +=over 4
 +
 +=item I<hostname>
 +
 +The configured hostname of the database connection. If a UNIX domain socket is
 +used, the parameter expands to "localhost".
 +
 +=item I<database>
 +
 +The name of the database of the current connection.
 +
 +=item I<username>
 +
 +The username used to connect to the database.
 +
 +=back
 +
 +Please note that parameters are only supported by PostgreSQL's protocol
 +version 3 and above which was introduced in version 7.4 of PostgreSQL.
 +
 +=item B<Column> I<type> [I<type instance>]
 +
 +Specify the I<type> and optional I<type instance> used to dispatch the value
 +of each result column. Detailed information about types and their
 +configuration can be found in L<types.db(5)>. The number and order of the
 +B<Column> options has to match the columns of the query result.
 +
 +=back
 +
 +The following predefined queries are available (the definitions can be found
 +in the F<postgresql_default.conf> file which, by default, is available at
 +C<I<prefix>/share/collectd/>):
 +
 +=over 4
 +
 +=item B<backends>
 +
 +This query collects the number of backends, i.E<nbsp>e. the number of
 +connected clients.
 +
 +=item B<transactions>
 +
 +This query collects the numbers of committed and rolled-back transactions of
 +the user tables.
 +
 +=item B<queries>
 +
 +This query collects the numbers of various table modifications (i.E<nbsp>e.
 +insertions, updates, deletions) of the user tables.
 +
 +=item B<query_plans>
 +
 +This query collects the numbers of various table scans and returned tuples of
 +the user tables.
 +
 +=item B<table_states>
 +
 +This query collects the numbers of live and dead rows in the user tables.
 +
 +=item B<disk_io>
 +
 +This query collects disk block access counts for user tables.
 +
 +=item B<disk_usage>
 +
 +This query collects the on-disk size of the database in bytes.
 +
 +=back
 +
 +The B<Database> block defines one PostgreSQL database for which to collect
 +statistics. It accepts a single mandatory argument which specifies the
 +database name. None of the other options are required. PostgreSQL will use
 +default values as documented in the section "CONNECTING TO A DATABASE" in the
 +L<psql(1)> manpage. However, be aware that those defaults may be influenced by
 +the user collectd is run as and special environment variables. See the manpage
 +for details.
 +
 +=over 4
 +
 +=item B<Host> I<hostname>
 +
 +Specify the hostname or IP of the PostgreSQL server to connect to. If the
 +value begins with a slash, it is interpreted as the directory name in which to
 +look for the UNIX domain socket.
 +
 +This option is also used to determine the hostname that is associated with a
 +collected data set. If it has been omitted or either begins with with a slash
 +or equals B<localhost> it will be replaced with the global hostname definition
 +of collectd. Any other value will be passed literally to collectd when
 +dispatching values. Also see the global B<Hostname> and B<FQDNLookup> options.
 +
 +=item B<Port> I<port>
 +
 +Specify the TCP port or the local UNIX domain socket file extension of the
 +server.
 +
 +=item B<User> I<username>
 +
 +Specify the username to be used when connecting to the server.
 +
 +=item B<Password> I<password>
 +
 +Specify the password to be used when connecting to the server.
 +
 +=item B<SSLMode> I<disable>|I<allow>|I<prefer>|I<require>
 +
 +Specify whether to use an SSL connection when contacting the server. The
 +following modes are supported:
 +
 +=over 4
 +
 +=item I<disable>
 +
 +Do not use SSL at all.
 +
 +=item I<allow>
 +
 +First, try to connect without using SSL. If that fails, try using SSL.
 +
 +=item I<prefer> (default)
 +
 +First, try to connect using SSL. If that fails, try without using SSL.
 +
 +=item I<require>
 +
 +Use SSL only.
 +
 +=back
 +
 +=item B<KRBSrvName> I<kerberos_service_name>
 +
 +Specify the Kerberos service name to use when authenticating with Kerberos 5
 +or GSSAPI. See the sections "Kerberos authentication" and "GSSAPI" of the
 +B<PostgreSQL Documentation> for details.
 +
 +=item B<Service> I<service_name>
 +
 +Specify the PostgreSQL service name to use for additional parameters. That
 +service has to be defined in F<pg_service.conf> and holds additional
 +connection parameters. See the section "The Connection Service File" in the
 +B<PostgreSQL Documentation> for details.
 +
 +=item B<Query> I<query>
 +
 +Specify a I<query> which should be executed for the database connection. This
 +may be any of the predefined or user-defined queries. If no such option is
 +given, it defaults to "backends", "transactions", "queries", "query_plans",
 +"table_states", "disk_io" and "disk_usage". Else, the specified queries are
 +used only.
 +
 +=back
 +
  =head2 Plugin C<powerdns>
  
  The C<powerdns> plugin queries statistics from an authoritative PowerDNS
@@@ -1496,7 -1178,7 +1496,7 @@@ sensors. This may not be practical, esp
  Thus, you can use the B<Sensor>-option to pick the sensors you're interested
  in. Sometimes, however, it's easier/preferred to collect all sensors I<except> a
  few ones. This option enables you to do that: By setting B<IgnoreSelected> to
 -I<true> the effect of B<Sensor> is inversed: All selected sensors are ignored
 +I<true> the effect of B<Sensor> is inverted: All selected sensors are ignored
  and all other sensors are collected.
  
  =back
@@@ -1659,6 -1341,8 +1659,8 @@@ This option, although numeric, needs t
  use quotes around it! If no such statement is given only global information
  will be collected.
  
+ =back
  =head2 Plugin C<tcpconns>
  
  The C<tcpconns plugin> counts the number of currently established TCP
@@@ -1669,8 -1353,6 +1671,6 @@@ fine-tune the ports you are interested 
  
  =over 4
  
- =back
  =item B<ListeningPorts> I<true>|I<false>
  
  If this option is set to I<true>, statistics for all local ports for which a
@@@ -1699,32 -1381,6 +1699,32 @@@ port in numeric form
  
  =back
  
 +=head2 Plugin C<thermal>
 +
 +=over 4
 +
 +=item B<ForceUseProcfs> I<true>|I<false>
 +
 +By default, the C<thermal> plugin tries to read the statistics from the Linux
 +C<sysfs> interface. If that is not available, the plugin falls back to the
 +C<procfs> interface. By setting this option to I<true>, you can force the
 +plugin to use the latter. This option defaults to I<false>.
 +
 +=item B<Device> I<Device>
 +
 +Selects the name of the thermal device that you want to collect or ignore,
 +depending on the value of the B<IgnoreSelected> option. This option may be
 +used multiple times to specify a list of devices.
 +
 +=item B<IgnoreSelected> I<true>|I<false>
 +
 +Invert the selection: If set to true, all devices B<except> the ones that
 +match the device names specified by the B<Device> option are collected. By
 +default only selected devices are collected if a selection is made. If no
 +selection is configured at all, B<all> devices are selected.
 +
 +=back
 +
  =head2 Plugin C<unixsock>
  
  =over 4
@@@ -1949,7 -1605,6 +1949,7 @@@ L<types.db(5)>
  L<hddtemp(8)>,
  L<kstat(3KSTAT)>,
  L<mbmon(1)>,
 +L<psql(1)>,
  L<rrdtool(1)>,
  L<sensors(1)>
  
diff --combined src/common.h
  #endif
  
  #define sfree(ptr) \
-       if((ptr) != NULL) { \
-               free(ptr); \
-       } \
-       (ptr) = NULL
+       do { \
+               if((ptr) != NULL) { \
+                       free(ptr); \
+               } \
+               (ptr) = NULL; \
+       } while (0)
  
  #define STATIC_ARRAY_SIZE(a) (sizeof (a) / sizeof (*(a)))
  
  char *sstrncpy (char *dest, const char *src, size_t n);
 +int ssnprintf (char *dest, size_t n, const char *format, ...);
  char *sstrdup(const char *s);
  void *smalloc(size_t size);
  char *sstrerror (int errnum, char *buf, size_t buflen);
@@@ -200,9 -201,4 +202,9 @@@ int notification_init (notification_t *
        notification_init (n, NOTIF_FAILURE, NULL, \
                        (vl)->host, (vl)->plugin, (vl)->plugin_instance, \
                        (ds)->type, (vl)->type_instance)
 +
 +typedef int (*dirwalk_callback_f)(const char *filename);
 +int walk_directory (const char *dir, dirwalk_callback_f callback);
 +int read_file_contents (const char *filename, char *buf, int bufsize);
 +
  #endif /* COMMON_H */
diff --combined src/memcached.c
@@@ -127,17 -127,30 +127,30 @@@ static int memcached_query_daemon (cha
  
        {
                struct pollfd p;
-               int n;
+               int timeout;
+               int status;
  
+               memset (&p, 0, sizeof (p));
                p.fd = fd;
-               p.events = POLLIN|POLLERR|POLLHUP;
+               p.events = POLLIN | POLLERR | POLLHUP;
                p.revents = 0;
  
-               n = poll(&p, 1, 3);
-               if (n <= 0) {
-                       ERROR ("memcached: poll() failed or timed out");
-                       return -1;
+               status = poll (&p, /* nfds = */ 1, /* timeout = */ interval_g);
+               if (status <= 0)
+               {
+                       if (status == 0)
+                       {
+                               ERROR ("memcached: poll(2) timed out after %i seconds.", interval_g);
+                       }
+                       else
+                       {
+                               char errbuf[1024];
+                               ERROR ("memcached: poll(2) failed: %s",
+                                               sstrerror (errno, errbuf, sizeof (errbuf)));
+                       }
+                       shutdown (fd, SHUT_RDWR);
+                       close (fd);
+                       return (-1);
                }
        }
  
@@@ -200,10 -213,11 +213,10 @@@ static int memcached_config (const cha
        } else if (strcasecmp (key, "Port") == 0) {
                int port = (int) (atof (value));
                if ((port > 0) && (port <= 65535)) {
 -                      snprintf (memcached_port, sizeof (memcached_port), "%i", port);
 +                      ssnprintf (memcached_port, sizeof (memcached_port), "%i", port);
                } else {
 -                      strncpy (memcached_port, value, sizeof (memcached_port));
 +                      sstrncpy (memcached_port, value, sizeof (memcached_port));
                }
 -              memcached_port[sizeof (memcached_port) - 1] = '\0';
        } else {
                return -1;
        }
@@@ -225,11 -239,13 +238,11 @@@ static void submit_counter (const char 
        vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
 +      sstrncpy (vl.type, type, sizeof (vl.type));
        if (type_inst != NULL)
 -      {
 -              strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
 -              vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
 -      }
 +              sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
  
 -      plugin_dispatch_values (type, &vl);
 +      plugin_dispatch_values (&vl);
  } /* void memcached_submit_cmd */
  /* }}} */
  
@@@ -247,11 -263,13 +260,11 @@@ static void submit_counter2 (const cha
        vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
 +      sstrncpy (vl.type, type, sizeof (vl.type));
        if (type_inst != NULL)
 -      {
 -              strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
 -              vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
 -      }
 +              sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
  
 -      plugin_dispatch_values (type, &vl);
 +      plugin_dispatch_values (&vl);
  } /* void memcached_submit_cmd */
  /* }}} */
  
@@@ -268,11 -286,13 +281,11 @@@ static void submit_gauge (const char *t
        vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
 +      sstrncpy (vl.type, type, sizeof (vl.type));
        if (type_inst != NULL)
 -      {
 -              strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
 -              vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
 -      }
 +              sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
  
 -      plugin_dispatch_values (type, &vl);
 +      plugin_dispatch_values (&vl);
  }
  /* }}} */
  
@@@ -290,11 -310,13 +303,11 @@@ static void submit_gauge2 (const char *
        vl.time = time (NULL);
        sstrncpy (vl.host, hostname_g, sizeof (vl.host));
        sstrncpy (vl.plugin, "memcached", sizeof (vl.plugin));
 +      sstrncpy (vl.type, type, sizeof (vl.type));
        if (type_inst != NULL)
 -      {
 -              strncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
 -              vl.type_instance[sizeof (vl.type_instance) - 1] = '\0';
 -      }
 +              sstrncpy (vl.type_instance, type_inst, sizeof (vl.type_instance));
  
 -      plugin_dispatch_values (type, &vl);
 +      plugin_dispatch_values (&vl);
  }
  /* }}} */