AC_CHECK_HEADERS(utmp.h)
AC_CHECK_HEADERS(utmpx.h)
+# For apache plugin
+AC_CHECK_HEADERS(curl/curl.h)
+
# For quota module
AC_CHECK_HEADERS(grp.h pwd.h sys/ucred.h)
AC_CHECK_HEADERS(ctype.h)
[with_libresolv="no"])
AM_CONDITIONAL(BUILD_WITH_LIBRESOLV, test "x$with_libresolv" = "xyes")
+with_libcurl="yes"
+AC_CHECK_LIB(curl, curl_easy_init,
+[
+ AC_DEFINE(HAVE_LIBCURL, 1, [Define to 1 if you have the 'curl' library (-lcurl).])
+],
+[with_libcurl="no"])
+AM_CONDITIONAL(BUILD_WITH_LIBCURL, test "x$with_libcurl" = "xyes")
+
+if test "x$with_libcurl" = "xyes"
+then
+ with_libcurl_libs=`curl-config --libs`
+ if test "x$with_libcurl_libs" != "x"
+ then
+ BUILD_WITH_LIBCURL_LIBS="$with_libcurl_libs";
+ AC_SUBST(BUILD_WITH_LIBCURL_LIBS)
+ fi
+fi
+
m4_divert_once([HELP_WITH], [
collectd additional packages:])
m4_divert_once([HELP_ENABLE], [
collectd modules:])
+AC_COLLECTD([apache], [disable], [module], [Apache httpd statistics])
AC_COLLECTD([battery], [disable], [module], [battery statistics])
AC_COLLECTD([cpu], [disable], [module], [cpu usage statistics])
AC_COLLECTD([cpufreq], [disable], [module], [system cpu frequency statistics])
Configuration:
Libraries:
+ libcurl . . . . . . $with_libcurl
librrd . . . . . . $with_rrdtool
lm_sensors . . . . $with_lm_sensors
libstatgrab . . . . $with_libstatgrab
$GraphDefs =
{
+ apache_bytes => ['DEF:min_raw={file}:count:MIN',
+ 'DEF:avg_raw={file}:count:AVERAGE',
+ 'DEF:max_raw={file}:count:MAX',
+ 'CDEF:min=min_raw,8,*',
+ 'CDEF:avg=avg_raw,8,*',
+ 'CDEF:max=max_raw,8,*',
+ 'CDEF:mytime=avg_raw,TIME,TIME,IF',
+ 'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+ 'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+ 'CDEF:avg_sample=avg_raw,UN,0,avg_raw,IF,sample_len,*',
+ 'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
+ "AREA:avg#$HalfBlue",
+ "LINE1:avg#$FullBlue:Bit/s",
+ 'GPRINT:min:MIN:%5.1lf%s Min,',
+ 'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+ 'GPRINT:max:MAX:%5.1lf%s Max,',
+ 'GPRINT:avg:LAST:%5.1lf%s Last',
+ 'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l'
+ ],
+ apache_requests => ['DEF:min={file}:count:MIN',
+ 'DEF:avg={file}:count:AVERAGE',
+ 'DEF:max={file}:count:MAX',
+ "AREA:max#$HalfBlue",
+ "AREA:min#$Canvas",
+ "LINE1:avg#$FullBlue:Requests/s",
+ 'GPRINT:min:MIN:%6.2lf Min,',
+ 'GPRINT:avg:AVERAGE:%6.2lf Avg,',
+ 'GPRINT:max:MAX:%6.2lf Max,',
+ 'GPRINT:avg:LAST:%6.2lf Last'
+ ],
+ apache_scoreboard => ['DEF:min={file}:count:MIN',
+ 'DEF:avg={file}:count:AVERAGE',
+ 'DEF:max={file}:count:MAX',
+ "AREA:max#$HalfBlue",
+ "AREA:min#$Canvas",
+ "LINE1:avg#$FullBlue:Processes",
+ 'GPRINT:min:MIN:%6.2lf Min,',
+ 'GPRINT:avg:AVERAGE:%6.2lf Avg,',
+ 'GPRINT:max:MAX:%6.2lf Max,',
+ 'GPRINT:avg:LAST:%6.2lf Last'
+ ],
charge => [
'DEF:avg={file}:charge:AVERAGE',
'DEF:min={file}:charge:MIN',
our $GraphArgs =
{
+ apache_bytes => ['-t', 'apache traffic', '-v', 'Bit/s'],
+ apache_requests => ['-t', 'apache requests', '-v', 'Requests/s'],
+ apache_scoreboard => ['-t', 'apache scoreboard {inst}', '-v', 'Processes'],
charge => ['-t', '{host} charge', '-v', 'Ampere hours'],
cpu => ['-t', '{host} cpu{inst} usage', '-v', 'Percent', '-l', '0'],
cpufreq => ['-t', '{host} cpu{inst} usage', '-v', 'Mhz'],
our $GraphMulti =
{
+ apache_scoreboard => \&output_graph_apache_scoreboard,
cpu => \&output_graph_cpu,
cpufreq => 1,
disk => 1,
return (@ret);
}
+sub output_graph_apache_scoreboard
+{
+ my @inst = @_;
+ my @ret = ();
+
+ die if (@inst < 2);
+
+ my @colors = get_n_colors (scalar (@inst));
+
+ for (my $i = 0; $i < scalar (@inst); $i++)
+ {
+ my $inst = $inst[$i];
+ push (@ret,
+ "DEF:avg_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:AVERAGE",
+ "DEF:min_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MIN",
+ "DEF:max_$i=$AbsDir/apache_scoreboard-$inst.rrd:count:MAX");
+ }
+
+ for (my $i = 0; $i < scalar (@inst); $i++)
+ {
+ my $inst = $inst[$i];
+ my $color = $colors[$i];
+
+ if (length ($inst) > 15)
+ {
+ $inst = substr ($inst, 0, 12) . '...';
+ }
+ else
+ {
+ $inst = sprintf ('%-15s', $inst);
+ }
+
+ push (@ret,
+ "LINE1:avg_$i#$color:$inst",
+ "GPRINT:min_$i:MIN:%6.2lf Min,",
+ "GPRINT:avg_$i:AVERAGE:%6.2lf Avg,",
+ "GPRINT:max_$i:MAX:%6.2lf Max,",
+ "GPRINT:avg_$i:LAST:%6.2lf Last\\l");
+ }
+
+ return (@ret);
+}
+
sub output_graph_ping
{
my @inst = @_;
pkglib_LTLIBRARIES =
+if BUILD_MODULE_APACHE
+pkglib_LTLIBRARIES += apache.la
+apache_la_SOURCES = apache.c
+apache_la_LDFLAGS = -module -avoid-version
+if BUILD_WITH_LIBCURL
+apache_la_LDFLAGS += $(BUILD_WITH_LIBCURL_LIBS)
+endif
+collectd_LDADD += "-dlopen" apache.la
+collectd_DEPENDENCIES += apache.la
+endif
+
if BUILD_MODULE_BATTERY
pkglib_LTLIBRARIES += battery.la
battery_la_SOURCES = battery.c
pkglib_LTLIBRARIES += wireless.la
wireless_la_SOURCES = wireless.c
wireless_la_LDFLAGS = -module -avoid-version
-# FIXME Make `-lm' conditional
-wireless_la_LDFLAGS += -lm
collectd_LDADD += "-dlopen" wireless.la
collectd_DEPENDENCIES += wireless.la
endif
--- /dev/null
+/**
+ * collectd - src/apache.c
+ * Copyright (C) 2006 Florian octo Forster
+ *
+ * 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; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "configfile.h"
+
+#define MODULE_NAME "apache"
+
+#if HAVE_LIBCURL && HAVE_CURL_CURL_H
+# define APACHE_HAVE_READ 1
+# include <curl/curl.h>
+#else
+# define APACHE_HAVE_READ 0
+#endif
+
+static char *url = NULL;
+static char *user = NULL;
+static char *pass = NULL;
+
+#if APACHE_HAVE_READ
+static CURL *curl = NULL;
+
+static char apache_buffer[4096];
+static int apache_buffer_len = 0;
+static char apache_curl_error[CURL_ERROR_SIZE];
+#endif
+
+static char *bytes_file = "apache/apache_bytes.rrd";
+static char *bytes_ds_def[] =
+{
+ "DS:count:COUNTER:25:0:U",
+ NULL
+};
+static int bytes_ds_num = 1;
+
+static char *requests_file = "apache/apache_requests.rrd";
+static char *requests_ds_def[] =
+{
+ "DS:count:COUNTER:25:0:U",
+ NULL
+};
+static int requests_ds_num = 1;
+
+static char *scoreboard_file = "apache/apache_scoreboard-%s.rrd";
+static char *scoreboard_ds_def[] =
+{
+ "DS:count:GAUGE:25:0:U",
+ NULL
+};
+static int scoreboard_ds_num = 1;
+
+static char *config_keys[] =
+{
+ "URL",
+ "User",
+ "Password",
+ NULL
+};
+static int config_keys_num = 3;
+
+
+static size_t apache_curl_callback (void *buf, size_t size, size_t nmemb, void *stream)
+{
+ size_t len = size * nmemb;
+
+ if ((apache_buffer_len + len) >= 4096)
+ {
+ len = 4095 - apache_buffer_len;
+ }
+
+ if (len <= 0)
+ return (len);
+
+ memcpy (apache_buffer + apache_buffer_len, (char *) buf, len);
+ apache_buffer_len += len;
+ apache_buffer[apache_buffer_len] = '\0';
+
+ return (len);
+}
+
+static int config_set (char **var, char *value)
+{
+ if (*var != NULL)
+ {
+ free (*var);
+ *var = NULL;
+ }
+
+ if ((*var = strdup (value)) == NULL)
+ return (1);
+ else
+ return (0);
+}
+
+static int config (char *key, char *value)
+{
+ if (strcasecmp (key, "url") == 0)
+ return (config_set (&url, value));
+ else if (strcasecmp (key, "user") == 0)
+ return (config_set (&user, value));
+ else if (strcasecmp (key, "password") == 0)
+ return (config_set (&pass, value));
+ else
+ return (-1);
+}
+
+static void init (void)
+{
+#if APACHE_HAVE_READ
+ static char credentials[1024];
+
+ if (curl != NULL)
+ {
+ curl_easy_cleanup (curl);
+ }
+
+ if ((curl = curl_easy_init ()) == NULL)
+ {
+ syslog (LOG_ERR, "apache: `curl_easy_init' failed.");
+ return;
+ }
+
+ curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, apache_curl_callback);
+ curl_easy_setopt (curl, CURLOPT_USERAGENT, PACKAGE_NAME"/"PACKAGE_VERSION);
+ curl_easy_setopt (curl, CURLOPT_ERRORBUFFER, apache_curl_error);
+
+ if (user != NULL)
+ {
+ if (snprintf (credentials, 1024, "%s:%s", user, pass == NULL ? "" : pass) >= 1024)
+ {
+ syslog (LOG_ERR, "apache: Credentials would have been truncated.");
+ return;
+ }
+
+ curl_easy_setopt (curl, CURLOPT_USERPWD, credentials);
+ }
+
+ if (url != NULL)
+ {
+ curl_easy_setopt (curl, CURLOPT_URL, url);
+ }
+#endif /* APACHE_HAVE_READ */
+}
+
+static void bytes_write (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, bytes_file, val, bytes_ds_def, bytes_ds_num);
+}
+
+static void requests_write (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, requests_file, val, requests_ds_def, requests_ds_num);
+}
+
+static void scoreboard_write (char *host, char *inst, char *val)
+{
+ char buf[1024];
+
+ if (snprintf (buf, 1024, scoreboard_file, inst) >= 1024)
+ return;
+
+ rrd_update_file (host, buf, val, scoreboard_ds_def, scoreboard_ds_num);
+}
+
+#if APACHE_HAVE_READ
+static void submit (char *type, char *inst, long long value)
+{
+ char buf[1024];
+ int status;
+
+ status = snprintf (buf, 1024, "%u:%lli", (unsigned int) curtime, value);
+ if (status < 0)
+ {
+ syslog (LOG_ERR, "apache: bytes_submit: snprintf failed");
+ return;
+ }
+ else if (status >= 1024)
+ {
+ syslog (LOG_WARNING, "apache: bytes_submit: snprintf was truncated");
+ return;
+ }
+
+ plugin_submit (type, inst, buf);
+}
+
+static void submit_scoreboard (char *buf)
+{
+ /*
+ * Scoreboard Key:
+ * "_" Waiting for Connection, "S" Starting up, "R" Reading Request,
+ * "W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
+ * "C" Closing connection, "L" Logging, "G" Gracefully finishing,
+ * "I" Idle cleanup of worker, "." Open slot with no current process
+ */
+ long long open = 0LL;
+ long long waiting = 0LL;
+ long long starting = 0LL;
+ long long reading = 0LL;
+ long long sending = 0LL;
+ long long keepalive = 0LL;
+ long long dnslookup = 0LL;
+ long long closing = 0LL;
+ long long logging = 0LL;
+ long long finishing = 0LL;
+ long long idle_cleanup = 0LL;
+
+ int i;
+
+ for (i = 0; buf[i] != '\0'; i++)
+ {
+ if (buf[i] == '.') open++;
+ else if (buf[i] == '_') waiting++;
+ else if (buf[i] == 'S') starting++;
+ else if (buf[i] == 'R') reading++;
+ else if (buf[i] == 'W') sending++;
+ else if (buf[i] == 'K') keepalive++;
+ else if (buf[i] == 'D') dnslookup++;
+ else if (buf[i] == 'C') closing++;
+ else if (buf[i] == 'L') logging++;
+ else if (buf[i] == 'G') finishing++;
+ else if (buf[i] == 'I') idle_cleanup++;
+ }
+
+ submit ("apache_scoreboard", "open" , open);
+ submit ("apache_scoreboard", "waiting" , waiting);
+ submit ("apache_scoreboard", "starting" , starting);
+ submit ("apache_scoreboard", "reading" , reading);
+ submit ("apache_scoreboard", "sending" , sending);
+ submit ("apache_scoreboard", "keepalive", keepalive);
+ submit ("apache_scoreboard", "dnslookup", dnslookup);
+ submit ("apache_scoreboard", "closing" , closing);
+ submit ("apache_scoreboard", "logging" , logging);
+ submit ("apache_scoreboard", "finishing", finishing);
+ submit ("apache_scoreboard", "idle_cleanup", idle_cleanup);
+}
+
+static void apache_read (void)
+{
+ int i;
+
+ char *ptr;
+ char *lines[16];
+ int lines_num = 0;
+
+ char *fields[4];
+ int fields_num;
+
+ if (curl == NULL)
+ return;
+ if (url == NULL)
+ return;
+
+ if (curl_easy_perform (curl) != 0)
+ {
+ syslog (LOG_WARNING, "apache: curl_easy_perform failed: %s", apache_curl_error);
+ return;
+ }
+
+ ptr = apache_buffer;
+ while ((lines[lines_num] = strtok (ptr, "\n\r")) != NULL)
+ {
+ ptr = NULL;
+ lines_num++;
+
+ if (lines_num >= 16)
+ break;
+ }
+
+ for (i = 0; i < lines_num; i++)
+ {
+ fields_num = strsplit (lines[i], fields, 4);
+
+ if (fields_num == 3)
+ {
+ if ((strcmp (fields[0], "Total") == 0)
+ && (strcmp (fields[1], "Accesses:") == 0))
+ submit ("apache_requests", NULL, atoll (fields[2]));
+ else if ((strcmp (fields[0], "Total") == 0)
+ && (strcmp (fields[1], "kBytes:") == 0))
+ submit ("apache_bytes", NULL, 1024LL * atoll (fields[2]));
+ }
+ else if (fields_num == 2)
+ {
+ if (strcmp (fields[0], "Scoreboard:") == 0)
+ submit_scoreboard (fields[1]);
+ }
+ }
+
+ apache_buffer_len = 0;
+}
+#else
+# define apache_read NULL
+#endif /* APACHE_HAVE_READ */
+
+void module_register (void)
+{
+ plugin_register (MODULE_NAME, init, apache_read, NULL);
+ plugin_register ("apache_requests", NULL, NULL, requests_write);
+ plugin_register ("apache_bytes", NULL, NULL, bytes_write);
+ plugin_register ("apache_scoreboard", NULL, NULL, scoreboard_write);
+ cf_register (MODULE_NAME, config, config_keys, config_keys_num);
+}
+
+#undef MODULE_NAME
if ((cf_cb = cf_search (type)) == NULL)
{
- syslog (LOG_WARNING, "Plugin `%s' did not register a callback.\n", type);
+ syslog (LOG_WARNING, "Plugin `%s' did not register a callback.", type);
return (-1);
}
}
if (i >= cf_cb->keys_num)
- syslog (LOG_WARNING, "Plugin `%s' did not register for value `%s'.\n", type, key);
+ syslog (LOG_WARNING, "Plugin `%s' did not register for value `%s'.", type, key);
free (key);
free (value);
+ DBG ("return (%i)", ret);
+
return (ret);
}
AUTOMAKE_OPTIONS = foreign no-dependencies
+if COMPILER_IS_GCC
+AM_CFLAGS = -Wall -Werror
+endif
+
noinst_LTLIBRARIES = liboping.la
#liboping_la_CFLAGS =
/*
* private (static) functions
*/
+static int ping_timeval_add (struct timeval *tv1, struct timeval *tv2,
+ struct timeval *res)
+{
+ res->tv_sec = tv1->tv_sec + tv2->tv_sec;
+ res->tv_usec = tv1->tv_usec + tv2->tv_usec;
+
+ while (res->tv_usec > 1000000)
+ {
+ res->tv_usec -= 1000000;
+ res->tv_sec++;
+ }
+
+ return (0);
+}
+
static int ping_timeval_sub (struct timeval *tv1, struct timeval *tv2,
struct timeval *res)
{
return (0);
}
-static int ping_receive_all (pinghost_t *ph)
+static int ping_receive_all (pingobj_t *obj)
{
fd_set readfds;
int num_readfds;
int max_readfds;
+ pinghost_t *ph;
pinghost_t *ptr;
struct timeval endtime;
int ret;
+ ph = obj->head;
ret = 0;
for (ptr = ph; ptr != NULL; ptr = ptr->next)
ptr->latency = -1.0;
- if (gettimeofday (&endtime, NULL) == -1)
+ if (gettimeofday (&nowtime, NULL) == -1)
return (-1);
- endtime.tv_sec += 1;
+
+ /* Set up timeout */
+ timeout.tv_sec = (time_t) obj->timeout;
+ timeout.tv_usec = (suseconds_t) (1000000 * (obj->timeout - ((double) timeout.tv_sec)));
+
+ dprintf ("Set timeout to %i.%06i seconds\n",
+ (int) timeout.tv_sec,
+ (int) timeout.tv_usec);
+
+ ping_timeval_add (&nowtime, &timeout, &endtime);
while (1)
{
return (0);
}
+/*
+ * Set the TTL of a socket protocol independently.
+ */
+static int ping_set_ttl (pinghost_t *ph, int ttl)
+{
+ int ret = -2;
+
+ if (ph->addrfamily == AF_INET)
+ {
+ ret = setsockopt (ph->fd, IPPROTO_IP, IP_TTL, &ttl, sizeof (ttl));
+ }
+ else if (ph->addrfamily == AF_INET6)
+ {
+ ret = setsockopt (ph->fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &ttl, sizeof (ttl));
+ }
+
+ return (ret);
+}
+
static int ping_get_ident (void)
{
int fd;
if (ping_send_all (obj->head) < 0)
return (-1);
- if ((ret = ping_receive_all (obj->head)) < 0)
+ if ((ret = ping_receive_all (obj)) < 0)
return (-2);
return (ret);
#ifdef AI_ADDRCONFIG
ai_hints.ai_flags |= AI_ADDRCONFIG;
#endif
- ai_hints.ai_family = PF_UNSPEC;
+ ai_hints.ai_family = obj->addrfamily;
ai_hints.ai_socktype = SOCK_RAW;
if ((ph = ping_alloc ()) == NULL)
ph->next = obj->head;
obj->head = ph;
+ ping_set_ttl (ph, obj->ttl);
+
return (0);
}
if (ping_host_add (pingobj, value) < 0)
{
- syslog (LOG_ERR, "ping: `ping_host_add' failed.\n");
- return (-1);
+ syslog (LOG_WARNING, "ping: `ping_host_add' failed.\n");
}
return (0);
static char *rrd_other = "vserver-%s/traffic-other.rrd";
static char *rrd_unspec = "vserver-%s/traffic-unspec.rrd";
-static char *rrd_thread = "vserver-%s/threads.rrd";
+static char *rrd_thread = "vserver-%s/vs_threads.rrd";
static char *rrd_load = "vserver-%s/load.rrd";
#include "common.h"
#include "plugin.h"
-#include <math.h>
-
#define MODULE_NAME "wireless"
#define BUFSIZE 1024
static char *ds_def[] =
{
"DS:quality:GAUGE:"COLLECTD_HEARTBEAT":0:U",
- "DS:power:GAUGE:"COLLECTD_HEARTBEAT":0:U",
- "DS:noise:GAUGE:"COLLECTD_HEARTBEAT":0:U",
+ "DS:power:GAUGE:"COLLECTD_HEARTBEAT":U:0",
+ "DS:noise:GAUGE:"COLLECTD_HEARTBEAT":U:0",
NULL
};
static int ds_num = 3;
}
#if WIRELESS_HAVE_READ
+#if 0
static double wireless_dbm_to_watt (double dbm)
{
double watt;
return (watt);
}
+#endif
static void wireless_submit (char *device,
double quality, double power, double noise)
power = atof (fields[3]);
noise = atof (fields[4]);
+ /* Fill in invalid values when conversion failed.. */
if (quality == 0.0)
- quality = -1.0;
+ quality = -1.0; /* quality >= 0 */
- if (power >= 0.0)
- power = -1.0;
- else
- power = wireless_dbm_to_watt (power);
+ if (power == 0.0)
+ power = 1.0; /* power <= 0 */
- if (noise >= 0.0)
- noise = -1.0;
- else
- noise = wireless_dbm_to_watt (noise);
+ if (noise == 0.0)
+ noise = 1.0; /* noise <= 0 */
wireless_submit (device, quality, power, noise);
}
void module_register (void)
{
- plugin_register (MODULE_NAME, wireless_init, wireless_read, wireless_write);
+ plugin_register (MODULE_NAME, wireless_init, wireless_read, wireless_write);
}
#undef BUFSIZE