* lpar plugin: New plugins for "logical partitions", a virtualization
technique of POWER CPUs. Thanks to Aurélien Reynaud for his code and
patience.
+ * modbus plugin: Support for libmodbus 2.9.2 has been added and the
+ license has been changes to LGPLv2.1.
* mysql plugin: Backwards compatibility code has been removed. The
data sets used have been improved.
* network plugin: The default buffer size has been increased to
fi
AC_CHECK_HEADERS(credis.h,
[with_libcredis="yes"],
- [with_libcredis="no ('credis.h' not found)"])
+ [with_libcredis="no (credis.h not found)"])
fi
if test "x$with_libcredis" = "xyes"
then
$PKG_CONFIG --exists 'modbus' 2>/dev/null
if test $? -ne 0
then
- with_libmodbus="no (pkg-config doesn't know library)"
+ with_libmodbus="no (pkg-config doesn't know modbus)"
fi
fi
if test "x$with_libmodbus" = "xuse_pkgconfig"
fi
AC_CHECK_HEADERS(oping.h,
[with_liboping="yes"],
- [with_liboping="no ('oping.h' not found)"])
+ [with_liboping="no (oping.h not found)"])
fi
if test "x$with_liboping" = "xyes"
then
fi
if test "x$with_libpcap" = "xyes"
then
- AC_CHECK_HEADERS(pcap-bpf.h)
+ AC_CHECK_HEADERS(pcap-bpf.h,,
+ [with_libpcap="no (pcap-bpf.h not found)"])
fi
AM_CONDITIONAL(BUILD_WITH_LIBPCAP, test "x$with_libpcap" = "xyes")
# }}}
fi
AC_CHECK_HEADERS(routeros_api.h,
[with_librouteros="yes"],
- [with_librouteros="no ('routeros_api.h' not found)"])
+ [with_librouteros="no (routeros_api.h not found)"])
fi
if test "x$with_librouteros" = "xyes"
then
if test "$?" != "0"
then
with_libstatgrab_pkg_config="no"
- with_libstatgrab="no ($PKG_CONFIG doesn't know libstatgrab)"
+ with_libstatgrab="no (pkg-config doesn't know libstatgrab)"
temp_result="not found"
fi
AC_MSG_RESULT([$temp_result])
$PKG_CONFIG --exists 'libupsclient' 2>/dev/null
if test $? -ne 0
then
- with_libupsclient="no (pkg-config doesn't know library)"
+ with_libupsclient="no (pkg-config doesn't know libupsclient)"
fi
fi
if test "x$with_libupsclient" = "xuse_pkgconfig"
$PKG_CONFIG --exists 'varnishapi' 2>/dev/null
if test $? -ne 0
then
- with_libvarnish="no (pkg-config doesn't know library)"
+ with_libvarnish="no (pkg-config doesn't know varnishapi)"
fi
fi
if test "x$with_libvarnish" = "xuse_pkgconfig"
then
with_libxml2="yes"
else
- with_libxml2="no (pkg-config doesn't know library)"
+ with_libxml2="no (pkg-config doesn't know libxml-2.0)"
fi
pkg-config --exists libvirt 2>/dev/null
then
with_libvirt="yes"
else
- with_libvirt="no (pkg-config doesn't know library)"
+ with_libvirt="no (pkg-config doesn't know libvirt)"
fi
fi
if test "x$with_libxml2" = "xyes"
$PKG_CONFIG --exists OpenIPMIpthread 2>/dev/null
if test "$?" != "0"
then
- with_libopenipmipthread="no ($PKG_CONFIG doesn't know OpenIPMIpthread)"
+ with_libopenipmipthread="no (pkg-config doesn't know OpenIPMIpthread)"
fi
AC_MSG_RESULT([$with_libopenipmipthread])
fi
PKG_CHECK_MODULES([LIBNOTIFY], [libnotify],
[with_libnotify="yes"],
- [with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)"])
+ [if test "x$LIBNOTIFY_PKG_ERRORS" = "x"; then
+ with_libnotify="no"
+ else
+ with_libnotify="no ($LIBNOTIFY_PKG_ERRORS)"
+ fi])
# Check for enabled/disabled features
#
then
plugin_cpu="yes"
plugin_memory="yes"
- plugin_swap="yes"
plugin_uptime="yes"
+ if test "x$ac_system" = "xDarwin"
+ then
+ plugin_swap="yes"
+ fi
fi
if test "x$have_sysctlbyname" = "xyes"
then
plugin_swap="yes"
fi
-if test "x$have_swapctl" = "xyes"
+if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_two_args" = "xyes"
then
plugin_swap="yes"
fi
#<Plugin hddtemp>
# Host "127.0.0.1"
# Port "7634"
-#
-# #----------------------------------------------------------------#
-# # `TranslateDevicename' enables backwards compatibility behavior #
-# # and is enabled by default. Setting this option to `false' is #
-# # highly recommended. #
-# #----------------------------------------------------------------#
-# TranslateDevicename false
#</Plugin>
#<Plugin interface>
# </Host>
#</Plugin>
+#<Plugin "swap">
+# ReportByDevice false
+#</Plugin>
+
#<Plugin "table">
# <Table "/proc/slabinfo">
# Instance "slabinfo"
=head2 Plugin C<swap>
The I<Swap plugin> collects information about used and available swap space. On
-I<Solaris>, the following options are available:
+I<Linux> and I<Solaris>, the following options are available:
=over 4
=item B<ReportByDevice> B<false>|B<true>
-Configures how to report physical swap devices. If set to B<false> is used (the
+Configures how to report physical swap devices. If set to B<false> (the
default), the summary over all swap devices is reported only, i.e. the globally
used and available space over all devices. If B<true> is configured, the used
and available space of each device will be reported separately.
-This option is only available if the I<Swap plugin> can use the L<swapctl(2)>
-mechanism under I<Solaris>.
+This option is only available if the I<Swap plugin> can read C</proc/swaps>
+(under Linux) or use the L<swapctl(2)> mechanism (under I<Solaris>).
=back
# include <math.h>
#endif
-/* for ntohl and htonl */
-#if HAVE_ARPA_INET_H
-# include <arpa/inet.h>
-#endif
-
/* for getaddrinfo */
#include <sys/types.h>
#include <sys/socket.h>
# include <netinet/in.h>
#endif
+/* for ntohl and htonl */
+#if HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
+
#ifdef HAVE_LIBKSTAT
extern kstat_ctl_t *kc;
#endif
/**
* collectd - src/configfile.c
- * Copyright (C) 2005-2010 Florian octo Forster
+ * Copyright (C) 2005-2011 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
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
* Sebastian tokkee Harl <sh at tokkee.org>
**/
return (0);
} /* }}} int cf_util_get_flag */
-/* Assures that the config option is a string. The string is then converted to
- * a port number using `service_name_to_port_number' and returned. Returns the
- * port number in the range [1-65535] or less than zero upon failure. */
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. The string is then converted to a port number using
+ * `service_name_to_port_number' and returned.
+ * Returns the port number in the range [1-65535] or less than zero upon
+ * failure. */
int cf_util_get_port_number (const oconfig_item_t *ci) /* {{{ */
{
- if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ int tmp;
+
+ if ((ci->values_num != 1)
+ || ((ci->values[0].type != OCONFIG_TYPE_STRING)
+ && (ci->values[0].type != OCONFIG_TYPE_NUMBER)))
{
- ERROR ("cf_util_get_port_number: The %s option requires "
+ ERROR ("cf_util_get_port_number: The \"%s\" option requires "
"exactly one string argument.", ci->key);
return (-1);
}
- return (service_name_to_port_number (ci->values[0].value.string));
+ if (ci->values[0].type == OCONFIG_TYPE_STRING)
+ return (service_name_to_port_number (ci->values[0].value.string));
+
+ assert (ci->values[0].type == OCONFIG_TYPE_NUMBER);
+ tmp = (int) (ci->values[0].value.number + 0.5);
+ if ((tmp < 1) || (tmp > 65535))
+ {
+ ERROR ("cf_util_get_port_number: The \"%s\" option requires "
+ "a service name or a port number. The number "
+ "you specified, %i, is not in the valid "
+ "range of 1-65535.",
+ ci->key, tmp);
+ return (-1);
+ }
+
+ return (tmp);
} /* }}} int cf_util_get_port_number */
int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value) /* {{{ */
#define CONFIGFILE_H
/**
* collectd - src/configfile.h
- * Copyright (C) 2005-2010 Florian octo Forster
+ * Copyright (C) 2005-2011 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
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
**/
#include "collectd.h"
int cf_util_get_flag (const oconfig_item_t *ci,
unsigned int *ret_value, unsigned int flag);
-/* Assures that the config option is a string. The string is then converted to
- * a port number using `service_name_to_port_number' and returned. Returns the
- * port number in the range [1-65535] or less than zero upon failure. */
+/* Assures that the config option is a string or a number if the correct range
+ * of 1-65535. The string is then converted to a port number using
+ * `service_name_to_port_number' and returned.
+ * Returns the port number in the range [1-65535] or less than zero upon
+ * failure. */
int cf_util_get_port_number (const oconfig_item_t *ci);
int cf_util_get_cdtime (const oconfig_item_t *ci, cdtime_t *ret_value);
#include <poll.h>
#include <pcap.h>
-#if HAVE_PCAP_BPF_H
-# include <pcap-bpf.h>
-#endif
+#include <pcap-bpf.h>
/*
* Private data types
return (0);
} /* }}} int lcc_set_errno */
-/* lcc_strdup: Since `strdup' is an XSI extension, we provide our own version
- * here. */
-__attribute__((malloc, nonnull (1)))
-static char *lcc_strdup (const char *str) /* {{{ */
-{
- size_t strsize;
- char *ret;
-
- strsize = strlen (str) + 1;
- ret = (char *) malloc (strsize);
- if (ret != NULL)
- memcpy (ret, str, strsize);
- return (ret);
-} /* }}} char *lcc_strdup */
-
-__attribute__((nonnull (1, 2)))
static char *lcc_strescape (char *dest, const char *src, size_t dest_size) /* {{{ */
{
size_t dest_pos;
size_t src_pos;
+ if ((dest == NULL) || (src == NULL))
+ return (NULL);
+
dest_pos = 0;
src_pos = 0;
lcc_chomp (buffer);
LCC_DEBUG ("receive: <-- %s\n", buffer);
- res.lines[i] = lcc_strdup (buffer);
+ res.lines[i] = strdup (buffer);
if (res.lines[i] == NULL)
{
lcc_set_errno (c, ENOMEM);
if (values_names != NULL)
{
- values_names[i] = lcc_strdup (key);
+ values_names[i] = strdup (key);
if (values_names[i] == NULL)
BAIL_OUT (ENOMEM);
}
char *type;
char *type_instance;
- string_copy = lcc_strdup (string);
+ string_copy = strdup (string);
if (string_copy == NULL)
{
lcc_set_errno (c, ENOMEM);
* Copyright (C) 2010,2011 noris network AG
*
* 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.
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; only version 2.1 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.
+ * Lesser 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
+ * You should have received a copy of the GNU Lesser 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 Forster <octo at noris.net>
/**
* collectd - src/mysql.c
- * Copyright (C) 2006-2009 Florian octo Forster
+ * Copyright (C) 2006-2010 Florian octo Forster
* Copyright (C) 2008 Mirko Buffoni
* Copyright (C) 2009 Doug MacEachern
* Copyright (C) 2009 Sebastian tokkee Harl
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Authors:
- * Florian octo Forster <octo at verplant.org>
+ * Florian octo Forster <octo at collectd.org>
* Mirko Buffoni <briareos at eswat.org>
* Doug MacEachern <dougm at hyperic.com>
* Sebastian tokkee Harl <sh at tokkee.org>
/**
* collectd - src/plugin.c
- * Copyright (C) 2005-2010 Florian octo Forster
+ * Copyright (C) 2005-2011 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
}
}
+ le = llist_search (read_list, rf->rf_name);
+ if (le != NULL)
+ {
+ pthread_mutex_unlock (&read_lock);
+ WARNING ("The read function \"%s\" is already registered. "
+ "Check for duplicate \"LoadPlugin\" lines "
+ "in your configuration!",
+ rf->rf_name);
+ return (EINVAL);
+ }
+
le = llentry_create (rf->rf_name, rf);
if (le == NULL)
{
int (*callback) (void))
{
read_func_t *rf;
+ int status;
- rf = (read_func_t *) malloc (sizeof (read_func_t));
+ rf = malloc (sizeof (*rf));
if (rf == NULL)
{
- char errbuf[1024];
- ERROR ("plugin_register_read: malloc failed: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- return (-1);
+ ERROR ("plugin_register_read: malloc failed.");
+ return (ENOMEM);
}
memset (rf, 0, sizeof (read_func_t));
rf->rf_interval.tv_nsec = 0;
rf->rf_effective_interval = rf->rf_interval;
- return (plugin_insert_read (rf));
+ status = plugin_insert_read (rf);
+ if (status != 0)
+ sfree (rf);
+
+ return (status);
} /* int plugin_register_read */
int plugin_register_complex_read (const char *group, const char *name,
user_data_t *user_data)
{
read_func_t *rf;
+ int status;
- rf = (read_func_t *) malloc (sizeof (read_func_t));
+ rf = malloc (sizeof (*rf));
if (rf == NULL)
{
ERROR ("plugin_register_complex_read: malloc failed.");
- return (-1);
+ return (ENOMEM);
}
memset (rf, 0, sizeof (read_func_t));
rf->rf_udata = *user_data;
}
- return (plugin_insert_read (rf));
+ status = plugin_insert_read (rf);
+ if (status != 0)
+ sfree (rf);
+
+ return (status);
} /* int plugin_register_complex_read */
int plugin_register_write (const char *name,
plugin_init_cb callback);
int plugin_register_read (const char *name,
int (*callback) (void));
+/* "user_data" will be freed automatically, unless
+ * "plugin_register_complex_read" returns an error (non-zero). */
int plugin_register_complex_read (const char *group, const char *name,
plugin_read_cb callback,
const struct timespec *interval,
static int rc_write (const data_set_t *ds, const value_list_t *vl,
user_data_t __attribute__((unused)) *user_data)
{
- char filename[512];
+ char filename[PATH_MAX];
char values[512];
char *values_array[2];
int status;
return (0);
} /* int rc_write */
+static int rc_flush (__attribute__((unused)) cdtime_t timeout, /* {{{ */
+ const char *identifier,
+ __attribute__((unused)) user_data_t *ud)
+{
+ char filename[PATH_MAX + 1];
+ int status;
+
+ if (identifier == NULL)
+ return (EINVAL);
+
+ if (datadir != NULL)
+ ssnprintf (filename, sizeof (filename), "%s/%s.rrd", datadir, identifier);
+ else
+ ssnprintf (filename, sizeof (filename), "%s.rrd", identifier);
+
+ status = rrdc_connect (daemon_address);
+ if (status != 0)
+ {
+ ERROR ("rrdcached plugin: rrdc_connect (%s) failed with status %i.",
+ daemon_address, status);
+ return (-1);
+ }
+
+ status = rrdc_flush (filename);
+ if (status != 0)
+ {
+ ERROR ("rrdcached plugin: rrdc_flush (%s) failed with status %i.",
+ filename, status);
+ return (-1);
+ }
+ DEBUG ("rrdcached plugin: rrdc_flush (%s): Success.", filename);
+
+ return (0);
+} /* }}} int rc_flush */
+
static int rc_shutdown (void)
{
rrdc_disconnect ();
config_keys, config_keys_num);
plugin_register_init ("rrdcached", rc_init);
plugin_register_write ("rrdcached", rc_write, /* user_data = */ NULL);
+ plugin_register_flush ("rrdcached", rc_flush, /* user_data = */ NULL);
plugin_register_shutdown ("rrdcached", rc_shutdown);
} /* void module_register */
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#if KERNEL_LINUX
+# define SWAP_HAVE_CONFIG 1
/* No global variables */
/* #endif KERNEL_LINUX */
#elif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
+# define SWAP_HAVE_CONFIG 1
static derive_t pagesize;
-
-static const char *config_keys[] =
-{
- "ReportByDevice"
-};
-static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
-
-static _Bool report_by_device = 0;
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
#elif defined(VM_SWAPUSAGE)
# error "No applicable input method."
#endif /* HAVE_LIBSTATGRAB */
-static int swap_init (void)
+#if SWAP_HAVE_CONFIG
+static const char *config_keys[] =
+{
+ "ReportByDevice"
+};
+static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
+
+static _Bool report_by_device = 0;
+
+static int swap_config (const char *key, const char *value) /* {{{ */
+{
+ if (strcasecmp ("ReportByDevice", key) == 0)
+ {
+ if (IS_TRUE (value))
+ report_by_device = 1;
+ else
+ report_by_device = 0;
+ }
+ else
+ {
+ return (-1);
+ }
+
+ return (0);
+} /* }}} int swap_config */
+#endif /* SWAP_HAVE_CONFIG */
+
+static int swap_init (void) /* {{{ */
{
#if KERNEL_LINUX
/* No init stuff */
#endif /* HAVE_PERFSTAT */
return (0);
-}
+} /* }}} int swap_init */
-static void swap_submit_inst (const char *plugin_instance, /* {{{ */
- const char *type_instance, derive_t value, unsigned type)
+static void swap_submit (const char *plugin_instance, /* {{{ */
+ const char *type, const char *type_instance,
+ value_t value)
{
- value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- switch (type)
- {
- case DS_TYPE_GAUGE:
- values[0].gauge = (gauge_t) value;
- sstrncpy (vl.type, "swap", sizeof (vl.type));
- break;
- case DS_TYPE_DERIVE:
- values[0].derive = value;
- sstrncpy (vl.type, "swap_io", sizeof (vl.type));
- break;
- default:
- ERROR ("swap plugin: swap_submit called with wrong"
- " type");
- }
+ assert (type != NULL);
- vl.values = values;
+ vl.values = &value;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "swap", sizeof (vl.plugin));
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ if (type_instance != NULL)
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
plugin_dispatch_values (&vl);
} /* }}} void swap_submit_inst */
-static void swap_submit (const char *type_instance, derive_t value, unsigned type)
+static void swap_submit_gauge (const char *plugin_instance, /* {{{ */
+ const char *type_instance, gauge_t value)
+{
+ value_t v;
+
+ v.gauge = value;
+ swap_submit (plugin_instance, "swap", type_instance, v);
+} /* }}} void swap_submit_gauge */
+
+static void swap_submit_derive (const char *plugin_instance, /* {{{ */
+ const char *type_instance, derive_t value)
{
- swap_submit_inst (/* plugin instance = */ NULL,
- type_instance, value, type);
-}
+ value_t v;
+
+ v.derive = value;
+ swap_submit (plugin_instance, "swap_io", type_instance, v);
+} /* }}} void swap_submit_derive */
+
#if KERNEL_LINUX
-static int swap_read (void) /* {{{ */
+static int swap_read_separate (void) /* {{{ */
{
FILE *fh;
char buffer[1024];
- char *fields[8];
- int numfields;
+ fh = fopen ("/proc/swaps", "r");
+ if (fh == NULL)
+ {
+ char errbuf[1024];
+ WARNING ("swap plugin: fopen (/proc/swaps) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (-1);
+ }
+
+ while (fgets (buffer, sizeof (buffer), fh) != NULL)
+ {
+ char *fields[8];
+ int numfields;
+ char *endptr;
+
+ char path[PATH_MAX];
+ gauge_t size;
+ gauge_t used;
+ gauge_t free;
+
+ numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
+ if (numfields != 5)
+ continue;
+
+ sstrncpy (path, fields[0], sizeof (path));
+ escape_slashes (path, sizeof (path));
+
+ errno = 0;
+ endptr = NULL;
+ size = strtod (fields[2], &endptr);
+ if ((endptr == fields[2]) || (errno != 0))
+ continue;
+
+ errno = 0;
+ endptr = NULL;
+ used = strtod (fields[3], &endptr);
+ if ((endptr == fields[3]) || (errno != 0))
+ continue;
+
+ if (size < used)
+ continue;
+
+ free = size - used;
+
+ swap_submit_gauge (path, "used", used);
+ swap_submit_gauge (path, "free", free);
+ }
- _Bool old_kernel=0;
+ fclose (fh);
- derive_t swap_used = 0;
- derive_t swap_cached = 0;
- derive_t swap_free = 0;
- derive_t swap_total = 0;
- derive_t swap_in = 0;
- derive_t swap_out = 0;
+ return (0);
+} /* }}} int swap_read_separate */
- if ((fh = fopen ("/proc/meminfo", "r")) == NULL)
+static int swap_read_combined (void) /* {{{ */
+{
+ FILE *fh;
+ char buffer[1024];
+
+ uint8_t have_data = 0;
+ gauge_t swap_used = 0.0;
+ gauge_t swap_cached = 0.0;
+ gauge_t swap_free = 0.0;
+ gauge_t swap_total = 0.0;
+
+ fh = fopen ("/proc/meminfo", "r");
+ if (fh == NULL)
{
char errbuf[1024];
- WARNING ("memory: fopen: %s",
+ WARNING ("swap plugin: fopen (/proc/meminfo) failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
+ char *fields[8];
+ int numfields;
+
numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
if (numfields < 2)
continue;
if (strcasecmp (fields[0], "SwapTotal:") == 0)
- strtoderive (fields[1], &swap_total);
+ {
+ swap_total = strtod (fields[1], /* endptr = */ NULL);
+ have_data |= 0x01;
+ }
else if (strcasecmp (fields[0], "SwapFree:") == 0)
- strtoderive (fields[1], &swap_free);
+ {
+ swap_free = strtod (fields[1], /* endptr = */ NULL);
+ have_data |= 0x02;
+ }
else if (strcasecmp (fields[0], "SwapCached:") == 0)
- strtoderive (fields[1], &swap_cached);
+ {
+ swap_cached = strtod (fields[1], /* endptr = */ NULL);
+ have_data |= 0x04;
+ }
}
- if (fclose (fh))
- {
- char errbuf[1024];
- WARNING ("memory: fclose: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- }
+ fclose (fh);
- if ((swap_total == 0LL) || ((swap_free + swap_cached) > swap_total))
- return (-1);
+ if (have_data != 0x07)
+ return (ENOENT);
+
+ if (isnan (swap_total)
+ || (swap_total <= 0.0)
+ || ((swap_free + swap_cached) > swap_total))
+ return (EINVAL);
swap_used = swap_total - (swap_free + swap_cached);
- if ((fh = fopen ("/proc/vmstat", "r")) == NULL)
+ swap_submit_gauge (NULL, "used", 1024.0 * swap_used);
+ swap_submit_gauge (NULL, "free", 1024.0 * swap_free);
+ swap_submit_gauge (NULL, "cached", 1024.0 * swap_cached);
+
+ return (0);
+} /* }}} int swap_read_combined */
+
+static int swap_read_io (void) /* {{{ */
+{
+ FILE *fh;
+ char buffer[1024];
+
+ _Bool old_kernel = 0;
+
+ uint8_t have_data = 0;
+ derive_t swap_in = 0;
+ derive_t swap_out = 0;
+
+ fh = fopen ("/proc/vmstat", "r");
+ if (fh == NULL)
{
- // /proc/vmstat does not exist in kernels <2.6
- if ((fh = fopen ("/proc/stat", "r")) == NULL )
+ /* /proc/vmstat does not exist in kernels <2.6 */
+ fh = fopen ("/proc/stat", "r");
+ if (fh == NULL)
{
char errbuf[1024];
WARNING ("swap: fopen: %s",
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
+ char *fields[8];
+ int numfields;
+
numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
if (!old_kernel)
continue;
if (strcasecmp ("pswpin", fields[0]) == 0)
+ {
strtoderive (fields[1], &swap_in);
+ have_data |= 0x01;
+ }
else if (strcasecmp ("pswpout", fields[0]) == 0)
+ {
strtoderive (fields[1], &swap_out);
+ have_data |= 0x02;
+ }
}
else /* if (old_kernel) */
{
}
} /* while (fgets) */
- if (fclose (fh))
- {
- char errbuf[1024];
- WARNING ("swap: fclose: %s",
- sstrerror (errno, errbuf, sizeof (errbuf)));
- }
+ fclose (fh);
+
+ if (have_data != 0x03)
+ return (ENOENT);
+
+ swap_submit_derive (NULL, "in", swap_in);
+ swap_submit_derive (NULL, "out", swap_out);
+
+ return (0);
+} /* }}} int swap_read_io */
- swap_submit ("used", 1024 * swap_used, DS_TYPE_GAUGE);
- swap_submit ("free", 1024 * swap_free, DS_TYPE_GAUGE);
- swap_submit ("cached", 1024 * swap_cached, DS_TYPE_GAUGE);
- swap_submit ("in", swap_in, DS_TYPE_DERIVE);
- swap_submit ("out", swap_out, DS_TYPE_DERIVE);
+static int swap_read (void) /* {{{ */
+{
+ if (report_by_device)
+ swap_read_separate ();
+ else
+ swap_read_combined ();
+
+ swap_read_io ();
return (0);
} /* }}} int swap_read */
* pagesize);
swap_avail = (derive_t) ((ai.ani_max - ai.ani_resv) * pagesize);
- swap_submit ("used", swap_alloc, DS_TYPE_GAUGE);
- swap_submit ("free", swap_avail, DS_TYPE_GAUGE);
- swap_submit ("reserved", swap_resv, DS_TYPE_GAUGE);
+ swap_submit_gauge (NULL, "used", swap_alloc);
+ swap_submit_gauge (NULL, "free", swap_avail);
+ swap_submit_gauge (NULL, "reserved", swap_resv);
return (0);
} /* }}} int swap_read_kstat */
continue;
}
- /* Okay, using "/" as swap device would be super-weird, but
- * we'll handle it anyway to cover all cases. */
- if (strcmp ("/", s->swt_ent[i].ste_path) == 0)
- sstrncpy (path, "root", sizeof (path));
- else
- {
- int j;
-
- s->swt_ent[i].ste_path[PATH_MAX - 1] = 0;
- /* Don't copy the leading slash */
- sstrncpy (path, &s->swt_ent[i].ste_path[1], sizeof (path));
- /* Convert slashes to dashes, just like the "df" plugin. */
- for (j = 0; path[j] != 0; j++)
- if (path[j] == '/')
- path[j] = '-';
- }
+ sstrncpy (path, s->swt_ent[i].ste_path, sizeof (path));
+ escape_slashes (path, sizeof (path));
- swap_submit_inst (path, "used", this_total - this_avail, DS_TYPE_GAUGE);
- swap_submit_inst (path, "free", this_avail, DS_TYPE_GAUGE);
+ swap_submit_gauge (path, "used", (gauge_t) (this_total - this_avail));
+ swap_submit_gauge (path, "free", (gauge_t) this_avail);
} /* for (swap_num) */
if (total < avail)
* values have already been dispatched from within the loop. */
if (!report_by_device)
{
- swap_submit ("used", total - avail, DS_TYPE_GAUGE);
- swap_submit ("free", avail, DS_TYPE_GAUGE);
+ swap_submit_gauge (NULL, "used", (gauge_t) (total - avail));
+ swap_submit_gauge (NULL, "free", (gauge_t) avail);
}
sfree (s_paths);
sfree (s);
return (0);
} /* }}} int swap_read */
-
-/* Configuration: Present when swapctl or both methods are available. */
-static int swap_config (const char *key, const char *value) /* {{{ */
-{
- if (strcasecmp ("ReportByDevice", key) == 0)
- {
- if (IS_TRUE (value))
- report_by_device = 1;
- else
- report_by_device = 0;
- }
- else
- {
- return (-1);
- }
-
- return (0);
-} /* }}} int swap_config */
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
#elif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS
return (-1);
}
- swap_submit ("used", used, DS_TYPE_GAUGE);
- swap_submit ("free", total - used, DS_TYPE_GAUGE);
+ swap_submit_gauge (NULL, "used", (gauge_t) used);
+ swap_submit_gauge (NULL, "free", (gauge_t) (total - used));
sfree (swap_entries);
return (-1);
/* The returned values are bytes. */
- swap_submit ("used", (derive_t) sw_usage.xsu_used, DS_TYPE_GAUGE);
- swap_submit ("free", (derive_t) sw_usage.xsu_avail, DS_TYPE_GAUGE);
+ swap_submit_gauge (NULL, "used", (gauge_t) sw_usage.xsu_used);
+ swap_submit_gauge (NULL, "free", (gauge_t) sw_usage.xsu_avail);
return (0);
} /* }}} int swap_read */
free = total - used;
- swap_submit ("used", used, DS_TYPE_GAUGE);
- swap_submit ("free", free, DS_TYPE_GAUGE);
+ swap_submit_gauge (NULL, "used", (gauge_t) used);
+ swap_submit_gauge (NULL, "free", (gauge_t) free);
return (0);
} /* }}} int swap_read */
if (swap == NULL)
return (-1);
- swap_submit ("used", (derive_t) swap->used, DS_TYPE_GAUGE);
- swap_submit ("free", (derive_t) swap->free, DS_TYPE_GAUGE);
+ swap_submit_gauge (NULL, "used", (gauge_t) swap->used);
+ swap_submit_gauge (NULL, "free", (gauge_t) swap->free);
return (0);
} /* }}} int swap_read */
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
- swap_submit ("used", (derive_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize, DS_TYPE_GAUGE);
- swap_submit ("free", (derive_t) pmemory.pgsp_free * pagesize , DS_TYPE_GAUGE);
+ swap_submit_gauge (NULL, "used", (gauge_t) (pmemory.pgsp_total - pmemory.pgsp_free) * pagesize);
+ swap_submit_gauge (NULL, "free", (gauge_t) pmemory.pgsp_free * pagesize );
return (0);
} /* }}} int swap_read */
void module_register (void)
{
-#if HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS
+#if SWAP_HAVE_CONFIG
plugin_register_config ("swap", swap_config, config_keys, config_keys_num);
#endif
plugin_register_init ("swap", swap_init);
#include "common.h"
#include "plugin.h"
-#include <arpa/inet.h>
#include <netinet/in.h>
+#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
apache_idle_workers value:GAUGE:0:65535
apache_requests value:DERIVE:0:U
apache_scoreboard value:GAUGE:0:65535
-arc_counts demand_data:DERIVE:0:U, demand_metadata:DERIVE:0:U, prefetch_data:DERIVE:0:U, prefetch_metadata:DERIVE:0:U
-arc_l2_bytes read:DERIVE:0:U, write:DERIVE:0:U
-arc_l2_size value:GAUGE:0:U
-arc_ratio value:GAUGE:0:U
-arc_size current:GAUGE:0:U, target:GAUGE:0:U, minlimit:GAUGE:0:U, maxlimit:GAUGE:0:U
ath_nodes value:GAUGE:0:65535
ath_stat value:DERIVE:0:U
bitrate value:GAUGE:0:4294967295
vs_memory value:GAUGE:0:9223372036854775807
vs_processes value:GAUGE:0:65535
vs_threads value:GAUGE:0:65535
+#
+# Legacy types
+# (required for the v5 upgrade target)
+#
+arc_counts demand_data:COUNTER:0:U, demand_metadata:COUNTER:0:U, prefetch_data:COUNTER:0:U, prefetch_metadata:COUNTER:0:U
+arc_l2_bytes read:COUNTER:0:U, write:COUNTER:0:U
+arc_l2_size value:GAUGE:0:U
+arc_ratio value:GAUGE:0:U
+arc_size current:GAUGE:0:U, target:GAUGE:0:U, minlimit:GAUGE:0:U, maxlimit:GAUGE:0:U
+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
if (fields_num < 2)
return;
+ /* Ignore lines which begin with a hash sign. */
+ if (fields[0][0] == '#')
+ return;
+
ds = (data_set_t *) malloc (sizeof (data_set_t));
if (ds == NULL)
return;
return 1;
}
+#if HAVE_NETINET_IP6_H
static int
handle_ipv6 (struct ip6_hdr *ipv6, int len)
{
return (1); /* Success */
} /* int handle_ipv6 */
+/* #endif HAVE_NETINET_IP6_H */
+
+#else /* if !HAVE_NETINET_IP6_H */
+static int
+handle_ipv6 (__attribute__((unused)) void *pkg,
+ __attribute__((unused)) int len)
+{
+ return (0);
+}
+#endif /* !HAVE_NETINET_IP6_H */
static int
handle_ip(const struct ip *ip, int len)
struct in6_addr d_addr;
if (ip->ip_v == 6)
- return (handle_ipv6 ((struct ip6_hdr *) ip, len));
+ return (handle_ipv6 ((void *) ip, len));
in6_addr_from_buffer (&s_addr, &ip->ip_src.s_addr, sizeof (ip->ip_src.s_addr), AF_INET);
in6_addr_from_buffer (&d_addr, &ip->ip_dst.s_addr, sizeof (ip->ip_dst.s_addr), AF_INET);
return 0;
memcpy(buf, pkt, len);
if (ETHERTYPE_IPV6 == etype)
- return (handle_ipv6 ((struct ip6_hdr *) buf, len));
+ return (handle_ipv6 ((void *) buf, len));
else
return handle_ip((struct ip *) buf, len);
}
return 0;
if (ETHERTYPE_IPV6 == etype)
- return (handle_ipv6 ((struct ip6_hdr *) pkt, len));
+ return (handle_ipv6 ((void *) pkt, len));
else
return handle_ip((struct ip *) pkt, len);
}
/* outstanding allocations */
varnish_submit_gauge (conf->instance, "sm", "requests", "outstanding", VSL_stats->sm_nobj);
/* bytes allocated */
- varnish_submit_gauge (conf->instance, "sm", "bytes", "allocated", VSL_stats->sm_balloc);
+ varnish_submit_gauge (conf->instance, "sm", "total_bytes", "allocated", VSL_stats->sm_balloc);
/* bytes free */
- varnish_submit_gauge (conf->instance, "sm", "bytes", "free", VSL_stats->sm_bfree);
+ varnish_submit_gauge (conf->instance, "sm", "total_bytes", "free", VSL_stats->sm_bfree);
}
if (conf->collect_sma)
/* SMA outstanding bytes */
varnish_submit_gauge (conf->instance, "sma", "bytes", "outstanding", VSL_stats->sma_nbytes);
/* SMA bytes allocated */
- varnish_submit_gauge (conf->instance, "sma", "bytes", "allocated", VSL_stats->sma_balloc);
+ varnish_submit_gauge (conf->instance, "sma", "total_bytes", "allocated", VSL_stats->sma_balloc);
/* SMA bytes free */
- varnish_submit_gauge (conf->instance, "sma", "bytes", "free" , VSL_stats->sma_bfree);
+ varnish_submit_gauge (conf->instance, "sma", "total_bytes", "free" , VSL_stats->sma_bfree);
}
if (conf->collect_sms)
/* SMS outstanding bytes */
varnish_submit_gauge (conf->instance, "sms", "bytes", "outstanding", VSL_stats->sms_nbytes);
/* SMS bytes allocated */
- varnish_submit_gauge (conf->instance, "sms", "bytes", "allocated", VSL_stats->sms_balloc);
+ varnish_submit_gauge (conf->instance, "sms", "total_bytes", "allocated", VSL_stats->sms_balloc);
/* SMS bytes freed */
- varnish_submit_gauge (conf->instance, "sms", "bytes", "free", VSL_stats->sms_bfree);
+ varnish_submit_gauge (conf->instance, "sms", "total_bytes", "free", VSL_stats->sms_bfree);
}
if (conf->collect_totals)