Merge branch 'kr/ctxt'
authorFlorian Forster <octo@noris.net>
Wed, 29 Sep 2010 15:06:00 +0000 (17:06 +0200)
committerFlorian Forster <octo@noris.net>
Wed, 29 Sep 2010 15:06:00 +0000 (17:06 +0200)
bindings/perl/lib/Collectd.pm
src/apache.c
src/collectd-perl.pod
src/collectd.conf.in
src/collectd.conf.pod
src/curl_json.c
src/mysql.c
src/nginx.c
src/perl.c
src/types.db

index f1b5d85..ca3b5d2 100644 (file)
@@ -465,35 +465,6 @@ sub plugin_flush {
        }
 }
 
-sub plugin_flush_one {
-       my $timeout = shift;
-       my $name    = shift;
-
-       WARNING ("Collectd::plugin_flush_one is deprecated - "
-               . "use Collectd::plugin_flush instead.");
-
-       if (! (defined ($timeout) && defined ($name))) {
-               ERROR ("Usage: Collectd::plugin_flush_one(timeout, name)");
-               return;
-       }
-
-       plugin_flush (plugins => $name, timeout => $timeout);
-}
-
-sub plugin_flush_all {
-       my $timeout = shift;
-
-       WARNING ("Collectd::plugin_flush_all is deprecated - "
-               . "use Collectd::plugin_flush instead.");
-
-       if (! defined ($timeout)) {
-               ERROR ("Usage: Collectd::plugin_flush_all(timeout)");
-               return;
-       }
-
-       plugin_flush (timeout => $timeout);
-}
-
 sub fc_call {
        my $type    = shift;
        my $name    = shift;
index 3d6d957..506ba84 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * collectd - src/apache.c
- * Copyright (C) 2006-2009  Florian octo Forster
+ * Copyright (C) 2006-2010  Florian octo Forster
  * Copyright (C) 2007       Florent EppO Monbillard
  * Copyright (C) 2009       Amit Gupta
  *
@@ -144,6 +144,8 @@ static size_t apache_header_callback (void *buf, size_t size, size_t nmemb,
                st->server_type = APACHE;
        else if (strstr (buf, "lighttpd") != NULL)
                st->server_type = LIGHTTPD;
+       else if (strstr (buf, "IBM_HTTP_Server") != NULL)
+               st->server_type = APACHE;
        else
        {
                const char *hdr = buf;
@@ -333,57 +335,22 @@ static int config (oconfig_item_t *ci)
 {
        int status = 0;
        int i;
-       oconfig_item_t *lci = NULL; /* legacy config */
 
        for (i = 0; i < ci->children_num; i++)
        {
                oconfig_item_t *child = ci->children + i;
 
-               if (strcasecmp ("Instance", child->key) == 0 && child->children_num > 0)
+               if (strcasecmp ("Instance", child->key) == 0)
                        config_add (child);
                else
-               {
-                       /* legacy mode - convert to <Instance ...> config */
-                       if (lci == NULL)
-                       {
-                               lci = malloc (sizeof(*lci));
-                               if (lci == NULL)
-                               {
-                                       ERROR ("apache plugin: malloc failed.");
-                                       return (-1);
-                               }
-                               memset (lci, '\0', sizeof (*lci));
-                       }
-
-                       lci->children_num++;
-                       lci->children =
-                               realloc (lci->children,
-                                        lci->children_num * sizeof (*child));
-                       if (lci->children == NULL)
-                       {
-                               ERROR ("apache plugin: realloc failed.");
-                               return (-1);
-                       }
-                       memcpy (&lci->children[lci->children_num-1], child, sizeof (*child));
-               }
+                       WARNING ("apache plugin: The configuration option "
+                                       "\"%s\" is not allowed here. Did you "
+                                       "forget to add an <Instance /> block "
+                                       "around the configuration?",
+                                       child->key);
        } /* for (ci->children) */
 
-       if (lci)
-       {
-               /* create a <Instance ""> entry */
-               lci->key = "Instance";
-               lci->values_num = 1;
-               lci->values = (oconfig_value_t *) malloc (lci->values_num * sizeof (oconfig_value_t));
-               lci->values[0].type = OCONFIG_TYPE_STRING;
-               lci->values[0].value.string = "";
-
-               status = config_add (lci);
-               sfree (lci->values);
-               sfree (lci->children);
-               sfree (lci);
-       }
-
-       return status;
+       return (status);
 } /* int config */
 
 /* initialize curl for each host */
@@ -420,6 +387,8 @@ static int init_host (apache_t *st) /* {{{ */
                        st->server_type = APACHE;
                else if (strcasecmp(st->server, "lighttpd") == 0)
                        st->server_type = LIGHTTPD;
+               else if (strcasecmp(st->server, "ibm_http_server") == 0)
+                       st->server_type = APACHE;
                else
                        WARNING ("apache plugin: Unknown `Server' setting: %s",
                                        st->server);
index 5c11b65..6b44722 100644 (file)
@@ -376,11 +376,6 @@ is found (and the number of values matches the number of data-sources) then the
 type, data-set and value-list is passed to all write-callbacks that are
 registered with the daemon.
 
-B<Note>: Prior to version 4.4 of collectd, the data-set type used to be passed
-as the first argument to B<plugin_register>. This syntax is still supported
-for backwards compatibility but has been deprecated and will be removed in
-some future version of collectd.
-
 =item B<plugin_write> ([B<plugins> => I<...>][, B<datasets> => I<...>],
 B<valuelists> => I<...>)
 
@@ -405,23 +400,6 @@ argument has been specified, only named plugins will be flushed. The value of
 the B<plugins> and B<identifiers> arguments may either be a string or a
 reference to an array of strings.
 
-=item B<plugin_flush_one> (I<timeout>, I<plugin>)
-
-This is identical to using "plugin_flush (timeout =E<gt> I<timeout>, plugins
-=E<gt> I<plugin>".
-
-B<Note>: Starting with version 4.5 of collectd, B<plugin_flush_one> has been
-deprecated and will be removed in some future version of collectd. Use
-B<plugin_flush> instead.
-
-=item B<plugin_flush_all> (I<timeout>)
-
-This is identical to using "plugin_flush (timeout =E<gt> I<timeout>)".
-
-B<Note>: Starting with version 4.5 of collectd, B<plugin_flush_all> has been
-deprecated and will be removed in some future version of collectd. Use
-B<plugin_flush> instead.
-
 =item B<plugin_dispatch_notification> (I<notification>)
 
 Submits a I<notification> to the daemon which will then pass it to all
index cc125dd..12cec75 100644 (file)
 ##############################################################################
 
 #<Plugin apache>
-#      URL "http://localhost/status?auto"
-#      User "www-user"
-#      Password "secret"
-#      CACert "/etc/ssl/ca.crt"
+#  <Instance "local">
+#    URL "http://localhost/status?auto"
+#    User "www-user"
+#    Password "secret"
+#    CACert "/etc/ssl/ca.crt"
+#  </Instance>
 #</Plugin>
 
 #<Plugin apcups>
index af07cdf..4b7a2e3 100644 (file)
@@ -199,7 +199,25 @@ Since its C<mod_status> module is very similar to Apache's, B<lighttpd> is
 also supported. It introduces a new field, called C<BusyServers>, to count the
 number of currently connected clients. This field is also supported.
 
-The following options are accepted by the C<apache>-plugin:
+The configuration of the I<Apache> plugin consists of one or more
+C<E<lt>InstanceE<nbsp>/E<gt>> blocks. Each block requires one string argument
+as the instance name. For example:
+
+ <Plugin "apache">
+   <Instance "www1">
+     URL "http://www1.example.com/mod_status?auto"
+   </Instance>
+   <Instance "www2">
+     URL "http://www2.example.com/mod_status?auto"
+   </Instance>
+ </Plugin>
+
+The instance name will be used as the I<plugin instance>. To emulate the old
+(versionE<nbsp>4) behavior, you can use an empty string (""). In order for the
+plugin to work correctly, each instance name must be unique. This is not
+enforced by the plugin and it is your responsibility to ensure it.
+
+The following options are accepted within each I<Instance> block:
 
 =over 4
 
@@ -207,7 +225,7 @@ The following options are accepted by the C<apache>-plugin:
 
 Sets the URL of the C<mod_status> output. This needs to be the output generated
 by C<ExtendedStatus on> and it needs to be the machine readable output
-generated by appending the C<?auto> argument.
+generated by appending the C<?auto> argument. This option is I<mandatory>.
 
 =item B<User> I<Username>
 
index 21deed6..fbac7ad 100644 (file)
@@ -98,18 +98,12 @@ static size_t cj_curl_callback (void *buf, /* {{{ */
     return (0);
 
   status = yajl_parse(db->yajl, (unsigned char *)buf, len);
-  if (status == yajl_status_ok)
-  {
-    status = yajl_parse_complete(db->yajl);
-    return (len);
-  }
-  else if (status == yajl_status_insufficient_data)
-    return (len);
-
-  if (status != yajl_status_ok)
+  if ((status != yajl_status_ok)
+      && (status != yajl_status_insufficient_data))
   {
     unsigned char *msg =
-      yajl_get_error(db->yajl, 1, (unsigned char *)buf, len);
+      yajl_get_error(db->yajl, /* verbose = */ 1,
+          /* jsonText = */ (unsigned char *) buf, (unsigned int) len);
     ERROR ("curl_json plugin: yajl_parse failed: %s", msg);
     yajl_free_error(db->yajl, msg);
     return (0); /* abort write callback */
@@ -768,9 +762,14 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */
   }
 
   status = curl_easy_perform (curl);
-
-  yajl_free (db->yajl);
-  db->yajl = yprev;
+  if (status != 0)
+  {
+    ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
+           status, db->curl_errbuf, url);
+    yajl_free (db->yajl);
+    db->yajl = yprev;
+    return (-1);
+  }
 
   curl_easy_getinfo(curl, CURLINFO_EFFECTIVE_URL, &url);
   curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &rc);
@@ -778,18 +777,30 @@ static int cj_curl_perform (cj_t *db, CURL *curl) /* {{{ */
   /* The response code is zero if a non-HTTP transport was used. */
   if ((rc != 0) && (rc != 200))
   {
-    ERROR ("curl_json plugin: curl_easy_perform failed with response code %ld (%s)",
-           rc, url);
+    ERROR ("curl_json plugin: curl_easy_perform failed with "
+        "response code %ld (%s)", rc, url);
+    yajl_free (db->yajl);
+    db->yajl = yprev;
     return (-1);
   }
 
-  if (status != 0)
+  status = yajl_parse_complete (db->yajl);
+  if (status != yajl_status_ok)
   {
-    ERROR ("curl_json plugin: curl_easy_perform failed with status %i: %s (%s)",
-           status, db->curl_errbuf, url);
+    unsigned char *errmsg;
+
+    errmsg = yajl_get_error (db->yajl, /* verbose = */ 0,
+        /* jsonText = */ NULL, /* jsonTextLen = */ 0);
+    ERROR ("curl_json plugin: yajl_parse_complete failed: %s",
+        (char *) errmsg);
+    yajl_free_error (db->yajl, errmsg);
+    yajl_free (db->yajl);
+    db->yajl = yprev;
     return (-1);
   }
 
+  yajl_free (db->yajl);
+  db->yajl = yprev;
   return (0);
 } /* }}} int cj_curl_perform */
 
index 48ad528..a01bbe4 100644 (file)
@@ -42,7 +42,6 @@
 
 struct mysql_database_s /* {{{ */
 {
-       /* instance == NULL  =>  legacy mode */
        char *instance;
        char *host;
        char *user;
@@ -243,10 +242,10 @@ static MYSQL *getconnection (mysql_database_t *db)
                int err;
                if ((err = mysql_ping (db->con)) != 0)
                {
-                       WARNING ("mysql_ping failed for %s: %s",
-                                       (db->instance != NULL)
-                                       ? db->instance
-                                       : "<legacy>",
+                       /* Assured by "mysql_config_database" */
+                       assert (db->instance != NULL);
+                       WARNING ("mysql_ping failed for instance \"%s\": %s",
+                                       db->instance,
                                        mysql_error (db->con));
                        db->state = 0;
                }
@@ -290,29 +289,13 @@ static MYSQL *getconnection (mysql_database_t *db)
 
 static void set_host (mysql_database_t *db, char *buf, size_t buflen)
 {
-       /* XXX legacy mode - use hostname_g */
-       if (db->instance == NULL)
+       if ((db->host == NULL)
+                       || (strcmp ("", db->host) == 0)
+                       || (strcmp ("localhost", db->host) == 0))
                sstrncpy (buf, hostname_g, buflen);
        else
-       {
-               if ((db->host == NULL)
-                               || (strcmp ("", db->host) == 0)
-                               || (strcmp ("localhost", db->host) == 0))
-                       sstrncpy (buf, hostname_g, buflen);
-               else
-                       sstrncpy (buf, db->host, buflen);
-       }
-}
-
-static void set_plugin_instance (mysql_database_t *db,
-               char *buf, size_t buflen)
-{
-       /* XXX legacy mode - no plugin_instance */
-       if (db->instance == NULL)
-               sstrncpy (buf, "", buflen);
-       else
-               sstrncpy (buf, db->instance, buflen);
-}
+               sstrncpy (buf, db->host, buflen);
+} /* void set_host */
 
 static void submit (const char *type, const char *type_instance,
                value_t *values, size_t values_len, mysql_database_t *db)
@@ -325,7 +308,10 @@ static void submit (const char *type, const char *type_instance,
        set_host (db, vl.host, sizeof (vl.host));
 
        sstrncpy (vl.plugin, "mysql", sizeof (vl.plugin));
-       set_plugin_instance (db, vl.plugin_instance, sizeof (vl.plugin_instance));
+
+       /* Assured by "mysql_config_database" */
+       assert (db->instance != NULL);
+       sstrncpy (vl.plugin_instance, db->instance, sizeof (vl.plugin_instance));
 
        sstrncpy (vl.type, type, sizeof (vl.type));
        if (type_instance != NULL)
@@ -508,8 +494,10 @@ static int mysql_read_slave_stats (mysql_database_t *db, MYSQL *con)
                sql = row[SLAVE_SQL_RUNNING_IDX];
 
                set_host (db, n.host, sizeof (n.host));
-               set_plugin_instance (db,
-                               n.plugin_instance, sizeof (n.plugin_instance));
+
+               /* Assured by "mysql_config_database" */
+               assert (db->instance != NULL);
+               sstrncpy (n.plugin_instance, db->instance, sizeof (n.plugin_instance));
 
                if (((io == NULL) || (strcasecmp (io, "yes") != 0))
                                && (db->slave_io_running))
index 6976842..36d3d8d 100644 (file)
@@ -38,10 +38,9 @@ static char *cacert      = NULL;
 
 static CURL *curl = NULL;
 
-#define ABUFFER_SIZE 16384
-static char nginx_buffer[ABUFFER_SIZE];
-static int  nginx_buffer_len = 0;
-static char nginx_curl_error[CURL_ERROR_SIZE];
+static char   nginx_buffer[16384];
+static size_t nginx_buffer_len = 0;
+static char   nginx_curl_error[CURL_ERROR_SIZE];
 
 static const char *config_keys[] =
 {
@@ -59,17 +58,19 @@ static size_t nginx_curl_callback (void *buf, size_t size, size_t nmemb,
 {
   size_t len = size * nmemb;
 
-  if ((nginx_buffer_len + len) >= ABUFFER_SIZE)
+  /* Check if the data fits into the memory. If not, truncate it. */
+  if ((nginx_buffer_len + len) >= sizeof (nginx_buffer))
   {
-    len = (ABUFFER_SIZE - 1) - nginx_buffer_len;
+    assert (sizeof (nginx_buffer) > nginx_buffer_len);
+    len = (sizeof (nginx_buffer) - 1) - nginx_buffer_len;
   }
 
   if (len <= 0)
     return (len);
 
-  memcpy (nginx_buffer + nginx_buffer_len, (char *) buf, len);
+  memcpy (&nginx_buffer[nginx_buffer_len], buf, len);
   nginx_buffer_len += len;
-  nginx_buffer[nginx_buffer_len] = '\0';
+  nginx_buffer[nginx_buffer_len] = 0;
 
   return (len);
 }
index a2f5da2..afb3ba7 100644 (file)
@@ -1610,40 +1610,29 @@ static XS (Collectd_plugin_unregister_ds)
 static XS (Collectd_plugin_dispatch_values)
 {
        SV *values     = NULL;
-       int values_idx = 0;
 
        int ret = 0;
 
        dXSARGS;
 
-       if (2 == items) {
-               log_warn ("Collectd::plugin_dispatch_values with two arguments "
-                               "is deprecated - pass the type through values->{type}.");
-               values_idx = 1;
-       }
-       else if (1 != items) {
+       if (1 != items) {
                log_err ("Usage: Collectd::plugin_dispatch_values(values)");
                XSRETURN_EMPTY;
        }
 
        log_debug ("Collectd::plugin_dispatch_values: values=\"%s\"",
-                       SvPV_nolen (ST (values_idx)));
+                       SvPV_nolen (ST (/* stack index = */ 0)));
 
-       values = ST (values_idx);
+       values = ST (/* stack index = */ 0);
 
+       /* Make sure the argument is a hash reference. */
        if (! (SvROK (values) && (SVt_PVHV == SvTYPE (SvRV (values))))) {
                log_err ("Collectd::plugin_dispatch_values: Invalid values.");
                XSRETURN_EMPTY;
        }
 
-       if (((2 == items) && (NULL == ST (0))) || (NULL == values))
-               XSRETURN_EMPTY;
-
-       if ((2 == items) && (NULL == hv_store ((HV *)SvRV (values), "type", 4,
-                       newSVsv (ST (0)), 0))) {
-               log_err ("Collectd::plugin_dispatch_values: Could not store type.");
+       if (NULL == values)
                XSRETURN_EMPTY;
-       }
 
        ret = pplugin_dispatch_values (aTHX_ (HV *)SvRV (values));
 
index f75e600..1b0020f 100644 (file)
@@ -100,8 +100,6 @@ mysql_handler               value:COUNTER:0:U
 mysql_locks            value:COUNTER:0:U
 mysql_log_position     value:COUNTER:0:4294967295
 mysql_octets           rx:COUNTER:0:4294967295, tx:COUNTER:0:4294967295
-mysql_qcache           hits:COUNTER:0:U, inserts:COUNTER:0:U, not_cached:COUNTER:0:U, lowmem_prunes:COUNTER:0:U, queries_in_cache:GAUGE:0:U
-mysql_threads          running:GAUGE:0:U, connected:GAUGE:0:U, cached:GAUGE:0:U, created:COUNTER:0:U
 nfs_procedure          value:COUNTER:0:4294967295
 nginx_connections      value:GAUGE:0:U
 nginx_requests         value:COUNTER:0:134217728