PKG_PROG_PKG_CONFIG
AC_CHECK_PROG([have_protoc_c], [protoc-c], [yes], [no])
-AC_CHECK_HEADERS([google/protobuf-c/protobuf-c.h],
- [have_protobuf_c_h="yes"],
- [have_protobuf_c_h="no"])
-if test "x$have_protoc_c" = "xyes" && test "x$have_protobuf_c_h" != "xyes"
+if test "x$have_protoc_c" = "xno"
then
- have_protoc_c="no (unable to find <google/protobuf-c/protobuf-c.h>)"
+ have_protoc_c="no (protoc-c compiler not found)"
+fi
+
+if test "x$have_protoc_c" = "xyes"
+then
+ AC_CHECK_HEADERS([protobuf-c/protobuf-c.h google/protobuf-c/protobuf-c.h],
+ [have_protoc_c="yes"; break],
+ [have_protoc_c="no (<google/protobuf-c/protobuf-c.h> not found)"])
+fi
+if test "x$have_protoc_c" = "xyes"
+then
+ AC_CHECK_LIB([protobuf-c], [protobuf_c_message_pack],
+ [have_protoc_c="yes"],
+ [have_protoc_c="no (libprotobuf-c not found)"])
+
fi
AM_CONDITIONAL(HAVE_PROTOC_C, test "x$have_protoc_c" = "xyes")
AC_CHECK_FUNCS(getvfsstat, [have_getvfsstat="yes"])
have_listmntent="no"
AC_CHECK_FUNCS(listmntent, [have_listmntent="yes"])
+have_getmntent_r="no"
+AC_CHECK_FUNCS(getmntent_r, [have_getmntent_r="yes"])
have_getmntent="no"
AC_CHECK_FUNCS(getmntent, [have_getmntent="c"])
GCRYPT_CPPFLAGS=`"$with_libgcrypt_config" --cflags 2>/dev/null`
fi
- if test "x$GCRYPT_LDFLAGS" = "x"
- then
- gcrypt_exec_prefix=`"$with_libgcrypt_config" --exec-prefix 2>/dev/null`
- GCRYPT_LDFLAGS="-L$gcrypt_exec_prefix/lib"
- fi
-
if test "x$GCRYPT_LIBS" = "x"
then
GCRYPT_LIBS=`"$with_libgcrypt_config" --libs 2>/dev/null`
SAVE_CPPFLAGS="$CPPFLAGS"
SAVE_LDFLAGS="$LDFLAGS"
+SAVE_LIBS="$LIBS"
CPPFLAGS="$CPPFLAGS $GCRYPT_CPPFLAGS"
LDFLAGS="$LDFLAGS $GCRYPT_LDFLAGS"
+LIBS="$LIBS $GCRYPT_LIBS"
if test "x$with_libgcrypt" = "xyes"
then
if test "x$with_libgcrypt" = "xyes"
then
- if test "x$GCRYPT_LDFLAGS" != "x"
- then
- AC_MSG_NOTICE([gcrypt LDFLAGS: $GCRYPT_LDFLAGS])
- fi
AC_CHECK_LIB(gcrypt, gcry_md_hash_buffer,
[with_libgcrypt="yes"],
[with_libgcrypt="no (symbol gcry_md_hash_buffer not found)"])
CPPFLAGS="$SAVE_CPPFLAGS"
LDFLAGS="$SAVE_LDFLAGS"
+LIBS="$SAVE_LIBS"
if test "x$with_libgcrypt" = "xyes"
then
plugin_df="yes"
fi
+if test "x$c_cv_have_getmntent_r" = "xyes"
+then
+ plugin_df="yes"
+fi
+
# Df plugin: Check if we have either `statfs' or `statvfs' second.
if test "x$plugin_df" = "xyes"
then
if BUILD_PLUGIN_CGROUPS
pkglib_LTLIBRARIES += cgroups.la
-cgroups_la_SOURCES = cgroups.c \
- utils_ignorelist.c utils_ignorelist.h
+cgroups_la_SOURCES = cgroups.c
cgroups_la_LDFLAGS = $(PLUGIN_LDFLAGS)
cgroups_la_LIBADD = libmount.la
endif
if BUILD_PLUGIN_DF
pkglib_LTLIBRARIES += df.la
-df_la_SOURCES = df.c \
- utils_ignorelist.c utils_ignorelist.h
+df_la_SOURCES = df.c
df_la_LDFLAGS = $(PLUGIN_LDFLAGS)
df_la_LIBADD = libmount.la
endif
if BUILD_PLUGIN_DISK
pkglib_LTLIBRARIES += disk.la
-disk_la_SOURCES = disk.c \
- utils_ignorelist.c utils_ignorelist.h
+disk_la_SOURCES = disk.c
disk_la_CFLAGS = $(AM_CFLAGS)
disk_la_LDFLAGS = $(PLUGIN_LDFLAGS)
disk_la_LIBADD =
if BUILD_PLUGIN_INTERFACE
pkglib_LTLIBRARIES += interface.la
-interface_la_SOURCES = interface.c \
- utils_ignorelist.c utils_ignorelist.h
+interface_la_SOURCES = interface.c
interface_la_CFLAGS = $(AM_CFLAGS)
interface_la_LDFLAGS = $(PLUGIN_LDFLAGS)
interface_la_LIBADD =
if BUILD_PLUGIN_IPMI
pkglib_LTLIBRARIES += ipmi.la
-ipmi_la_SOURCES = ipmi.c \
- utils_ignorelist.c utils_ignorelist.h
+ipmi_la_SOURCES = ipmi.c
ipmi_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_OPENIPMI_CFLAGS)
ipmi_la_LDFLAGS = $(PLUGIN_LDFLAGS)
ipmi_la_LIBADD = $(BUILD_WITH_OPENIPMI_LIBS)
if BUILD_PLUGIN_IRQ
pkglib_LTLIBRARIES += irq.la
-irq_la_SOURCES = irq.c \
- utils_ignorelist.c utils_ignorelist.h
+irq_la_SOURCES = irq.c
irq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif
if BUILD_PLUGIN_MADWIFI
pkglib_LTLIBRARIES += madwifi.la
-madwifi_la_SOURCES = madwifi.c madwifi.h \
- utils_ignorelist.c utils_ignorelist.h
+madwifi_la_SOURCES = madwifi.c madwifi.h
madwifi_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif
if BUILD_PLUGIN_MD
pkglib_LTLIBRARIES += md.la
-md_la_SOURCES = md.c \
- utils_ignorelist.c utils_ignorelist.h
+md_la_SOURCES = md.c
md_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif
if BUILD_PLUGIN_MIC
pkglib_LTLIBRARIES += mic.la
-mic_la_SOURCES = mic.c \
- utils_ignorelist.c utils_ignorelist.h
+mic_la_SOURCES = mic.c
mic_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_MIC_LIBPATH)
mic_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_MIC_CPPFLAGS)
mic_la_LIBADD = $(BUILD_WITH_MIC_LDADD)
if BUILD_PLUGIN_NETAPP
pkglib_LTLIBRARIES += netapp.la
-netapp_la_SOURCES = netapp.c \
- utils_ignorelist.c utils_ignorelist.h
+netapp_la_SOURCES = netapp.c
netapp_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBNETAPP_CPPFLAGS)
netapp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(LIBNETAPP_LDFLAGS)
netapp_la_LIBADD = $(LIBNETAPP_LIBS)
if BUILD_PLUGIN_ONEWIRE
pkglib_LTLIBRARIES += onewire.la
-onewire_la_SOURCES = onewire.c \
- utils_ignorelist.c utils_ignorelist.h
+onewire_la_SOURCES = onewire.c
onewire_la_CFLAGS = $(AM_CFLAGS)
onewire_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBOWCAPI_CPPFLAGS)
onewire_la_LIBADD = $(BUILD_WITH_LIBOWCAPI_LIBS)
if BUILD_PLUGIN_PROTOCOLS
pkglib_LTLIBRARIES += protocols.la
-protocols_la_SOURCES = protocols.c \
- utils_ignorelist.c utils_ignorelist.h
+protocols_la_SOURCES = protocols.c
protocols_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif
if BUILD_PLUGIN_SENSORS
pkglib_LTLIBRARIES += sensors.la
-sensors_la_SOURCES = sensors.c \
- utils_ignorelist.c utils_ignorelist.h
+sensors_la_SOURCES = sensors.c
sensors_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSENSORS_CFLAGS)
sensors_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSENSORS_LDFLAGS)
sensors_la_LIBADD = -lsensors
if BUILD_PLUGIN_SMART
if BUILD_WITH_LIBUDEV
pkglib_LTLIBRARIES += smart.la
-smart_la_SOURCES = smart.c \
- utils_ignorelist.c utils_ignorelist.h
+smart_la_SOURCES = smart.c
smart_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBATASMART_CPPFLAGS)
smart_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBATASMART_LDFLAGS)
smart_la_LIBADD = $(BUILD_WITH_LIBATASMART_LIBS) -ludev
if BUILD_PLUGIN_THERMAL
pkglib_LTLIBRARIES += thermal.la
-thermal_la_SOURCES = thermal.c \
- utils_ignorelist.c utils_ignorelist.h
+thermal_la_SOURCES = thermal.c
thermal_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif
if BUILD_PLUGIN_VIRT
pkglib_LTLIBRARIES += virt.la
-virt_la_SOURCES = virt.c \
- utils_ignorelist.c utils_ignorelist.h
+virt_la_SOURCES = virt.c
virt_la_CFLAGS = $(AM_CFLAGS) \
$(BUILD_WITH_LIBVIRT_CFLAGS) $(BUILD_WITH_LIBXML2_CFLAGS)
virt_la_LIBADD = $(BUILD_WITH_LIBVIRT_LIBS) $(BUILD_WITH_LIBXML2_LIBS)
echo "$@ has some POD errors!"; false; \
fi
+AM_V_PROTOC_C = $(am__v_PROTOC_C_@AM_V@)
+am__v_PROTOC_C_ = $(am__v_PROTOC_C_@AM_DEFAULT_V@)
+am__v_PROTOC_C_0 = @echo " PROTOC-C " $@;
+am__v_PROTOC_C_1 =
+
# Protocol buffer for the "pinba" plugin.
EXTRA_DIST += pinba.proto
-if HAVE_PROTOC_C
+if BUILD_PLUGIN_PINBA
CLEANFILES += pinba.pb-c.c pinba.pb-c.h
BUILT_SOURCES += pinba.pb-c.c pinba.pb-c.h
pinba.pb-c.c pinba.pb-c.h: pinba.proto
- protoc-c -I$(srcdir) --c_out . $(srcdir)/pinba.proto
+ $(AM_V_PROTOC_C)protoc-c -I$(srcdir) --c_out . $(srcdir)/pinba.proto
endif
# Protocol buffer for the "write_riemann" plugin.
EXTRA_DIST += riemann.proto
-if HAVE_PROTOC_C
+if BUILD_PLUGIN_WRITE_RIEMANN
CLEANFILES += riemann.pb-c.c riemann.pb-c.h
BUILT_SOURCES += riemann.pb-c.c riemann.pb-c.h
riemann.pb-c.c riemann.pb-c.h: riemann.proto
- protoc-c -I$(srcdir) --c_out . $(srcdir)/riemann.proto
+ $(AM_V_PROTOC_C)protoc-c -I$(srcdir) --c_out . $(srcdir)/riemann.proto
endif
install-exec-hook:
test_utils_vl_lookup_LDADD = liblookup.la daemon/libplugin_mock.la
TESTS = test_utils_mount test_utils_vl_lookup
+
+if BUILD_PLUGIN_CEPH
+test_plugin_ceph_SOURCES = ceph_test.c
+test_plugin_ceph_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBYAJL_CPPFLAGS)
+test_plugin_ceph_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBYAJL_LDFLAGS)
+test_plugin_ceph_LDADD = daemon/libcommon.la daemon/libplugin_mock.la $(BUILD_WITH_LIBYAJL_LIBS)
+check_PROGRAMS += test_plugin_ceph
+TESTS += test_plugin_ceph
+endif
switch (r.reply_type)
{
case AMQP_RESPONSE_NORMAL:
- sstrncpy (buffer, "Success", sizeof (buffer));
+ sstrncpy (buffer, "Success", buffer_size);
break;
case AMQP_RESPONSE_NONE:
- sstrncpy (buffer, "Missing RPC reply type", sizeof (buffer));
+ sstrncpy (buffer, "Missing RPC reply type", buffer_size);
break;
case AMQP_RESPONSE_LIBRARY_EXCEPTION:
return (sstrerror (r.library_error, buffer, buffer_size));
#endif
else
- sstrncpy (buffer, "End of stream", sizeof (buffer));
+ sstrncpy (buffer, "End of stream", buffer_size);
break;
case AMQP_RESPONSE_SERVER_EXCEPTION:
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;
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)
{
if (status != 0)
{
char errbuf[1024];
- INFO ("getaddrinfo failed: %s",
+ INFO ("apcups plugin: getaddrinfo failed: %s",
(status == EAI_SYSTEM)
? sstrerror (errno, errbuf, sizeof (errbuf))
: gai_strerror (status));
if (sd < 0)
{
- DEBUG ("Unable to open a socket");
+ DEBUG ("apcups plugin: Unable to open a socket");
freeaddrinfo (ai_return);
return (-1);
}
if (status != 0) /* `connect(2)' failed */
{
char errbuf[1024];
- INFO ("connect failed: %s",
+ INFO ("apcups plugin: connect failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
close (sd);
return (-1);
}
- DEBUG ("Done opening a socket %i", sd);
+ DEBUG ("apcups plugin: Done opening a socket %i", sd);
return (sd);
} /* int net_open (char *host, char *service, int port) */
*/
if (status != 0)
{
- DEBUG ("apc_query_server (%s, %i) = %i",
+ DEBUG ("apcups plugin: apc_query_server (%s, %i) = %i",
conf_host == NULL
? APCUPS_DEFAULT_HOST
: conf_host,
if (tmp->name == NULL)
{
ERROR ("bind plugin: strdup failed.");
- free (tmp);
+ sfree (views);
return (-1);
}
/**
* collectd - src/ceph.c
* Copyright (C) 2011 New Dream Network
+ * Copyright (C) 2015 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:
- * Colin McCabe <cmccabe@alumni.cmu.edu>
- * Dennis Zou <yunzou@cisco.com>
- * Dan Ryder <daryder@cisco.com>
+ * Colin McCabe <cmccabe at alumni.cmu.edu>
+ * Dennis Zou <yunzou at cisco.com>
+ * Dan Ryder <daryder at cisco.com>
+ * Florian octo Forster <octo at collectd.org>
**/
#define _DEFAULT_SOURCE
sfree(d);
}
-/**
- * Compact ds name by removing special characters and trimming length to
- * DATA_MAX_NAME_LEN if necessary
- */
-static void compact_ds_name(char *source, char *dest)
+/* compact_ds_name removed the special characters ":", "_", "-" and "+" from the
+ * intput string. Characters following these special characters are capitalized.
+ * Trailing "+" and "-" characters are replaces with the strings "Plus" and
+ * "Minus". */
+static int compact_ds_name (char *buffer, size_t buffer_size, char const *src)
{
- int keys_num = 0, i;
- char *save_ptr = NULL, *tmp_ptr = source;
- char *keys[16];
- char len_str[3];
- char tmp[DATA_MAX_NAME_LEN];
- size_t key_chars_remaining = (DATA_MAX_NAME_LEN-1);
- int reserved = 0;
- int offset = 0;
- memset(tmp, 0, sizeof(tmp));
- if(source == NULL || dest == NULL || source[0] == '\0' || dest[0] != '\0')
- {
- return;
- }
- size_t src_len = strlen(source);
- snprintf(len_str, sizeof(len_str), "%zu", src_len);
- unsigned char append_status = 0x0;
- append_status |= (source[src_len - 1] == '-') ? 0x1 : 0x0;
- append_status |= (source[src_len - 1] == '+') ? 0x2 : 0x0;
- while ((keys[keys_num] = strtok_r(tmp_ptr, ":_-+", &save_ptr)) != NULL)
- {
- tmp_ptr = NULL;
- /** capitalize 1st char **/
- keys[keys_num][0] = toupper(keys[keys_num][0]);
- keys_num++;
- if(keys_num >= 16)
- {
- break;
- }
- }
- /** concatenate each part of source string **/
- for(i = 0; i < keys_num; i++)
- {
- strncat(tmp, keys[i], key_chars_remaining);
- key_chars_remaining -= strlen(keys[i]);
- }
- tmp[DATA_MAX_NAME_LEN - 1] = '\0';
- /** to coordinate limitation of length of type_instance
- * we will truncate ds_name
- * when the its length is more than
- * DATA_MAX_NAME_LEN
- */
- if(strlen(tmp) > DATA_MAX_NAME_LEN - 1)
+ char *src_copy;
+ size_t src_len;
+ char *ptr = buffer;
+ size_t ptr_size = buffer_size;
+ _Bool append_plus = 0;
+ _Bool append_minus = 0;
+
+ if ((buffer == NULL) || (buffer_size <= strlen ("Minus")) || (src == NULL))
+ return EINVAL;
+
+ src_copy = strdup (src);
+ src_len = strlen(src);
+
+ /* Remove trailing "+" and "-". */
+ if (src_copy[src_len - 1] == '+')
{
- append_status |= 0x4;
- /** we should reserve space for
- * len_str
- */
- reserved += 2;
+ append_plus = 1;
+ src_len--;
+ src_copy[src_len] = 0;
}
- if(append_status & 0x1)
+ else if (src_copy[src_len - 1] == '-')
{
- /** we should reserve space for
- * "Minus"
- */
- reserved += 5;
+ append_minus = 1;
+ src_len--;
+ src_copy[src_len] = 0;
}
- if(append_status & 0x2)
+
+ /* Split at special chars, capitalize first character, append to buffer. */
+ char *dummy = src_copy;
+ char *token;
+ char *save_ptr = NULL;
+ while ((token = strtok_r (dummy, ":_-+", &save_ptr)) != NULL)
{
- /** we should reserve space for
- * "Plus"
- */
- reserved += 4;
+ size_t len;
+
+ dummy = NULL;
+
+ token[0] = toupper ((int) token[0]);
+
+ assert (ptr_size > 1);
+
+ len = strlen (token);
+ if (len >= ptr_size)
+ len = ptr_size - 1;
+
+ assert (len > 0);
+ assert (len < ptr_size);
+
+ sstrncpy (ptr, token, len + 1);
+ ptr += len;
+ ptr_size -= len;
+
+ assert (*ptr == 0);
+ if (ptr_size <= 1)
+ break;
}
- snprintf(dest, DATA_MAX_NAME_LEN - reserved, "%s", tmp);
- offset = strlen(dest);
- switch (append_status)
+
+ /* Append "Plus" or "Minus" if "+" or "-" has been stripped above. */
+ if (append_plus || append_minus)
{
- case 0x1:
- memcpy(dest + offset, "Minus", 5);
- break;
- case 0x2:
- memcpy(dest + offset, "Plus", 5);
- break;
- case 0x4:
- memcpy(dest + offset, len_str, 2);
- break;
- case 0x5:
- memcpy(dest + offset, "Minus", 5);
- memcpy(dest + offset + 5, len_str, 2);
- break;
- case 0x6:
- memcpy(dest + offset, "Plus", 4);
- memcpy(dest + offset + 4, len_str, 2);
- break;
- default:
- break;
+ char const *append = "Plus";
+ if (append_minus)
+ append = "Minus";
+
+ size_t offset = buffer_size - (strlen (append) + 1);
+ if (offset > strlen (buffer))
+ offset = strlen (buffer);
+
+ sstrncpy (buffer + offset, append, buffer_size - offset);
}
+
+ sfree (src_copy);
+ return 0;
+}
+
+static _Bool has_suffix (char const *str, char const *suffix)
+{
+ size_t str_len = strlen (str);
+ size_t suffix_len = strlen (suffix);
+ size_t offset;
+
+ if (suffix_len > str_len)
+ return 0;
+ offset = str_len - suffix_len;
+
+ if (strcmp (str + offset, suffix) == 0)
+ return 1;
+
+ return 0;
+}
+
+/* count_parts returns the number of elements a "foo.bar.baz" style key has. */
+static size_t count_parts (char const *key)
+{
+ char const *ptr;
+ size_t parts_num = 0;
+
+ for (ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.'))
+ parts_num++;
+
+ return parts_num;
}
/**
* Parse key to remove "type" if this is for schema and initiate compaction
*/
-static int parse_keys(const char *key_str, char *ds_name)
+static int parse_keys (char *buffer, size_t buffer_size, const char *key_str)
{
- char *ptr, *rptr;
- size_t ds_name_len = 0;
- /**
- * allow up to 100 characters before compaction - compact_ds_name will not
- * allow more than DATA_MAX_NAME_LEN chars
- */
- int max_str_len = 100;
- char tmp_ds_name[max_str_len];
- memset(tmp_ds_name, 0, sizeof(tmp_ds_name));
- if(ds_name == NULL || key_str == NULL || key_str[0] == '\0' ||
- ds_name[0] != '\0')
- {
- return -1;
- }
- if((ptr = strchr(key_str, '.')) == NULL
- || (rptr = strrchr(key_str, '.')) == NULL)
+ char tmp[2 * buffer_size];
+
+ if (buffer == NULL || buffer_size == 0 || key_str == NULL || strlen (key_str) == 0)
+ return EINVAL;
+
+ if ((count_parts (key_str) > 2) && has_suffix (key_str, ".type"))
{
- memcpy(tmp_ds_name, key_str, max_str_len - 1);
- goto compact;
- }
+ /* strip ".type" suffix iff the key has more than two parts. */
+ size_t sz = strlen (key_str) - strlen (".type") + 1;
- ds_name_len = (rptr - ptr) > max_str_len ? max_str_len : (rptr - ptr);
- if((ds_name_len == 0) || strncmp(rptr + 1, "type", 4))
- { /** copy whole key **/
- memcpy(tmp_ds_name, key_str, max_str_len - 1);
+ if (sz > sizeof (tmp))
+ sz = sizeof (tmp);
+ sstrncpy (tmp, key_str, sz);
}
else
- {/** more than two keys **/
- memcpy(tmp_ds_name, key_str, ((rptr - key_str) > (max_str_len - 1) ?
- (max_str_len - 1) : (rptr - key_str)));
+ {
+ sstrncpy (tmp, key_str, sizeof (tmp));
}
- compact: compact_ds_name(tmp_ds_name, ds_name);
- return 0;
+ return compact_ds_name (buffer, buffer_size, tmp);
}
/**
((pc_type & PERFCOUNTER_LATENCY) ? DSET_LATENCY : DSET_BYTES);
d->ds_types[d->ds_num] = type;
- if(parse_keys(name, ds_name))
+ if (parse_keys(ds_name, sizeof (ds_name), name))
{
return 1;
}
char ds_name[DATA_MAX_NAME_LEN];
memset(ds_name, 0, sizeof(ds_name));
- if(parse_keys(key, ds_name))
+ if (parse_keys (ds_name, sizeof (ds_name), key))
{
return 1;
}
{
ERROR("ceph plugin: cconn_connect: connect(%d) failed: error %d",
fd, err);
+ close(fd);
return err;
}
err = -errno;
ERROR("ceph plugin: cconn_connect: fcntl(%d, O_NONBLOCK) error %d",
fd, err);
+ close(fd);
return err;
}
io->asok = fd;
--- /dev/null
+/**
+ * collectd - src/ceph_test.c
+ * Copyright (C) 2015 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; only version 2 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.
+ *
+ * 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 collectd.org>
+ **/
+
+#include "ceph.c" /* sic */
+#include "testing.h"
+
+DEF_TEST(parse_keys)
+{
+ struct {
+ char *str;
+ char *want;
+ } cases[] = {
+ {"WBThrottle.bytes_dirtied.description.bytes_wb.description.ios_dirtied.description.ios_wb.type", "WBThrottle.bytesDirtied.description.bytesWb.description.iosDirt"},
+ {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", "Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"},
+ {"foo:bar", "FooBar"},
+ {"foo:bar+", "FooBarPlus"},
+ {"foo:bar-", "FooBarMinus"},
+ {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa+", "AaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaPlus"},
+ {"aa.bb.cc.dd.ee.ff", "Aa.bb.cc.dd.ee.ff"},
+ {"aa.bb.cc.dd.ee.ff.type", "Aa.bb.cc.dd.ee.ff"},
+ {"aa.type", "Aa.type"},
+ };
+ size_t i;
+
+ for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
+ {
+ char got[DATA_MAX_NAME_LEN];
+
+ memset (got, 0, sizeof (got));
+
+ CHECK_ZERO (parse_keys (got, sizeof (got), cases[i].str));
+
+ CHECK_ZERO (strcmp (got, cases[i].want));
+ }
+
+ return 0;
+}
+
+int main (void)
+{
+ RUN_TEST(parse_keys);
+
+ END_TEST;
+}
+
+/* vim: set sw=2 sts=2 et : */
#<Plugin "battery">
# ValuesPercentage false
-# ReportDegraded
+# ReportDegraded false
#</Plugin>
#<Plugin "bind">
port_host = mach_host_self ();
- /* FIXME: Free `cpu_list' if it's not NULL */
- if ((status = host_processors (port_host, &cpu_list, &cpu_list_len)) != KERN_SUCCESS)
+ status = host_processors (port_host, &cpu_list, &cpu_list_len);
+ if (status == KERN_INVALID_ARGUMENT)
{
- ERROR ("cpu plugin: host_processors returned %i", (int) status);
+ ERROR ("cpu plugin: Don't have a privileged host control port. "
+ "The most common cause for this problem is "
+ "that collectd is running without root "
+ "privileges, which are required to read CPU "
+ "load information. "
+ "<https://collectd.org/bugs/22>");
+ cpu_list_len = 0;
+ return (-1);
+ }
+ if (status != KERN_SUCCESS)
+ {
+ ERROR ("cpu plugin: host_processors() failed with status %d.", (int) status);
cpu_list_len = 0;
return (-1);
}
- DEBUG ("host_processors returned %i %s", (int) cpu_list_len, cpu_list_len == 1 ? "processor" : "processors");
INFO ("cpu plugin: Found %i processor%s.", (int) cpu_list_len, cpu_list_len == 1 ? "" : "s");
/* #endif PROCESSOR_CPU_LOAD_INFO */
&& (ds->ds[i].type != DS_TYPE_GAUGE)
&& (ds->ds[i].type != DS_TYPE_DERIVE)
&& (ds->ds[i].type != DS_TYPE_ABSOLUTE))
+ {
+ sfree (rates);
return (-1);
+ }
- if (ds->ds[i].type == DS_TYPE_GAUGE)
+ if (ds->ds[i].type == DS_TYPE_GAUGE)
{
status = ssnprintf (buffer + offset, buffer_len - offset,
",%lf", vl->values[i].gauge);
- }
+ }
else if (store_rates != 0)
{
if (rates == NULL)
plugin.c plugin.h \
utils_cache.c utils_cache.h \
utils_complain.c utils_complain.h \
+ utils_ignorelist.c utils_ignorelist.h \
utils_llist.c utils_llist.h \
utils_random.c utils_random.h \
utils_tail_match.c utils_tail_match.h \
#if HAVE_SETLOCALE
if (setlocale (LC_NUMERIC, COLLECTD_LOCALE) == NULL)
WARNING ("setlocale (\"%s\") failed.", COLLECTD_LOCALE);
+
+ /* Update the environment, so that libraries that are calling
+ * setlocale(LC_NUMERIC, "") don't accidentally revert these changes. */
+ unsetenv ("LC_ALL");
+ setenv ("LC_NUMERIC", COLLECTD_LOCALE, /* overwrite = */ 1);
#endif
#if HAVE_LIBKSTAT
#include <sys/socket.h>
#include <netdb.h>
+#include <poll.h>
+
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
const char *ptr;
size_t nleft;
ssize_t status;
+ struct pollfd pfd;
ptr = (const char *) buf;
nleft = count;
+
+ /* checking for closed peer connection */
+ pfd.fd = fd;
+ pfd.events = POLLIN | POLLHUP;
+ pfd.revents = 0;
+ if (poll(&pfd, 1, 0) > 0) {
+ char buffer[32];
+ if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) {
+ // if recv returns zero (even though poll() said there is data to be read),
+ // that means the connection has been closed
+ return -1;
+ }
+ }
while (nleft > 0)
{
if (md == NULL)
return;
- pthread_mutex_destroy(&md->lock);
md_entry_free (md->head);
pthread_mutex_destroy (&md->lock);
free (md);
write_threads_num = 5;
}
- start_write_threads ((size_t) write_threads_num);
-
if ((list_init == NULL) && (read_heap == NULL))
return;
le = le->next;
}
+ start_write_threads ((size_t) write_threads_num);
+
max_read_interval = global_option_get_time ("MaxReadInterval",
DEFAULT_MAX_READ_INTERVAL);
#include "plugin.h"
+char hostname_g[] = "example.com";
+
+int plugin_register_complex_config (const char *type, int (*callback) (oconfig_item_t *))
+{
+ return ENOTSUP;
+}
+
+int plugin_register_init (const char *name, plugin_init_cb callback)
+{
+ return ENOTSUP;
+}
+
+int plugin_register_read (const char *name, int (*callback) (void))
+{
+ return ENOTSUP;
+}
+
+int plugin_register_shutdown (const char *name, int (*callback) (void))
+{
+ return ENOTSUP;
+}
+
+int plugin_dispatch_values (value_list_t const *vl)
+{
+ return ENOTSUP;
+}
+
void plugin_log (int level, char const *format, ...)
{
char buffer[1024];
printf ("plugin_log (%i, \"%s\");\n", level, buffer);
}
+cdtime_t plugin_get_interval (void)
+{
+ return TIME_T_TO_CDTIME_T (10);
+}
+
/* vim: set sw=2 sts=2 et : */
*value = n->value;
free_node (n);
+ --t->size;
rebalance (t, p);
return (0);
--- /dev/null
+/**
+ * collectd - src/utils_ignorelist.c
+ * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
+ * Copyright (C) 2008 Florian Forster <octo at collectd.org>
+ *
+ * This program is free software; you can redistribute it and/
+ * or modify it under the terms of the GNU General Public Li-
+ * cence as published by the Free Software Foundation; either
+ * version 2 of the Licence, or any later version.
+ *
+ * This program is distributed in the hope that it will be use-
+ * ful, but WITHOUT ANY WARRANTY; without even the implied war-
+ * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * Licence along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
+ * USA.
+ *
+ * Authors:
+ * Lubos Stanek <lubek at users.sourceforge.net>
+ * Florian Forster <octo at collectd.org>
+ **/
+/**
+ * ignorelist handles plugin's list of configured collectable
+ * entries with global ignore action
+ **/
+/**
+ * Usage:
+ *
+ * Define plugin's global pointer variable of type ignorelist_t:
+ * ignorelist_t *myconfig_ignore;
+ * If you know the state of the global ignore (IgnoreSelected),
+ * allocate the variable with:
+ * myconfig_ignore = ignorelist_create (YourKnownIgnore);
+ * If you do not know the state of the global ignore,
+ * initialize the global variable and set the ignore flag later:
+ * myconfig_ignore = ignorelist_init ();
+ * Append single entries in your cf_register'ed callback function:
+ * ignorelist_add (myconfig_ignore, newentry);
+ * When you hit the IgnoreSelected config option,
+ * offer it to the list:
+ * ignorelist_ignore (myconfig_ignore, instantly_got_value_of_ignore);
+ * That is all for the ignorelist initialization.
+ * Later during read and write (plugin's registered functions) get
+ * the information whether this entry would be collected or not:
+ * if (ignorelist_match (myconfig_ignore, thisentry))
+ * return;
+ **/
+
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "common.h"
+#include "plugin.h"
+#include "utils_ignorelist.h"
+
+/*
+ * private prototypes
+ */
+struct ignorelist_item_s
+{
+#if HAVE_REGEX_H
+ regex_t *rmatch; /* regular expression entry identification */
+#endif
+ char *smatch; /* string entry identification */
+ struct ignorelist_item_s *next;
+};
+typedef struct ignorelist_item_s ignorelist_item_t;
+
+struct ignorelist_s
+{
+ int ignore; /* ignore entries */
+ ignorelist_item_t *head; /* pointer to the first entry */
+};
+
+/* *** *** *** ********************************************* *** *** *** */
+/* *** *** *** *** *** *** private functions *** *** *** *** *** *** */
+/* *** *** *** ********************************************* *** *** *** */
+
+static inline void ignorelist_append (ignorelist_t *il, ignorelist_item_t *item)
+{
+ assert ((il != NULL) && (item != NULL));
+
+ item->next = il->head;
+ il->head = item;
+}
+
+#if HAVE_REGEX_H
+static int ignorelist_append_regex(ignorelist_t *il, const char *entry)
+{
+ int rcompile;
+ regex_t *regtemp;
+ int errsize;
+ char *regerr = NULL;
+ ignorelist_item_t *new;
+
+ /* create buffer */
+ if ((regtemp = malloc(sizeof(regex_t))) == NULL)
+ {
+ ERROR ("cannot allocate new config entry");
+ return (1);
+ }
+ memset (regtemp, '\0', sizeof(regex_t));
+
+ /* compile regex */
+ if ((rcompile = regcomp (regtemp, entry, REG_EXTENDED)) != 0)
+ {
+ /* prepare message buffer */
+ errsize = regerror(rcompile, regtemp, NULL, 0);
+ if (errsize)
+ regerr = smalloc(errsize);
+ /* get error message */
+ if (regerror (rcompile, regtemp, regerr, errsize))
+ {
+ fprintf (stderr, "Cannot compile regex %s: %i/%s",
+ entry, rcompile, regerr);
+ ERROR ("Cannot compile regex %s: %i/%s",
+ entry, rcompile, regerr);
+ }
+ else
+ {
+ fprintf (stderr, "Cannot compile regex %s: %i",
+ entry, rcompile);
+ ERROR ("Cannot compile regex %s: %i",
+ entry, rcompile);
+ }
+
+ if (errsize)
+ sfree (regerr);
+ regfree (regtemp);
+ sfree (regtemp);
+ return (1);
+ }
+ DEBUG("regex compiled: %s - %i", entry, rcompile);
+
+ /* create new entry */
+ if ((new = malloc(sizeof(ignorelist_item_t))) == NULL)
+ {
+ ERROR ("cannot allocate new config entry");
+ regfree (regtemp);
+ sfree (regtemp);
+ return (1);
+ }
+ memset (new, '\0', sizeof(ignorelist_item_t));
+ new->rmatch = regtemp;
+
+ /* append new entry */
+ ignorelist_append (il, new);
+
+ return (0);
+} /* int ignorelist_append_regex(ignorelist_t *il, const char *entry) */
+#endif
+
+static int ignorelist_append_string(ignorelist_t *il, const char *entry)
+{
+ ignorelist_item_t *new;
+
+ /* create new entry */
+ if ((new = malloc(sizeof(ignorelist_item_t))) == NULL )
+ {
+ ERROR ("cannot allocate new entry");
+ return (1);
+ }
+ memset (new, '\0', sizeof(ignorelist_item_t));
+ new->smatch = sstrdup(entry);
+
+ /* append new entry */
+ ignorelist_append (il, new);
+
+ return (0);
+} /* int ignorelist_append_string(ignorelist_t *il, const char *entry) */
+
+#if HAVE_REGEX_H
+/*
+ * check list for entry regex match
+ * return 1 if found
+ */
+static int ignorelist_match_regex (ignorelist_item_t *item, const char *entry)
+{
+ assert ((item != NULL) && (item->rmatch != NULL)
+ && (entry != NULL) && (strlen (entry) > 0));
+
+ /* match regex */
+ if (regexec (item->rmatch, entry, 0, NULL, 0) == 0)
+ return (1);
+
+ return (0);
+} /* int ignorelist_match_regex (ignorelist_item_t *item, const char *entry) */
+#endif
+
+/*
+ * check list for entry string match
+ * return 1 if found
+ */
+static int ignorelist_match_string (ignorelist_item_t *item, const char *entry)
+{
+ assert ((item != NULL) && (item->smatch != NULL)
+ && (entry != NULL) && (strlen (entry) > 0));
+
+ if (strcmp (entry, item->smatch) == 0)
+ return (1);
+
+ return (0);
+} /* int ignorelist_match_string (ignorelist_item_t *item, const char *entry) */
+
+
+/* *** *** *** ******************************************** *** *** *** */
+/* *** *** *** *** *** *** public functions *** *** *** *** *** *** */
+/* *** *** *** ******************************************** *** *** *** */
+
+/*
+ * create the ignorelist_t with known ignore state
+ * return pointer to ignorelist_t
+ */
+ignorelist_t *ignorelist_create (int invert)
+{
+ ignorelist_t *il;
+
+ /* smalloc exits if it failes */
+ il = (ignorelist_t *) smalloc (sizeof (ignorelist_t));
+ memset (il, '\0', sizeof (ignorelist_t));
+
+ /*
+ * ->ignore == 0 => collect
+ * ->ignore == 1 => ignore
+ */
+ il->ignore = invert ? 0 : 1;
+
+ return (il);
+} /* ignorelist_t *ignorelist_create (int ignore) */
+
+/*
+ * free memory used by ignorelist_t
+ */
+void ignorelist_free (ignorelist_t *il)
+{
+ ignorelist_item_t *this;
+ ignorelist_item_t *next;
+
+ if (il == NULL)
+ return;
+
+ for (this = il->head; this != NULL; this = next)
+ {
+ next = this->next;
+#if HAVE_REGEX_H
+ if (this->rmatch != NULL)
+ {
+ regfree (this->rmatch);
+ sfree (this->rmatch);
+ this->rmatch = NULL;
+ }
+#endif
+ if (this->smatch != NULL)
+ {
+ sfree (this->smatch);
+ this->smatch = NULL;
+ }
+ sfree (this);
+ }
+
+ sfree (il);
+ il = NULL;
+} /* void ignorelist_destroy (ignorelist_t *il) */
+
+/*
+ * set ignore state of the ignorelist_t
+ */
+void ignorelist_set_invert (ignorelist_t *il, int invert)
+{
+ if (il == NULL)
+ {
+ DEBUG("ignore call with ignorelist_t == NULL");
+ return;
+ }
+
+ il->ignore = invert ? 0 : 1;
+} /* void ignorelist_set_invert (ignorelist_t *il, int ignore) */
+
+/*
+ * append entry into ignorelist_t
+ * return 1 for success
+ */
+int ignorelist_add (ignorelist_t *il, const char *entry)
+{
+ int ret;
+ size_t entry_len;
+
+ if (il == NULL)
+ {
+ DEBUG ("add called with ignorelist_t == NULL");
+ return (1);
+ }
+
+ entry_len = strlen (entry);
+
+ /* append nothing */
+ if (entry_len == 0)
+ {
+ DEBUG("not appending: empty entry");
+ return (1);
+ }
+
+#if HAVE_REGEX_H
+ /* regex string is enclosed in "/.../" */
+ if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/')
+ {
+ char *entry_copy;
+ size_t entry_copy_size;
+
+ /* We need to copy `entry' since it's const */
+ entry_copy_size = entry_len - 1;
+ entry_copy = smalloc (entry_copy_size);
+ sstrncpy (entry_copy, entry + 1, entry_copy_size);
+
+ DEBUG("I'm about to add regex entry: %s", entry_copy);
+ ret = ignorelist_append_regex(il, entry_copy);
+ sfree (entry_copy);
+ }
+ else
+#endif
+ {
+ DEBUG("to add entry: %s", entry);
+ ret = ignorelist_append_string(il, entry);
+ }
+
+ return (ret);
+} /* int ignorelist_add (ignorelist_t *il, const char *entry) */
+
+/*
+ * check list for entry
+ * return 1 for ignored entry
+ */
+int ignorelist_match (ignorelist_t *il, const char *entry)
+{
+ ignorelist_item_t *traverse;
+
+ /* if no entries, collect all */
+ if ((il == NULL) || (il->head == NULL))
+ return (0);
+
+ if ((entry == NULL) || (strlen (entry) == 0))
+ return (0);
+
+ /* traverse list and check entries */
+ for (traverse = il->head; traverse != NULL; traverse = traverse->next)
+ {
+#if HAVE_REGEX_H
+ if (traverse->rmatch != NULL)
+ {
+ if (ignorelist_match_regex (traverse, entry))
+ return (il->ignore);
+ }
+ else
+#endif
+ {
+ if (ignorelist_match_string (traverse, entry))
+ return (il->ignore);
+ }
+ } /* for traverse */
+
+ return (1 - il->ignore);
+} /* int ignorelist_match (ignorelist_t *il, const char *entry) */
+
--- /dev/null
+/**
+ * collectd - src/utils_ignorelist.h
+ * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
+ *
+ * This program is free software; you can redistribute it and/
+ * or modify it under the terms of the GNU General Public Li-
+ * cence as published by the Free Software Foundation; either
+ * version 2 of the Licence, or any later version.
+ *
+ * This program is distributed in the hope that it will be use-
+ * ful, but WITHOUT ANY WARRANTY; without even the implied war-
+ * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public Licence for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * Licence along with this program; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
+ * USA.
+ *
+ * Authors:
+ * Lubos Stanek <lubek at users.sourceforge.net>
+ **/
+/**
+ * ignorelist handles plugin's list of configured collectable
+ * entries with global ignore action
+ **/
+
+#ifndef UTILS_IGNORELIST_H
+#define UTILS_IGNORELIST_H 1
+
+#include "collectd.h"
+
+#if HAVE_REGEX_H
+# include <regex.h>
+#endif
+
+/* public prototypes */
+
+struct ignorelist_s;
+typedef struct ignorelist_s ignorelist_t;
+
+/*
+ * create the ignorelist_t with known ignore state
+ * return pointer to ignorelist_t
+ */
+ignorelist_t *ignorelist_create (int invert);
+
+/*
+ * free memory used by ignorelist_t
+ */
+void ignorelist_free (ignorelist_t *il);
+
+/*
+ * set ignore state of the ignorelist_t
+ */
+void ignorelist_set_invert (ignorelist_t *il, int invert);
+
+/*
+ * append entry to ignorelist_t
+ * returns zero on success, non-zero upon failure.
+ */
+int ignorelist_add (ignorelist_t *il, const char *entry);
+
+/*
+ * check list for entry
+ * return 1 for ignored entry
+ */
+int ignorelist_match (ignorelist_t *il, const char *entry);
+
+#endif /* UTILS_IGNORELIST_H */
}
if (fgets(buffer, buffer_len, fp) == NULL) {
ERROR("fhcount: fgets: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
+ fclose(fp);
return(EXIT_FAILURE);
}
fclose(fp);
if (dir->path == NULL)
{
ERROR ("filecount plugin: strdup failed.");
+ sfree (dir);
return (-1);
}
} else {
ERROR ("irq plugin: unable to get CPU count from first line "
"of /proc/interrupts");
+ fclose (fh);
return (-1);
}
}
else if (FIELD_IS ("listen_disabled_num"))
{
- submit_derive ("memcached_connections", "listen_disabled", atof (fields[2]), st);
+ submit_derive ("connections", "listen_disabled", atof (fields[2]), st);
}
/*
status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host));
if (status != 0)
+ {
+ sfree (host);
return (status);
+ }
if (host->host[0] == 0)
+ {
+ sfree (host);
return (EINVAL);
+ }
for (i = 0; i < ci->children_num; i++)
{
return (0);
}
-static void ntpd_submit (char *type, char *type_inst, double value)
+static void ntpd_submit (char *type, char *type_inst, gauge_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
* sets the LSB based on whether the peer was reachable. If the LSB is zero,
* the values are out of date. */
static void ntpd_submit_reach (char *type, char *type_inst, uint8_t reach,
- double value)
+ gauge_t value)
{
if (!(reach & 1))
value = NAN;
int ps_num;
int ps_size;
+ gauge_t offset_loop;
+ gauge_t freq_loop;
+ gauge_t offset_error;
+
int status;
int i;
+ /* On Linux, if the STA_NANO bit is set in ik->status, then ik->offset
+ * is is nanoseconds, otherwise it's microseconds.
+ * TODO(octo): STA_NANO is defined in the Linux specific <sys/timex.h> header. */
+ double scale_loop = 1e-6;
+ double scale_error = 1e-6;
+
ik = NULL;
ik_num = 0;
ik_size = 0;
}
/* kerninfo -> estimated error */
+ offset_loop = scale_loop * ((gauge_t) ntohl (ik->offset));
+ freq_loop = ntpd_read_fp (ik->freq);
+ offset_error = scale_error * ((gauge_t) ntohl (ik->esterror));
DEBUG ("info_kernel:\n"
- " pll offset = %.8f\n"
- " pll frequency = %.8f\n" /* drift compensation */
- " est error = %.8f\n",
- ntpd_read_fp (ik->offset),
- ntpd_read_fp (ik->freq),
- ntpd_read_fp (ik->esterror));
-
- ntpd_submit ("frequency_offset", "loop", ntpd_read_fp (ik->freq));
- ntpd_submit ("time_offset", "loop", ntpd_read_fp (ik->offset));
- ntpd_submit ("time_offset", "error", ntpd_read_fp (ik->esterror));
+ " pll offset = %.8g\n"
+ " pll frequency = %.8g\n" /* drift compensation */
+ " est error = %.8g\n",
+ offset_loop, freq_loop, offset_error);
+
+ ntpd_submit ("frequency_offset", "loop", freq_loop);
+ ntpd_submit ("time_offset", "loop", offset_loop);
+ ntpd_submit ("time_offset", "error", offset_error);
free (ik);
ik = NULL;
const char* const default_server_fields[] = /* {{{ */
{
- "latency"
+ "latency",
"packetcache-hit",
"packetcache-miss",
"packetcache-size",
{
DEBUG ("ProcessMatch: compiling the regular expression \"%s\" failed.", regexp);
sfree(new->re);
+ sfree(new);
return;
}
}
{
rc = malloc (sizeof (*rc));
if (rc == NULL)
+ {
+ pthread_mutex_unlock (&cache_lock);
return (-1);
+ }
rc->values_num = 0;
rc->values = NULL;
rc->first_value = 0;
cache = c_avl_create ((int (*) (const void *, const void *)) strcmp);
if (cache == NULL)
{
+ pthread_mutex_unlock (&cache_lock);
ERROR ("rrdtool plugin: c_avl_create failed.");
return (-1);
}
status = cf_util_get_string(ci, &hd->name);
if (status != 0)
+ {
+ sfree (hd);
return status;
+ }
hd->sess_handle = NULL;
hd->interval = 0;
tmp_unsigned = (uint32_t) *vl->val.integer;
tmp_signed = (int32_t) *vl->val.integer;
- if ((vl->type == ASN_INTEGER)
- || (vl->type == ASN_GAUGE))
+ if (vl->type == ASN_INTEGER)
prefer_signed = 1;
DEBUG ("snmp plugin: Parsed int32 value is %"PRIu64".", tmp_unsigned);
res = NULL;
sfree (errstr);
+ sfree (vl.values);
csnmp_host_close_session (host);
return (-1);
else
values[0].gauge = (gauge_t) c_avl_size (metric->set);
}
- else
- values[0].derive = (derive_t) metric->value;
+ else { /* STATSD_COUNTER */
+ /*
+ * Expand a single value to two metrics:
+ *
+ * - The absolute counter, as a gauge
+ * - A derived rate for this counter
+ */
+ values[0].derive = (derive_t) metric->value;
+ plugin_dispatch_values(&vl);
+
+ sstrncpy(vl.type, "gauge", sizeof (vl.type));
+ values[0].gauge = (gauge_t) metric->value;
+ }
return (plugin_dispatch_values (&vl));
} /* }}} int statsd_metric_submit_unsafe */
while (c_avl_pick (metrics_tree, &key, &value) == 0)
{
sfree (key);
- sfree (value);
+ statsd_metric_free (value);
}
c_avl_destroy (metrics_tree);
metrics_tree = NULL;
cache_ratio value:GAUGE:0:100
cache_result value:DERIVE:0:U
cache_size value:GAUGE:0:U
+capacity value:GAUGE:0:U
ceph_bytes value:GAUGE:U:U
ceph_latency value:GAUGE:U:U
ceph_rate value:DERIVE:0:U
+++ /dev/null
-/**
- * collectd - src/utils_ignorelist.c
- * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
- * Copyright (C) 2008 Florian Forster <octo at collectd.org>
- *
- * This program is free software; you can redistribute it and/
- * or modify it under the terms of the GNU General Public Li-
- * cence as published by the Free Software Foundation; either
- * version 2 of the Licence, or any later version.
- *
- * This program is distributed in the hope that it will be use-
- * ful, but WITHOUT ANY WARRANTY; without even the implied war-
- * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public
- * Licence along with this program; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
- * USA.
- *
- * Authors:
- * Lubos Stanek <lubek at users.sourceforge.net>
- * Florian Forster <octo at collectd.org>
- **/
-/**
- * ignorelist handles plugin's list of configured collectable
- * entries with global ignore action
- **/
-/**
- * Usage:
- *
- * Define plugin's global pointer variable of type ignorelist_t:
- * ignorelist_t *myconfig_ignore;
- * If you know the state of the global ignore (IgnoreSelected),
- * allocate the variable with:
- * myconfig_ignore = ignorelist_create (YourKnownIgnore);
- * If you do not know the state of the global ignore,
- * initialize the global variable and set the ignore flag later:
- * myconfig_ignore = ignorelist_init ();
- * Append single entries in your cf_register'ed callback function:
- * ignorelist_add (myconfig_ignore, newentry);
- * When you hit the IgnoreSelected config option,
- * offer it to the list:
- * ignorelist_ignore (myconfig_ignore, instantly_got_value_of_ignore);
- * That is all for the ignorelist initialization.
- * Later during read and write (plugin's registered functions) get
- * the information whether this entry would be collected or not:
- * if (ignorelist_match (myconfig_ignore, thisentry))
- * return;
- **/
-
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "common.h"
-#include "plugin.h"
-#include "utils_ignorelist.h"
-
-/*
- * private prototypes
- */
-struct ignorelist_item_s
-{
-#if HAVE_REGEX_H
- regex_t *rmatch; /* regular expression entry identification */
-#endif
- char *smatch; /* string entry identification */
- struct ignorelist_item_s *next;
-};
-typedef struct ignorelist_item_s ignorelist_item_t;
-
-struct ignorelist_s
-{
- int ignore; /* ignore entries */
- ignorelist_item_t *head; /* pointer to the first entry */
-};
-
-/* *** *** *** ********************************************* *** *** *** */
-/* *** *** *** *** *** *** private functions *** *** *** *** *** *** */
-/* *** *** *** ********************************************* *** *** *** */
-
-static inline void ignorelist_append (ignorelist_t *il, ignorelist_item_t *item)
-{
- assert ((il != NULL) && (item != NULL));
-
- item->next = il->head;
- il->head = item;
-}
-
-#if HAVE_REGEX_H
-static int ignorelist_append_regex(ignorelist_t *il, const char *entry)
-{
- int rcompile;
- regex_t *regtemp;
- int errsize;
- char *regerr = NULL;
- ignorelist_item_t *new;
-
- /* create buffer */
- if ((regtemp = malloc(sizeof(regex_t))) == NULL)
- {
- ERROR ("cannot allocate new config entry");
- return (1);
- }
- memset (regtemp, '\0', sizeof(regex_t));
-
- /* compile regex */
- if ((rcompile = regcomp (regtemp, entry, REG_EXTENDED)) != 0)
- {
- /* prepare message buffer */
- errsize = regerror(rcompile, regtemp, NULL, 0);
- if (errsize)
- regerr = smalloc(errsize);
- /* get error message */
- if (regerror (rcompile, regtemp, regerr, errsize))
- {
- fprintf (stderr, "Cannot compile regex %s: %i/%s",
- entry, rcompile, regerr);
- ERROR ("Cannot compile regex %s: %i/%s",
- entry, rcompile, regerr);
- }
- else
- {
- fprintf (stderr, "Cannot compile regex %s: %i",
- entry, rcompile);
- ERROR ("Cannot compile regex %s: %i",
- entry, rcompile);
- }
-
- if (errsize)
- sfree (regerr);
- regfree (regtemp);
- sfree (regtemp);
- return (1);
- }
- DEBUG("regex compiled: %s - %i", entry, rcompile);
-
- /* create new entry */
- if ((new = malloc(sizeof(ignorelist_item_t))) == NULL)
- {
- ERROR ("cannot allocate new config entry");
- regfree (regtemp);
- sfree (regtemp);
- return (1);
- }
- memset (new, '\0', sizeof(ignorelist_item_t));
- new->rmatch = regtemp;
-
- /* append new entry */
- ignorelist_append (il, new);
-
- return (0);
-} /* int ignorelist_append_regex(ignorelist_t *il, const char *entry) */
-#endif
-
-static int ignorelist_append_string(ignorelist_t *il, const char *entry)
-{
- ignorelist_item_t *new;
-
- /* create new entry */
- if ((new = malloc(sizeof(ignorelist_item_t))) == NULL )
- {
- ERROR ("cannot allocate new entry");
- return (1);
- }
- memset (new, '\0', sizeof(ignorelist_item_t));
- new->smatch = sstrdup(entry);
-
- /* append new entry */
- ignorelist_append (il, new);
-
- return (0);
-} /* int ignorelist_append_string(ignorelist_t *il, const char *entry) */
-
-#if HAVE_REGEX_H
-/*
- * check list for entry regex match
- * return 1 if found
- */
-static int ignorelist_match_regex (ignorelist_item_t *item, const char *entry)
-{
- assert ((item != NULL) && (item->rmatch != NULL)
- && (entry != NULL) && (strlen (entry) > 0));
-
- /* match regex */
- if (regexec (item->rmatch, entry, 0, NULL, 0) == 0)
- return (1);
-
- return (0);
-} /* int ignorelist_match_regex (ignorelist_item_t *item, const char *entry) */
-#endif
-
-/*
- * check list for entry string match
- * return 1 if found
- */
-static int ignorelist_match_string (ignorelist_item_t *item, const char *entry)
-{
- assert ((item != NULL) && (item->smatch != NULL)
- && (entry != NULL) && (strlen (entry) > 0));
-
- if (strcmp (entry, item->smatch) == 0)
- return (1);
-
- return (0);
-} /* int ignorelist_match_string (ignorelist_item_t *item, const char *entry) */
-
-
-/* *** *** *** ******************************************** *** *** *** */
-/* *** *** *** *** *** *** public functions *** *** *** *** *** *** */
-/* *** *** *** ******************************************** *** *** *** */
-
-/*
- * create the ignorelist_t with known ignore state
- * return pointer to ignorelist_t
- */
-ignorelist_t *ignorelist_create (int invert)
-{
- ignorelist_t *il;
-
- /* smalloc exits if it failes */
- il = (ignorelist_t *) smalloc (sizeof (ignorelist_t));
- memset (il, '\0', sizeof (ignorelist_t));
-
- /*
- * ->ignore == 0 => collect
- * ->ignore == 1 => ignore
- */
- il->ignore = invert ? 0 : 1;
-
- return (il);
-} /* ignorelist_t *ignorelist_create (int ignore) */
-
-/*
- * free memory used by ignorelist_t
- */
-void ignorelist_free (ignorelist_t *il)
-{
- ignorelist_item_t *this;
- ignorelist_item_t *next;
-
- if (il == NULL)
- return;
-
- for (this = il->head; this != NULL; this = next)
- {
- next = this->next;
-#if HAVE_REGEX_H
- if (this->rmatch != NULL)
- {
- regfree (this->rmatch);
- sfree (this->rmatch);
- this->rmatch = NULL;
- }
-#endif
- if (this->smatch != NULL)
- {
- sfree (this->smatch);
- this->smatch = NULL;
- }
- sfree (this);
- }
-
- sfree (il);
- il = NULL;
-} /* void ignorelist_destroy (ignorelist_t *il) */
-
-/*
- * set ignore state of the ignorelist_t
- */
-void ignorelist_set_invert (ignorelist_t *il, int invert)
-{
- if (il == NULL)
- {
- DEBUG("ignore call with ignorelist_t == NULL");
- return;
- }
-
- il->ignore = invert ? 0 : 1;
-} /* void ignorelist_set_invert (ignorelist_t *il, int ignore) */
-
-/*
- * append entry into ignorelist_t
- * return 1 for success
- */
-int ignorelist_add (ignorelist_t *il, const char *entry)
-{
- int ret;
- size_t entry_len;
-
- if (il == NULL)
- {
- DEBUG ("add called with ignorelist_t == NULL");
- return (1);
- }
-
- entry_len = strlen (entry);
-
- /* append nothing */
- if (entry_len == 0)
- {
- DEBUG("not appending: empty entry");
- return (1);
- }
-
-#if HAVE_REGEX_H
- /* regex string is enclosed in "/.../" */
- if ((entry_len > 2) && (entry[0] == '/') && entry[entry_len - 1] == '/')
- {
- char *entry_copy;
- size_t entry_copy_size;
-
- /* We need to copy `entry' since it's const */
- entry_copy_size = entry_len - 1;
- entry_copy = smalloc (entry_copy_size);
- sstrncpy (entry_copy, entry + 1, entry_copy_size);
-
- DEBUG("I'm about to add regex entry: %s", entry_copy);
- ret = ignorelist_append_regex(il, entry_copy);
- sfree (entry_copy);
- }
- else
-#endif
- {
- DEBUG("to add entry: %s", entry);
- ret = ignorelist_append_string(il, entry);
- }
-
- return (ret);
-} /* int ignorelist_add (ignorelist_t *il, const char *entry) */
-
-/*
- * check list for entry
- * return 1 for ignored entry
- */
-int ignorelist_match (ignorelist_t *il, const char *entry)
-{
- ignorelist_item_t *traverse;
-
- /* if no entries, collect all */
- if ((il == NULL) || (il->head == NULL))
- return (0);
-
- if ((entry == NULL) || (strlen (entry) == 0))
- return (0);
-
- /* traverse list and check entries */
- for (traverse = il->head; traverse != NULL; traverse = traverse->next)
- {
-#if HAVE_REGEX_H
- if (traverse->rmatch != NULL)
- {
- if (ignorelist_match_regex (traverse, entry))
- return (il->ignore);
- }
- else
-#endif
- {
- if (ignorelist_match_string (traverse, entry))
- return (il->ignore);
- }
- } /* for traverse */
-
- return (1 - il->ignore);
-} /* int ignorelist_match (ignorelist_t *il, const char *entry) */
-
+++ /dev/null
-/**
- * collectd - src/utils_ignorelist.h
- * Copyright (C) 2006 Lubos Stanek <lubek at users.sourceforge.net>
- *
- * This program is free software; you can redistribute it and/
- * or modify it under the terms of the GNU General Public Li-
- * cence as published by the Free Software Foundation; either
- * version 2 of the Licence, or any later version.
- *
- * This program is distributed in the hope that it will be use-
- * ful, but WITHOUT ANY WARRANTY; without even the implied war-
- * ranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- * See the GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public
- * Licence along with this program; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
- * USA.
- *
- * Authors:
- * Lubos Stanek <lubek at users.sourceforge.net>
- **/
-/**
- * ignorelist handles plugin's list of configured collectable
- * entries with global ignore action
- **/
-
-#ifndef UTILS_IGNORELIST_H
-#define UTILS_IGNORELIST_H 1
-
-#include "collectd.h"
-
-#if HAVE_REGEX_H
-# include <regex.h>
-#endif
-
-/* public prototypes */
-
-struct ignorelist_s;
-typedef struct ignorelist_s ignorelist_t;
-
-/*
- * create the ignorelist_t with known ignore state
- * return pointer to ignorelist_t
- */
-ignorelist_t *ignorelist_create (int invert);
-
-/*
- * free memory used by ignorelist_t
- */
-void ignorelist_free (ignorelist_t *il);
-
-/*
- * set ignore state of the ignorelist_t
- */
-void ignorelist_set_invert (ignorelist_t *il, int invert);
-
-/*
- * append entry to ignorelist_t
- * returns zero on success, non-zero upon failure.
- */
-int ignorelist_add (ignorelist_t *il, const char *entry);
-
-/*
- * check list for entry
- * return 1 for ignored entry
- */
-int ignorelist_match (ignorelist_t *il, const char *entry);
-
-#endif /* UTILS_IGNORELIST_H */
#warn "This version of `getmntent' hat not yet been implemented!"
/* #endif HAVE_SEQ_GETMNTENT */
+#elif HAVE_GETMNTENT_R
+static cu_mount_t *cu_mount_getmntent (void)
+{
+ FILE *fp;
+ struct mntent me;
+ char mntbuf[1024];
+
+ cu_mount_t *first = NULL;
+ cu_mount_t *last = NULL;
+ cu_mount_t *new = NULL;
+
+ DEBUG ("utils_mount: (void); COLLECTD_MNTTAB = %s", COLLECTD_MNTTAB);
+
+ if ((fp = setmntent (COLLECTD_MNTTAB, "r")) == NULL)
+ {
+ char errbuf[1024];
+ ERROR ("setmntent (%s): %s", COLLECTD_MNTTAB,
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ return (NULL);
+ }
+
+ while (getmntent_r (fp, &me, mntbuf, sizeof (mntbuf) ))
+ {
+ if ((new = malloc (sizeof (cu_mount_t))) == NULL)
+ break;
+ memset (new, '\0', sizeof (cu_mount_t));
+
+ /* Copy values from `struct mntent *' */
+ new->dir = sstrdup (me.mnt_dir);
+ new->spec_device = sstrdup (me.mnt_fsname);
+ new->type = sstrdup (me.mnt_type);
+ new->options = sstrdup (me.mnt_opts);
+ new->device = get_device_name (new->options);
+ new->next = NULL;
+
+ DEBUG ("utils_mount: new = {dir = %s, spec_device = %s, type = %s, options = %s, device = %s}",
+ new->dir, new->spec_device, new->type, new->options, new->device);
+
+ /* Append to list */
+ if (first == NULL)
+ {
+ first = new;
+ last = new;
+ }
+ else
+ {
+ last->next = new;
+ last = new;
+ }
+ }
+
+ endmntent (fp);
+
+ DEBUG ("utils_mount: return (0x%p)", (void *) first);
+
+ return (first);
+} /* HAVE_GETMNTENT_R */
+
#elif HAVE_ONE_GETMNTENT
static cu_mount_t *cu_mount_getmntent (void)
{
ssize_t status = 0;
status = swrite (cb->sock_fd, cb->send_buf, strlen (cb->send_buf));
- if (status < 0)
+ if (status != 0)
{
const char *protocol = cb->protocol ? cb->protocol : WG_DEFAULT_PROTOCOL;