X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fapache.c;h=13c8db66801291fb05cac46171ce089e14175e47;hb=0156c3098b39c4b7996891ec8342ed9c3f6d4aaa;hp=8458ce15d1c9b58bdd8c9c24220e844242443f3a;hpb=344be4992285313e8855c8114993b692ae08775e;p=collectd.git diff --git a/src/apache.c b/src/apache.c index 8458ce15..13c8db66 100644 --- a/src/apache.c +++ b/src/apache.c @@ -78,6 +78,7 @@ static void apache_free (apache_t *st) curl_easy_cleanup(st->curl); st->curl = NULL; } + sfree (st); } /* apache_free */ static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb, @@ -584,12 +585,9 @@ static void submit_scoreboard (char *buf, apache_t *st) static int apache_read_host (user_data_t *user_data) /* {{{ */ { - int i; - char *ptr; char *saveptr; - char *lines[16]; - int lines_num = 0; + char *line; char *fields[4]; int fields_num; @@ -629,29 +627,17 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */ ptr = st->apache_buffer; saveptr = NULL; - while ((lines[lines_num] = strtok_r (ptr, "\n\r", &saveptr)) != NULL) + while ((line = strtok_r (ptr, "\n\r", &saveptr)) != NULL) { ptr = NULL; - lines_num++; - - if (lines_num >= 16) - break; - } - - for (i = 0; i < lines_num; i++) - { - fields_num = strsplit (lines[i], fields, 4); + fields_num = strsplit (line, fields, STATIC_ARRAY_SIZE (fields)); if (fields_num == 3) { - if ((strcmp (fields[0], "Total") == 0) - && (strcmp (fields[1], "Accesses:") == 0)) - submit_derive ("apache_requests", "", - atoll (fields[2]), st); - else if ((strcmp (fields[0], "Total") == 0) - && (strcmp (fields[1], "kBytes:") == 0)) - submit_derive ("apache_bytes", "", - 1024LL * atoll (fields[2]), st); + if ((strcmp (fields[0], "Total") == 0) && (strcmp (fields[1], "Accesses:") == 0)) + submit_derive ("apache_requests", "", atoll (fields[2]), st); + else if ((strcmp (fields[0], "Total") == 0) && (strcmp (fields[1], "kBytes:") == 0)) + submit_derive ("apache_bytes", "", 1024LL * atoll (fields[2]), st); } else if (fields_num == 2) { @@ -671,9 +657,18 @@ static int apache_read_host (user_data_t *user_data) /* {{{ */ return (0); } /* }}} int apache_read_host */ +static int apache_init (void) /* {{{ */ +{ + /* Call this while collectd is still single-threaded to avoid + * initialization issues in libgcrypt. */ + curl_global_init (CURL_GLOBAL_SSL); + return (0); +} /* }}} int apache_init */ + void module_register (void) { plugin_register_complex_config ("apache", config); + plugin_register_init ("apache", apache_init); } /* void module_register */ /* vim: set sw=8 noet fdm=marker : */