disk plugin: send disk_merged,disk_io_time,pending_operations only when real data exists for device
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq --no-install-recommends
+ iptables-dev
libatasmart-dev
libcap-dev
libcurl4-gnutls-dev
perl
protobuf-c-compiler
python-dev
-script: sh build.sh && ./configure && make distcheck
+script: sh build.sh && ./configure --with-python=/usr/bin/python && make distcheck DISTCHECK_CONFIGURE_FLAGS="--with-python=/usr/bin/python"
--- /dev/null
+# Thanks !
+
+Thanks for your feedback & contributions to the
+[collectd project](https://collectd.org/) !
+
+## Need help using collectd ?
+
+Please use the
+[collectd mailing list](http://mailman.verplant.org/listinfo/collectd) or the
+[#collectd IRC channel](https://webchat.freenode.net/?channels=#collectd).
+We'd like to keep the github issue tracker for bugreports and patch reviews.
+
+## Found a bug ?
+
+Please mention the exact collectd version you're using, how it was installed
+(built from source, or installed from packages. Where was it downloaded
+from). Which operating system/architecture, distribution and version are you
+running collectd on.
+
+If collectd crashes, try to get a
+[stack trace](https://collectd.org/wiki/index.php/Core_file).
+
+## Fixed a bug ? Want to add a feature ?
+
+Using git/github to submit changes is not mandatory. Sending patches to the
+[mailing-list](http://mailman.verplant.org/listinfo/collectd) is also fine.
+In both cases, take a quick look at the
+[submission guidelines](https://collectd.org/wiki/index.php/Submitting_patches)
+and the [coding style recommendations](https://collectd.org/wiki/index.php/Coding_style).
+
+Please try to submit **bugfixes** to the
+[oldest release branch](https://github.com/collectd/collectd/milestones) on
+which the bug is found, so that it gets included in every future **bugfix
+release**.
+
+Please try to submit **new features** to the master branch (which will become
+the next **feature release**).
+
* libprotobuf-c, protoc-c (optional)
Used by the `pinba' plugin to generate a parser for the network packets
- sent by the Pinba PHP extension, and by the `write_riemann' plugin to
- generate events to be sent to a Riemann server.
+ sent by the Pinba PHP extension.
<http://code.google.com/p/protobuf-c/>
* libpython (optional)
`varnish' plugin.
<http://varnish-cache.org>
+ * riemann-c-client (optional)
+ For the `write_riemann' plugin.
+ <https://github.com/algernon/riemann-c-client>
+
Configuring / Compiling / Installing
------------------------------------
- bison
- libtool
- libtool-ltdl
+- pkg-config
The `build.sh' script takes no arguments.
{
try
{
- this._jmx_connector.close();
+ if (this._jmx_connector != null) {
+ this._jmx_connector.close();
+ }
}
catch (Exception e)
{
done
}
-check_for_application lex yacc autoheader aclocal automake autoconf
+check_for_application lex bison autoheader aclocal automake autoconf
# Actually we don't need the pkg-config executable, but we need the M4 macros.
# We check for `pkg-config' here and hope that M4 macros will then be
dnl Process this file with autoconf to produce a configure script.
AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)])
-AC_CONFIG_SRCDIR(src/)
+AC_CONFIG_SRCDIR(src/target_set.c)
AC_CONFIG_HEADERS(src/config.h)
AC_CONFIG_AUX_DIR([libltdl/config])
#
AC_PROG_CC
AC_PROG_CPP
+AC_PROG_EGREP
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_MAKE_SET
PKG_PROG_PKG_CONFIG
+AC_CACHE_CHECK([if bison is the parser generator],
+ [collectd_cv_prog_bison],
+ [AS_IF([$YACC --version 2>/dev/null | $EGREP -q '^bison '],
+ [collectd_cv_prog_bison=yes], [collectd_cv_prog_bison=no]
+ )]
+)
+
+if test "x$collectd_cv_prog_bison" = "xno" && test ! -f "${srcdir}/src/liboconfig/parser.c"
+then
+ AC_MSG_ERROR([bison is missing and you do not have ${srcdir}/src/liboconfig/parser.c. Please install bison])
+fi
+
AC_CHECK_PROG([have_protoc_c], [protoc-c], [yes], [no])
if test "x$have_protoc_c" = "xno"
then
AC_DEFINE([KERNEL_OPENBSD], 1, [True if program is to be compiled for an OpenBSD kernel])
ac_system="OpenBSD"
;;
+ *netbsd*)
+ AC_DEFINE([KERNEL_NETBSD], 1, [True if program is to be compiled for a NetBSD kernel])
+ ac_system="NetBSD"
+ ;;
*aix*)
AC_DEFINE([KERNEL_AIX], 1, [True if program is to be compiled for a AIX kernel])
ac_system="AIX"
AC_CHECK_HEADERS(stdio.h errno.h math.h stdarg.h syslog.h fcntl.h signal.h assert.h sys/types.h sys/socket.h sys/select.h poll.h netdb.h arpa/inet.h sys/resource.h sys/param.h kstat.h regex.h sys/ioctl.h endian.h sys/isa_defs.h fnmatch.h libgen.h)
+# For entropy plugin on newer NetBSD
+AC_CHECK_HEADERS(sys/rndio.h, [], [],
+[#if HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#if HAVE_SYS_IOCTL_H
+# include <sys/ioctl.h>
+#endif
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+])
+
# For ping library
AC_CHECK_HEADERS(netinet/in_systm.h, [], [],
[#if HAVE_STDINT_H
AC_MSG_RESULT([no])
fi
+AC_MSG_CHECKING([for sysctl kern.cp_time])
+if test -x /sbin/sysctl
+then
+ /sbin/sysctl kern.cp_time >/dev/null 2>&1
+ if test $? -eq 0
+ then
+ AC_MSG_RESULT([yes])
+ AC_DEFINE(HAVE_SYSCTL_KERN_CP_TIME, 1,
+ [Define if sysctl supports kern.cp_time])
+ else
+ AC_MSG_RESULT([no])
+ fi
+else
+ AC_MSG_RESULT([no])
+fi
+
# For hddtemp module
AC_CHECK_HEADERS(linux/major.h)
have_linux_raid_md_u_h="no"
fi
-# For the swap module
+# For the wireless module
have_linux_wireless_h="no"
if test "x$ac_system" = "xLinux"
then
#endif
])
-AC_CHECK_HEADERS(pwd.h grp.h sys/un.h ctype.h limits.h xfs/xqm.h fs_info.h fshelp.h paths.h mntent.h mnttab.h sys/fstyp.h sys/fs_types.h sys/mntent.h sys/mnttab.h sys/statfs.h sys/statvfs.h sys/vfs.h sys/vfstab.h sys/vmmeter.h kvm.h wordexp.h locale.h)
+AC_CHECK_HEADERS([ \
+ ctype.h \
+ fs_info.h \
+ fshelp.h \
+ grp.h \
+ kvm.h \
+ limits.h \
+ locale.h \
+ mntent.h \
+ mnttab.h \
+ paths.h \
+ pwd.h \
+ sys/fs_types.h \
+ sys/fstyp.h \
+ sys/mntent.h \
+ sys/mnttab.h \
+ sys/statfs.h \
+ sys/statvfs.h \
+ sys/un.h \
+ sys/vfs.h \
+ sys/vfstab.h \
+ sys/vmmeter.h \
+ wordexp.h \
+])
+
+AC_CHECK_HEADERS([xfs/xqm.h], [], [],
+[
+#define _GNU_SOURCE
+])
# For the dns plugin
AC_CHECK_HEADERS(arpa/nameser.h)
# Checks for typedefs, structures, and compiler characteristics.
#
AC_C_CONST
-AC_C_INLINE
-AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
-AC_TYPE_SSIZE_T
AC_TYPE_UID_T
-AC_TYPE_UINT32_T
AC_HEADER_TIME
#
if test "x$have_clock_gettime" = "xyes"
then
AC_DEFINE(HAVE_CLOCK_GETTIME, 1, [Define if the clock_gettime(2) function is available.])
-else
- AC_MSG_WARN(cannot find clock_gettime)
fi
nanosleep_needs_rt="no"
#include <kvm.h>
])
+
+AC_CHECK_MEMBERS([struct kinfo_proc2.p_pid, struct kinfo_proc2.p_uru_maxrss],
+ [
+ AC_DEFINE(HAVE_STRUCT_KINFO_PROC2_NETBSD, 1,
+ [Define if struct kinfo_proc2 exists in the NetBSD variant.])
+ have_struct_kinfo_proc2_netbsd="yes"
+ ],
+ [
+ have_struct_kinfo_proc2_netbsd="no"
+ ],
+ [
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <kvm.h>
+ ])
+
+
+
AC_CHECK_MEMBERS([struct udphdr.uh_dport, struct udphdr.uh_sport], [], [],
[#define _BSD_SOURCE
#define _DEFAULT_SOURCE
# }}}
# --with-librrd {{{
-# AC_ARG_WITH (package, help-string, [action-if-given], [action-if-not-given])
librrd_cflags=""
librrd_ldflags=""
-librrd_threadsafe="yes"
+librrd_threadsafe="no"
librrd_rrdc_update="no"
-AC_ARG_WITH(librrd, [AS_HELP_STRING([--with-librrd@<:@=PREFIX@:>@], [Path to rrdtool.])],
-[ if test "x$withval" != "xno" && test "x$withval" != "xyes"
- then
- librrd_cflags="-I$withval/include"
- librrd_ldflags="-L$withval/lib"
- with_librrd="yes"
- else
- with_librrd="$withval"
- fi
-], [with_librrd="yes"])
+AC_ARG_WITH(librrd,
+ [AS_HELP_STRING([--with-librrd@<:@=PREFIX@:>@], [Path to rrdtool.])],
+ [
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"
+ then
+ librrd_cflags="-I$withval/include"
+ librrd_ldflags="-L$withval/lib"
+ with_librrd="yes"
+ else
+ with_librrd="$withval"
+ fi
+ ],
+ [with_librrd="yes"]
+)
+
if test "x$with_librrd" = "xyes"
then
- SAVE_CPPFLAGS="$CPPFLAGS"
- SAVE_LDFLAGS="$LDFLAGS"
+ SAVE_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $librrd_ldflags"
+ PKG_CHECK_MODULES([RRD], [librrd >= 1.6.0],
+ [
+ AC_CHECK_LIB([rrd], [rrd_update_r],
+ [librrd_threadsafe="yes"],
+ [:]
+ )
+ AC_CHECK_LIB([rrd], [rrdc_update],
+ [librrd_rrdc_update="yes"],
+ [:]
+ )
+ ],[:]
+ )
+ LDFLAGS="$SAVE_LDFLAGS"
- CPPFLAGS="$CPPFLAGS $librrd_cflags"
- LDFLAGS="$LDFLAGS $librrd_ldflags"
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $RRD_CFLAGS $librrd_cflags"
- AC_CHECK_HEADERS(rrd.h,, [with_librrd="no (rrd.h not found)"])
+ AC_CHECK_HEADERS([rrd.h],, [with_librrd="no (rrd.h not found)"])
- CPPFLAGS="$SAVE_CPPFLAGS"
- LDFLAGS="$SAVE_LDFLAGS"
+ CPPFLAGS="$SAVE_CPPFLAGS"
fi
-if test "x$with_librrd" = "xyes"
-then
- SAVE_CPPFLAGS="$CPPFLAGS"
- SAVE_LDFLAGS="$LDFLAGS"
- CPPFLAGS="$CPPFLAGS $librrd_cflags"
- LDFLAGS="$LDFLAGS $librrd_ldflags"
+if test "x$with_librrd" = "xyes" && test "x$librrd_threadsafe" = "xno"
+then
+ SAVE_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $librrd_ldflags"
- AC_CHECK_LIB(rrd_th, rrd_update_r,
- [with_librrd="yes"
- librrd_ldflags="$librrd_ldflags -lrrd_th -lm"
- ],
- [librrd_threadsafe="no"
- AC_CHECK_LIB(rrd, rrd_update,
- [with_librrd="yes"
- librrd_ldflags="$librrd_ldflags -lrrd -lm"
- ],
- [with_librrd="no (symbol 'rrd_update' not found)"],
- [-lm])
- ],
- [-lm])
+ AC_CHECK_LIB([rrd_th], [rrd_update_r],
+ [
+ librrd_ldflags="$librrd_ldflags -lrrd_th"
+ librrd_threadsafe="yes"
+ AC_CHECK_LIB([rrd_th], [rrdc_update],
+ [librrd_rrdc_update="yes"],
+ [:],
+ )
+ ],
+ [:]
+ )
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
- if test "x$librrd_threadsafe" = "xyes"
- then
- AC_CHECK_LIB(rrd_th, rrdc_update, [librrd_rrdc_update="yes"], [librrd_rrdc_update="no"])
- else
- AC_CHECK_LIB(rrd, rrdc_update, [librrd_rrdc_update="yes"], [librrd_rrdc_update="no"])
- fi
+if test "x$with_librrd" = "xyes" && test "x$librrd_threadsafe" = "xno"
+then
+ SAVE_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $librrd_ldflags"
- CPPFLAGS="$SAVE_CPPFLAGS"
- LDFLAGS="$SAVE_LDFLAGS"
+ AC_CHECK_LIB([rrd], [rrd_update],
+ [
+ librrd_ldflags="$librrd_ldflags -lrrd"
+ AC_CHECK_LIB([rrd], [rrdc_update],
+ [librrd_rrdc_update="yes"],
+ [:]
+ )
+ ],
+ [with_librrd="no (symbol 'rrd_update' not found)"]
+ )
+ LDFLAGS="$SAVE_LDFLAGS"
fi
+
if test "x$with_librrd" = "xyes"
then
- BUILD_WITH_LIBRRD_CFLAGS="$librrd_cflags"
- BUILD_WITH_LIBRRD_LDFLAGS="$librrd_ldflags"
- AC_SUBST(BUILD_WITH_LIBRRD_CFLAGS)
- AC_SUBST(BUILD_WITH_LIBRRD_LDFLAGS)
+ BUILD_WITH_LIBRRD_CFLAGS="$RRD_CFLAGS $librrd_cflags"
+ BUILD_WITH_LIBRRD_LDFLAGS="$librrd_ldflags"
+ BUILD_WITH_LIBRRD_LIBS="$RRD_LIBS"
+ AC_SUBST(BUILD_WITH_LIBRRD_CFLAGS)
+ AC_SUBST(BUILD_WITH_LIBRRD_LDFLAGS)
+ AC_SUBST(BUILD_WITH_LIBRRD_LIBS)
fi
if test "x$librrd_threadsafe" = "xyes"
then
- AC_DEFINE(HAVE_THREADSAFE_LIBRRD, 1, [Define to 1 if you have the threadsafe rrd library (-lrrd_th).])
+ AC_DEFINE([HAVE_THREADSAFE_LIBRRD], [1],
+ [Define to 1 if the rrd library is thread-safe]
+ )
fi
# }}}
if test "x$with_libstatgrab" = "xyes"
then
SAVE_CFLAGS="$CFLAGS"
+ SAVE_LDFLAGS="$LDFLAGS"
SAVE_LIBS="$LIBS"
CFLAGS="$CFLAGS $with_libstatgrab_cflags"
fi
# }}}
+# --with-libxenctrl {{{
+with_libxenctrl_cppflags=""
+with_libxenctrl_ldflags=""
+AC_ARG_WITH(libxenctrl, [AS_HELP_STRING([--with-libxenctrl@<:@=PREFIX@:>@], [Path to libxenctrl.])],
+[
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"
+ then
+ with_libxenctrl_cppflags="-I$withval/include"
+ with_libxenctrl_ldflags="-L$withval/lib"
+ with_libxenctrl="yes"
+ else
+ with_libxenctrl="$withval"
+ fi
+],
+[
+ with_libxenctrl="yes"
+])
+if test "x$with_libxenctrl" = "xyes"
+then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libxenctrl_cppflags"
+
+ AC_CHECK_HEADERS(xenctrl.h, [with_libxenctrl="yes"], [with_libxenctrl="no (xenctrl.h not found)"])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+fi
+if test "x$with_libxenctrl" = "xyes"
+then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ SAVE_LDFLAGS="$LDFLAGS"
+ CPPFLAGS="$CPPFLAGS $with_libxenctrl_cppflags"
+ LDFLAGS="$LDFLAGS $with_libxenctrl_ldflags"
+
+ #Xen versions older than 3.4 has no xc_getcpuinfo()
+ AC_CHECK_LIB(xenctrl, xc_getcpuinfo, [with_libxenctrl="yes"], [with_libxenctrl="no (symbol 'xc_getcpuinfo' not found)"], [])
+
+ CPPFLAGS="$SAVE_CPPFLAGS"
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+
# --with-libxmms {{{
with_xmms_config="xmms-config"
with_xmms_cflags=""
[with_libnotify="no (pkg-config doesn't know libnotify)"]
)
+PKG_CHECK_MODULES([RIEMANN_C], [riemann-client >= 1.8.0],
+ [with_riemann_c="yes"],
+ [with_riemann_c="no (pkg-config doesn't know riemann-c-client)"])
+
# Check for enabled/disabled features
#
plugin_vmem="no"
plugin_vserver="no"
plugin_wireless="no"
+plugin_xencpu="no"
plugin_zfs_arc="no"
plugin_zone="no"
plugin_zookeeper="no"
if test "x$ac_system" = "xLinux"
then
plugin_battery="yes"
+ plugin_cgroups="yes"
plugin_conntrack="yes"
plugin_contextswitch="yes"
- plugin_cgroups="yes"
plugin_cpu="yes"
plugin_cpufreq="yes"
plugin_disk="yes"
plugin_tcpconns="yes"
fi
+if test "x$ac_system" = "xNetBSD"
+then
+ plugin_disk="yes"
+ plugin_entropy="yes"
+ plugin_irq="yes"
+ plugin_processes="yes"
+fi
+
# Mac OS X devices
if test "x$with_libiokit" = "xyes"
then
if test "x$ac_system" = "xAIX"
then
- plugin_tcpconns="yes"
plugin_ipc="yes"
+ plugin_tcpconns="yes"
fi
# FreeBSD
if test "x$with_perfstat" = "xyes"
then
- plugin_cpu="yes"
plugin_contextswitch="yes"
+ plugin_cpu="yes"
plugin_disk="yes"
- plugin_memory="yes"
- plugin_swap="yes"
plugin_interface="yes"
plugin_load="yes"
+ plugin_memory="yes"
+ plugin_swap="yes"
plugin_uptime="yes"
fi
plugin_swap="yes"
fi
+if test "x$have_swapctl" = "xyes" && test "x$c_cv_have_swapctl_three_args" = "xyes"
+then
+ plugin_swap="yes"
+fi
+
if test "x$with_kvm_openfiles$with_kvm_nlist" = "xyesyes"
then
plugin_tcpconns="yes"
plugin_virt="yes"
fi
+if test "x$with_libxenctrl" = "xyes"
+then
+ plugin_xencpu="yes"
+fi
m4_divert_once([HELP_ENABLE], [
collectd plugins:])
m4_divert_once([HELP_ENABLE], [])
-AC_PLUGIN([aggregation], [yes], [Aggregation plugin])
-AC_PLUGIN([amqp], [$with_librabbitmq], [AMQP output plugin])
-AC_PLUGIN([apache], [$with_libcurl], [Apache httpd statistics])
-AC_PLUGIN([apcups], [yes], [Statistics of UPSes by APC])
-AC_PLUGIN([apple_sensors], [$with_libiokit], [Apple's hardware sensors])
-AC_PLUGIN([aquaero], [$with_libaquaero5], [Aquaero's hardware sensors])
-AC_PLUGIN([ascent], [$plugin_ascent], [AscentEmu player statistics])
-AC_PLUGIN([barometer], [$plugin_barometer], [Barometer sensor on I2C])
-AC_PLUGIN([battery], [$plugin_battery], [Battery statistics])
-AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics])
-AC_PLUGIN([ceph], [$plugin_ceph], [Ceph daemon statistics])
-AC_PLUGIN([conntrack], [$plugin_conntrack], [nf_conntrack statistics])
-AC_PLUGIN([contextswitch], [$plugin_contextswitch], [context switch statistics])
-AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics])
-AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics])
-AC_PLUGIN([csv], [yes], [CSV output plugin])
-AC_PLUGIN([curl], [$with_libcurl], [CURL generic web statistics])
-AC_PLUGIN([curl_json], [$plugin_curl_json], [CouchDB statistics])
-AC_PLUGIN([curl_xml], [$plugin_curl_xml], [CURL generic xml statistics])
-AC_PLUGIN([cgroups], [$plugin_cgroups], [CGroups CPU usage accounting])
-AC_PLUGIN([dbi], [$with_libdbi], [General database statistics])
-AC_PLUGIN([df], [$plugin_df], [Filesystem usage statistics])
-AC_PLUGIN([disk], [$plugin_disk], [Disk usage statistics])
-AC_PLUGIN([drbd], [$plugin_drbd], [DRBD statistics])
-AC_PLUGIN([dns], [$with_libpcap], [DNS traffic analysis])
-AC_PLUGIN([email], [yes], [EMail statistics])
-AC_PLUGIN([entropy], [$plugin_entropy], [Entropy statistics])
-AC_PLUGIN([ethstat], [$plugin_ethstat], [Stats from NIC driver])
-AC_PLUGIN([exec], [yes], [Execution of external programs])
-AC_PLUGIN([fhcount], [$plugin_fhcount], [File handles statistics])
-AC_PLUGIN([filecount], [yes], [Count files in directories])
-AC_PLUGIN([fscache], [$plugin_fscache], [fscache statistics])
-AC_PLUGIN([gmond], [$with_libganglia], [Ganglia plugin])
-AC_PLUGIN([hddtemp], [yes], [Query hddtempd])
-AC_PLUGIN([interface], [$plugin_interface], [Interface traffic statistics])
-AC_PLUGIN([ipc], [$plugin_ipc], [IPC statistics])
-AC_PLUGIN([ipmi], [$plugin_ipmi], [IPMI sensor statistics])
-AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
-AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics])
-AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics])
-AC_PLUGIN([java], [$with_java], [Embed the Java Virtual Machine])
-AC_PLUGIN([load], [$plugin_load], [System load])
-AC_PLUGIN([logfile], [yes], [File logging plugin])
-AC_PLUGIN([log_logstash], [$plugin_log_logstash], [Logstash json_event compatible logging])
-AC_PLUGIN([lpar], [$with_perfstat], [AIX logical partitions statistics])
-AC_PLUGIN([lvm], [$with_liblvm2app], [LVM statistics])
-AC_PLUGIN([madwifi], [$have_linux_wireless_h], [Madwifi wireless statistics])
-AC_PLUGIN([match_empty_counter], [yes], [The empty counter match])
-AC_PLUGIN([match_hashed], [yes], [The hashed match])
-AC_PLUGIN([match_regex], [yes], [The regex match])
-AC_PLUGIN([match_timediff], [yes], [The timediff match])
-AC_PLUGIN([match_value], [yes], [The value match])
-AC_PLUGIN([mbmon], [yes], [Query mbmond])
-AC_PLUGIN([md], [$have_linux_raid_md_u_h], [md (Linux software RAID) devices])
-AC_PLUGIN([memcachec], [$with_libmemcached], [memcachec statistics])
-AC_PLUGIN([memcached], [yes], [memcached statistics])
-AC_PLUGIN([memory], [$plugin_memory], [Memory usage])
-AC_PLUGIN([mic], [$with_mic], [Intel Many Integrated Core stats])
-AC_PLUGIN([modbus], [$with_libmodbus], [Modbus plugin])
-AC_PLUGIN([mqtt], [$with_libmosquitto], [MQTT output plugin])
-AC_PLUGIN([multimeter], [$plugin_multimeter], [Read multimeter values])
-AC_PLUGIN([mysql], [$with_libmysql], [MySQL statistics])
-AC_PLUGIN([netapp], [$with_libnetapp], [NetApp plugin])
-AC_PLUGIN([netlink], [$with_libmnl], [Enhanced Linux network statistics])
-AC_PLUGIN([network], [yes], [Network communication plugin])
-AC_PLUGIN([nfs], [$plugin_nfs], [NFS statistics])
-AC_PLUGIN([nginx], [$with_libcurl], [nginx statistics])
-AC_PLUGIN([notify_desktop], [$with_libnotify], [Desktop notifications])
-AC_PLUGIN([notify_email], [$with_libesmtp], [Email notifier])
-AC_PLUGIN([notify_nagios], [yes], [Nagios notification plugin])
-AC_PLUGIN([ntpd], [yes], [NTPd statistics])
-AC_PLUGIN([numa], [$plugin_numa], [NUMA virtual memory statistics])
-AC_PLUGIN([nut], [$with_libupsclient], [Network UPS tools statistics])
-AC_PLUGIN([olsrd], [yes], [olsrd statistics])
-AC_PLUGIN([onewire], [$with_libowcapi], [OneWire sensor statistics])
-AC_PLUGIN([openldap], [$with_libldap], [OpenLDAP statistics])
-AC_PLUGIN([openvpn], [yes], [OpenVPN client statistics])
-AC_PLUGIN([oracle], [$with_oracle], [Oracle plugin])
-AC_PLUGIN([perl], [$plugin_perl], [Embed a Perl interpreter])
-AC_PLUGIN([pf], [$have_net_pfvar_h], [BSD packet filter (PF) statistics])
+AC_PLUGIN([aggregation], [yes], [Aggregation plugin])
+AC_PLUGIN([amqp], [$with_librabbitmq], [AMQP output plugin])
+AC_PLUGIN([apache], [$with_libcurl], [Apache httpd statistics])
+AC_PLUGIN([apcups], [yes], [Statistics of UPSes by APC])
+AC_PLUGIN([apple_sensors], [$with_libiokit], [Apple hardware sensors])
+AC_PLUGIN([aquaero], [$with_libaquaero5], [Aquaero hardware sensors])
+AC_PLUGIN([ascent], [$plugin_ascent], [AscentEmu player statistics])
+AC_PLUGIN([barometer], [$plugin_barometer], [Barometer sensor on I2C])
+AC_PLUGIN([battery], [$plugin_battery], [Battery statistics])
+AC_PLUGIN([bind], [$plugin_bind], [ISC Bind nameserver statistics])
+AC_PLUGIN([ceph], [$plugin_ceph], [Ceph daemon statistics])
+AC_PLUGIN([cgroups], [$plugin_cgroups], [CGroups CPU usage accounting])
+AC_PLUGIN([conntrack], [$plugin_conntrack], [nf_conntrack statistics])
+AC_PLUGIN([contextswitch], [$plugin_contextswitch], [context switch statistics])
+AC_PLUGIN([cpu], [$plugin_cpu], [CPU usage statistics])
+AC_PLUGIN([cpufreq], [$plugin_cpufreq], [CPU frequency statistics])
+AC_PLUGIN([csv], [yes], [CSV output plugin])
+AC_PLUGIN([curl], [$with_libcurl], [CURL generic web statistics])
+AC_PLUGIN([curl_json], [$plugin_curl_json], [CouchDB statistics])
+AC_PLUGIN([curl_xml], [$plugin_curl_xml], [CURL generic xml statistics])
+AC_PLUGIN([dbi], [$with_libdbi], [General database statistics])
+AC_PLUGIN([df], [$plugin_df], [Filesystem usage statistics])
+AC_PLUGIN([disk], [$plugin_disk], [Disk usage statistics])
+AC_PLUGIN([dns], [$with_libpcap], [DNS traffic analysis])
+AC_PLUGIN([drbd], [$plugin_drbd], [DRBD statistics])
+AC_PLUGIN([email], [yes], [EMail statistics])
+AC_PLUGIN([entropy], [$plugin_entropy], [Entropy statistics])
+AC_PLUGIN([ethstat], [$plugin_ethstat], [Stats from NIC driver])
+AC_PLUGIN([exec], [yes], [Execution of external programs])
+AC_PLUGIN([fhcount], [$plugin_fhcount], [File handles statistics])
+AC_PLUGIN([filecount], [yes], [Count files in directories])
+AC_PLUGIN([fscache], [$plugin_fscache], [fscache statistics])
+AC_PLUGIN([gmond], [$with_libganglia], [Ganglia plugin])
+AC_PLUGIN([hddtemp], [yes], [Query hddtempd])
+AC_PLUGIN([interface], [$plugin_interface], [Interface traffic statistics])
+AC_PLUGIN([ipc], [$plugin_ipc], [IPC statistics])
+AC_PLUGIN([ipmi], [$plugin_ipmi], [IPMI sensor statistics])
+AC_PLUGIN([iptables], [$with_libiptc], [IPTables rule counters])
+AC_PLUGIN([ipvs], [$plugin_ipvs], [IPVS connection statistics])
+AC_PLUGIN([irq], [$plugin_irq], [IRQ statistics])
+AC_PLUGIN([java], [$with_java], [Embed the Java Virtual Machine])
+AC_PLUGIN([load], [$plugin_load], [System load])
+AC_PLUGIN([log_logstash], [$plugin_log_logstash], [Logstash json_event compatible logging])
+AC_PLUGIN([logfile], [yes], [File logging plugin])
+AC_PLUGIN([lpar], [$with_perfstat], [AIX logical partitions statistics])
+AC_PLUGIN([lvm], [$with_liblvm2app], [LVM statistics])
+AC_PLUGIN([madwifi], [$have_linux_wireless_h], [Madwifi wireless statistics])
+AC_PLUGIN([match_empty_counter], [yes], [The empty counter match])
+AC_PLUGIN([match_hashed], [yes], [The hashed match])
+AC_PLUGIN([match_regex], [yes], [The regex match])
+AC_PLUGIN([match_timediff], [yes], [The timediff match])
+AC_PLUGIN([match_value], [yes], [The value match])
+AC_PLUGIN([mbmon], [yes], [Query mbmond])
+AC_PLUGIN([md], [$have_linux_raid_md_u_h], [md (Linux software RAID) devices])
+AC_PLUGIN([memcachec], [$with_libmemcached], [memcachec statistics])
+AC_PLUGIN([memcached], [yes], [memcached statistics])
+AC_PLUGIN([memory], [$plugin_memory], [Memory usage])
+AC_PLUGIN([mic], [$with_mic], [Intel Many Integrated Core stats])
+AC_PLUGIN([modbus], [$with_libmodbus], [Modbus plugin])
+AC_PLUGIN([mqtt], [$with_libmosquitto], [MQTT output plugin])
+AC_PLUGIN([multimeter], [$plugin_multimeter], [Read multimeter values])
+AC_PLUGIN([mysql], [$with_libmysql], [MySQL statistics])
+AC_PLUGIN([netapp], [$with_libnetapp], [NetApp plugin])
+AC_PLUGIN([netlink], [$with_libmnl], [Enhanced Linux network statistics])
+AC_PLUGIN([network], [yes], [Network communication plugin])
+AC_PLUGIN([nfs], [$plugin_nfs], [NFS statistics])
+AC_PLUGIN([nginx], [$with_libcurl], [nginx statistics])
+AC_PLUGIN([notify_desktop], [$with_libnotify], [Desktop notifications])
+AC_PLUGIN([notify_email], [$with_libesmtp], [Email notifier])
+AC_PLUGIN([notify_nagios], [yes], [Nagios notification plugin])
+AC_PLUGIN([ntpd], [yes], [NTPd statistics])
+AC_PLUGIN([numa], [$plugin_numa], [NUMA virtual memory statistics])
+AC_PLUGIN([nut], [$with_libupsclient], [Network UPS tools statistics])
+AC_PLUGIN([olsrd], [yes], [olsrd statistics])
+AC_PLUGIN([onewire], [$with_libowcapi], [OneWire sensor statistics])
+AC_PLUGIN([openldap], [$with_libldap], [OpenLDAP statistics])
+AC_PLUGIN([openvpn], [yes], [OpenVPN client statistics])
+AC_PLUGIN([oracle], [$with_oracle], [Oracle plugin])
+AC_PLUGIN([perl], [$plugin_perl], [Embed a Perl interpreter])
+AC_PLUGIN([pf], [$have_net_pfvar_h], [BSD packet filter (PF) statistics])
# FIXME: Check for libevent, too.
-AC_PLUGIN([pinba], [$have_protoc_c], [Pinba statistics])
-AC_PLUGIN([ping], [$with_liboping], [Network latency statistics])
-AC_PLUGIN([postgresql], [$with_libpq], [PostgreSQL database statistics])
-AC_PLUGIN([powerdns], [yes], [PowerDNS statistics])
-AC_PLUGIN([processes], [$plugin_processes], [Process statistics])
-AC_PLUGIN([protocols], [$plugin_protocols], [Protocol (IP, TCP, ...) statistics])
-AC_PLUGIN([python], [$with_python], [Embed a Python interpreter])
-AC_PLUGIN([redis], [$with_libhiredis], [Redis plugin])
-AC_PLUGIN([routeros], [$with_librouteros], [RouterOS plugin])
-AC_PLUGIN([rrdcached], [$librrd_rrdc_update], [RRDTool output plugin])
-AC_PLUGIN([rrdtool], [$with_librrd], [RRDTool output plugin])
-AC_PLUGIN([sensors], [$with_libsensors], [lm_sensors statistics])
-AC_PLUGIN([serial], [$plugin_serial], [serial port traffic])
-AC_PLUGIN([sigrok], [$with_libsigrok], [sigrok acquisition sources])
-AC_PLUGIN([smart], [$with_libatasmart], [SMART statistics])
-AC_PLUGIN([snmp], [$with_libnetsnmp], [SNMP querying plugin])
-AC_PLUGIN([statsd], [yes], [StatsD plugin])
-AC_PLUGIN([swap], [$plugin_swap], [Swap usage statistics])
-AC_PLUGIN([syslog], [$have_syslog], [Syslog logging plugin])
-AC_PLUGIN([table], [yes], [Parsing of tabular data])
-AC_PLUGIN([tail], [yes], [Parsing of logfiles])
-AC_PLUGIN([tail_csv], [yes], [Parsing of CSV files])
-AC_PLUGIN([tape], [$plugin_tape], [Tape drive statistics])
-AC_PLUGIN([target_notification], [yes], [The notification target])
-AC_PLUGIN([target_replace], [yes], [The replace target])
-AC_PLUGIN([target_scale],[yes], [The scale target])
-AC_PLUGIN([target_set], [yes], [The set target])
-AC_PLUGIN([target_v5upgrade], [yes], [The v5upgrade target])
-AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics])
-AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics])
-AC_PLUGIN([ted], [$plugin_ted], [Read The Energy Detective values])
-AC_PLUGIN([thermal], [$plugin_thermal], [Linux ACPI thermal zone statistics])
-AC_PLUGIN([threshold], [yes], [Threshold checking plugin])
-AC_PLUGIN([tokyotyrant], [$with_libtokyotyrant], [TokyoTyrant database statistics])
-AC_PLUGIN([turbostat], [$plugin_turbostat], [Advanced statistic on Intel cpu states])
-AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin])
-AC_PLUGIN([uptime], [$plugin_uptime], [Uptime statistics])
-AC_PLUGIN([users], [$plugin_users], [User statistics])
-AC_PLUGIN([uuid], [yes], [UUID as hostname plugin])
-AC_PLUGIN([varnish], [$with_libvarnish], [Varnish cache statistics])
-AC_PLUGIN([virt], [$plugin_virt], [Virtual machine statistics])
-AC_PLUGIN([vmem], [$plugin_vmem], [Virtual memory statistics])
-AC_PLUGIN([vserver], [$plugin_vserver], [Linux VServer statistics])
-AC_PLUGIN([wireless], [$plugin_wireless], [Wireless statistics])
-AC_PLUGIN([write_graphite], [yes], [Graphite / Carbon output plugin])
-AC_PLUGIN([write_http], [$with_libcurl], [HTTP output plugin])
-AC_PLUGIN([write_kafka], [$with_librdkafka], [Kafka output plugin])
-AC_PLUGIN([write_log], [yes], [Log output plugin])
-AC_PLUGIN([write_mongodb], [$with_libmongoc], [MongoDB output plugin])
-AC_PLUGIN([write_redis], [$with_libhiredis], [Redis output plugin])
-AC_PLUGIN([write_riemann], [$have_protoc_c], [Riemann output plugin])
-AC_PLUGIN([write_sensu], [yes], [Sensu output plugin])
-AC_PLUGIN([write_tsdb], [yes], [TSDB output plugin])
-AC_PLUGIN([xmms], [$with_libxmms], [XMMS statistics])
-AC_PLUGIN([zfs_arc], [$plugin_zfs_arc], [ZFS ARC statistics])
-AC_PLUGIN([zone], [$plugin_zone], [Solaris container statistics])
-AC_PLUGIN([zookeeper], [yes], [Zookeeper statistics])
+AC_PLUGIN([pinba], [$have_protoc_c], [Pinba statistics])
+AC_PLUGIN([ping], [$with_liboping], [Network latency statistics])
+AC_PLUGIN([postgresql], [$with_libpq], [PostgreSQL database statistics])
+AC_PLUGIN([powerdns], [yes], [PowerDNS statistics])
+AC_PLUGIN([processes], [$plugin_processes], [Process statistics])
+AC_PLUGIN([protocols], [$plugin_protocols], [Protocol (IP, TCP, ...) statistics])
+AC_PLUGIN([python], [$with_python], [Embed a Python interpreter])
+AC_PLUGIN([redis], [$with_libhiredis], [Redis plugin])
+AC_PLUGIN([routeros], [$with_librouteros], [RouterOS plugin])
+AC_PLUGIN([rrdcached], [$librrd_rrdc_update], [RRDTool output plugin])
+AC_PLUGIN([rrdtool], [$with_librrd], [RRDTool output plugin])
+AC_PLUGIN([sensors], [$with_libsensors], [lm_sensors statistics])
+AC_PLUGIN([serial], [$plugin_serial], [serial port traffic])
+AC_PLUGIN([sigrok], [$with_libsigrok], [sigrok acquisition sources])
+AC_PLUGIN([smart], [$with_libatasmart], [SMART statistics])
+AC_PLUGIN([snmp], [$with_libnetsnmp], [SNMP querying plugin])
+AC_PLUGIN([statsd], [yes], [StatsD plugin])
+AC_PLUGIN([swap], [$plugin_swap], [Swap usage statistics])
+AC_PLUGIN([syslog], [$have_syslog], [Syslog logging plugin])
+AC_PLUGIN([table], [yes], [Parsing of tabular data])
+AC_PLUGIN([tail], [yes], [Parsing of logfiles])
+AC_PLUGIN([tail_csv], [yes], [Parsing of CSV files])
+AC_PLUGIN([tape], [$plugin_tape], [Tape drive statistics])
+AC_PLUGIN([target_notification], [yes], [The notification target])
+AC_PLUGIN([target_replace], [yes], [The replace target])
+AC_PLUGIN([target_scale], [yes], [The scale target])
+AC_PLUGIN([target_set], [yes], [The set target])
+AC_PLUGIN([target_v5upgrade], [yes], [The v5upgrade target])
+AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics])
+AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics])
+AC_PLUGIN([ted], [$plugin_ted], [Read The Energy Detective values])
+AC_PLUGIN([thermal], [$plugin_thermal], [Linux ACPI thermal zone statistics])
+AC_PLUGIN([threshold], [yes], [Threshold checking plugin])
+AC_PLUGIN([tokyotyrant], [$with_libtokyotyrant], [TokyoTyrant database statistics])
+AC_PLUGIN([turbostat], [$plugin_turbostat], [Advanced statistic on Intel cpu states])
+AC_PLUGIN([unixsock], [yes], [Unixsock communication plugin])
+AC_PLUGIN([uptime], [$plugin_uptime], [Uptime statistics])
+AC_PLUGIN([users], [$plugin_users], [User statistics])
+AC_PLUGIN([uuid], [yes], [UUID as hostname plugin])
+AC_PLUGIN([varnish], [$with_libvarnish], [Varnish cache statistics])
+AC_PLUGIN([virt], [$plugin_virt], [Virtual machine statistics])
+AC_PLUGIN([vmem], [$plugin_vmem], [Virtual memory statistics])
+AC_PLUGIN([vserver], [$plugin_vserver], [Linux VServer statistics])
+AC_PLUGIN([wireless], [$plugin_wireless], [Wireless statistics])
+AC_PLUGIN([write_graphite], [yes], [Graphite / Carbon output plugin])
+AC_PLUGIN([write_http], [$with_libcurl], [HTTP output plugin])
+AC_PLUGIN([write_kafka], [$with_librdkafka], [Kafka output plugin])
+AC_PLUGIN([write_log], [yes], [Log output plugin])
+AC_PLUGIN([write_mongodb], [$with_libmongoc], [MongoDB output plugin])
+AC_PLUGIN([write_redis], [$with_libhiredis], [Redis output plugin])
+AC_PLUGIN([write_riemann], [$with_riemann_c], [Riemann output plugin])
+AC_PLUGIN([write_sensu], [yes], [Sensu output plugin])
+AC_PLUGIN([write_tsdb], [yes], [TSDB output plugin])
+AC_PLUGIN([xencpu], [$plugin_xencpu], [Xen Host CPU usage])
+AC_PLUGIN([xmms], [$with_libxmms], [XMMS statistics])
+AC_PLUGIN([zfs_arc], [$plugin_zfs_arc], [ZFS ARC statistics])
+AC_PLUGIN([zone], [$plugin_zone], [Solaris container statistics])
+AC_PLUGIN([zookeeper], [yes], [Zookeeper statistics])
dnl Default configuration file
# Load either syslog or logfile
libupsclient . . . . $with_libupsclient
libvarnish . . . . . $with_libvarnish
libvirt . . . . . . . $with_libvirt
+ libxenctrl . . . . . $with_libxenctrl
libxml2 . . . . . . . $with_libxml2
libxmms . . . . . . . $with_libxmms
libyajl . . . . . . . $with_libyajl
oracle . . . . . . . $with_oracle
protobuf-c . . . . . $have_protoc_c
python . . . . . . . $with_python
+ riemann-c-client . . $with_riemann_c
Features:
daemon mode . . . . . $enable_daemon
write_riemann . . . . $enable_write_riemann
write_sensu . . . . . $enable_write_sensu
write_tsdb . . . . . $enable_write_tsdb
+ xencpu . . . . . . . $enable_xencpu
xmms . . . . . . . . $enable_xmms
zfs_arc . . . . . . . $enable_zfs_arc
zone . . . . . . . . $enable_zone
my $ident = shift;
my $all_files;
my @ret = ();
+ my $temp;
+ my $hosts;
my $cache_key = ident_to_string ($ident);
if (defined ($Cache->{'get_files_by_ident'}{$cache_key}))
return ($ret)
}
- $all_files = _get_all_files ();
+ if ($ident->{'hostname'})
+ {
+ $all_files = [];
+ $hosts = $ident->{'hostname'};
+ foreach (@$hosts)
+ {
+ $temp = get_files_for_host ($_);
+ push (@$all_files, @$temp);
+ }
+ }
+ else
+ {
+ $all_files = _get_all_files ();
+ }
@ret = grep { _filter_ident ($ident, $_) == 0 } (@$all_files);
%{?el7:%global _has_lvm2app_h 1}
%{?el7:%global _has_libudev 1}
%{?el7:%global _has_recent_librrd 1}
-%{?el7:%global _has_broken_libmemcached 1}
%{?el7:%global _has_iproute 1}
%{?el7:%global _has_atasmart 1}
%{?el7:%global _has_hiredis 1}
%{?el7:%global _has_asm_msr_index 1}
%{?el7:%global _has_libmosquitto 1}
+%{?el7:%global _has_libmodbus 1}
+%{?el7:%global _has_xmms 1}
# plugins enabled by default
%define with_aggregation 0%{!?_without_aggregation:1}
%define with_madwifi 0%{!?_without_madwifi:1}
%define with_mbmon 0%{!?_without_mbmon:1}
%define with_md 0%{!?_without_md:1}
-%define with_memcachec 0%{!?_without_memcachec:0%{!?_has_broken_libmemcached:1}}
+%define with_memcachec 0%{!?_without_memcachec:1}
%define with_memcached 0%{!?_without_memcached:1}
%define with_memory 0%{!?_without_memory:1}
%define with_multimeter 0%{!?_without_multimeter:1}
%define with_write_http 0%{!?_without_write_http:1}
%define with_write_log 0%{!?_without_write_log:1}
%define with_write_redis 0%{!?_without_write_redis:0%{?_has_hiredis}}
-%define with_write_riemann 0%{!?_without_write_riemann:1}
+%define with_write_riemann 0%{!?_without_write_riemann:0%{?_has_recent_riemann_c_client}}
%define with_write_sensu 0%{!?_without_write_sensu:1}
%define with_write_tsdb 0%{!?_without_write_tsdb:1}
+%define with_xmms 0%{!?_without_xmms:0%{?_has_xmms}}
%define with_zfs_arc 0%{!?_without_zfs_arc:1}
%define with_zookeeper 0%{!?_without_zookeeper:1}
%define with_write_kafka 0%{!?_without_write_kafka:0}
# plugin write_mongodb disabled, requires libmongoc
%define with_write_mongodb 0%{!?_without_write_mongodb:0}
-# plugin xmms disabled, requires xmms
-%define with_xmms 0%{!?_without_xmms:0}
# plugin zone disabled, requires Solaris
%define with_zone 0%{!?_without_zone:0}
Summary: statistics collection and monitoring daemon
Name: collectd
-Version: 5.5.0
+Version: 5.5.1
Release: 1%{?dist}
URL: http://collectd.org
Source: http://collectd.org/files/%{name}-%{version}.tar.bz2
The riemann plugin submits values to Riemann, an event stream processor.
%endif
+%if %{with_xmms}
+%package xmms
+Summary: XMMS plugin for collectd
+Group: System Environment/Daemons
+Requires: %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: xmms-devel
+%description xmms
+The xmms plugin collects information from the XMMS music player.
+%endif
+
%package collection3
Summary: Web-based viewer for collectd
Group: System Environment/Daemons
%{_includedir}/collectd/network_buffer.h
%{_includedir}/collectd/lcc_features.h
%{_libdir}/pkgconfig/libcollectdclient.pc
+%{_libdir}/libcollectdclient.so
%files -n libcollectdclient
-%{_libdir}/libcollectdclient.so
%{_libdir}/libcollectdclient.so.*
%files -n collectd-utils
%{_libdir}/%{name}/write_riemann.so
%endif
+%if %{with_xmms}
+%files xmms
+%{_libdir}/%{name}/xmms.so
+%endif
+
%files collection3
%{_localstatedir}/www/collection3
%{_sysconfdir}/httpd/conf.d/collection3.conf
- Install collectdctl, collectd-tg and collectd-nagios in collectd-utils.rpm
- Add build-dependency on libcap-devel
-* Mon Aug 19 2013 Marc Fournier <marc.fournier@camptocamp.com> 5.4.0-1
+* Mon Aug 19 2013 Marc Fournier <marc.fournier@camptocamp.com> 5.4.2-1
- New upstream version
- Build netlink plugin by default
- Enable cgroups, lvm and statsd plugins
- Enable (but don't build by default) mic, aquaero and sigrok plugins
+- Enable modbus, memcachec and xmms plugins on RHEL7
* Tue Aug 06 2013 Marc Fournier <marc.fournier@camptocamp.com> 5.3.1-1
- New upstream version
[Unit]
-Description=Collectd
-After=local-fs.target network.target
-Requires=local-fs.target network.target
+Description=Collectd statistics daemon
+Documentation=man:collectd(1) man:collectd.conf(5)
+After=local-fs.target network-online.target
+Requires=local-fs.target network-online.target
[Service]
ExecStart=/usr/sbin/collectd
# socket once the daemon is ready. See systemd.service(5) for more details.
Type=notify
-# Restart the collectd daemon after a 10 seconds delay, in case it crashes.
+# Restart the collectd daemon when it fails.
Restart=on-failure
[Install]
pkglib_LTLIBRARIES += amqp.la
amqp_la_SOURCES = amqp.c \
utils_cmd_putval.c utils_cmd_putval.h \
- utils_parse_option.c utils_parse_option.h \
+ utils_parse_option.c utils_parse_option.h \
utils_format_graphite.c utils_format_graphite.h \
utils_format_json.c utils_format_json.h
amqp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
if BUILD_PLUGIN_RRDCACHED
pkglib_LTLIBRARIES += rrdcached.la
rrdcached_la_SOURCES = rrdcached.c utils_rrdcreate.c utils_rrdcreate.h
-rrdcached_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+rrdcached_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRRD_LDFLAGS)
rrdcached_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBRRD_CFLAGS)
-rrdcached_la_LIBADD = $(BUILD_WITH_LIBRRD_LDFLAGS)
+rrdcached_la_LIBADD = $(BUILD_WITH_LIBRRD_LIBS)
endif
if BUILD_PLUGIN_RRDTOOL
pkglib_LTLIBRARIES += rrdtool.la
rrdtool_la_SOURCES = rrdtool.c utils_rrdcreate.c utils_rrdcreate.h
-rrdtool_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+rrdtool_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRRD_LDFLAGS)
rrdtool_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBRRD_CFLAGS)
-rrdtool_la_LIBADD = $(BUILD_WITH_LIBRRD_LDFLAGS)
+rrdtool_la_LIBADD = $(BUILD_WITH_LIBRRD_LIBS)
endif
if BUILD_PLUGIN_SENSORS
if BUILD_PLUGIN_WRITE_RIEMANN
pkglib_LTLIBRARIES += write_riemann.la
-write_riemann_la_SOURCES = write_riemann.c write_riemann_threshold.c
-nodist_write_riemann_la_SOURCES = riemann.pb-c.c riemann.pb-c.h
-write_riemann_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-write_riemann_la_LIBADD = -lprotobuf-c
+write_riemann_la_SOURCES = write_riemann.c write_riemann_threshold.c write_riemann_threshold.h
+write_riemann_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(RIEMANN_C_LIBS)
+write_riemann_la_CFLAGS = $(AM_CFLAGS) $(RIEMANN_C_CFLAGS)
endif
if BUILD_PLUGIN_WRITE_SENSU
write_tsdb_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif
+if BUILD_PLUGIN_XENCPU
+pkglib_LTLIBRARIES += xencpu.la
+xencpu_la_SOURCES = xencpu.c
+xencpu_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+xencpu_la_LIBADD = -lxenctrl
+endif
+
if BUILD_PLUGIN_XMMS
pkglib_LTLIBRARIES += xmms.la
xmms_la_SOURCES = xmms.c
$(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 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
- $(AM_V_PROTOC_C)protoc-c -I$(srcdir) --c_out . $(srcdir)/riemann.proto
-endif
-
install-exec-hook:
$(mkinstalldirs) $(DESTDIR)$(sysconfdir)
if test -e $(DESTDIR)$(sysconfdir)/collectd.conf; \
DEBUG ("aggregation plugin: Creating new instance.");
- inst = malloc (sizeof (*inst));
+ inst = calloc (1, sizeof (*inst));
if (inst == NULL)
{
- ERROR ("aggregation plugin: malloc() failed.");
+ ERROR ("aggregation plugin: calloc() failed.");
return (NULL);
}
- memset (inst, 0, sizeof (*inst));
pthread_mutex_init (&inst->lock, /* attr = */ NULL);
inst->ds_type = ds->ds[0].type;
#define INIT_STATE(field) do { \
inst->state_ ## field = NULL; \
if (agg->calc_ ## field) { \
- inst->state_ ## field = malloc (sizeof (*inst->state_ ## field)); \
+ inst->state_ ## field = calloc (1, sizeof (*inst->state_ ## field)); \
if (inst->state_ ## field == NULL) { \
agg_instance_destroy (inst); \
free (inst); \
- ERROR ("aggregation plugin: malloc() failed."); \
+ ERROR ("aggregation plugin: calloc() failed."); \
return (NULL); \
} \
- memset (inst->state_ ## field, 0, sizeof (*inst->state_ ## field)); \
} \
} while (0)
int status;
int i;
- agg = malloc (sizeof (*agg));
+ agg = calloc (1, sizeof (*agg));
if (agg == NULL)
{
- ERROR ("aggregation plugin: malloc failed.");
+ ERROR ("aggregation plugin: calloc failed.");
return (-1);
}
- memset (agg, 0, sizeof (*agg));
sstrncpy (agg->ident.host, "/.*/", sizeof (agg->ident.host));
sstrncpy (agg->ident.plugin, "/.*/", sizeof (agg->ident.plugin));
if (tmp == NULL)
{
ERROR ("amqp plugin: realloc failed.");
+ sfree (subscriber_threads);
camqp_config_free (conf);
return (ENOMEM);
}
int status;
int i;
- conf = malloc (sizeof (*conf));
+ conf = calloc (1, sizeof (*conf));
if (conf == NULL)
{
- ERROR ("amqp plugin: malloc failed.");
+ ERROR ("amqp plugin: calloc failed.");
return (ENOMEM);
}
/* Initialize "conf" {{{ */
- memset (conf, 0, sizeof (*conf));
conf->publish = publish;
conf->name = NULL;
conf->format = CAMQP_FORMAT_COMMAND;
return (0);
}
- if (len <= 0)
+ if (len == 0)
return (len);
if ((st->apache_buffer_fill + len) >= st->apache_buffer_size)
{
char *temp;
- temp = (char *) realloc (st->apache_buffer,
+ temp = realloc (st->apache_buffer,
st->apache_buffer_fill + len + 1);
if (temp == NULL)
{
return (0);
}
- if (len <= 0)
+ if (len == 0)
return (len);
/* look for the Server header */
int i;
int status;
- st = malloc (sizeof (*st));
+ st = calloc (1, sizeof (*st));
if (st == NULL)
{
- ERROR ("apache plugin: malloc failed.");
+ ERROR ("apache plugin: calloc failed.");
return (-1);
}
- memset (st, 0, sizeof (*st));
st->timeout = -1;
st = user_data->data;
+ int status;
+
+ char *content_type;
+ static const char *text_plain = "text/plain";
+
assert (st->url != NULL);
/* (Assured by `config_add') */
if (st->curl == NULL)
{
- int status;
-
status = init_host (st);
if (status != 0)
return (-1);
st->server_type = APACHE;
}
+ status = curl_easy_getinfo (st->curl, CURLINFO_CONTENT_TYPE, &content_type);
+ if ((status == CURLE_OK) && (content_type != NULL) &&
+ (strncasecmp (content_type, text_plain, strlen (text_plain)) != 0))
+ {
+ WARNING ("apache plugin: `Content-Type' response header is not `%s' "
+ "(received: `%s'). Expecting unparseable data. Please check `URL' "
+ "parameter (missing `?auto' suffix ?)",
+ text_plain, content_type);
+ }
+
ptr = st->apache_buffer;
saveptr = NULL;
while ((line = strtok_r (ptr, "\n\r", &saveptr)) != NULL)
* Returns zero on success
* Returns non-zero on error
*/
-static int net_send (int *sockfd, char *buff, int len)
+static int net_send (int *sockfd, const char *buff, int len)
{
uint16_t packet_size;
return (0);
} /* int apcups_config */
-static void apc_submit_generic (char *type, char *type_inst, double value)
+static void apc_submit_generic (const char *type, const char *type_inst, double value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
static int as_init (void)
{
kern_return_t status;
-
+
if (io_master_port != MACH_PORT_NULL)
{
mach_port_deallocate (mach_task_self (),
#include <curl/curl.h>
#include <libxml/parser.h>
-static char *races_list[] = /* {{{ */
+static const char *races_list[] = /* {{{ */
{
NULL,
"Human", /* 1 */
}; /* }}} */
#define RACES_LIST_LENGTH STATIC_ARRAY_SIZE (races_list)
-static char *classes_list[] = /* {{{ */
+static const char *classes_list[] = /* {{{ */
{
NULL,
"Warrior", /* 1 */
}; /* }}} */
#define CLASSES_LIST_LENGTH STATIC_ARRAY_SIZE (classes_list)
-static char *genders_list[] = /* {{{ */
+static const char *genders_list[] = /* {{{ */
{
"Male",
"Female"
{
size_t len = size * nmemb;
- if (len <= 0)
+ if (len == 0)
return (len);
if ((ascent_buffer_fill + len) >= ascent_buffer_size)
{
char *temp;
- temp = (char *) realloc (ascent_buffer,
+ temp = realloc (ascent_buffer,
ascent_buffer_fill + len + 1);
if (temp == NULL)
{
*/
static int temp_list_add(temperature_list_t * list, const char * sensor)
{
- temperature_list_t * new_temp;
+ temperature_list_t *new_temp;
- new_temp = (temperature_list_t *) malloc(sizeof(*new_temp));
+ new_temp = malloc(sizeof (*new_temp));
if(new_temp == NULL)
return -1;
*
* @return detected sensor type
*/
-enum Sensor_type Detect_sensor_type(void)
+static enum Sensor_type detect_sensor_type(void)
{
if(BMP085_detect())
return Sensor_BMP085;
}
/* detect sensor type - this will also set slave address */
- sensor_type = Detect_sensor_type();
+ sensor_type = detect_sensor_type();
/* init correct sensor type */
switch(sensor_type)
} /* }}} void submit_capacity */
#if HAVE_IOKIT_PS_IOPOWERSOURCES_H || HAVE_IOKIT_IOKITLIB_H
-static double dict_get_double (CFDictionaryRef dict, char *key_string) /* {{{ */
+static double dict_get_double (CFDictionaryRef dict, const char *key_string) /* {{{ */
{
double val_double;
long long val_int;
*ret_voltage = temp_double / 1000.0;
}
}
-
+
CFRelease (bat_root_dict);
}
* IOPowerSources. IOKit, on the other hand, only reports the full
* capacity. We use the two to calculate the current charged capacity. */
gauge_t charge_rel = NAN; /* Current charge in percent */
- gauge_t capacity_charged = NAN; /* Charged capacity */
+ gauge_t capacity_charged; /* Charged capacity */
gauge_t capacity_full = NAN; /* Total capacity */
gauge_t capacity_design = NAN; /* Full design capacity */
# define BIND_DEFAULT_URL "http://localhost:8053/"
#endif
-/*
+/*
* Some types used for the callback functions. `translation_table_ptr_t' and
* `list_info_ptr_t' are passed to the callbacks in the `void *user_data'
* pointer.
{
size_t len = size * nmemb;
- if (len <= 0)
+ if (len == 0)
return (len);
if ((bind_buffer_fill + len) >= bind_buffer_size)
{
char *temp;
- temp = realloc(bind_buffer, bind_buffer_fill + len + 1);
+ temp = realloc (bind_buffer, bind_buffer_fill + len + 1);
if (temp == NULL)
{
ERROR ("bind plugin: realloc failed.");
return (0);
} /* }}} int bind_xml_read_timestamp */
-/*
+/*
* bind_parse_generic_name_value
*
* Reads statistics in the form:
return (0);
} /* }}} int bind_parse_generic_name_value */
-/*
+/*
* bind_parse_generic_value_list
*
* Reads statistics in the form:
{ /* Parse the <counters> tag {{{ */
char plugin_instance[DATA_MAX_NAME_LEN];
translation_table_ptr_t table_ptr =
- {
+ {
nsstats_translation_table,
nsstats_translation_table_length,
plugin_instance
for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
{
- xmlNode *node;
-
node = zone_nodes->nodesetval->nodeTab[i];
assert (node != NULL);
{
char plugin_instance[DATA_MAX_NAME_LEN];
translation_table_ptr_t table_ptr =
- {
+ {
resstats_translation_table,
resstats_translation_table_length,
plugin_instance
return (-1);
}
- tmp = (char **) realloc (view->zones,
+ tmp = realloc (view->zones,
sizeof (char *) * (view->zones_num + 1));
if (tmp == NULL)
{
return (-1);
}
- tmp = (cb_view_t *) realloc (views, sizeof (*views) * (views_num + 1));
+ tmp = realloc (views, sizeof (*views) * (views_num + 1));
if (tmp == NULL)
{
ERROR ("bind plugin: realloc failed.");
};
/** Valid types for ceph defined in types.db */
-const char * ceph_dset_types [CEPH_DSET_TYPES_NUM] =
+static const char * const ceph_dset_types [CEPH_DSET_TYPES_NUM] =
{"ceph_latency", "ceph_bytes", "ceph_rate"};
/******* ceph_daemon *******/
return -ENOMEM;
}
- d->ds_names[d->ds_num] = malloc(sizeof(char) * DATA_MAX_NAME_LEN);
+ d->ds_names[d->ds_num] = malloc(DATA_MAX_NAME_LEN);
if(!d->ds_names[d->ds_num])
{
return -ENOMEM;
}
g_daemons = tmp;
- nd = malloc(sizeof(*nd));
+ nd = malloc(sizeof (*nd));
if(!nd)
{
return ENOMEM;
static int add_last(struct ceph_daemon *d, const char *ds_n, double cur_sum,
uint64_t cur_count)
{
- d->last_poll_data[d->last_idx] = malloc(1 * sizeof(struct last_data));
+ d->last_poll_data[d->last_idx] = malloc(sizeof (*d->last_poll_data[d->last_idx]));
if(!d->last_poll_data[d->last_idx])
{
return -ENOMEM;
if(!d->last_poll_data)
{
- d->last_poll_data = malloc(1 * sizeof(struct last_data *));
+ d->last_poll_data = malloc(sizeof (*d->last_poll_data));
if(!d->last_poll_data)
{
return -ENOMEM;
fd = socket(PF_UNIX, SOCK_STREAM, 0);
if(fd < 0)
{
- int err = -errno;
+ err = -errno;
ERROR("ceph plugin: cconn_connect: socket(PF_UNIX, SOCK_STREAM, 0) "
"failed: error %d", err);
return err;
}
else
{
- int ret = cconn_handle_event(io);
+ ret = cconn_handle_event(io);
if(ret)
{
WARNING("ceph plugin: cconn_handle_event(name=%s,"
struct case_s
{
- char *key;
- char *value;
+ const char *key;
+ const char *value;
};
typedef struct case_s case_t;
yajl_handle hndl;
#if HAVE_YAJL_V2
hndl = yajl_alloc (&callbacks, NULL, &ctx);
- CHECK_ZERO (traverse_json ((unsigned char *) json, (uint32_t) strlen (json), hndl));
+ CHECK_ZERO (traverse_json ((const unsigned char *) json, (uint32_t) strlen (json), hndl));
CHECK_ZERO (yajl_complete_parse (hndl));
#else
hndl = yajl_alloc (&callbacks, NULL, NULL, &ctx);
- CHECK_ZERO (traverse_json ((unsigned char *) json, (uint32_t) strlen (json), hndl));
+ CHECK_ZERO (traverse_json ((const unsigned char *) json, (uint32_t) strlen (json), hndl));
CHECK_ZERO (yajl_parse_complete (hndl));
#endif
DEF_TEST(parse_keys)
{
struct {
- char *str;
- char *want;
+ const char *str;
+ const 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"},
an integer if the data-source is a counter, or a double if the data-source is
of type "gauge". You can submit an undefined gauge-value by using B<U>. When
submitting B<U> to a counter the behavior is undefined. The time is given as
-epoch (i.E<nbsp>e. standard UNIX time).
+epoch (i.E<nbsp>e. standard UNIX time) or B<N> to use the current time.
You can mix options and values, but the order is important: Options only
effect following values, so specifying an option as last field is allowed, but
new_values = (gauge_t *)calloc (match_ds_num_g, sizeof (*new_values));
if (new_values == NULL)
{
- fprintf (stderr, "malloc failed: %s\n", strerror (errno));
+ fprintf (stderr, "calloc failed: %s\n", strerror (errno));
return (RET_UNKNOWN);
}
new_names = (char **)calloc (match_ds_num_g, sizeof (*new_names));
if (new_names == NULL)
{
- fprintf (stderr, "malloc failed: %s\n", strerror (errno));
+ fprintf (stderr, "calloc failed: %s\n", strerror (errno));
free (new_values);
return (RET_UNKNOWN);
}
return (((ret - range->invert) == 0) ? 0 : 1);
} /* int match_range */
+__attribute__((noreturn))
static void usage (const char *name)
{
fprintf (stderr, "Usage: %s <-s socket> <-n value_spec> <-H hostname> [options]\n"
case 'd':
{
char **tmp;
- tmp = (char **) realloc (match_ds_g,
+ tmp = realloc (match_ds_g,
(match_ds_num_g + 1)
* sizeof (char *));
if (tmp == NULL)
lcc_value_list_t *vl;
int host_num;
- vl = malloc (sizeof (*vl));
+ vl = calloc (1, sizeof (*vl));
if (vl == NULL)
{
- fprintf (stderr, "malloc failed.\n");
+ fprintf (stderr, "calloc failed.\n");
return (NULL);
}
- memset (vl, 0, sizeof (*vl));
vl->values = calloc (/* nmemb = */ 1, sizeof (*vl->values));
if (vl->values == NULL)
else
{
lcc_server_t *srv;
-
+
srv = lcc_server_create (net, conf_destination, conf_service);
if (srv == NULL)
{
# Lines beginning with a single `#' belong to plugins which have been built #
# but are disabled by default. #
# #
-# Lines begnning with `##' belong to plugins which have not been built due #
+# Lines beginning with `##' belong to plugins which have not been built due #
# to missing dependencies or because they have been deactivated explicitly. #
##############################################################################
#@BUILD_PLUGIN_WRITE_RIEMANN_TRUE@LoadPlugin write_riemann
#@BUILD_PLUGIN_WRITE_SENSU_TRUE@LoadPlugin write_sensu
#@BUILD_PLUGIN_WRITE_TSDB_TRUE@LoadPlugin write_tsdb
+#@BUILD_PLUGIN_XENCPU_TRUE@LoadPlugin xencpu
#@BUILD_PLUGIN_XMMS_TRUE@LoadPlugin xmms
#@BUILD_PLUGIN_ZFS_ARC_TRUE@LoadPlugin zfs_arc
#@BUILD_PLUGIN_ZONE_TRUE@LoadPlugin zone
## None of the following option should be set manually
## This plugin automatically detect most optimal options
## Only set values here if:
-## - The module ask you to
+## - The module asks you to
## - You want to disable the collection of some data
-## - Your (intel) CPU is not supported (yet) by the module
-## - The module generate a lot of errors 'MSR offset 0x... read failed'
+## - Your (Intel) CPU is not supported (yet) by the module
+## - The module generates a lot of errors 'MSR offset 0x... read failed'
## In the last two cases, please open a bug request
#
# TCCActivationTemp "100"
# ClientKey "/etc/ssl/client.pem"
# ClientCert "/etc/ssl/client.crt"
# ClientKeyPass "secret"
+# Header "X-Custom-Header: custom_value"
# SSLVersion "TLSv1"
# Format "Command"
# StoreRates false
The syntax of this config file is similar to the config file of the famous
I<Apache> webserver. Each line contains either an option (a key and a list of
one or more values) or a section-start or -end. Empty lines and everything
-after a non-quoted hash-symbol (C<#>) is ignored. I<Keys> are unquoted
+after a non-quoted hash-symbol (C<#>) are ignored. I<Keys> are unquoted
strings, consisting only of alphanumeric characters and the underscore (C<_>)
character. Keys are handled case insensitive by I<collectd> itself and all
plugins included with it. I<Values> can either be an I<unquoted string>, a
=item B<BaseDir> I<Directory>
-Sets the base directory. This is the directory beneath all RRD-files are
+Sets the base directory. This is the directory beneath which all RRD-files are
created. Possibly more subdirectories are created. This is also the working
directory for the daemon.
Only the first B<LoadPlugin> statement or block for a given plugin name has any
effect. This is useful when you want to split up the configuration into smaller
files and want each file to be "self contained", i.e. it contains a B<Plugin>
-block I<and> then appropriate B<LoadPlugin> statement. The downside is that if
+block I<and> the appropriate B<LoadPlugin> statement. The downside is that if
you have multiple conflicting B<LoadPlugin> blocks, e.g. when they specify
different intervals, only one of them (the first one encountered) will take
effect and all others will be silently ignored.
=item B<Interval> I<Seconds>
Sets a plugin-specific interval for collecting metrics. This overrides the
-global B<Interval> setting. If a plugin provides own support for specifying an
-interval, that setting will take precedence.
+global B<Interval> setting. If a plugin provides its own support for specifying
+an interval, that setting will take precedence.
=item B<FlushInterval> I<Seconds>
-Specifies the the interval, in seconds, to call the flush callback if it's
-defined in this plugin. By default, this is disabled
+Specifies the interval, in seconds, to call the flush callback if it's
+defined in this plugin. By default, this is disabled.
=item B<FlushTimeout> I<Seconds>
in combination with recursively including a directory to easily be able to
arbitrarily mix configuration files and other documents (e.g. README files).
The given example is similar to the first example above but includes all files
-matching C<*.conf> in any subdirectory of C</etc/collectd.d>:
-
- Include "/etc/collectd.d" "*.conf"
+matching C<*.conf> in any subdirectory of C</etc/collectd.d>.
=back
-If more than one files are included by a single B<Include> option, the files
+If more than one file is included by a single B<Include> option, the files
will be included in lexicographical order (as defined by the C<strcmp>
function). Thus, you can e.E<nbsp>g. use numbered prefixes to specify the
order in which the files are loaded.
=item B<MaxReadInterval> I<Seconds>
-Read plugin doubles interval between queries after each failed attempt
+A read plugin doubles the interval between queries after each failed attempt
to get data.
This options limits the maximum value of the interval. The default value is
=item B<IgnoreSelected> I<true>|I<false>
-If no configuration if given, the B<traffic>-plugin will collect data from
+If no configuration if given, the B<interface>-plugin will collect data from
all interfaces. This may not be practical, especially for loopback- and
similar interfaces. Thus, you can use the B<Interface>-option to pick the
interfaces you're interested in. Sometimes, however, it's easier/preferred
=item B<UniqueName> I<true>|I<false>
-Interface name is not unique on Solaris (KSTAT), interface name is unique
-only within a module/instance. Following tuple is considered unique:
+Interface name is not unique on Solaris (KSTAT), interface name is unique
+only within a module/instance. Following tuple is considered unique:
(ks_module, ks_instance, ks_name)
If this option is set to true, interface name contains above three fields
separated by an underscore. For more info on KSTAT, visit
=item B<BindDN> I<BindDN>
-Name in the form of an LDAP distinguished name intended to be used for
+Name in the form of an LDAP distinguished name intended to be used for
authentication. Defaults to empty string to establish an anonymous authorization.
=item B<Password> I<Password>
-Password for simple bind authentication. If this option is not set,
+Password for simple bind authentication. If this option is not set,
unauthenticated bind operation is used.
=item B<StartTLS> B<true|false>
I<true> the effect of B<Sensor> is inverted: All selected sensors are ignored
and all other sensors are collected.
+=item B<UseLabels> I<true>|I<false>
+
+Configures how sensor readings are reported. When set to I<true>, sensor
+readings are reported using their descriptive label (e.g. "VCore"). When set to
+I<false> (the default) the sensor name is used ("in0").
+
=back
=head2 Plugin C<sigrok>
=item B<DigitalTemperatureSensor> I<true>|I<false>
Boolean enabling the collection of the temperature of each core.
-This option should only be used if the automated detectionfails or
+This option should only be used if the automated detectionfails or
if you want to disable this feature.
=item B<DigitalTemperatureSensor> I<true>|I<false>
Boolean enabling the collection of the temperature of each package.
-This option should only be used if the automated detectionfails or
+This option should only be used if the automated detectionfails or
if you want to disable this feature.
=item B<TCCActivationTemp> I<Temperature>
Password required to load the private key in B<ClientKey>.
+=item B<Header> I<Header>
+
+A HTTP header to add to the request. Multiple headers are added if this option is specified more than once. Example:
+
+ Header "X-Custom-Header: custom_value"
+
=item B<SSLVersion> B<SSLv2>|B<SSLv3>|B<TLSv1>|B<TLSv1_0>|B<TLSv1_1>|B<TLSv1_2>
Define which SSL protocol version must be used. By default C<libcurl> will
Service name or port number to connect to. Defaults to C<5555>.
-=item B<Protocol> B<UDP>|B<TCP>
+=item B<Protocol> B<UDP>|B<TCP>|B<TLS>
Specify the protocol to use when communicating with I<Riemann>. Defaults to
B<TCP>.
+=item B<TLSCertFile> I<Path>
+
+When using the B<TLS> protocol, path to a PEM certificate to present
+to remote host.
+
+=item B<TLSCAFile> I<Path>
+
+When using the B<TLS> protocol, path to a PEM CA certificate to
+use to validate the remote hosts's identity.
+
+=item B<TLSKeyFile> I<Path>
+
+When using the B<TLS> protocol, path to a PEM private key associated
+with the certificate defined by B<TLSCertFile>.
+
=item B<Batch> B<true>|B<false>
If set to B<true> and B<Protocol> is set to B<TCP>,
Maximum payload size for a riemann packet. Defaults to 8192
+=item B<BatchFlushTimeout> I<seconds>
+
+Maximum amount of seconds to wait in between to batch flushes.
+No timeout by default.
+
=item B<StoreRates> B<true>|B<false>
If set to B<true> (the default), convert counter values to rates. If set to
=back
+=head2 Plugin C<xencpu>
+
+This plugin collects metrics of hardware CPU load for machine running Xen
+hypervisor. Load is calculated from 'idle time' value, provided by Xen.
+Result is reported using the C<percent> type, for each CPU (core).
+
+This plugin doesn't have any options (yet).
+
=head2 Plugin C<zookeeper>
The I<zookeeper plugin> will collect statistics from a I<Zookeeper> server
=item B<TypeInstance> I<String>
+=item B<MetaDataSet> I<String> I<String>
+
Set the appropriate field to the given string. The strings for plugin instance
and type instance may be empty, the strings for host and plugin may not be
empty. It's currently not possible to set the type of a value this way.
extern char *optarg;
extern int optind;
+__attribute__((noreturn))
static void exit_usage (const char *name, int status) {
fprintf ((status == 0) ? stdout : stderr,
"Usage: %s [options] <command> [cmd options]\n\n"
values_len = 0;
value = tmp;
- while (value != 0) {
+ while (value != NULL) {
char *dot, *endptr;
tmp = strchr (value, (int)':');
static int loop = 0;
static int restart = 0;
-static char *pidfile = NULL;
-static pid_t collectd_pid = 0;
+static const char *pidfile = NULL;
+static pid_t collectd_pid = 0;
-static void exit_usage (char *name)
+__attribute__((noreturn))
+static void exit_usage (const char *name)
{
printf ("Usage: %s <options> [-- <collectd options>]\n"
dev_null = open ("/dev/null", O_RDWR);
if (dev_null == -1) {
- syslog (LOG_ERR, "Error: couldn't failed to open /dev/null: %s", strerror (errno));
+ syslog (LOG_ERR, "Error: couldn't open /dev/null: %s", strerror (errno));
return -1;
}
if (dup2 (dev_null, STDIN_FILENO) == -1) {
+ close (dev_null);
syslog (LOG_ERR, "Error: couldn't connect STDIN to /dev/null: %s", strerror (errno));
return -1;
}
if (dup2 (dev_null, STDOUT_FILENO) == -1) {
+ close (dev_null);
syslog (LOG_ERR, "Error: couldn't connect STDOUT to /dev/null: %s", strerror (errno));
return -1;
}
if (dup2 (dev_null, STDERR_FILENO) == -1) {
+ close (dev_null);
syslog (LOG_ERR, "Error: couldn't connect STDERR to /dev/null: %s", strerror (errno));
return -1;
}
if (pnumcpu != numcpu || perfcpu == NULL)
{
- if (perfcpu != NULL)
- free(perfcpu);
+ free(perfcpu);
perfcpu = malloc(numcpu * sizeof(perfstat_cpu_t));
}
pnumcpu = numcpu;
* DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Sven Trenkel <collectd at semidefinite.de>
+ * Sven Trenkel <collectd at semidefinite.de>
**/
/* Some python versions don't include this by default. */
} while (0)
static inline void CPY_STRCAT(PyObject **a, PyObject *b) {
PyObject *ret;
-
+
if (!a || !*a)
return;
-
+
ret = PyUnicode_Concat(*a, b);
Py_DECREF(*a);
*a = ret;
return PyBytes_FromString(buf);
#else
return PyString_FromString(buf);
-#endif
+#endif
}
void cpy_log_exception(const char *context);
size_t len;
len = size * nmemb;
- if (len <= 0)
+ if (len == 0)
return (len);
wp = user_data;
size_t temp_size;
temp_size = wp->buffer_fill + len + 1;
- temp = (char *) realloc (wp->buffer, temp_size);
+ temp = realloc (wp->buffer, temp_size);
if (temp == NULL)
{
ERROR ("curl plugin: realloc failed.");
static int cc_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
oconfig_item_t *ci)
{
+ struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
WARNING ("curl plugin: `%s' needs exactly one string argument.", name);
return (-1);
}
- *dest = curl_slist_append(*dest, ci->values[0].value.string);
- if (*dest == NULL)
+ temp = curl_slist_append(*dest, ci->values[0].value.string);
+ if (temp == NULL)
return (-1);
+ *dest = temp;
+
return (0);
} /* }}} int cc_config_append_string */
WARNING ("curl plugin: Ignoring arguments for the `Match' block.");
}
- match = (web_match_t *) malloc (sizeof (*match));
+ match = calloc (1, sizeof (*match));
if (match == NULL)
{
- ERROR ("curl plugin: malloc failed.");
+ ERROR ("curl plugin: calloc failed.");
return (-1);
}
- memset (match, 0, sizeof (*match));
status = 0;
for (i = 0; i < ci->children_num; i++)
if (wp->pass != NULL)
credentials_size += strlen (wp->pass);
- wp->credentials = (char *) malloc (credentials_size);
+ wp->credentials = malloc (credentials_size);
if (wp->credentials == NULL)
{
ERROR ("curl plugin: malloc failed.");
return (-1);
}
- page = (web_page_t *) malloc (sizeof (*page));
+ page = calloc (1, sizeof (*page));
if (page == NULL)
{
- ERROR ("curl plugin: malloc failed.");
+ ERROR ("curl plugin: calloc failed.");
return (-1);
}
- memset (page, 0, sizeof (*page));
page->url = NULL;
page->user = NULL;
page->pass = NULL;
web_page_t *prev;
prev = pages_g;
- while ((prev != NULL) && (prev->next != NULL))
+ while (prev->next != NULL)
prev = prev->next;
prev->next = page;
}
len = size * nmemb;
- if (len <= 0)
+ if (len == 0)
return (len);
db = user_data;
static int cj_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
oconfig_item_t *ci)
{
+ struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
WARNING ("curl_json plugin: `%s' needs exactly one string argument.", name);
return (-1);
}
- *dest = curl_slist_append(*dest, ci->values[0].value.string);
- if (*dest == NULL)
+ temp = curl_slist_append(*dest, ci->values[0].value.string);
+ if (temp == NULL)
return (-1);
+ *dest = temp;
+
return (0);
} /* }}} int cj_config_append_string */
return (-1);
}
- key = (cj_key_t *) malloc (sizeof (*key));
+ key = calloc (1, sizeof (*key));
if (key == NULL)
{
- ERROR ("curl_json plugin: malloc failed.");
+ ERROR ("curl_json plugin: calloc failed.");
return (-1);
}
- memset (key, 0, sizeof (*key));
key->magic = CJ_KEY_MAGIC;
if (strcasecmp ("Key", ci->key) == 0)
if (db->pass != NULL)
credentials_size += strlen (db->pass);
- db->credentials = (char *) malloc (credentials_size);
+ db->credentials = malloc (credentials_size);
if (db->credentials == NULL)
{
ERROR ("curl_json plugin: malloc failed.");
return (-1);
}
- db = (cj_t *) malloc (sizeof (*db));
+ db = calloc (1, sizeof (*db));
if (db == NULL)
{
- ERROR ("curl_json plugin: malloc failed.");
+ ERROR ("curl_json plugin: calloc failed.");
return (-1);
}
- memset (db, 0, sizeof (*db));
db->timeout = -1;
static int cj_sock_perform (cj_t *db) /* {{{ */
{
char errbuf[1024];
- struct sockaddr_un sa_unix = {};
+ struct sockaddr_un sa_unix = { 0 };
sa_unix.sun_family = AF_UNIX;
sstrncpy (sa_unix.sun_path, db->sock, sizeof (sa_unix.sun_path));
return (0);
}
- if (len <= 0)
+ if (len == 0)
return (len);
if ((db->buffer_fill + len) >= db->buffer_size)
{
char *temp;
- temp = (char *) realloc (db->buffer,
+ temp = realloc (db->buffer,
db->buffer_fill + len + 1);
if (temp == NULL)
{
}
llist_destroy (list);
- list = NULL;
} /* }}} void cx_list_free */
static void cx_free (void *arg) /* {{{ */
static int cx_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
oconfig_item_t *ci)
{
+ struct curl_slist *temp = NULL;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
WARNING ("curl_xml plugin: `%s' needs exactly one string argument.", name);
return (-1);
}
- *dest = curl_slist_append(*dest, ci->values[0].value.string);
- if (*dest == NULL)
+ temp = curl_slist_append(*dest, ci->values[0].value.string);
+ if (temp == NULL)
return (-1);
+ *dest = temp;
+
return (0);
} /* }}} int cx_config_append_string */
return (0);
} /* }}} cx_check_type */
-static xmlXPathObjectPtr cx_evaluate_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
+static xmlXPathObjectPtr cx_evaluate_xpath (xmlXPathContextPtr xpath_ctx, /* {{{ */
xmlChar *expr)
{
xmlXPathObjectPtr xpath_obj;
{
WARNING ("curl_xml plugin: "
"relative xpath expression \"%s\" is expected to return "
- "only text/attribute node which is not the case. Skipping...",
+ "only text/attribute node which is not the case. Skipping...",
xpath->values[index].path);
xmlXPathFreeObject (values_node_obj);
return (-1);
vl->values[index].absolute = (absolute_t) strtoull (node_value,
/* endptr = */ NULL, /* base = */ 0);
break;
- case DS_TYPE_GAUGE:
+ case DS_TYPE_GAUGE:
vl->values[index].gauge = (gauge_t) strtod (node_value,
/* endptr = */ NULL);
}
static int cx_handle_base_xpath (char const *plugin_instance, /* {{{ */
char const *host,
- xmlXPathContextPtr xpath_ctx, const data_set_t *ds,
+ xmlXPathContextPtr xpath_ctx, const data_set_t *ds,
char *base_xpath, cx_xpath_t *xpath)
{
int total_nodes;
value_list_t vl = VALUE_LIST_INIT;
- base_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST base_xpath);
+ base_node_obj = cx_evaluate_xpath (xpath_ctx, BAD_CAST base_xpath);
if (base_node_obj == NULL)
return -1; /* error is logged already */
}
/* If base_xpath returned multiple results, then */
- /* Instance in the xpath block is required */
+ /* Instance in the xpath block is required */
if (total_nodes > 1 && xpath->instance == NULL)
{
ERROR ("curl_xml plugin: "
sstrncpy (vl.plugin, "curl_xml", sizeof (vl.plugin));
sstrncpy (vl.host, (host != NULL) ? host : hostname_g, sizeof (vl.host));
if (plugin_instance != NULL)
- sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
for (i = 0; i < total_nodes; i++)
{
} /* for (i = 0; i < total_nodes; i++) */
/* free up the allocated memory */
- xmlXPathFreeObject (base_node_obj);
+ xmlXPathFreeObject (base_node_obj);
- return (0);
+ return (0);
} /* }}} cx_handle_base_xpath */
-static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */
+static int cx_handle_parsed_xml(xmlDocPtr doc, /* {{{ */
xmlXPathContextPtr xpath_ctx, cx_t *db)
{
llentry_t *le;
const data_set_t *ds;
cx_xpath_t *xpath;
int status=-1;
-
+
le = llist_head (db->list);
while (le != NULL)
char *url;
url = db->url;
- db->buffer_fill = 0;
+ db->buffer_fill = 0;
status = curl_easy_perform (curl);
if (status != CURLE_OK)
{
sfree (xpath->values);
xpath->values_len = 0;
- xpath->values = (cx_values_t *) malloc (sizeof (cx_values_t) * ci->values_num);
+ xpath->values = malloc (sizeof (cx_values_t) * ci->values_num);
if (xpath->values == NULL)
return (-1);
xpath->values_len = (size_t) ci->values_num;
int status;
int i;
- xpath = malloc (sizeof (*xpath));
+ xpath = calloc (1, sizeof (*xpath));
if (xpath == NULL)
{
- ERROR ("curl_xml plugin: malloc failed.");
+ ERROR ("curl_xml plugin: calloc failed.");
return (-1);
}
- memset (xpath, 0, sizeof (*xpath));
status = cf_util_get_string (ci, &xpath->path);
if (status != 0)
if (db->pass != NULL)
credentials_size += strlen (db->pass);
- db->credentials = (char *) malloc (credentials_size);
+ db->credentials = malloc (credentials_size);
if (db->credentials == NULL)
{
ERROR ("curl_xml plugin: malloc failed.");
return (-1);
}
- db = (cx_t *) malloc (sizeof (*db));
+ db = calloc (1, sizeof (*db));
if (db == NULL)
{
- ERROR ("curl_xml plugin: malloc failed.");
+ ERROR ("curl_xml plugin: calloc failed.");
return (-1);
}
- memset (db, 0, sizeof (*db));
db->timeout = -1;
while ((dirlen > 0) && (dir[dirlen - 1] == '/'))
dir[--dirlen] = '\0';
- if (dirlen <= 0) {
+ if (dirlen == 0) {
free (dir);
return (-1);
}
/* TODO
* Remove all settings but `-f' and `-C'
*/
+__attribute__((noreturn))
static void exit_usage (int status)
{
printf ("Usage: "PACKAGE_NAME" [OPTIONS]\n\n"
#endif /* COLLECT_DAEMON */
#ifdef KERNEL_LINUX
-int notify_upstart (void)
+static int notify_upstart (void)
{
char const *upstart_job = getenv("UPSTART_JOB");
return 1;
}
-int notify_systemd (void)
+static int notify_systemd (void)
{
int fd;
const char *notifysocket;
struct sigaction sig_term_action;
struct sigaction sig_usr1_action;
struct sigaction sig_pipe_action;
- char *configfile = CONFIGFILE;
+ const char *configfile = CONFIGFILE;
int test_config = 0;
int test_readall = 0;
const char *basedir;
# pragma GCC poison strcpy strcat strtok
#endif
-/*
+/*
* Special hack for the perl plugin: Because the later included perl.h defines
* a macro which is never used, but contains `sprintf', we cannot poison that
* identifies just yet. The parl plugin will do that itself once perl.h is
return (strdup (static_buffer));
/* Allocate a buffer large enough to hold the string. */
- alloc_buffer = malloc (alloc_buffer_size);
+ alloc_buffer = calloc (1, alloc_buffer_size);
if (alloc_buffer == NULL)
return (NULL);
- memset (alloc_buffer, 0, alloc_buffer_size);
/* Print again into this new buffer. */
va_start (ap, format);
/* Do not use `strdup' here, because it's not specified in POSIX. It's
* ``only'' an XSI extension. */
sz = strlen (s) + 1;
- r = (char *) malloc (sizeof (char) * sz);
+ r = malloc (sz);
if (r == NULL)
{
ERROR ("sstrdup: Out of memory.");
size_t sep_len;
size_t i;
- if ((buffer_size < 1) || (fields_num <= 0))
+ if ((buffer_size < 1) || (fields_num == 0))
return (-1);
memset (buffer, 0, buffer_size);
return ((int) strlen (buffer));
}
-int strsubstitute (char *str, char c_from, char c_to)
-{
- int ret;
-
- if (str == NULL)
- return (-1);
-
- ret = 0;
- while (*str != '\0')
- {
- if (*str == c_from)
- {
- *str = c_to;
- ret++;
- }
- str++;
- }
-
- return (ret);
-} /* int strsubstitute */
-
int escape_string (char *buffer, size_t buffer_size)
{
char *temp;
if (buffer_size < 3)
return (EINVAL);
- temp = (char *) malloc (buffer_size);
+ temp = calloc (1, buffer_size);
if (temp == NULL)
return (ENOMEM);
- memset (temp, 0, buffer_size);
temp[0] = '"';
j = 1;
#define sfree(ptr) \
do { \
- if((ptr) != NULL) { \
- free(ptr); \
- } \
+ free(ptr); \
(ptr) = NULL; \
} while (0)
*/
void replace_special (char *buffer, size_t buffer_size);
-int strsubstitute (char *str, char c_from, char c_to);
-
/*
* NAME
* strunescape
EXPECT_EQ_STR ("collectd", ptr);
sfree(ptr);
- OK(ptr == NULL);
ptr = sstrdup (NULL);
OK(ptr == NULL);
typedef struct cf_value_map_s
{
- char *key;
+ const char *key;
int (*func) (oconfig_item_t *);
} cf_value_map_t;
typedef struct cf_global_option_s
{
- char *key;
+ const char *key;
char *value;
- char *def;
+ const char *def;
} cf_global_option_t;
/*
static int dispatch_value_plugindir (oconfig_item_t *ci)
{
assert (strcasecmp (ci->key, "PluginDir") == 0);
-
+
if (ci->values_num != 1)
return (-1);
if (ci->values[0].type != OCONFIG_TYPE_STRING)
static int dispatch_block_plugin (oconfig_item_t *ci)
{
int i;
- char *name;
+ const char *name;
cf_complex_callback_t *cb;
return (0);
}
- temp = (oconfig_item_t *) realloc (dst->children,
+ temp = realloc (dst->children,
sizeof (oconfig_item_t)
* (dst->children_num + src->children_num - 1));
if (temp == NULL)
if ((src == NULL) || (src->children_num == 0))
return (0);
- temp = (oconfig_item_t *) realloc (dst->children,
+ temp = realloc (dst->children,
sizeof (oconfig_item_t)
* (dst->children_num + src->children_num));
if (temp == NULL)
return (NULL);
}
- root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t));
+ root = calloc (1, sizeof (*root));
if (root == NULL)
{
- ERROR ("configfile: malloc failed.");
+ ERROR ("configfile: calloc failed.");
closedir (dh);
return (NULL);
}
- memset (root, 0, sizeof (oconfig_item_t));
while ((de = readdir (dh)) != NULL)
{
}
++filenames_num;
- tmp = (char **) realloc (filenames,
+ tmp = realloc (filenames,
filenames_num * sizeof (*filenames));
if (tmp == NULL) {
ERROR ("configfile: realloc failed.");
return (NULL);
}
- root = (oconfig_item_t *) malloc (sizeof (oconfig_item_t));
+ root = calloc (1, sizeof (*root));
if (root == NULL)
{
- ERROR ("configfile: malloc failed.");
+ ERROR ("configfile: calloc failed.");
return (NULL);
}
- memset (root, '\0', sizeof (oconfig_item_t));
/* wordexp() might return a sorted list already. That's not
* documented though, so let's make sure we get what we want. */
} /* oconfig_item_t *cf_read_generic */
#endif /* !HAVE_WORDEXP_H */
-/*
+/*
* Public functions
*/
int global_option_set (const char *option, const char *value)
if (i >= cf_global_options_num)
return (NULL);
-
+
return ((cf_global_options[i].value != NULL)
? cf_global_options[i].value
: cf_global_options[i].def);
cf_unregister (type);
/* This pointer will be free'd in `cf_unregister' */
- if ((cf_cb = (cf_callback_t *) malloc (sizeof (cf_callback_t))) == NULL)
+ if ((cf_cb = malloc (sizeof (*cf_cb))) == NULL)
return;
cf_cb->type = type;
{
cf_complex_callback_t *new;
- new = (cf_complex_callback_t *) malloc (sizeof (cf_complex_callback_t));
+ new = malloc (sizeof (*new));
if (new == NULL)
return (-1);
return (0);
} /* int cf_register_complex */
-int cf_read (char *filename)
+int cf_read (const char *filename)
{
oconfig_item_t *conf;
int i;
/*
* DESCRIPTION
* Remove a registered plugin from the internal data structures.
- *
+ *
* PARAMETERS
* `type' Name of the plugin (must be the same as passed to
* `plugin_register'
* Returns zero upon success and non-zero otherwise. A error-message will have
* been printed in this case.
*/
-int cf_read (char *filename);
+int cf_read (const char *filename);
int global_option_set (const char *option, const char *value);
const char *global_option_get (const char *option);
return (NULL);
sz = strlen (orig) + 1;
- dest = (char *) malloc (sz);
+ dest = malloc (sz);
if (dest == NULL)
return (NULL);
return (-1);
}
- m = (fc_match_t *) malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
{
- ERROR ("fc_config_add_match: malloc failed.");
+ ERROR ("fc_config_add_match: calloc failed.");
return (-1);
}
- memset (m, 0, sizeof (*m));
sstrncpy (m->name, ptr->name, sizeof (m->name));
memcpy (&m->proc, &ptr->proc, sizeof (m->proc));
return (-1);
}
- t = (fc_target_t *) malloc (sizeof (*t));
+ t = calloc (1, sizeof (*t));
if (t == NULL)
{
- ERROR ("fc_config_add_target: malloc failed.");
+ ERROR ("fc_config_add_target: calloc failed.");
return (-1);
}
- memset (t, 0, sizeof (*t));
sstrncpy (t->name, ptr->name, sizeof (t->name));
memcpy (&t->proc, &ptr->proc, sizeof (t->proc));
{
t->user_data = NULL;
}
-
+
if (*targets_head != NULL)
{
ptr = *targets_head;
return (-1);
}
- rule = (fc_rule_t *) malloc (sizeof (*rule));
+ rule = calloc (1, sizeof (*rule));
if (rule == NULL)
{
- ERROR ("fc_config_add_rule: malloc failed.");
+ ERROR ("fc_config_add_rule: calloc failed.");
return (-1);
}
- memset (rule, 0, sizeof (*rule));
- rule->next = NULL;
if (ci->values_num == 1)
{
if (chain == NULL)
{
- chain = (fc_chain_t *) malloc (sizeof (*chain));
+ chain = calloc (1, sizeof (*chain));
if (chain == NULL)
{
- ERROR ("fc_config_add_chain: malloc failed.");
+ ERROR ("fc_config_add_chain: calloc failed.");
return (-1);
}
- memset (chain, 0, sizeof (*chain));
sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name));
- chain->rules = NULL;
- chain->targets = NULL;
- chain->next = NULL;
}
for (i = 0; i < ci->children_num; i++)
}
plugin = child->values[j].value.string;
- temp = (fc_writer_t *) realloc (plugin_list, (plugin_list_len + 2)
+ temp = realloc (plugin_list, (plugin_list_len + 2)
* (sizeof (*plugin_list)));
if (temp == NULL)
{
DEBUG ("fc_register_match (%s);", name);
- m = (fc_match_t *) malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
return (-ENOMEM);
- memset (m, 0, sizeof (*m));
sstrncpy (m->name, name, sizeof (m->name));
memcpy (&m->proc, &proc, sizeof (m->proc));
- m->next = NULL;
if (match_list_head == NULL)
{
DEBUG ("fc_register_target (%s);", name);
- t = (fc_target_t *) malloc (sizeof (*t));
+ t = calloc (1, sizeof (*t));
if (t == NULL)
return (-ENOMEM);
- memset (t, 0, sizeof (*t));
sstrncpy (t->name, name, sizeof (t->name));
memcpy (&t->proc, &proc, sizeof (t->proc));
- t->next = NULL;
if (target_list_head == NULL)
{
int fc_default_action (const data_set_t *ds, value_list_t *vl);
-/*
+/*
* Shortcut for global configuration
*/
int fc_configure (const oconfig_item_t *ci);
return (NULL);
sz = strlen (orig) + 1;
- dest = (char *) malloc (sz);
+ dest = malloc (sz);
if (dest == NULL)
return (NULL);
{
meta_entry_t *e;
- e = (meta_entry_t *) malloc (sizeof (*e));
+ e = calloc (1, sizeof (*e));
if (e == NULL)
{
- ERROR ("md_entry_alloc: malloc failed.");
+ ERROR ("md_entry_alloc: calloc failed.");
return (NULL);
}
- memset (e, 0, sizeof (*e));
e->key = md_strdup (key);
if (e->key == NULL)
return (e);
} /* }}} meta_entry_t *md_entry_alloc */
-static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
+/* XXX: The lock on md must be held while calling this function! */
+static meta_entry_t *md_entry_clone_contents (const meta_entry_t *orig) /* {{{ */
{
meta_entry_t *copy;
- if (orig == NULL)
- return (NULL);
+ /* WARNINGS :
+ * - we do not check that orig != NULL here. You should have done it before.
+ * - we do not set copy->next. DO NOT FORGET TO SET copy->next IN YOUR FUNCTION
+ */
copy = md_entry_alloc (orig->key);
if (copy == NULL)
else
copy->value = orig->value;
+ return (copy);
+} /* }}} meta_entry_t *md_entry_clone_contents */
+
+static meta_entry_t *md_entry_clone (const meta_entry_t *orig) /* {{{ */
+{
+ meta_entry_t *copy;
+
+ if (orig == NULL)
+ return (NULL);
+
+ copy = md_entry_clone_contents(orig);
+
copy->next = md_entry_clone (orig->next);
return (copy);
} /* }}} meta_entry_t *md_entry_clone */
} /* }}} int md_entry_insert */
/* XXX: The lock on md must be held while calling this function! */
+static int md_entry_insert_clone (meta_data_t *md, meta_entry_t *orig) /* {{{ */
+{
+ meta_entry_t *e;
+ meta_entry_t *this;
+ meta_entry_t *prev;
+
+ /* WARNINGS :
+ * - we do not check that md and e != NULL here. You should have done it before.
+ * - we do not use the lock. You should have set it before.
+ */
+
+ e = md_entry_clone_contents(orig);
+
+ prev = NULL;
+ this = md->head;
+ while (this != NULL)
+ {
+ if (strcasecmp (e->key, this->key) == 0)
+ break;
+
+ prev = this;
+ this = this->next;
+ }
+
+ if (this == NULL)
+ {
+ /* This key does not exist yet. */
+ if (md->head == NULL)
+ md->head = e;
+ else
+ {
+ assert (prev != NULL);
+ prev->next = e;
+ }
+
+ e->next = NULL;
+ }
+ else /* (this != NULL) */
+ {
+ if (prev == NULL)
+ md->head = e;
+ else
+ prev->next = e;
+
+ e->next = this->next;
+ }
+
+ if (this != NULL)
+ {
+ this->next = NULL;
+ md_entry_free (this);
+ }
+
+ return (0);
+} /* }}} int md_entry_insert_clone */
+
+/* XXX: The lock on md must be held while calling this function! */
static meta_entry_t *md_entry_lookup (meta_data_t *md, /* {{{ */
const char *key)
{
{
meta_data_t *md;
- md = (meta_data_t *) malloc (sizeof (*md));
+ md = calloc (1, sizeof (*md));
if (md == NULL)
{
- ERROR ("meta_data_create: malloc failed.");
+ ERROR ("meta_data_create: calloc failed.");
return (NULL);
}
- memset (md, 0, sizeof (*md));
- md->head = NULL;
pthread_mutex_init (&md->lock, /* attr = */ NULL);
return (md);
return (copy);
} /* }}} meta_data_t *meta_data_clone */
+int meta_data_clone_merge (meta_data_t **dest, meta_data_t *orig) /* {{{ */
+{
+ meta_entry_t *e;
+
+ if (orig == NULL)
+ return (0);
+
+ if (*dest == NULL) {
+ *dest = meta_data_clone(orig);
+ return(0);
+ }
+
+ pthread_mutex_lock (&orig->lock);
+ for (e=orig->head; e != NULL; e = e->next)
+ {
+ md_entry_insert_clone((*dest), e);
+ }
+ pthread_mutex_unlock (&orig->lock);
+
+ return (0);
+} /* }}} int meta_data_clone_merge */
+
void meta_data_destroy (meta_data_t *md) /* {{{ */
{
if (md == NULL)
pthread_mutex_lock (&md->lock);
for (e = md->head; e != NULL; e = e->next)
- ++count;
+ ++count;
if (count == 0)
{
*toc = calloc(count, sizeof(**toc));
for (e = md->head; e != NULL; e = e->next)
(*toc)[i++] = strdup(e->key);
-
+
pthread_mutex_unlock (&md->lock);
return count;
} /* }}} int meta_data_toc */
ERROR ("meta_data_get_string: md_strdup failed.");
return (-ENOMEM);
}
-
+
pthread_mutex_unlock (&md->lock);
*value = temp;
meta_data_t *meta_data_create (void);
meta_data_t *meta_data_clone (meta_data_t *orig);
+int meta_data_clone_merge (meta_data_t **dest, meta_data_t *orig);
void meta_data_destroy (meta_data_t *md);
int meta_data_exists (meta_data_t *md, const char *key);
{
callback_func_t *cf;
- cf = (callback_func_t *) malloc (sizeof (*cf));
+ cf = calloc (1, sizeof (*cf));
if (cf == NULL)
{
- ERROR ("plugin: create_register_callback: malloc failed.");
+ ERROR ("plugin: create_register_callback: calloc failed.");
return (-1);
}
- memset (cf, 0, sizeof (*cf));
cf->cf_callback = callback;
if (ud == NULL)
return (status);
}
-static void plugin_free_loaded ()
+static void plugin_free_loaded (void)
{
void *key;
void *value;
read_func_t *rf;
int status;
- rf = malloc (sizeof (*rf));
+ rf = calloc (1, sizeof (*rf));
if (rf == NULL)
{
- ERROR ("plugin_register_read: malloc failed.");
+ ERROR ("plugin_register_read: calloc failed.");
return (ENOMEM);
}
- memset (rf, 0, sizeof (read_func_t));
rf->rf_callback = (void *) callback;
rf->rf_udata.data = NULL;
rf->rf_udata.free_func = NULL;
read_func_t *rf;
int status;
- rf = malloc (sizeof (*rf));
+ rf = calloc (1,sizeof (*rf));
if (rf == NULL)
{
- ERROR ("plugin_register_complex_read: malloc failed.");
+ ERROR ("plugin_register_complex_read: calloc failed.");
return (ENOMEM);
}
- memset (rf, 0, sizeof (read_func_t));
rf->rf_callback = (void *) callback;
if (group != NULL)
sstrncpy (rf->rf_group, group, sizeof (rf->rf_group));
static char *plugin_flush_callback_name (const char *name)
{
- char *flush_prefix = "flush/";
+ const char *flush_prefix = "flush/";
size_t prefix_size;
char *flush_name;
size_t name_size;
prefix_size = strlen(flush_prefix);
name_size = strlen(name);
- flush_name = malloc (sizeof(char) * (name_size + prefix_size + 1));
+ flush_name = malloc (name_size + prefix_size + 1);
if (flush_name == NULL)
{
ERROR ("plugin_flush_callback_name: malloc failed.");
if (ctx.flush_interval != 0)
{
char *flush_name;
- user_data_t ud;
flush_callback_t *cb;
flush_name = plugin_flush_callback_name (name);
if (flush_name == NULL)
return (-1);
- cb = malloc(sizeof(flush_callback_t));
+ cb = malloc(sizeof (*cb));
if (cb == NULL)
{
ERROR ("plugin_register_flush: malloc failed.");
}
cb->timeout = ctx.flush_timeout;
- ud.data = cb;
- ud.free_func = plugin_flush_timeout_callback_free;
+ ud->data = cb;
+ ud->free_func = plugin_flush_timeout_callback_free;
status = plugin_register_complex_read (
/* group = */ "flush",
/* name = */ flush_name,
/* callback = */ plugin_flush_timeout_callback,
/* interval = */ ctx.flush_interval,
- /* user data = */ &ud);
+ /* user data = */ ud);
sfree (flush_name);
if (status != 0)
return (-1);
}
- ds_copy = (data_set_t *) malloc (sizeof (data_set_t));
+ ds_copy = malloc (sizeof (*ds_copy));
if (ds_copy == NULL)
return (-1);
memcpy(ds_copy, ds, sizeof (data_set_t));
- ds_copy->ds = (data_source_t *) malloc (sizeof (data_source_t)
+ ds_copy->ds = malloc (sizeof (*ds_copy->ds)
* ds->ds_num);
if (ds_copy->ds == NULL)
{
void plugin_init_all (void)
{
char const *chain_name;
- long write_threads_num;
llentry_t *le;
int status;
int free_meta_data = 0;
- if ((vl == NULL) || (vl->type[0] == 0)
- || (vl->values == NULL) || (vl->values_len < 1))
+ assert(vl);
+ assert(vl->plugin);
+
+ if (vl->type[0] == 0 || vl->values == NULL || vl->values_len < 1)
{
ERROR ("plugin_dispatch_values: Invalid value list "
"from plugin %s.", vl->plugin);
assert (template->values_len == 1);
- /* Calculate sum for Gauge to calculate percent if needed */
+ /* Calculate sum for Gauge to calculate percent if needed */
if (DS_TYPE_GAUGE == store_type) {
va_start (ap, store_type);
while (42)
return (-1);
}
- meta = (notification_meta_t *) malloc (sizeof (notification_meta_t));
+ meta = calloc (1, sizeof (*meta));
if (meta == NULL)
{
- ERROR ("plugin_notification_meta_add: malloc failed.");
+ ERROR ("plugin_notification_meta_add: calloc failed.");
return (-1);
}
- memset (meta, 0, sizeof (notification_meta_t));
sstrncpy (meta->name, name, sizeof (meta->name));
meta->type = type;
* Since some writers dynamically build their name it can be hard for
* the configuring person to know it. This function will fill this gap.
*/
-void plugin_log_available_writers ();
+void plugin_log_available_writers (void);
/*
* NAME
int plugin_thread_create (pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg);
+/*
+ * Plugins need to implement this
+ */
+
+void module_register (void);
+
#endif /* PLUGIN_H */
#include "plugin.h"
#include "configfile.h"
+#include "types_list.h"
static int parse_ds (data_source_t *dsrc, char *buf, size_t buf_len)
{
if (fields[0][0] == '#')
return;
- ds = (data_set_t *) malloc (sizeof (data_set_t));
+ ds = calloc (1, sizeof (*ds));
if (ds == NULL)
return;
- memset (ds, '\0', sizeof (data_set_t));
-
sstrncpy (ds->type, fields[0], sizeof (ds->type));
ds->ds_num = fields_num - 1;
{
assert (n->right != NULL);
b_bottom = BALANCE (n->right);
- assert ((b_bottom >= -1) || (b_bottom <= 1));
+ assert ((b_bottom >= -1) && (b_bottom <= 1));
if (b_bottom == 1)
n = rotate_right_left (t, n);
else
{
assert (n->left != NULL);
b_bottom = BALANCE (n->left);
- assert ((b_bottom >= -1) || (b_bottom <= 1));
+ assert ((b_bottom >= -1) && (b_bottom <= 1));
if (b_bottom == -1)
n = rotate_left_right (t, n);
else
if (compare == NULL)
return (NULL);
- if ((t = (c_avl_tree_t *) malloc (sizeof (c_avl_tree_t))) == NULL)
+ if ((t = malloc (sizeof (*t))) == NULL)
return (NULL);
t->root = NULL;
c_avl_node_t *nptr;
int cmp;
- if ((new = (c_avl_node_t *) malloc (sizeof (c_avl_node_t))) == NULL)
+ if ((new = malloc (sizeof (*new))) == NULL)
return (-1);
new->key = key;
if (t == NULL)
return (NULL);
- iter = (c_avl_iterator_t *) malloc (sizeof (c_avl_iterator_t));
+ iter = calloc (1, sizeof (*iter));
if (iter == NULL)
return (NULL);
- memset (iter, '\0', sizeof (c_avl_iterator_t));
iter->tree = t;
return (iter);
{
cache_entry_t *ce;
- ce = (cache_entry_t *) malloc (sizeof (cache_entry_t));
+ ce = calloc (1, sizeof (*ce));
if (ce == NULL)
{
- ERROR ("utils_cache: cache_alloc: malloc failed.");
+ ERROR ("utils_cache: cache_alloc: calloc failed.");
return (NULL);
}
- memset (ce, '\0', sizeof (cache_entry_t));
ce->values_num = values_num;
ce->values_gauge = calloc (values_num, sizeof (*ce->values_gauge));
int status;
int i;
-
+
pthread_mutex_lock (&cache_lock);
now = cdtime ();
continue;
/* If entry has not been updated, add to `keys' array */
- tmp = (char **) realloc ((void *) keys,
+ tmp = realloc ((void *) keys,
(keys_len + 1) * sizeof (char *));
if (tmp == NULL)
{
else
{
ret_num = ce->values_num;
- ret = (gauge_t *) malloc (ret_num * sizeof (gauge_t));
+ ret = malloc (ret_num * sizeof (*ret));
if (ret == NULL)
{
ERROR ("utils_cache: uc_get_rate_by_name: malloc failed.");
return (ret);
} /* gauge_t *uc_get_rate */
-size_t uc_get_size() {
+size_t uc_get_size (void) {
size_t size_arrays = 0;
pthread_mutex_lock (&cache_lock);
if (ce->history_length < num_steps)
{
gauge_t *tmp;
- size_t i;
tmp = realloc (ce->history, sizeof (*ce->history)
* num_steps * ce->values_num);
int uc_get_rate_by_name (const char *name, gauge_t **ret_values, size_t *ret_values_num);
gauge_t *uc_get_rate (const data_set_t *ds, const value_list_t *vl);
-size_t uc_get_size();
+size_t uc_get_size (void);
int uc_get_names (char ***ret_names, cdtime_t **ret_times, size_t *ret_number);
int uc_get_state (const data_set_t *ds, const value_list_t *vl);
} /* c_release */
/* vim: set sw=4 ts=4 tw=78 noexpandtab : */
-
if (compare == NULL)
return (NULL);
- h = malloc (sizeof (*h));
+ h = calloc (1, sizeof (*h));
if (h == NULL)
return (NULL);
- memset (h, 0, sizeof (*h));
pthread_mutex_init (&h->lock, /* attr = */ NULL);
h->compare = compare;
-
+
h->list = NULL;
h->list_len = 0;
h->list_size = 0;
/* Reorganize the heap from bottom up. */
reheap (h, /* parent of this node = */ (index - 1) / 2, DIR_UP);
-
+
pthread_mutex_unlock (&h->lock);
return (0);
} /* int c_heap_insert */
**/
/**
* 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),
ignorelist_item_t *entry;
int status;
- re = malloc (sizeof (*re));
+ re = calloc (1, sizeof (*re));
if (re == NULL)
{
- ERROR ("ignorelist_append_regex: malloc failed.");
+ ERROR ("ignorelist_append_regex: calloc failed.");
return (ENOMEM);
}
- memset (re, 0, sizeof (*re));
status = regcomp (re, re_str, REG_EXTENDED);
if (status != 0)
return (status);
}
- entry = malloc (sizeof (*entry));
+ entry = calloc (1, sizeof (*entry));
if (entry == NULL)
{
- ERROR ("ignorelist_append_regex: malloc failed.");
+ ERROR ("ignorelist_append_regex: calloc failed.");
regfree (re);
sfree (re);
return (ENOMEM);
}
- memset (entry, 0, sizeof (*entry));
entry->rmatch = re;
ignorelist_append (il, entry);
ignorelist_item_t *new;
/* create new entry */
- if ((new = malloc(sizeof(ignorelist_item_t))) == NULL )
+ if ((new = calloc(1, sizeof (*new))) == NULL )
{
ERROR ("cannot allocate new entry");
return (1);
}
- memset (new, '\0', sizeof(ignorelist_item_t));
new->smatch = sstrdup(entry);
/* append new entry */
{
ignorelist_t *il;
- il = malloc (sizeof (*il));
+ il = calloc (1, sizeof (*il));
if (il == NULL)
return NULL;
- memset (il, 0, sizeof (*il));
/*
* ->ignore == 0 => collect
}
sfree (il);
- il = NULL;
} /* void ignorelist_destroy (ignorelist_t *il) */
/*
{
llist_t *ret;
- ret = (llist_t *) malloc (sizeof (llist_t));
+ ret = calloc (1, sizeof (*ret));
if (ret == NULL)
return (NULL);
- memset (ret, '\0', sizeof (llist_t));
-
return (ret);
}
{
llentry_t *e;
- e = (llentry_t *) malloc (sizeof (llentry_t));
+ e = malloc (sizeof (*e));
if (e)
{
e->key = key;
}
ret_len = end - begin;
- ret = (char *) malloc (sizeof (char) * (ret_len + 1));
+ ret = malloc (ret_len + 1);
if (ret == NULL)
{
ERROR ("utils_match: match_substr: malloc failed.");
DEBUG ("utils_match: match_create_callback: regex = %s, excluderegex = %s",
regex, excluderegex);
- obj = (cu_match_t *) malloc (sizeof (cu_match_t));
+ obj = calloc (1, sizeof (*obj));
if (obj == NULL)
return (NULL);
- memset (obj, '\0', sizeof (cu_match_t));
status = regcomp (&obj->regex, regex, REG_EXTENDED | REG_NEWLINE);
if (status != 0)
cu_match_value_t *user_data;
cu_match_t *obj;
- user_data = (cu_match_value_t *) malloc (sizeof (cu_match_value_t));
+ user_data = calloc (1, sizeof (*user_data));
if (user_data == NULL)
return (NULL);
- memset (user_data, '\0', sizeof (cu_match_value_t));
user_data->ds_type = match_ds_type;
obj = match_create_callback (regex, excluderegex,
#include "collectd.h"
#include "utils_time.h"
+#include "utils_random.h"
#include <pthread.h>
+
static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
static _Bool have_seed = 0;
static unsigned short seed[3];
#include "collectd.h"
#include "common.h"
+#include "utils_subst.h"
char *subst (char *buf, size_t buflen, const char *string, size_t off1, size_t off2,
const char *replacement)
len = off1 + strlen (replacement) + strlen (string) - off2 + 1;
- buf = (char *)malloc (len);
+ buf = malloc (len);
if (NULL == buf)
return NULL;
*
* The function returns 'buf' on success, NULL else.
*/
-char *subst (char *buf, size_t buflen, const char *string, int off1, int off2,
+char *subst (char *buf, size_t buflen, const char *string, size_t off1, size_t off2,
const char *replacement);
/*
DEF_TEST(subst)
{
struct {
- char *str;
+ const char *str;
int off1;
int off2;
- char *rplmt;
- char *want;
+ const char *rplmt;
+ const char *want;
} cases[] = {
{"foo_____bar", 3, 8, " - ", "foo - bar"}, /* documentation example */
{"foo bar", 0, 2, "m", "mo bar"}, /* beginning, shorten */
DEF_TEST(subst_string)
{
struct {
- char *str; char *srch; char *rplmt; char *want;
+ const char *str;
+ const char *srch;
+ const char *rplmt;
+ const char *want;
} cases[] = {
{"Hello %{name}", "%{name}", "world", "Hello world"},
{"abcccccc", "abc", "cab", "ccccccab"},
{
cu_tail_t *obj;
- obj = (cu_tail_t *) malloc (sizeof (cu_tail_t));
+ obj = calloc (1, sizeof (*obj));
if (obj == NULL)
return (NULL);
- memset (obj, '\0', sizeof (cu_tail_t));
obj->file = strdup (file);
if (obj->file == NULL)
{
cu_tail_match_t *obj;
- obj = (cu_tail_match_t *) malloc (sizeof (cu_tail_match_t));
+ obj = calloc (1, sizeof (*obj));
if (obj == NULL)
return (NULL);
- memset (obj, '\0', sizeof (cu_tail_match_t));
obj->tail = cu_tail_create (filename);
if (obj->tail == NULL)
{
cu_tail_match_match_t *temp;
- temp = (cu_tail_match_match_t *) realloc (obj->matches,
+ temp = realloc (obj->matches,
sizeof (cu_tail_match_match_t) * (obj->matches_num + 1));
if (temp == NULL)
return (-1);
if (match == NULL)
return (-1);
- user_data = (cu_tail_match_simple_t *) malloc (sizeof (cu_tail_match_simple_t));
+ user_data = calloc (1, sizeof (*user_data));
if (user_data == NULL)
{
match_destroy (match);
return (-1);
}
- memset (user_data, '\0', sizeof (cu_tail_match_simple_t));
sstrncpy (user_data->plugin, plugin, sizeof (user_data->plugin));
if (plugin_instance != NULL)
threshold_t *threshold_search (const value_list_t *vl);
-int ut_search_threshold (const value_list_t *vl,
+int ut_search_threshold (const value_list_t *vl,
threshold_t *ret_threshold);
#endif /* UTILS_THRESHOLD_H */
if (localtime_r (&t_spec.tv_sec, &t_tm) == NULL) {
char errbuf[1024];
- int status = errno;
+ status = errno;
ERROR ("format_rfc3339: localtime_r failed: %s",
sstrerror (status, errbuf, sizeof (errbuf)));
return (status);
* manner is that comparing times and calculating differences is as simple as
* it is with "time_t", i.e. a simple integer comparison / subtraction works.
*/
-/*
+/*
* cdtime_t is defined in "collectd.h" */
/* typedef uint64_t cdtime_t; */
else if (src_type == DBI_TYPE_STRING)
{
const char *value;
-
+
value = dbi_result_get_string_idx (res, index);
if (value == NULL)
sstrncpy (buffer, "", buffer_size);
* </Result>
* ...
* </Query>
- *
+ *
* <Database "plugin_instance1">
* Driver "mysql"
* Interval 120
return (-1);
}
- option = (cdbi_driver_option_t *) realloc (db->driver_options,
+ option = realloc (db->driver_options,
sizeof (*option) * (db->driver_options_num + 1));
if (option == NULL)
{
return (-1);
}
- db = (cdbi_database_t *) malloc (sizeof (*db));
+ db = calloc (1, sizeof (*db));
if (db == NULL)
{
- ERROR ("dbi plugin: malloc failed.");
+ ERROR ("dbi plugin: calloc failed.");
return (-1);
}
- memset (db, 0, sizeof (*db));
status = cf_util_get_string (ci, &db->name);
if (status != 0)
while ((status == 0) && (db->queries_num > 0))
{
size_t j;
- db->q_prep_areas = (udb_query_preparation_area_t **) calloc (
- db->queries_num, sizeof (*db->q_prep_areas));
+ db->q_prep_areas = calloc (db->queries_num, sizeof (*db->q_prep_areas));
if (db->q_prep_areas == NULL)
{
- WARNING ("dbi plugin: malloc failed");
+ WARNING ("dbi plugin: calloc failed");
status = -1;
break;
}
{
cdbi_database_t **temp;
- temp = (cdbi_database_t **) realloc (databases,
+ temp = realloc (databases,
sizeof (*databases) * (databases_num + 1));
if (temp == NULL)
{
column_names = NULL;
column_values = NULL;
- res = NULL;
statement = udb_query_get_statement (q);
assert (statement != NULL);
}
/* Allocate `column_names' and `column_values'. {{{ */
- column_names = (char **) calloc (column_num, sizeof (char *));
+ column_names = calloc (column_num, sizeof (*column_names));
if (column_names == NULL)
{
- ERROR ("dbi plugin: malloc failed.");
+ ERROR ("dbi plugin: calloc failed.");
BAIL_OUT (-1);
}
- column_names[0] = (char *) calloc (column_num,
- DATA_MAX_NAME_LEN * sizeof (char));
+ column_names[0] = calloc (column_num, DATA_MAX_NAME_LEN);
if (column_names[0] == NULL)
{
- ERROR ("dbi plugin: malloc failed.");
+ ERROR ("dbi plugin: calloc failed.");
BAIL_OUT (-1);
}
for (i = 1; i < column_num; i++)
column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
- column_values = (char **) calloc (column_num, sizeof (char *));
+ column_values = calloc (column_num, sizeof (*column_values));
if (column_values == NULL)
{
- ERROR ("dbi plugin: malloc failed.");
+ ERROR ("dbi plugin: calloc failed.");
BAIL_OUT (-1);
}
- column_values[0] = (char *) calloc (column_num,
- DATA_MAX_NAME_LEN * sizeof (char));
+ column_values[0] = calloc (column_num, DATA_MAX_NAME_LEN);
if (column_values[0] == NULL)
{
- ERROR ("dbi plugin: malloc failed.");
+ ERROR ("dbi plugin: calloc failed.");
BAIL_OUT (-1);
}
for (i = 1; i < column_num; i++)
plugin_dispatch_values (&vl);
} /* void disk_submit */
-#if KERNEL_LINUX
-static void submit_in_progress (char const *disk_name, gauge_t in_progress)
+#if KERNEL_FREEBSD || KERNEL_LINUX
+static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time)
{
- value_t v;
+ value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
- if (ignorelist_match (ignorelist, disk_name) != 0)
+ if (ignorelist_match (ignorelist, plugin_instance) != 0)
return;
- v.gauge = in_progress;
+ values[0].derive = io_time;
+ values[1].derive = weighted_time;
- vl.values = &v;
- vl.values_len = 1;
+ vl.values = values;
+ vl.values_len = 2;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "disk", sizeof (vl.plugin));
- sstrncpy (vl.plugin_instance, disk_name, sizeof (vl.plugin_instance));
- sstrncpy (vl.type, "pending_operations", sizeof (vl.type));
+ sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, "disk_io_time", sizeof (vl.type));
plugin_dispatch_values (&vl);
-}
+} /* void submit_io_time */
+#endif /* KERNEL_FREEBSD || KERNEL_LINUX */
-static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time)
+#if KERNEL_LINUX
+static void submit_in_progress (char const *disk_name, gauge_t in_progress)
{
- value_t values[2];
+ value_t v;
value_list_t vl = VALUE_LIST_INIT;
- if (ignorelist_match (ignorelist, plugin_instance) != 0)
+ if (ignorelist_match (ignorelist, disk_name) != 0)
return;
- values[0].derive = io_time;
- values[1].derive = weighted_time;
+ v.gauge = in_progress;
- vl.values = values;
- vl.values_len = 2;
+ vl.values = &v;
+ vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin, "disk", sizeof (vl.plugin));
- sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- sstrncpy (vl.type, "disk_io_time", sizeof (vl.type));
+ sstrncpy (vl.plugin_instance, disk_name, sizeof (vl.plugin_instance));
+ sstrncpy (vl.type, "pending_operations", sizeof (vl.type));
plugin_dispatch_values (&vl);
}
DEBUG ("CFStringCreateWithCString (%s) failed.", key);
return (-1LL);
}
-
+
/* get => we don't need to release (== free) the object */
val_obj = (CFNumberRef) CFDictionaryGetValue (dict, key_obj);
struct gident *geom_id;
const char *disk_name;
- long double read_time, write_time;
+ long double read_time, write_time, busy_time, total_duration;
for (retry = 0, dirty = 1; retry < 5 && dirty == 1; retry++) {
if (snap != NULL)
disk_submit (disk_name, "disk_time",
(derive_t)(read_time*1000), (derive_t)(write_time*1000));
}
+ if (devstat_compute_statistics(snap_iter, NULL, 1.0,
+ DSM_TOTAL_BUSY_TIME, &busy_time,
+ DSM_TOTAL_DURATION, &total_duration,
+ DSM_NONE) != 0) {
+ WARNING("%s", devstat_errbuf);
+ }
+ else
+ {
+ submit_io_time(disk_name, busy_time, total_duration);
+ }
}
geom_stats_snapshot_free(snap);
#elif KERNEL_LINUX
FILE *fh;
char buffer[1024];
-
+
char *fields[32];
int numfields;
int fieldshift = 0;
#endif
int counter;
char name[DATA_MAX_NAME_LEN];
-
+
if ((ds = sg_get_disk_io_stats(&disks)) == NULL)
return (0);
-
+
for (counter=0; counter < disks; counter++) {
strncpy(name, ds->disk_name, sizeof(name));
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
int rnumdisk;
int i;
- if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0)
+ if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0)
{
char errbuf[1024];
WARNING ("disk plugin: perfstat_disk: %s",
}
if (numdisk != pnumdisk || stat_disk==NULL) {
- if (stat_disk!=NULL)
+ if (stat_disk!=NULL)
free(stat_disk);
stat_disk = (perfstat_disk_t *)calloc(numdisk, sizeof(perfstat_disk_t));
- }
+ }
pnumdisk = numdisk;
firstpath.name[0]='\0';
- if ((rnumdisk = perfstat_disk(&firstpath, stat_disk, sizeof(perfstat_disk_t), numdisk)) < 0)
+ if ((rnumdisk = perfstat_disk(&firstpath, stat_disk, sizeof(perfstat_disk_t), numdisk)) < 0)
{
char errbuf[1024];
WARNING ("disk plugin: perfstat_disk : %s",
return (-1);
}
- for (i = 0; i < rnumdisk; i++)
+ for (i = 0; i < rnumdisk; i++)
{
read_sectors = stat_disk[i].rblks*stat_disk[i].bsize;
write_sectors = stat_disk[i].wblks*stat_disk[i].bsize;
{
counter_list_t *entry;
- entry = (counter_list_t *) malloc (sizeof (counter_list_t));
+ entry = calloc (1, sizeof (*entry));
if (entry == NULL)
return (NULL);
- memset (entry, 0, sizeof (counter_list_t));
entry->key = key;
entry->value = value;
See: http://www.drbd.org/users-guide/ch-admin.html#s-performance-indicators
version: 8.3.11 (api:88/proto:86-96)
- srcversion: 71955441799F513ACA6DA60
+ srcversion: 71955441799F513ACA6DA60
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate B r-----
ns:64363752 nr:0 dw:357799284 dr:846902273 al:34987022 bm:18062 lo:0 \
pe:0 ua:0 ap:0 ep:1 wo:f oos:0
static void type_list_incr (type_list_t *list, char *name, int incr)
{
if (NULL == list->head) {
- list->head = (type_t *)smalloc (sizeof (type_t));
+ list->head = smalloc (sizeof (*list->head));
list->head->name = sstrdup (name);
list->head->value = incr;
}
if (NULL == ptr) {
- list->tail->next = (type_t *)smalloc (sizeof (type_t));
+ list->tail->next = smalloc (sizeof (*list->tail->next));
list->tail = list->tail->next;
list->tail->name = sstrdup (name);
{
struct sockaddr_un addr;
- char *path = (NULL == sock_file) ? SOCK_PATH : sock_file;
- char *group = (NULL == sock_group) ? COLLECTD_GRP_NAME : sock_group;
+ const char *path = (NULL == sock_file) ? SOCK_PATH : sock_file;
+ const char *group = (NULL == sock_group) ? COLLECTD_GRP_NAME : sock_group;
/* create UNIX socket */
errno = 0;
available_collectors = max_conns;
collectors =
- (collector_t **)smalloc (max_conns * sizeof (collector_t *));
+ smalloc (max_conns * sizeof (*collectors));
for (i = 0; i < max_conns; ++i) {
- collectors[i] = (collector_t *)smalloc (sizeof (collector_t));
+ collectors[i] = smalloc (sizeof (*collectors[i]));
collectors[i]->socket = NULL;
if (0 != (err = plugin_thread_create (&collectors[i]->thread,
break;
}
- connection = malloc (sizeof (*connection));
+ connection = calloc (1, sizeof (*connection));
if (connection == NULL)
{
close (remote);
continue;
}
- memset (connection, 0, sizeof (*connection));
connection->socket = fdopen (remote, "r");
connection->next = NULL;
for (ptr1 = l1->head, ptr2 = l2->head; NULL != ptr1;
ptr1 = ptr1->next, last = ptr2, ptr2 = ptr2->next) {
if (NULL == ptr2) {
- ptr2 = (type_t *)smalloc (sizeof (type_t));
+ ptr2 = smalloc (sizeof (*ptr2));
ptr2->name = NULL;
ptr2->next = NULL;
return (ENOMEM);
}
- map = malloc (sizeof (*map));
+ map = calloc (1, sizeof (*map));
if (map == NULL)
{
sfree (key);
- ERROR ("ethstat plugin: malloc(3) failed.");
+ ERROR ("ethstat plugin: calloc failed.");
return (ENOMEM);
}
- memset (map, 0, sizeof (*map));
sstrncpy (map->type, ci->values[1].value.string, sizeof (map->type));
if (ci->values_num == 3)
close (fd);
sfree (strings);
sfree (stats);
- ERROR("ethstat plugin: malloc(3) failed.");
+ ERROR("ethstat plugin: malloc failed.");
return (-1);
}
return (-1);
}
- pl = (program_list_t *) malloc (sizeof (program_list_t));
+ pl = calloc (1, sizeof (*pl));
if (pl == NULL)
{
- ERROR ("exec plugin: malloc failed.");
+ ERROR ("exec plugin: calloc failed.");
return (-1);
}
- memset (pl, '\0', sizeof (program_list_t));
if (strcasecmp ("NotificationExec", ci->key) == 0)
pl->flags |= PL_NOTIF_ACTION;
return (-1);
}
- pl->argv = (char **) malloc (ci->values_num * sizeof (char *));
+ pl->argv = calloc (ci->values_num, sizeof (*pl->argv));
if (pl->argv == NULL)
{
- ERROR ("exec plugin: malloc failed.");
+ ERROR ("exec plugin: calloc failed.");
sfree (pl->exec);
sfree (pl->user);
sfree (pl);
return (-1);
}
- memset (pl->argv, '\0', ci->values_num * sizeof (char *));
{
char *tmp = strrchr (ci->values[1].value.string, '/');
pl->argv[0] = strdup (buffer);
if (pl->argv[0] == NULL)
{
- ERROR ("exec plugin: malloc failed.");
+ ERROR ("exec plugin: strdup failed.");
sfree (pl->argv);
sfree (pl->exec);
sfree (pl->user);
if (pl->pid != 0)
continue;
- pln = (program_list_and_notification_t *) malloc (sizeof
- (program_list_and_notification_t));
+ pln = malloc (sizeof (*pln));
if (pln == NULL)
{
ERROR ("exec plugin: malloc failed.");
#include "collectd.h"
#include "common.h"
-#include "plugin.h"
+#include "plugin.h"
#include <sys/types.h>
#include <sys/stat.h>
}
/* Initialize `dir' */
- dir = (fc_directory_conf_t *) malloc (sizeof (*dir));
+ dir = calloc (1, sizeof (*dir));
if (dir == NULL)
{
- ERROR ("filecount plugin: malloc failed.");
+ ERROR ("filecount plugin: calloc failed.");
return (-1);
}
- memset (dir, 0, sizeof (*dir));
dir->path = strdup (ci->values[0].value.string);
if (dir->path == NULL)
{
fc_directory_conf_t **temp;
- temp = (fc_directory_conf_t **) realloc (directories,
+ temp = realloc (directories,
sizeof (*directories) * (directories_num + 1));
if (temp == NULL)
{
if (dir->mtime != 0)
dir->now = time (NULL);
-
+
status = walk_directory (dir->path, fc_read_dir_callback, dir,
/* include hidden */ (dir->options & FC_HIDDEN) ? 1 : 0);
if (status != 0)
}
loop = 1;
- setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_MULTICAST_LOOP,
+ status = setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_MULTICAST_LOOP,
(void *) &loop, sizeof (loop));
+ if (status != 0)
+ {
+ char errbuf[1024];
+ WARNING ("gmond plugin: setsockopt(2) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
memset (&mreq, 0, sizeof (mreq));
mreq.imr_multiaddr.s_addr = addr->sin_addr.s_addr;
mreq.imr_interface.s_addr = htonl (INADDR_ANY);
- setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
+
+ status = setsockopt (sockets[sockets_num].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(void *) &mreq, sizeof (mreq));
+ if (status != 0)
+ {
+ char errbuf[1024];
+ WARNING ("gmond plugin: setsockopt(2) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
} /* if (ai_ptr->ai_family == AF_INET) */
else if (ai_ptr->ai_family == AF_INET6)
{
}
loop = 1;
- setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
+ status = setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP,
(void *) &loop, sizeof (loop));
+ if (status != 0)
+ {
+ char errbuf[1024];
+ WARNING ("gmond plugin: setsockopt(2) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
memset (&mreq, 0, sizeof (mreq));
memcpy (&mreq.ipv6mr_multiaddr,
&addr->sin6_addr, sizeof (addr->sin6_addr));
mreq.ipv6mr_interface = 0; /* any */
- setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
+ status = setsockopt (sockets[sockets_num].fd, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP,
(void *) &mreq, sizeof (mreq));
+ if (status != 0)
+ {
+ char errbuf[1024];
+ WARNING ("gmond plugin: setsockopt(2) failed: %s",
+ sstrerror (errno, errbuf, sizeof (errbuf)));
+ }
} /* if (ai_ptr->ai_family == AF_INET6) */
sockets_num++;
return (se);
/* insert new entry */
- se = (staging_entry_t *) malloc (sizeof (*se));
+ se = calloc (1, sizeof (*se));
if (se == NULL)
return (NULL);
- memset (se, 0, sizeof (*se));
sstrncpy (se->key, key, sizeof (se->key));
se->flags = 0;
return (0);
} /* }}} int mc_receive_thread_stop */
-/*
+/*
* Config:
*
* <Plugin gmond>
struct ifaddrs *if_list;
struct ifaddrs *if_ptr;
-/* Darin/Mac OS X and possible other *BSDs */
+/* Darwin/Mac OS X and possible other *BSDs */
#if HAVE_STRUCT_IF_DATA
# define IFA_DATA if_data
# define IFA_RX_BYTES ifi_ibytes
incoming = atoll (fields[2]);
outgoing = atoll (fields[10]);
if_submit (device, "if_errors", incoming, outgoing);
+
+ incoming = atoll (fields[3]);
+ outgoing = atoll (fields[11]);
+ if_submit (device, "if_dropped", incoming, outgoing);
}
fclose (fh);
if (pnif != nif || ifstat == NULL)
{
- if (ifstat != NULL)
- free(ifstat);
- ifstat = malloc(nif * sizeof(perfstat_netinterface_t));
+ free(ifstat);
+ ifstat = malloc(nif * sizeof (*ifstat));
}
pnif = nif;
*nmemb = size / stsize;
- buff = (caddr_t)malloc (size);
+ buff = malloc (size);
if (buff == NULL) {
ERROR ("ipc plugin: ipc_get_info malloc failed.");
return (NULL);
msg_alloc_queues++;
msg_used_space += ipcinfo_msg[i].msg_cbytes;
msg_qnum += ipcinfo_msg[i].msg_qnum;
-
+ }
free(ipcinfo_msg);
ipc_submit_g("msg", "count", "queues", msg_alloc_queues);
{
/* `sensor_id_ptr' now points to "(123)". */
ssnprintf (sensor_name, sizeof (sensor_name),
- "%s %s", sensor_name_ptr, sensor_id_ptr);
+ "%s %s", sensor_name_ptr, sensor_id_ptr);
}
/* else: don't touch sensor_name. */
}
table = NULL;
chain = NULL;
- list = (ip_chain_t **) realloc (chain_list, (chain_num + 1) * sizeof (ip_chain_t *));
+ list = realloc (chain_list, (chain_num + 1) * sizeof (ip_chain_t *));
if (list == NULL)
{
char errbuf[1024];
}
chain_list = list;
- final = (ip_chain_t *) malloc( sizeof(temp) );
+ final = malloc(sizeof (*final));
if (final == NULL)
{
char errbuf[1024];
return 0;
} /* get_ti */
-static void cipvs_submit_connections (char *pi, char *ti, derive_t value)
+static void cipvs_submit_connections (const char *pi, const char *ti,
+ derive_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
return;
} /* cipvs_submit_connections */
-static void cipvs_submit_if (char *pi, char *t, char *ti,
+static void cipvs_submit_if (const char *pi, const char *t, const char *ti,
derive_t rx, derive_t tx)
{
value_t values[2];
return;
} /* cipvs_submit_if */
-static void cipvs_submit_dest (char *pi, struct ip_vs_dest_entry *de) {
+static void cipvs_submit_dest (const char *pi, struct ip_vs_dest_entry *de)
+{
struct ip_vs_stats_user stats = de->stats;
char ti[DATA_MAX_NAME_LEN];
return (NULL);
}
- cbi = (cjni_callback_info_t *) malloc (sizeof (*cbi));
+ cbi = calloc (1, sizeof (*cbi));
if (cbi == NULL)
{
- ERROR ("java plugin: cjni_callback_info_create: malloc failed.");
+ ERROR ("java plugin: cjni_callback_info_create: calloc failed.");
(*jvm_env)->ReleaseStringUTFChars (jvm_env, o_name, c_name);
return (NULL);
}
- memset (cbi, 0, sizeof (*cbi));
cbi->type = type;
cbi->name = strdup (c_name);
pthread_mutex_lock (&java_callbacks_lock);
- tmp = (cjni_callback_info_t *) realloc (java_callbacks,
+ tmp = realloc (java_callbacks,
(java_callbacks_num + 1) * sizeof (*java_callbacks));
if (tmp == NULL)
{
if (cjni_env == NULL)
{
/* This pointer is free'd in `cjni_jvm_env_destroy'. */
- cjni_env = (cjni_jvm_env_t *) malloc (sizeof (*cjni_env));
+ cjni_env = calloc (1, sizeof (*cjni_env));
if (cjni_env == NULL)
{
- ERROR ("java plugin: cjni_thread_attach: malloc failed.");
+ ERROR ("java plugin: cjni_thread_attach: calloc failed.");
return (NULL);
}
- memset (cjni_env, 0, sizeof (*cjni_env));
cjni_env->reference_counter = 0;
cjni_env->jvm_env = NULL;
return (-1);
}
- tmp = (char **) realloc (jvm_argv, sizeof (char *) * (jvm_argc + 1));
+ tmp = realloc (jvm_argv, sizeof (char *) * (jvm_argc + 1));
if (tmp == NULL)
{
ERROR ("java plugin: realloc failed.");
if (jvm_env == NULL)
return (-1);
- class = (java_plugin_class_t *) realloc (java_classes_list,
+ class = realloc (java_classes_list,
(java_classes_list_len + 1) * sizeof (*java_classes_list));
if (class == NULL)
{
/* Allocate a new callback info structure. This is going to be our user_data
* pointer. */
- cbi_ret = (cjni_callback_info_t *) malloc (sizeof (*cbi_ret));
+ cbi_ret = calloc (1, sizeof (*cbi_ret));
if (cbi_ret == NULL)
{
- ERROR ("java plugin: cjni_match_target_create: malloc failed.");
+ ERROR ("java plugin: cjni_match_target_create: calloc failed.");
BAIL_OUT (-1);
}
- memset (cbi_ret, 0, sizeof (*cbi_ret));
+
cbi_ret->object = NULL;
cbi_ret->type = type;
/* Allocate space for the char-pointers */
res.lines_num = (size_t) res.status;
res.status = 0;
- res.lines = (char **) malloc (res.lines_num * sizeof (char *));
+ res.lines = malloc (res.lines_num * sizeof (*res.lines));
if (res.lines == NULL)
{
lcc_set_errno (c, ENOMEM);
if (ret_con == NULL)
return (-1);
- c = (lcc_connection_t *) malloc (sizeof (*c));
+ c = calloc (1, sizeof (*c));
if (c == NULL)
return (-1);
- memset (c, 0, sizeof (*c));
status = lcc_open_socket (c, address);
if (status != 0)
/* Allocate space for the values */
if (ret_values != NULL)
{
- values = (gauge_t *) malloc (values_num * sizeof (*values));
+ values = malloc (values_num * sizeof (*values));
if (values == NULL)
BAIL_OUT (ENOMEM);
}
}
ident_num = res.lines_num;
- ident = (lcc_identifier_t *) malloc (ident_num * sizeof (*ident));
+ ident = malloc (ident_num * sizeof (*ident));
if (ident == NULL)
{
lcc_response_free (&res);
lcc_network_t *lcc_network_create (void);
void lcc_network_destroy (lcc_network_t *net);
-/*
+/*
* Add servers
*/
lcc_server_t *lcc_server_create (lcc_network_t *net,
{
lcc_network_t *net;
- net = malloc (sizeof (*net));
+ net = calloc (1, sizeof (*net));
if (net == NULL)
return (NULL);
- memset (net, 0, sizeof (*net));
net->servers = NULL;
if (service == NULL)
service = NET_DEFAULT_PORT;
- srv = malloc (sizeof (*srv));
+ srv = calloc (1, sizeof (*srv));
if (srv == NULL)
return (NULL);
- memset (srv, 0, sizeof (*srv));
srv->fd = -1;
srv->security_level = NONE;
return (NULL);
}
- nb = malloc (sizeof (*nb));
+ nb = calloc (1, sizeof (*nb));
if (nb == NULL)
return (NULL);
- memset (nb, 0, sizeof (*nb));
nb->size = size;
- nb->buffer = malloc (nb->size);
+ nb->buffer = calloc (1, nb->size);
if (nb->buffer == NULL)
{
free (nb);
return (NULL);
}
- memset (nb->buffer, 0, nb->size);
nb->ptr = nb->buffer;
nb->free = nb->size;
-AUTOMAKE_OPTIONS = foreign no-dependencies
-
BUILT_SOURCES = parser.h
#CLEANFILES = parser.[ch] scanner.c
AM_YFLAGS = -d
{
oconfig_item_t *ci_copy;
- ci_copy = (oconfig_item_t *) malloc (sizeof (*ci_copy));
+ ci_copy = calloc (1, sizeof (*ci_copy));
if (ci_copy == NULL)
{
- fprintf (stderr, "malloc failed.\n");
+ fprintf (stderr, "calloc failed.\n");
return (NULL);
}
- memset (ci_copy, 0, sizeof (*ci_copy));
ci_copy->values = NULL;
ci_copy->parent = NULL;
ci_copy->children = NULL;
for (i = 0; i < ci_copy->children_num; i++)
{
oconfig_item_t *child;
-
+
child = oconfig_clone (ci_orig->children + i);
if (child == NULL)
{
return (ci_copy);
} /* oconfig_item_t *oconfig_clone */
-void oconfig_free_all (oconfig_item_t *ci)
+static void oconfig_free_all (oconfig_item_t *ci)
{
int i;
{
oconfig_free_all (ci);
free (ci);
- ci = NULL;
}
/*
entire_file:
statement_list
{
- ci_root = malloc (sizeof (oconfig_item_t));
- memset (ci_root, '\0', sizeof (oconfig_item_t));
+ ci_root = calloc (1, sizeof (*ci_root));
ci_root->children = $1.statement;
ci_root->children_num = $1.statement_num;
}
| /* epsilon */
{
- ci_root = malloc (sizeof (oconfig_item_t));
- memset (ci_root, '\0', sizeof (oconfig_item_t));
+ ci_root = calloc (1, sizeof (*ci_root));
ci_root->children = NULL;
ci_root->children_num = 0;
}
%%
static int yyerror (const char *s)
{
- char *text;
+ const char *text;
if (*yytext == '\n')
text = "<newline>";
if (ml_free <= len) {
ml_len += len - ml_free + 1;
- ml_buffer = (char *)realloc (ml_buffer, ml_len);
+ ml_buffer = realloc (ml_buffer, ml_len);
if (NULL == ml_buffer)
YY_FATAL_ERROR ("out of dynamic memory in ml_append");
}
#define APPEND(bufptr, buflen, key, value) \
if ((buflen > 0) && (strlen (value) > 0)) { \
- int status = ssnprintf (bufptr, buflen, ", %s = %s", key, value); \
+ status = ssnprintf (bufptr, buflen, ", %s = %s", key, value); \
if (status > 0) { \
bufptr += status; \
buflen -= status; \
/**
- * There are several data streams provided by Madwifi plugin, some are
+ * There are several data streams provided by Madwifi plugin, some are
* connected to network interface, some are connected to each node
* associated to that interface. Nodes represents other sides in
* wireless communication, for example on network interface in AP mode,
* node_stat Node statistic counters
*
* Both statistic counters have type instances for each counter returned
- * by Madwifi. See madwifi.h for content of ieee80211_nodestats,
+ * by Madwifi. See madwifi.h for content of ieee80211_nodestats,
* ieee80211_stats and ath_stats structures. Type instances use the same
* name as fields in these structures (like ns_rx_dup). Some fields are
* not reported, because they are not counters (like ns_tx_deauth_code
* or ast_tx_rssi). Fields ns_rx_bytes and ns_tx_bytes are reported as
* node_octets data stream instead of type instance of node_stat.
* Statistics are not logged when they are zero.
- *
+ *
* There are two sets of these counters - the first 'WatchList' is a
* set of counters that are individually logged. The second 'MiscList'
* is a set of counters that are summed together and the sum is logged.
- * By default, the most important statistics are in the WatchList and
+ * By default, the most important statistics are in the WatchList and
* many error statistics are in MiscList. There are also many statistics
* that are not in any of these sets, so they are not monitored by default.
* It is possible to alter these lists using configuration options:
if (item_summed (i))
misc += val;
}
-
+
if (misc != 0)
submit_derive (dev, type_name, misc_name, mac, misc);
int status;
int num_success;
int num_fail;
-
+
if ((fh = fopen ("/proc/net/dev", "r")) == NULL)
{
WARNING ("madwifi plugin: opening /proc/net/dev failed");
/* procfs iteration is not safe because it does not check whether given
interface is madwifi interface and there are private ioctls used, which
- may do something completely different on non-madwifi devices.
+ may do something completely different on non-madwifi devices.
Therefore, it is not used unless explicitly enabled (and should be used
together with ignorelist). */
{
mec_match_t *m;
- m = (mec_match_t *) malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
{
- ERROR ("mec_create: malloc failed.");
+ ERROR ("mec_create: calloc failed.");
return (-ENOMEM);
}
- memset (m, 0, sizeof (*m));
if (ci->children_num != 0)
{
mh_match_t *m;
int i;
- m = (mh_match_t *) malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
{
- ERROR ("mh_create: malloc failed.");
+ ERROR ("mh_create: calloc failed.");
return (-ENOMEM);
}
- memset (m, 0, sizeof (*m));
for (i = 0; i < ci->children_num; i++)
{
return (-1);
}
- re = (mr_regex_t *) malloc (sizeof (*re));
+ re = calloc (1, sizeof (*re));
if (re == NULL)
{
- log_err ("mr_config_add_regex: malloc failed.");
+ log_err ("mr_config_add_regex: calloc failed.");
return (-1);
}
- memset (re, 0, sizeof (*re));
re->next = NULL;
re->re_str = strdup (ci->values[0].value.string);
char errmsg[1024];
regerror (status, &re->re, errmsg, sizeof (errmsg));
errmsg[sizeof (errmsg) - 1] = 0;
- log_err ("Compiling regex `%s' for `%s' failed: %s.",
+ log_err ("Compiling regex `%s' for `%s' failed: %s.",
re->re_str, ci->key, errmsg);
free (re->re_str);
free (re);
int status;
int i;
- m = (mr_match_t *) malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
{
- log_err ("mr_create: malloc failed.");
+ log_err ("mr_create: calloc failed.");
return (-ENOMEM);
}
- memset (m, 0, sizeof (*m));
-
+
m->invert = 0;
status = 0;
int status;
int i;
- m = (mt_match_t *) malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
{
- ERROR ("mt_create: malloc failed.");
+ ERROR ("mt_create: calloc failed.");
return (-ENOMEM);
}
- memset (m, 0, sizeof (*m));
m->future = 0;
m->past = 0;
static void mv_free_match (mv_match_t *m) /* {{{ */
{
size_t i;
-
+
if (m == NULL)
return;
free(m->data_sources[i]);
free(m->data_sources);
}
-
+
free (m);
} /* }}} void mv_free_match */
/* Allocate space for the char pointers */
new_data_sources_num = m->data_sources_num + ((size_t) ci->values_num);
- temp = (char **) realloc (m->data_sources,
+ temp = realloc (m->data_sources,
new_data_sources_num * sizeof (char *));
if (temp == NULL)
{
int status;
int i;
- m = (mv_match_t *) malloc (sizeof (*m));
+ m = calloc (1, sizeof (*m));
if (m == NULL)
{
- ERROR ("mv_create: malloc failed.");
+ ERROR ("mv_create: calloc failed.");
return (-ENOMEM);
}
- memset (m, 0, sizeof (*m));
m->min = NAN;
m->max = NAN;
if (m->satisfy == SATISFY_ANY)
break;
}
- else if (value_matches == 0)
+ else
{
status = FC_MATCH_NO_MATCH;
if (m->satisfy == SATISFY_ALL)
double value;
char *nextc;
- char *type;
- char *inst;
+ const char *type;
+ const char *inst;
*t++ = '\0';
trim_spaces (s);
WARNING ("memcachec plugin: Ignoring arguments for the `Match' block.");
}
- match = (web_match_t *) malloc (sizeof (*match));
+ match = calloc (1, sizeof (*match));
if (match == NULL)
{
- ERROR ("memcachec plugin: malloc failed.");
+ ERROR ("memcachec plugin: calloc failed.");
return (-1);
}
- memset (match, 0, sizeof (*match));
status = 0;
for (i = 0; i < ci->children_num; i++)
return (-1);
}
- page = (web_page_t *) malloc (sizeof (*page));
+ page = calloc (1, sizeof (*page));
if (page == NULL)
{
- ERROR ("memcachec plugin: malloc failed.");
+ ERROR ("memcachec plugin: calloc failed.");
return (-1);
}
- memset (page, 0, sizeof (*page));
page->server = NULL;
page->key = NULL;
web_page_t *prev;
prev = pages_g;
- while ((prev != NULL) && (prev->next != NULL))
+ while (prev->next != NULL)
prev = prev->next;
prev->next = page;
}
static int memcached_connect_inet (memcached_t *st)
{
- char *host;
- char *port;
+ const char *host;
+ const char *port;
struct addrinfo ai_hints;
struct addrinfo *ai_list, *ai_ptr;
static int memcached_query_daemon (char *buffer, size_t buffer_size, memcached_t *st)
{
- int fd = -1;
- int status;
+ int fd, status;
size_t buffer_fill;
fd = memcached_connect (st);
/* Disable automatic generation of default instance in the init callback. */
memcached_have_instances = 1;
- st = malloc (sizeof (*st));
+ st = calloc (1, sizeof (*st));
if (st == NULL)
{
- ERROR ("memcached plugin: malloc failed.");
+ ERROR ("memcached plugin: calloc failed.");
return (-1);
}
- memset (st, 0, sizeof (*st));
st->name = NULL;
st->socket = NULL;
st->host = NULL;
return (0);
/* No instances were configured, lets start a default instance. */
- st = malloc (sizeof (*st));
+ st = calloc (1, sizeof (*st));
if (st == NULL)
return (ENOMEM);
- memset (st, 0, sizeof (*st));
st->name = sstrdup ("__legacy__");
st->socket = NULL;
st->host = NULL;
* vm.stats.vm.v_inactive_count: 113730
* vm.stats.vm.v_cache_count: 10809
*/
- char *sysctl_keys[8] =
+ const char *sysctl_keys[8] =
{
"vm.stats.vm.v_page_size",
"vm.stats.vm.v_page_count",
REG_TYPE_UINT32,
REG_TYPE_FLOAT
}; /* }}} */
-enum mb_mreg_type_e /* {{{ */
+enum mb_mreg_type_e /* {{{ */
{
MREG_HOLDING,
MREG_INPUT
if (host == NULL)
return (EINVAL);
+#if COLLECT_DEBUG
modbus_set_debug (&host->connection, 1);
+#endif
/* We'll do the error handling ourselves. */
modbus_set_error_handling (&host->connection, NOP_ON_ERROR);
}
}
+#if COLLECT_DEBUG
modbus_set_debug (host->connection, 1);
+#endif
/* We'll do the error handling ourselves. */
modbus_set_error_recovery (host->connection, 0);
modbus_free (host->connection);
#endif
}
-
+
#if LEGACY_LIBMODBUS
/* Version 2.0.3: Pass the connection struct as a pointer and pass the slave
* id to each call of "read_holding_registers". */
int status;
int i;
- host = malloc (sizeof (*host));
+ host = calloc (1, sizeof (*host));
if (host == NULL)
return (ENOMEM);
- memset (host, 0, sizeof (*host));
host->slaves = NULL;
status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host));
conf = calloc (1, sizeof (*conf));
if (conf == NULL)
{
- ERROR ("mqtt plugin: malloc failed.");
+ ERROR ("mqtt plugin: calloc failed.");
return (-1);
}
conf->publish = 1;
conf = calloc (1, sizeof (*conf));
if (conf == NULL)
{
- ERROR ("mqtt plugin: malloc failed.");
+ ERROR ("mqtt plugin: calloc failed.");
return (-1);
}
conf->publish = 0;
cf_util_get_string (child, &conf->host);
else if (strcasecmp ("Port", child->key) == 0)
{
- int tmp = cf_util_get_port_number (child);
- if (tmp < 0)
+ status = cf_util_get_port_number (child);
+ if (status < 0)
ERROR ("mqtt plugin: Invalid port number.");
else
- conf->port = tmp;
+ conf->port = status;
}
else if (strcasecmp ("ClientId", child->key) == 0)
cf_util_get_string (child, &conf->client_id);
cf_util_get_string (child, &conf->password);
else if (strcasecmp ("QoS", child->key) == 0)
{
- int tmp = -1;
- status = cf_util_get_int (child, &tmp);
- if ((status != 0) || (tmp < 0) || (tmp > 2))
+ int qos = -1;
+ status = cf_util_get_int (child, &qos);
+ if ((status != 0) || (qos < 0) || (qos > 2))
ERROR ("mqtt plugin: Not a valid QoS setting.");
else
- conf->qos = tmp;
+ conf->qos = qos;
}
else if (strcasecmp ("Topic", child->key) == 0)
cf_util_get_string (child, &conf->topic);
static int mysql_read (user_data_t *ud);
-void mysql_read_default_options(struct st_mysql_options *options,
- const char *filename,const char *group);
-
static void mysql_database_free (void *arg) /* {{{ */
{
mysql_database_t *db;
return (-1);
}
- db = (mysql_database_t *) malloc (sizeof (*db));
+ db = calloc (1, sizeof (*db));
if (db == NULL)
{
- ERROR ("mysql plugin: malloc failed.");
+ ERROR ("mysql plugin: calloc failed.");
return (-1);
}
- memset (db, 0, sizeof (*db));
/* initialize all the pointers */
db->alias = NULL;
MYSQL_RES *res;
MYSQL_ROW row;
- char *query;
- int field_num;
+ const char *query;
+ int field_num;
unsigned long long position;
query = "SHOW MASTER STATUS";
MYSQL_RES *res;
MYSQL_ROW row;
- char *query;
- int field_num;
+ const char *query;
+ int field_num;
/* WTF? libmysqlclient does not seem to provide any means to
* translate a column name to a column index ... :-/ */
MYSQL_RES *res;
MYSQL_ROW row;
- char *query;
- struct {
- char *key;
- char *type;
- int ds_type;
- } metrics[] = {
- { "metadata_mem_pool_size", "bytes", DS_TYPE_GAUGE },
- { "lock_deadlocks", "mysql_locks", DS_TYPE_DERIVE },
- { "lock_timeouts", "mysql_locks", DS_TYPE_DERIVE },
- { "lock_row_lock_current_waits", "mysql_locks", DS_TYPE_DERIVE },
- { "buffer_pool_size", "bytes", DS_TYPE_GAUGE },
-
- { "buffer_pool_reads", "operations", DS_TYPE_DERIVE },
- { "buffer_pool_read_requests", "operations", DS_TYPE_DERIVE },
- { "buffer_pool_write_requests", "operations", DS_TYPE_DERIVE },
- { "buffer_pool_wait_free", "operations", DS_TYPE_DERIVE },
- { "buffer_pool_read_ahead", "operations", DS_TYPE_DERIVE },
- { "buffer_pool_read_ahead_evicted", "operations", DS_TYPE_DERIVE },
-
- { "buffer_pool_pages_total", "gauge", DS_TYPE_GAUGE },
- { "buffer_pool_pages_misc", "gauge", DS_TYPE_GAUGE },
- { "buffer_pool_pages_data", "gauge", DS_TYPE_GAUGE },
- { "buffer_pool_bytes_data", "gauge", DS_TYPE_GAUGE },
- { "buffer_pool_pages_dirty", "gauge", DS_TYPE_GAUGE },
- { "buffer_pool_bytes_dirty", "gauge", DS_TYPE_GAUGE },
- { "buffer_pool_pages_free", "gauge", DS_TYPE_GAUGE },
-
- { "buffer_pages_created", "operations", DS_TYPE_DERIVE },
- { "buffer_pages_written", "operations", DS_TYPE_DERIVE },
- { "buffer_pages_read", "operations", DS_TYPE_DERIVE },
- { "buffer_data_reads", "operations", DS_TYPE_DERIVE },
- { "buffer_data_written", "operations", DS_TYPE_DERIVE },
-
- { "os_data_reads", "operations", DS_TYPE_DERIVE },
- { "os_data_writes", "operations", DS_TYPE_DERIVE },
- { "os_data_fsyncs", "operations", DS_TYPE_DERIVE },
- { "os_log_bytes_written", "operations", DS_TYPE_DERIVE },
- { "os_log_fsyncs", "operations", DS_TYPE_DERIVE },
- { "os_log_pending_fsyncs", "operations", DS_TYPE_DERIVE },
- { "os_log_pending_writes", "operations", DS_TYPE_DERIVE },
-
- { "trx_rseg_history_len", "gauge", DS_TYPE_GAUGE },
-
- { "log_waits", "operations", DS_TYPE_DERIVE },
- { "log_write_requests", "operations", DS_TYPE_DERIVE },
- { "log_writes", "operations", DS_TYPE_DERIVE },
- { "adaptive_hash_searches", "operations", DS_TYPE_DERIVE },
-
- { "file_num_open_files", "gauge", DS_TYPE_GAUGE },
-
- { "ibuf_merges_insert", "operations", DS_TYPE_DERIVE },
- { "ibuf_merges_delete_mark", "operations", DS_TYPE_DERIVE },
- { "ibuf_merges_delete", "operations", DS_TYPE_DERIVE },
- { "ibuf_merges_discard_insert", "operations", DS_TYPE_DERIVE },
- { "ibuf_merges_discard_delete_mark","operations", DS_TYPE_DERIVE },
- { "ibuf_merges_discard_delete", "operations", DS_TYPE_DERIVE },
- { "ibuf_merges_discard_merges", "operations", DS_TYPE_DERIVE },
- { "ibuf_size", "bytes", DS_TYPE_GAUGE },
-
- { "innodb_activity_count", "gauge", DS_TYPE_GAUGE },
- { "innodb_dblwr_writes", "operations", DS_TYPE_DERIVE },
- { "innodb_dblwr_pages_written", "operations", DS_TYPE_DERIVE },
- { "innodb_dblwr_page_size", "gauge", DS_TYPE_GAUGE },
-
- { "innodb_rwlock_s_spin_waits", "operations", DS_TYPE_DERIVE },
- { "innodb_rwlock_x_spin_waits", "operations", DS_TYPE_DERIVE },
- { "innodb_rwlock_s_spin_rounds", "operations", DS_TYPE_DERIVE },
- { "innodb_rwlock_x_spin_rounds", "operations", DS_TYPE_DERIVE },
- { "innodb_rwlock_s_os_waits", "operations", DS_TYPE_DERIVE },
- { "innodb_rwlock_x_os_waits", "operations", DS_TYPE_DERIVE },
-
- { "dml_reads", "operations", DS_TYPE_DERIVE },
- { "dml_inserts", "operations", DS_TYPE_DERIVE },
- { "dml_deletes", "operations", DS_TYPE_DERIVE },
- { "dml_updates", "operations", DS_TYPE_DERIVE },
-
- { NULL, NULL, 0}
- };
+ const char *query;
+ struct {
+ const char *key;
+ const char *type;
+ int ds_type;
+ } metrics[] = {
+ { "metadata_mem_pool_size", "bytes", DS_TYPE_GAUGE },
+ { "lock_deadlocks", "mysql_locks", DS_TYPE_DERIVE },
+ { "lock_timeouts", "mysql_locks", DS_TYPE_DERIVE },
+ { "lock_row_lock_current_waits", "mysql_locks", DS_TYPE_DERIVE },
+ { "buffer_pool_size", "bytes", DS_TYPE_GAUGE },
+
+ { "buffer_pool_reads", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_read_requests", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_write_requests", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_wait_free", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_read_ahead", "operations", DS_TYPE_DERIVE },
+ { "buffer_pool_read_ahead_evicted", "operations", DS_TYPE_DERIVE },
+
+ { "buffer_pool_pages_total", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_misc", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_data", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_bytes_data", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_dirty", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_bytes_dirty", "gauge", DS_TYPE_GAUGE },
+ { "buffer_pool_pages_free", "gauge", DS_TYPE_GAUGE },
+
+ { "buffer_pages_created", "operations", DS_TYPE_DERIVE },
+ { "buffer_pages_written", "operations", DS_TYPE_DERIVE },
+ { "buffer_pages_read", "operations", DS_TYPE_DERIVE },
+ { "buffer_data_reads", "operations", DS_TYPE_DERIVE },
+ { "buffer_data_written", "operations", DS_TYPE_DERIVE },
+
+ { "os_data_reads", "operations", DS_TYPE_DERIVE },
+ { "os_data_writes", "operations", DS_TYPE_DERIVE },
+ { "os_data_fsyncs", "operations", DS_TYPE_DERIVE },
+ { "os_log_bytes_written", "operations", DS_TYPE_DERIVE },
+ { "os_log_fsyncs", "operations", DS_TYPE_DERIVE },
+ { "os_log_pending_fsyncs", "operations", DS_TYPE_DERIVE },
+ { "os_log_pending_writes", "operations", DS_TYPE_DERIVE },
+
+ { "trx_rseg_history_len", "gauge", DS_TYPE_GAUGE },
+
+ { "log_waits", "operations", DS_TYPE_DERIVE },
+ { "log_write_requests", "operations", DS_TYPE_DERIVE },
+ { "log_writes", "operations", DS_TYPE_DERIVE },
+ { "adaptive_hash_searches", "operations", DS_TYPE_DERIVE },
+
+ { "file_num_open_files", "gauge", DS_TYPE_GAUGE },
+
+ { "ibuf_merges_insert", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_delete_mark", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_delete", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_insert", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_delete_mark", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_delete", "operations", DS_TYPE_DERIVE },
+ { "ibuf_merges_discard_merges", "operations", DS_TYPE_DERIVE },
+ { "ibuf_size", "bytes", DS_TYPE_GAUGE },
+
+ { "innodb_activity_count", "gauge", DS_TYPE_GAUGE },
+ { "innodb_dblwr_writes", "operations", DS_TYPE_DERIVE },
+ { "innodb_dblwr_pages_written", "operations", DS_TYPE_DERIVE },
+ { "innodb_dblwr_page_size", "gauge", DS_TYPE_GAUGE },
+
+ { "innodb_rwlock_s_spin_waits", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_x_spin_waits", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_s_spin_rounds", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_x_spin_rounds", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_s_os_waits", "operations", DS_TYPE_DERIVE },
+ { "innodb_rwlock_x_os_waits", "operations", DS_TYPE_DERIVE },
+
+ { "dml_reads", "operations", DS_TYPE_DERIVE },
+ { "dml_inserts", "operations", DS_TYPE_DERIVE },
+ { "dml_deletes", "operations", DS_TYPE_DERIVE },
+ { "dml_updates", "operations", DS_TYPE_DERIVE },
+
+ { NULL, NULL, 0}
+ };
query = "SELECT name, count, type FROM information_schema.innodb_metrics WHERE status = 'enabled'";
while ((row = mysql_fetch_row (res)))
{
- int i;
+ int i;
char *key;
unsigned long long val;
key = row[0];
val = atoll (row[1]);
- for (i = 0;
- metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0;
- i++)
- ;
-
- if (metrics[i].key == NULL)
- continue;
-
- switch (metrics[i].ds_type) {
- case DS_TYPE_COUNTER:
- counter_submit(metrics[i].type, key, (counter_t)val, db);
- break;
- case DS_TYPE_GAUGE:
- gauge_submit(metrics[i].type, key, (gauge_t)val, db);
- break;
- case DS_TYPE_DERIVE:
- derive_submit(metrics[i].type, key, (derive_t)val, db);
- break;
- }
- }
-
- mysql_free_result(res);
- return (0);
+ for (i = 0; metrics[i].key != NULL && strcmp(metrics[i].key, key) != 0; i++)
+ ;
+
+ if (metrics[i].key == NULL)
+ continue;
+
+ switch (metrics[i].ds_type) {
+ case DS_TYPE_COUNTER:
+ counter_submit(metrics[i].type, key, (counter_t)val, db);
+ break;
+ case DS_TYPE_GAUGE:
+ gauge_submit(metrics[i].type, key, (gauge_t)val, db);
+ break;
+ case DS_TYPE_DERIVE:
+ derive_submit(metrics[i].type, key, (derive_t)val, db);
+ break;
+ }
+ }
+
+ mysql_free_result(res);
+ return (0);
}
static int mysql_read (user_data_t *ud)
{
mysql_database_t *db;
- MYSQL *con;
- MYSQL_RES *res;
- MYSQL_ROW row;
- char *query;
+ MYSQL *con;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ const char *query;
derive_t qcache_hits = 0;
derive_t qcache_inserts = 0;
unsigned long long traffic_incoming = 0ULL;
unsigned long long traffic_outgoing = 0ULL;
- unsigned long mysql_version = 0ULL;
+ unsigned long mysql_version = 0ULL;
if ((ud == NULL) || (ud->data == NULL))
{
if ((con = getconnection (db)) == NULL)
return (-1);
- mysql_version = mysql_get_server_version(con);
+ mysql_version = mysql_get_server_version(con);
query = "SHOW STATUS";
if (mysql_version >= 50002)
key = row[0];
val = atoll (row[1]);
- if (strncmp (key, "Com_",
+ if (strncmp (key, "Com_",
strlen ("Com_")) == 0)
{
if (val == 0ULL)
/* Ignore `prepared statements' */
if (strncmp (key, "Com_stmt_", strlen ("Com_stmt_")) != 0)
- counter_submit ("mysql_commands",
- key + strlen ("Com_"),
+ counter_submit ("mysql_commands",
+ key + strlen ("Com_"),
val, db);
}
- else if (strncmp (key, "Handler_",
+ else if (strncmp (key, "Handler_",
strlen ("Handler_")) == 0)
{
if (val == 0ULL)
continue;
- counter_submit ("mysql_handler",
- key + strlen ("Handler_"),
+ counter_submit ("mysql_handler",
+ key + strlen ("Handler_"),
val, db);
}
else if (strncmp (key, "Qcache_",
else if (strcmp (key, "Qcache_queries_in_cache") == 0)
qcache_queries_in_cache = (gauge_t) val;
}
- else if (strncmp (key, "Bytes_",
+ else if (strncmp (key, "Bytes_",
strlen ("Bytes_")) == 0)
{
if (strcmp (key, "Bytes_received") == 0)
else if (strcmp (key, "Bytes_sent") == 0)
traffic_outgoing += val;
}
- else if (strncmp (key, "Threads_",
+ else if (strncmp (key, "Threads_",
strlen ("Threads_")) == 0)
{
if (strcmp (key, "Threads_running") == 0)
}
else if (strncmp (key, "Sort_", strlen ("Sort_")) == 0)
{
- counter_submit ("mysql_sort", key + strlen ("Sort_"),
- val, db);
+ if (strcmp (key, "Sort_merge_passes") == 0)
+ counter_submit ("mysql_sort_merge_passes", NULL, val, db);
+ else if (strcmp (key, "Sort_rows") == 0)
+ counter_submit ("mysql_sort_rows", NULL, val, db);
+ else if (strcmp (key, "Sort_range") == 0)
+ counter_submit ("mysql_sort", "range", val, db);
+ else if (strcmp (key, "Sort_scan") == 0)
+ counter_submit ("mysql_sort", "scan", val, db);
+
}
}
mysql_free_result (res); res = NULL;
traffic_submit (traffic_incoming, traffic_outgoing, db);
if (mysql_version >= 50600 && db->innodb_stats)
- mysql_read_innodb_stats (db, con);
+ mysql_read_innodb_stats (db, con);
if (db->master_stats)
mysql_read_master_stats (db, con);
return d;
}
- d = malloc(sizeof(*d));
+ d = calloc (1, sizeof (*d));
if (d == NULL)
return (NULL);
- memset (d, 0, sizeof (*d));
d->next = NULL;
d->name = strdup(name);
return (NULL);
/* Not found: allocate. */
- new = malloc (sizeof (*new));
+ new = calloc (1, sizeof (*new));
if (new == NULL)
return (NULL);
- memset (new, 0, sizeof (*new));
new->next = NULL;
new->name = strdup (name);
return (NULL);
/* Not found: allocate. */
- new = malloc (sizeof (*new));
+ new = calloc (1, sizeof (*new));
if (new == NULL)
return (NULL);
- memset (new, 0, sizeof (*new));
new->next = NULL;
new->name = strdup (name);
} /* }}} cdtime_t cna_child_get_cdtime */
-/*
+/*
* Query functions
*
* These functions are called with appropriate data returned by the libnetapp
na_elem_iter_t counter_iter;
memset (&perf_data, 0, sizeof (perf_data));
-
+
perf_data.timestamp = cna_child_get_cdtime (data);
instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
if ((cfg_disk == NULL) || (data == NULL))
return (EINVAL);
-
+
timestamp = cna_child_get_cdtime (data);
instances = na_elem_child (data, "instances");
na_elem_t *elem_instances;
na_elem_iter_t iter_instances;
na_elem_t *elem_instance;
-
+
timestamp = cna_child_get_cdtime (data);
elem_instances = na_elem_child(data, "instances");
if ((v->flags & CFG_VOLUME_USAGE_SNAP) != 0)
cna_handle_volume_snap_usage(host, v);
-
+
if ((v->flags & CFG_VOLUME_USAGE_DF) == 0)
continue;
const char *instance;
cdtime_t timestamp;
-
+
timestamp = cna_child_get_cdtime (data);
instances = na_elem_child(na_elem_child (data, "instances"), "instance-data");
&& (HAS_ALL_FLAGS (counter_flags, 0x01 | 0x02)))
submit_two_derive (hostname, instance, "disk_octets", NULL,
disk_read, disk_written, timestamp, interval);
-
+
if ((cfg_system->flags & CFG_SYSTEM_NET)
&& (HAS_ALL_FLAGS (counter_flags, 0x04 | 0x08)))
submit_two_derive (hostname, instance, "if_octets", NULL,
if (host->cfg_volume_perf == NULL)
{
- cfg_volume_perf = malloc (sizeof (*cfg_volume_perf));
+ cfg_volume_perf = calloc (1, sizeof (*cfg_volume_perf));
if (cfg_volume_perf == NULL)
return (ENOMEM);
- memset (cfg_volume_perf, 0, sizeof (*cfg_volume_perf));
/* Set default flags */
cfg_volume_perf->query = NULL;
host->cfg_volume_perf = cfg_volume_perf;
}
cfg_volume_perf = host->cfg_volume_perf;
-
+
for (i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
-
+
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
cna_config_get_interval (item, &cfg_volume_perf->interval);
if (host->cfg_quota == NULL)
{
- cfg_quota = malloc (sizeof (*cfg_quota));
+ cfg_quota = calloc (1, sizeof (*cfg_quota));
if (cfg_quota == NULL)
return (ENOMEM);
- memset (cfg_quota, 0, sizeof (*cfg_quota));
cfg_quota->query = NULL;
host->cfg_quota = cfg_quota;
if (host->cfg_disk == NULL)
{
- cfg_disk = malloc (sizeof (*cfg_disk));
+ cfg_disk = calloc (1, sizeof (*cfg_disk));
if (cfg_disk == NULL)
return (ENOMEM);
- memset (cfg_disk, 0, sizeof (*cfg_disk));
/* Set default flags */
cfg_disk->flags = CFG_DISK_ALL;
host->cfg_disk = cfg_disk;
}
cfg_disk = host->cfg_disk;
-
+
for (i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
-
+
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
cna_config_get_interval (item, &cfg_disk->interval);
if (host->cfg_wafl == NULL)
{
- cfg_wafl = malloc (sizeof (*cfg_wafl));
+ cfg_wafl = calloc (1, sizeof (*cfg_wafl));
if (cfg_wafl == NULL)
return (ENOMEM);
- memset (cfg_wafl, 0, sizeof (*cfg_wafl));
/* Set default flags */
cfg_wafl->flags = CFG_WAFL_ALL;
for (i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
-
+
if (strcasecmp(item->key, "Interval") == 0)
cna_config_get_interval (item, &cfg_wafl->interval);
else if (!strcasecmp(item->key, "GetNameCache"))
if (host->cfg_volume_usage == NULL)
{
- cfg_volume_usage = malloc (sizeof (*cfg_volume_usage));
+ cfg_volume_usage = calloc (1, sizeof (*cfg_volume_usage));
if (cfg_volume_usage == NULL)
return (ENOMEM);
- memset (cfg_volume_usage, 0, sizeof (*cfg_volume_usage));
/* Set default flags */
cfg_volume_usage->query = NULL;
host->cfg_volume_usage = cfg_volume_usage;
}
cfg_volume_usage = host->cfg_volume_usage;
-
+
for (i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
-
+
/* if (!item || !item->key || !*item->key) continue; */
if (strcasecmp(item->key, "Interval") == 0)
cna_config_get_interval (item, &cfg_volume_usage->interval);
if (host->cfg_snapvault == NULL)
{
- cfg_snapvault = malloc (sizeof (*cfg_snapvault));
+ cfg_snapvault = calloc (1, sizeof (*cfg_snapvault));
if (cfg_snapvault == NULL)
return ENOMEM;
- memset (cfg_snapvault, 0, sizeof (*cfg_snapvault));
cfg_snapvault->query = NULL;
host->cfg_snapvault = cfg_snapvault;
{
cfg_system_t *cfg_system;
int i;
-
+
if ((host == NULL) || (ci == NULL))
return (EINVAL);
if (host->cfg_system == NULL)
{
- cfg_system = malloc (sizeof (*cfg_system));
+ cfg_system = calloc (1, sizeof (*cfg_system));
if (cfg_system == NULL)
return (ENOMEM);
- memset (cfg_system, 0, sizeof (*cfg_system));
/* Set default flags */
cfg_system->flags = CFG_SYSTEM_ALL;
{
host_config_t *host;
- host = malloc(sizeof(*host));
- if (! host)
+ host = calloc (1, sizeof (*host));
+ if (host == NULL)
return (NULL);
- memset (host, 0, sizeof (*host));
host->name = NULL;
host->protocol = NA_SERVER_TRANSPORT_HTTPS;
{
ir_ignorelist_t *entry;
- entry = (ir_ignorelist_t *) malloc (sizeof (ir_ignorelist_t));
+ entry = calloc (1, sizeof (*entry));
if (entry == NULL)
return (-1);
- memset (entry, '\0', sizeof (ir_ignorelist_t));
-
if (strcasecmp (dev, "All") != 0)
{
entry->device = strdup (dev);
{
char **temp;
- temp = (char **) realloc (iflist, (msg->ifi_index + 1) * sizeof (char *));
+ temp = realloc (iflist, (msg->ifi_index + 1) * sizeof (char *));
if (temp == NULL)
{
ERROR ("netlink plugin: update_iflist: realloc failed.");
const char *kind = NULL;
/* char *type_instance; */
- char *tc_type;
+ const char *tc_type;
char tc_inst[DATA_MAX_NAME_LEN];
_Bool stats_submitted = 0;
if (*ret_buffer_len < packet_len)
return (-1);
- pkg_values_types = (uint8_t *) malloc (num_values * sizeof (uint8_t));
+ pkg_values_types = malloc (num_values * sizeof (*pkg_values_types));
if (pkg_values_types == NULL)
{
ERROR ("network plugin: write_part_values: malloc failed.");
return (-1);
}
- pkg_values = (value_t *) malloc (num_values * sizeof (value_t));
+ pkg_values = malloc (num_values * sizeof (*pkg_values));
if (pkg_values == NULL)
{
free (pkg_values_types);
uint16_t pkg_length;
size_t payload_size;
- if (output_len <= 0)
+ if (output_len == 0)
return (EINVAL);
if (buffer_len < header_size)
warning_has_been_printed = 1;
}
- *ret_buffer += ph_length;
+ *ret_buffer = (void *) (((char *) *ret_buffer) + ph_length);
*ret_buffer_size -= ph_length;
return (0);
(void *) buffer,
sizeof (pkg_type));
memcpy ((void *) &pkg_length,
- (void *) (buffer + sizeof (pkg_type)),
+ (void *) (((char *) buffer) + sizeof (pkg_type)),
sizeof (pkg_length));
pkg_length = ntohs (pkg_length);
if ((type != SOCKENT_TYPE_CLIENT) && (type != SOCKENT_TYPE_SERVER))
return (NULL);
- se = malloc (sizeof (*se));
+ se = calloc (1, sizeof (*se));
if (se == NULL)
return (NULL);
- memset (se, 0, sizeof (*se));
se->type = type;
se->node = NULL;
continue;
}
- client->addr = malloc (sizeof (*client->addr));
+ client->addr = calloc (1, sizeof (*client->addr));
if (client->addr == NULL)
{
- ERROR ("network plugin: malloc failed.");
+ ERROR ("network plugin: calloc failed.");
close (client->fd);
client->fd = -1;
continue;
}
- memset (client->addr, 0, sizeof (*client->addr));
assert (sizeof (*client->addr) >= ai_ptr->ai_addrlen);
memcpy (client->addr, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
client->addrlen = ai_ptr->ai_addrlen;
freeaddrinfo (ai_list);
- if (se->data.server.fd_num <= 0)
+ if (se->data.server.fd_num == 0)
return (-1);
return (0);
} /* }}} int sockent_server_listen */
* these entries in the dispatch thread but put them in
* another list, so we don't have to allocate more and
* more of these structures. */
- ent = malloc (sizeof (receive_list_entry_t));
+ ent = calloc (1, sizeof (*ent));
if (ent == NULL)
{
- ERROR ("network plugin: malloc failed.");
+ ERROR ("network plugin: calloc failed.");
status = ENOMEM;
break;
}
- memset (ent, 0, sizeof (receive_list_entry_t));
+
ent->data = malloc (network_config_packet_size);
if (ent->data == NULL)
{
memset (&send_buffer_vl, 0, sizeof (send_buffer_vl));
} /* int network_init_buffer */
-static void networt_send_buffer_plain (sockent_t *se, /* {{{ */
+static void network_send_buffer_plain (sockent_t *se, /* {{{ */
const char *buffer, size_t buffer_size)
{
int status;
break;
} /* while (42) */
-} /* }}} void networt_send_buffer_plain */
+} /* }}} void network_send_buffer_plain */
#if HAVE_LIBGCRYPT
#define BUFFER_ADD(p,s) do { \
buffer_offset += (s); \
} while (0)
-static void networt_send_buffer_signed (sockent_t *se, /* {{{ */
+static void network_send_buffer_signed (sockent_t *se, /* {{{ */
const char *in_buffer, size_t in_buffer_size)
{
part_signature_sha256_t ps;
hd = NULL;
buffer_offset = PART_SIGNATURE_SHA256_SIZE + username_len + in_buffer_size;
- networt_send_buffer_plain (se, buffer, buffer_offset);
-} /* }}} void networt_send_buffer_signed */
+ network_send_buffer_plain (se, buffer, buffer_offset);
+} /* }}} void network_send_buffer_signed */
-static void networt_send_buffer_encrypted (sockent_t *se, /* {{{ */
+static void network_send_buffer_encrypted (sockent_t *se, /* {{{ */
const char *in_buffer, size_t in_buffer_size)
{
part_encryption_aes256_t pea;
- sizeof (pea.hash);
assert (buffer_size <= sizeof (buffer));
- DEBUG ("network plugin: networt_send_buffer_encrypted: "
+ DEBUG ("network plugin: network_send_buffer_encrypted: "
"buffer_size = %zu;", buffer_size);
pea.head.length = htons ((uint16_t) (PART_ENCRYPTION_AES256_SIZE
}
/* Send it out without further modifications */
- networt_send_buffer_plain (se, buffer, buffer_size);
-} /* }}} void networt_send_buffer_encrypted */
+ network_send_buffer_plain (se, buffer, buffer_size);
+} /* }}} void network_send_buffer_encrypted */
#undef BUFFER_ADD
#endif /* HAVE_LIBGCRYPT */
{
#if HAVE_LIBGCRYPT
if (se->data.client.security_level == SECURITY_LEVEL_ENCRYPT)
- networt_send_buffer_encrypted (se, buffer, buffer_len);
+ network_send_buffer_encrypted (se, buffer, buffer_len);
else if (se->data.client.security_level == SECURITY_LEVEL_SIGN)
- networt_send_buffer_signed (se, buffer, buffer_len);
+ network_send_buffer_signed (se, buffer, buffer_len);
else /* if (se->data.client.security_level == SECURITY_LEVEL_NONE) */
#endif /* HAVE_LIBGCRYPT */
- networt_send_buffer_plain (se, buffer, buffer_len);
+ network_send_buffer_plain (se, buffer, buffer_len);
} /* for (sending_sockets) */
} /* }}} void network_send_buffer */
}
/* No call to sockent_client_connect() here -- it is called from
- * networt_send_buffer_plain(). */
+ * network_send_buffer_plain(). */
status = sockent_add (se);
if (status != 0)
static const char *nfs4_server41_procedures_names[] =
{
"backchannel_ctl",
- "bind_conn_to_session",
+ "bind_conn_to_session",
"exchange_id",
"create_session",
"destroy_session",
} /* void nfs_procedures_submit */
#if KERNEL_LINUX
-static void nfs_submit_fields (int nfs_version, const char *instance,
+static void nfs_submit_fields (int nfs_version, const char *instance,
char **fields, size_t fields_num, const char **proc_names)
{
char plugin_instance[DATA_MAX_NAME_LEN];
return (EINVAL);
}
- nfs_submit_fields (nfs_version, instance, fields, fields_num,
+ nfs_submit_fields (nfs_version, instance, fields, fields_num,
proc_names);
return (0);
}
-static int nfs_submit_nfs4_server (const char *instance, char **fields,
+static int nfs_submit_nfs4_server (const char *instance, char **fields,
size_t fields_num)
{
static int suppress_warning = 0;
if (fields_num != NFS4_SERVER40_NUM_PROC &&
- fields_num != NFS4_SERVER41_NUM_PROC)
+ fields_num != NFS4_SERVER41_NUM_PROC)
{
if (!suppress_warning)
{
}
}
- nfs_submit_fields (4, instance, fields,
+ nfs_submit_fields (4, instance, fields,
nfs4_server40_procedures_names_num,
nfs4_server40_procedures_names);
{
fields += nfs4_server40_procedures_names_num;
- nfs_submit_fields (4, instance, fields,
- nfs4_server41_procedures_names_num,
+ nfs_submit_fields (4, instance, fields,
+ nfs4_server41_procedures_names_num,
nfs4_server41_procedures_names);
}
return (0);
}
-static int nfs_submit_nfs4_client (const char *instance, char **fields,
+static int nfs_submit_nfs4_client (const char *instance, char **fields,
size_t fields_num)
{
size_t proc40_names_num, proc41_names_num;
return (0);
}
-static void nfs_read_linux (FILE *fh, char *inst)
+static void nfs_read_linux (FILE *fh, const char *inst)
{
char buffer[1024];
else if (strcmp (fields[0], "proc4ops") == 0)
{
if (inst[0] == 's')
- nfs_submit_nfs4_server (inst, fields + 2,
+ nfs_submit_nfs4_server (inst, fields + 2,
(size_t) (fields_num - 2));
}
else if (strcmp (fields[0], "proc4") == 0)
{
if (inst[0] == 'c')
nfs_submit_nfs4_client (inst, fields + 2,
- (size_t) (fields_num - 2));
+ (size_t) (fields_num - 2));
}
} /* while (fgets) */
} /* void nfs_read_linux */
#endif /* KERNEL_LINUX */
#if HAVE_LIBKSTAT
-static int nfs_read_kstat (kstat_t *ksp, int nfs_version, char *inst,
+static int nfs_read_kstat (kstat_t *ksp, int nfs_version, const char *inst,
char const **proc_names, size_t proc_names_num)
{
char plugin_instance[DATA_MAX_NAME_LEN];
len = (sizeof (nginx_buffer) - 1) - nginx_buffer_len;
}
- if (len <= 0)
+ if (len == 0)
return (len);
memcpy (&nginx_buffer[nginx_buffer_len], buf, len);
return (0);
} /* void init */
-static void submit (char *type, char *inst, long long value)
+static void submit (const char *type, const char *inst, long long value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
/* Callback to get username and password */
static int authinteract (auth_client_request_t request, char **result,
int fields, void __attribute__((unused)) *arg)
-{
+{
int i;
for (i = 0; i < fields; i++)
{
if ( !smtp_auth_set_context (session, authctx)) {
pthread_mutex_unlock (&session_lock);
ERROR ("notify_email plugin: cannot set SMTP auth context");
- return (-1);
+ return (-1);
}
pthread_mutex_unlock (&session_lock);
{
char **tmp;
- tmp = (char **) realloc ((void *) recipients, (recipients_len + 1) * sizeof (char *));
+ tmp = realloc (recipients, (recipients_len + 1) * sizeof (char *));
if (tmp == NULL) {
ERROR ("notify_email: realloc failed.");
return (-1);
if (!(message = smtp_add_message (session))) {
pthread_mutex_unlock (&session_lock);
ERROR ("notify_email plugin: cannot set SMTP message");
- return (-1);
+ return (-1);
}
smtp_set_reverse_path (message, email_from);
smtp_set_header (message, "To", NULL, NULL);
/* Initiate a connection to the SMTP server and transfer the message. */
if (!smtp_start_session (session)) {
- char buf[MAXSTRING];
ERROR ("notify_email plugin: SMTP server problem: %s",
smtp_strerror (smtp_errno (), buf, sizeof buf));
pthread_mutex_unlock (&session_lock);
/* l_fp to double */
#define M_LFPTOD(r_i, r_uf, d) \
do { \
- register int32_t i; \
- register uint32_t f; \
+ register int32_t ri; \
+ register uint32_t rf; \
\
- i = (r_i); \
- f = (r_uf); \
- if (i < 0) { \
- M_NEG(i, f); \
- (d) = -((double) i + ((double) f) / 4294967296.0); \
+ ri = (r_i); \
+ rf = (r_uf); \
+ if (ri < 0) { \
+ M_NEG(ri, rf); \
+ (d) = -((double) ri + ((double) rf) / 4294967296.0); \
} else { \
- (d) = (double) i + ((double) f) / 4294967296.0; \
+ (d) = (double) ri + ((double) rf) / 4294967296.0; \
} \
} while (0)
};
/* List of reference clock names */
-static char *refclock_names[] =
+static const char *refclock_names[] =
{
"UNKNOWN", "LOCAL", "GPS_TRAK", "WWV_PST", /* 0- 3 */
"SPECTRACOM", "TRUETIME", "IRIG_AUDIO", "CHU_AUDIO", /* 4- 7 */
return (0);
}
-static void ntpd_submit (char *type, char *type_inst, gauge_t value)
+static void ntpd_submit (const char *type, const char *type_inst, gauge_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
/* Each time a peer is polled, ntpd shifts the reach register to the left and
* 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,
- gauge_t value)
+static void ntpd_submit_reach (const char *type, const char *type_inst,
+ uint8_t reach, gauge_t value)
{
if (!(reach & 1))
value = NAN;
static int ntpd_connect (void)
{
- char *host;
- char *port;
+ const char *host;
+ const char *port;
struct addrinfo ai_hints;
struct addrinfo *ai_list;
*/
DEBUG ("realloc (%p, %zu)", (void *) *res_data,
(items_num + pkt_item_num) * res_item_size);
- items = realloc ((void *) *res_data,
+ items = realloc (*res_data,
(items_num + pkt_item_num) * res_item_size);
if (items == NULL)
{
DEBUG ("nut plugin: nut_add_ups (name = %s);", name);
- ups = (nut_ups_t *) malloc (sizeof (nut_ups_t));
+ ups = calloc (1, sizeof (*ups));
if (ups == NULL)
{
- ERROR ("nut plugin: nut_add_ups: malloc failed.");
+ ERROR ("nut plugin: nut_add_ups: calloc failed.");
return (1);
}
- memset (ups, '\0', sizeof (nut_ups_t));
status = upscli_splitname (name, &ups->upsname, &ups->hostname,
&ups->port);
/* (Re-)Connect if we have no connection */
if (ups->conn == NULL)
{
- ups->conn = (collectd_upsconn_t *) malloc (sizeof (collectd_upsconn_t));
+ ups->conn = malloc (sizeof (*ups->conn));
if (ups->conn == NULL)
{
ERROR ("nut plugin: malloc failed.");
{
/* An empty line ends the table. */
buffer_len = strchomp (buffer);
- if (buffer_len <= 0)
+ if (buffer_len == 0)
{
(*callback) (lineno, /* fields_num = */ 0, /* fields = */ NULL);
break;
(*callback) (lineno, fields_num, fields);
lineno++;
} /* while (fgets) */
-
+
return (0);
} /* }}} int olsrd_read_table */
while (fgets (buffer, sizeof (buffer), fh) != NULL)
{
buffer_len = strchomp (buffer);
- if (buffer_len <= 0)
+ if (buffer_len == 0)
continue;
-
+
if (strcmp ("Table: Links", buffer) == 0)
olsrd_read_table (fh, olsrd_cb_links);
else if (strcmp ("Table: Neighbors", buffer) == 0)
} /* while (fgets) */
fclose (fh);
-
+
return (0);
} /* }}} int olsrd_read */
{
regmatch_t pmatch[3];
size_t nmatch = 3;
- direct_access_element_t *element = NULL;
+ direct_access_element_t *element;
DEBUG ("onewire plugin: direct_list_insert <%s>", config);
- element = (direct_access_element_t *) malloc (sizeof(*element));
+ element = malloc (sizeof (*element));
if (element == NULL)
{
ERROR ("onewire plugin: direct_list_insert - cannot allocate element");
int status;
status = ssnprintf (subpath, sizeof (subpath), "%s/main", path);
- if ((status > 0) && (status < sizeof (subpath)))
+ if ((status > 0) && (status < (int) sizeof (subpath)))
cow_read_bus (subpath);
status = ssnprintf (subpath, sizeof (subpath), "%s/aux", path);
- if ((status > 0) && (status < sizeof (subpath)))
+ if ((status > 0) && (status < (int) sizeof (subpath)))
cow_read_bus (subpath);
return (0);
else
status = ssnprintf (subpath, sizeof (subpath), "%s/%s",
path, buffer_ptr);
- if ((status <= 0) || (status >= sizeof (subpath)))
+ if ((status <= 0) || (status >= (int) sizeof (subpath)))
continue;
for (i = 0; i < ow_family_features_num; i++)
cred.bv_len = 0;
}
- rc = ldap_sasl_bind_s (st->ld, st->binddn, LDAP_SASL_SIMPLE, &cred,
+ rc = ldap_sasl_bind_s (st->ld, st->binddn, LDAP_SASL_SIMPLE, &cred,
NULL, NULL, NULL);
if (rc != LDAP_SUCCESS)
{
int i;
int status;
- st = malloc (sizeof (*st));
+ st = calloc (1, sizeof (*st));
if (st == NULL)
{
- ERROR ("openldap plugin: malloc failed.");
+ ERROR ("openldap plugin: calloc failed.");
return (-1);
}
- memset (st, 0, sizeof (*st));
status = cf_util_get_string (ci, &st->name);
if (status != 0)
} /* int openvpn_strsplit */
/* dispatches number of users */
-static void numusers_submit (char *pinst, char *tinst, gauge_t value)
+static void numusers_submit (const char *pinst, const char *tinst,
+ gauge_t value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
plugin_dispatch_values (&vl);
} /* void numusers_submit */
-/* dispatches stats about traffic (TCP or UDP) generated by the tunnel per single endpoint */
-static void iostats_submit (char *pinst, char *tinst, derive_t rx, derive_t tx)
+/* dispatches stats about traffic (TCP or UDP) generated by the tunnel
+ * per single endpoint */
+static void iostats_submit (const char *pinst, const char *tinst,
+ derive_t rx, derive_t tx)
{
value_t values[2];
value_list_t vl = VALUE_LIST_INIT;
} /* void traffic_submit */
/* dispatches stats about data compression shown when in single mode */
-static void compression_submit (char *pinst, char *tinst,
+static void compression_submit (const char *pinst, const char *tinst,
derive_t uncompressed, derive_t compressed)
{
value_t values[2];
plugin_dispatch_values (&vl);
} /* void compression_submit */
-static int single_read (char *name, FILE *fh)
+static int single_read (const char *name, FILE *fh)
{
char buffer[1024];
char *fields[4];
} /* int single_read */
/* for reading status version 1 */
-static int multi1_read (char *name, FILE *fh)
+static int multi1_read (const char *name, FILE *fh)
{
char buffer[1024];
char *fields[10];
} /* int multi1_read */
/* for reading status version 2 */
-static int multi2_read (char *name, FILE *fh)
+static int multi2_read (const char *name, FILE *fh)
{
char buffer[1024];
char *fields[10];
} /* int multi2_read */
/* for reading status version 3 */
-static int multi3_read (char *name, FILE *fh)
+static int multi3_read (const char *name, FILE *fh)
{
char buffer[1024];
char *fields[15];
} /* int multi3_read */
/* for reading status version 4 */
-static int multi4_read (char *name, FILE *fh)
+static int multi4_read (const char *name, FILE *fh)
{
char buffer[1024];
char *fields[11];
}
/* create a new vpn element since file, version and name are ok */
- temp = (vpn_status_t *) malloc (sizeof (vpn_status_t));
+ temp = malloc (sizeof (*temp));
if (temp == NULL)
{
char errbuf[1024];
temp->version = status_version;
temp->name = status_name;
- vpn_list = (vpn_status_t **) realloc (vpn_list, (vpn_num + 1) * sizeof (vpn_status_t *));
- if (vpn_list == NULL)
+ vpn_status_t **tmp_list = realloc (vpn_list, (vpn_num + 1) * sizeof (*vpn_list));
+ if (tmp_list == NULL)
{
char errbuf[1024];
ERROR ("openvpn plugin: realloc failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
+ sfree (vpn_list);
sfree (temp->file);
sfree (temp);
return (1);
}
+ vpn_list = tmp_list;
vpn_list[vpn_num] = temp;
vpn_num++;
* ValuesFrom "value"
* </Result>
* </Query>
- *
+ *
* <Database "plugin_instance1">
* ConnectID "db01"
* Username "oracle"
return (-1);
}
- db = (o_database_t *) malloc (sizeof (*db));
+ db = calloc (1, sizeof (*db));
if (db == NULL)
{
- ERROR ("oracle plugin: malloc failed.");
+ ERROR ("oracle plugin: calloc failed.");
return (-1);
}
- memset (db, 0, sizeof (*db));
db->name = NULL;
db->host = NULL;
db->connect_id = NULL;
if (db->q_prep_areas == NULL)
{
- WARNING ("oracle plugin: malloc failed");
+ WARNING ("oracle plugin: calloc failed");
status = -1;
break;
}
{
o_database_t **temp;
- temp = (o_database_t **) realloc (databases,
+ temp = realloc (databases,
sizeof (*databases) * (databases_num + 1));
if (temp == NULL)
{
{
ub4 param_counter = 0;
status = OCIAttrGet (oci_statement, OCI_HTYPE_STMT, /* {{{ */
- ¶m_counter, /* size pointer = */ NULL,
+ ¶m_counter, /* size pointer = */ NULL,
OCI_ATTR_PARAM_COUNT, oci_error);
if (status != OCI_SUCCESS)
{
} while (0); /* }}} */
/* Allocate the following buffers:
- *
+ *
* +---------------+-----------------------------------+
* ! Name ! Size !
* +---------------+-----------------------------------+
#define ALLOC_OR_FAIL(ptr, ptr_size) \
do { \
size_t alloc_size = (size_t) ((ptr_size)); \
- (ptr) = malloc (alloc_size); \
+ (ptr) = calloc (1, alloc_size); \
if ((ptr) == NULL) { \
FREE_ALL; \
- ERROR ("oracle plugin: o_read_database_query: malloc failed."); \
+ ERROR ("oracle plugin: o_read_database_query: calloc failed."); \
return (-1); \
} \
- memset ((ptr), 0, alloc_size); \
} while (0)
/* Initialize everything to NULL so the above works. */
ub4 connection_status;
server_handle = NULL;
- status = OCIAttrGet ((void *) db->oci_service_context, OCI_HTYPE_SVCCTX,
+ status = OCIAttrGet ((void *) db->oci_service_context, OCI_HTYPE_SVCCTX,
(void *) &server_handle, /* size pointer = */ NULL,
OCI_ATTR_SERVER, oci_error);
if (status != OCI_SUCCESS)
OCIHandleFree (databases[i]->oci_service_context, OCI_HTYPE_SVCCTX);
databases[i]->oci_service_context = NULL;
}
-
+
for (i = 0; i < queries_num; i++)
{
OCIStmt *oci_statement;
udb_query_set_user_data (queries[i], NULL);
}
}
-
+
OCIHandleFree (oci_env, OCI_HTYPE_ENV);
oci_env = NULL;
return -1;
}
- ds->ds = (data_source_t *)smalloc ((len + 1) * sizeof (data_source_t));
+ ds->ds = smalloc ((len + 1) * sizeof (*ds->ds));
ds->ds_num = len + 1;
for (i = 0; i <= len; ++i) {
hash = (HV *)SvRV (*tmp);
- *m = (notification_meta_t *)smalloc (sizeof (**m));
+ *m = smalloc (sizeof (**m));
if (NULL == (tmp = hv_fetch (hash, "name", 4, 0))) {
log_warn ("av2notification_meta: Skipping invalid "
assert (NULL != perl_threads);
- t = (c_ithread_t *)smalloc (sizeof (c_ithread_t));
+ t = smalloc (sizeof (*t));
memset (t, 0, sizeof (c_ithread_t));
t->interp = (NULL == base)
return -1;
}
- data = (pfc_user_data_t *)smalloc (sizeof (*data));
+ data = smalloc (sizeof (*data));
data->name = sstrdup (ci->values[0].value.string);
data->user_data = newSV (0);
static int perl_shutdown (void)
{
- c_ithread_t *t = NULL;
-
- int ret = 0;
+ c_ithread_t *t;
+ int ret;
dTHX;
return 0;
if (NULL == aTHX) {
- c_ithread_t *t = NULL;
-
pthread_mutex_lock (&perl_threads->mutex);
t = c_ithread_create (perl_threads->head->interp);
pthread_mutex_unlock (&perl_threads->mutex);
#endif
PERL_SYS_INIT3 (&argc, &argv, &environ);
- perl_threads = (c_ithread_list_t *)smalloc (sizeof (c_ithread_list_t));
+ perl_threads = smalloc (sizeof (*perl_threads));
memset (perl_threads, 0, sizeof (c_ithread_list_t));
pthread_mutex_init (&perl_threads->mutex, NULL);
value = ci->values[0].value.string;
- perl_argv = (char **)realloc (perl_argv,
+ perl_argv = realloc (perl_argv,
(++perl_argc + 1) * sizeof (char *));
if (NULL == perl_argv) {
perl_argv[perl_argc - 1] = "-d";
}
else {
- perl_argv[perl_argc - 1] = (char *)smalloc (strlen (value) + 4);
+ perl_argv[perl_argc - 1] = smalloc (strlen (value) + 4);
sstrncpy (perl_argv[perl_argc - 1], "-d:", 4);
sstrncpy (perl_argv[perl_argc - 1] + 3, value, strlen (value) + 1);
}
value = ci->values[0].value.string;
if (NULL == aTHX) {
- perl_argv = (char **)realloc (perl_argv,
+ perl_argv = realloc (perl_argv,
(++perl_argc + 1) * sizeof (char *));
if (NULL == perl_argv) {
exit (3);
}
- perl_argv[perl_argc - 1] = (char *)smalloc (strlen (value) + 3);
+ perl_argv[perl_argc - 1] = smalloc (strlen (value) + 3);
sstrncpy(perl_argv[perl_argc - 1], "-I", 3);
sstrncpy(perl_argv[perl_argc - 1] + 2, value, strlen (value) + 1);
void module_register (void)
{
perl_argc = 4;
- perl_argv = (char **)smalloc ((perl_argc + 1) * sizeof (char *));
+ perl_argv = smalloc ((perl_argc + 1) * sizeof (*perl_argv));
/* default options for the Perl interpreter */
perl_argv[0] = "";
const char *script)
{
pinba_statnode_t *node;
-
+
node = realloc (stat_nodes,
sizeof (*stat_nodes) * (stat_nodes_num + 1));
if (node == NULL)
node = stat_nodes + stat_nodes_num;
memset (node, 0, sizeof (*node));
-
+
/* reset strings */
node->name = NULL;
node->host = NULL;
node->script = NULL;
node->mem_peak = NAN;
-
+
/* fill query data */
strset (&node->name, name);
strset (&node->host, host);
strset (&node->server, server);
strset (&node->script, script);
-
+
/* increment counter */
stat_nodes_num++;
} /* }}} void service_statnode_add */
unsigned int index)
{
pinba_statnode_t *node;
-
+
if (stat_nodes_num == 0)
return 0;
-
+
/* begin collecting */
if (index == 0)
pthread_mutex_lock (&stat_nodes_lock);
-
+
/* end collecting */
if (index >= stat_nodes_num)
{
/* reset node */
node->mem_peak = NAN;
-
+
return (index + 1);
} /* }}} unsigned int service_statnode_collect */
unsigned int i;
pthread_mutex_lock (&stat_nodes_lock);
-
+
for (i = 0; i < stat_nodes_num; i++)
{
if ((stat_nodes[i].host != NULL)
service_statnode_process(&stat_nodes[i], request);
}
-
+
pthread_mutex_unlock(&stat_nodes_lock);
} /* }}} void service_process_request */
}
assert (ai_list != NULL);
- s = malloc (sizeof (*s));
+ s = calloc (1, sizeof (*s));
if (s == NULL)
{
freeaddrinfo (ai_list);
- ERROR ("pinba plugin: malloc failed.");
+ ERROR ("pinba plugin: calloc failed.");
return (NULL);
}
- memset (s, 0, sizeof (*s));
for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
if (status != 0)
break;
} /* for (ai_list) */
-
+
freeaddrinfo (ai_list);
if (s->fd_num < 1)
if (!socket)
return;
-
+
for (i = 0; i < socket->fd_num; i++)
{
if (socket->fd[i].fd < 0)
close (socket->fd[i].fd);
socket->fd[i].fd = -1;
}
-
+
sfree(socket);
} /* }}} void pinba_socket_free */
static int pinba_process_stats_packet (const uint8_t *buffer, /* {{{ */
size_t buffer_size)
{
- Pinba__Request *request;
-
+ Pinba__Request *request;
+
request = pinba__request__unpack (NULL, buffer_size, buffer);
-
+
if (!request)
return (-1);
service_process_request(request);
pinba__request__free_unpacked (request, NULL);
-
+
return (0);
} /* }}} int pinba_process_stats_packet */
static int plugin_config (oconfig_item_t *ci) /* {{{ */
{
int i;
-
+
/* The lock should not be necessary in the config callback, but let's be
* sure.. */
pthread_mutex_lock (&stat_nodes_lock);
}
pthread_mutex_unlock(&stat_nodes_lock);
-
+
return (0);
} /* }}} int pinba_config */
{
value_t value;
value_list_t vl = VALUE_LIST_INIT;
-
+
vl.values = &value;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sstrncpy (vl.plugin_instance, res->name, sizeof (vl.plugin_instance));
value.derive = res->req_count;
- sstrncpy (vl.type, "total_requests", sizeof (vl.type));
+ sstrncpy (vl.type, "total_requests", sizeof (vl.type));
plugin_dispatch_values (&vl);
value.derive = float_counter_get (&res->req_time, /* factor = */ 1000);
- sstrncpy (vl.type, "total_time_in_ms", sizeof (vl.type));
+ sstrncpy (vl.type, "total_time_in_ms", sizeof (vl.type));
plugin_dispatch_values (&vl);
value.derive = res->doc_size;
- sstrncpy (vl.type, "total_bytes", sizeof (vl.type));
+ sstrncpy (vl.type, "total_bytes", sizeof (vl.type));
plugin_dispatch_values (&vl);
value.derive = float_counter_get (&res->ru_utime, /* factor = */ 100);
{
unsigned int i=0;
pinba_statnode_t data;
-
+
while ((i = service_statnode_collect (&data, i)) != 0)
{
plugin_submit (&data);
}
-
+
return 0;
} /* }}} int plugin_read */
pthread_mutex_unlock (&ping_lock);
return (-1);
}
-
+
pthread_mutex_unlock (&ping_lock);
return (0);
} /* }}} int start_thread */
hostlist_t *hl;
char *host;
- hl = (hostlist_t *) malloc (sizeof (hostlist_t));
+ hl = malloc (sizeof (*hl));
if (hl == NULL)
{
char errbuf[1024];
int ref_cnt;
} c_psql_database_t;
-static char *def_queries[] = {
+static const char *const def_queries[] = {
"backends",
"transactions",
"queries",
c_psql_database_t **tmp;
c_psql_database_t *db;
- db = (c_psql_database_t *)malloc (sizeof(*db));
+ db = malloc (sizeof(*db));
if (NULL == db) {
log_err ("Out of memory.");
return NULL;
}
- tmp = (c_psql_database_t **)realloc (databases,
+ tmp = realloc (databases,
(databases_num + 1) * sizeof (*databases));
if (NULL == tmp) {
log_err ("Out of memory.");
static PGresult *c_psql_exec_query_params (c_psql_database_t *db,
udb_query_t *q, c_psql_user_data_t *data)
{
- char *params[db->max_params_num];
- char interval[64];
- int i;
+ const char *params[db->max_params_num];
+ char interval[64];
+ int i;
if ((data == NULL) || (data->params_num == 0))
return (c_psql_exec_query_noparams (db, q));
log_err ("calloc failed.");
BAIL_OUT (-1);
}
-
+
for (col = 0; col < column_num; ++col) {
/* Pointers returned by `PQfname' are freed by `PQclear' via
* `BAIL_OUT'. */
#undef VALUE_OR_NULL
if( db->expire_delay > 0 && vl->time < (cdtime() - vl->interval - db->expire_delay) ) {
- log_info ("c_psql_write: Skipped expired value @ %s - %s/%s-%s/%s-%s/%s",
+ log_info ("c_psql_write: Skipped expired value @ %s - %s/%s-%s/%s-%s/%s",
params[0], params[1], params[2], params[3], params[4], params[5], params[6] );
return 0;
}
data = udb_query_get_user_data (q);
if (NULL == data) {
- data = malloc (sizeof (*data));
+ data = calloc (1, sizeof (*data));
if (NULL == data) {
log_err ("Out of memory.");
return -1;
}
- memset (data, 0, sizeof (*data));
data->params = NULL;
data->params_num = 0;
if (strcasecmp (name, src_writers[i].name) != 0)
continue;
- tmp = (c_psql_writer_t **)realloc (*dst_writers,
+ tmp = realloc (*dst_writers,
sizeof (**dst_writers) * (*dst_writers_num + 1));
if (tmp == NULL) {
log_err ("Out of memory.");
return 1;
}
- tmp = (c_psql_writer_t *)realloc (writers,
+ tmp = realloc (writers,
sizeof (*writers) * (writers_num + 1));
if (tmp == NULL) {
log_err ("Out of memory.");
struct statname_lookup_s
{
- char *name;
- char *type;
- char *type_instance;
+ const char *name;
+ const char *type;
+ const char *type_instance;
};
typedef struct statname_lookup_s statname_lookup_t;
user-msec number of CPU milliseconds spent in 'user' mode
}}} */
-const char* const default_server_fields[] = /* {{{ */
+static const char* const default_server_fields[] = /* {{{ */
{
"latency",
"packetcache-hit",
"udp-answers",
"udp-queries",
}; /* }}} */
-int default_server_fields_num = STATIC_ARRAY_SIZE (default_server_fields);
+static int default_server_fields_num = STATIC_ARRAY_SIZE (default_server_fields);
-statname_lookup_t lookup_table[] = /* {{{ */
+static statname_lookup_t lookup_table[] = /* {{{ */
{
/*********************
* Server statistics *
{"unexpected-packets", "dns_answer", "unexpected"},
{"uptime", "uptime", NULL}
}; /* }}} */
-int lookup_table_length = STATIC_ARRAY_SIZE (lookup_table);
+static int lookup_table_length = STATIC_ARRAY_SIZE (lookup_table);
static llist_t *list = NULL;
return (-1);
assert (buffer_size > 0);
- buffer = (char *) malloc (buffer_size);
+ buffer = malloc (buffer_size);
if (buffer == NULL)
{
FUNC_ERROR ("malloc");
else if (status == 0)
break;
- buffer_new = (char *) realloc (buffer, buffer_size + status + 1);
+ buffer_new = realloc (buffer, buffer_size + status + 1);
if (buffer_new == NULL)
{
FUNC_ERROR ("realloc");
return (-1);
}
- temp = (char **) realloc (li->fields,
+ temp = realloc (li->fields,
sizeof (char *) * (li->fields_num + ci->values_num));
if (temp == NULL)
{
return (-1);
}
- item = (list_item_t *) malloc (sizeof (list_item_t));
+ item = calloc (1, sizeof (*item));
if (item == NULL)
{
- ERROR ("powerdns plugin: malloc failed.");
+ ERROR ("powerdns plugin: calloc failed.");
return (-1);
}
- memset (item, '\0', sizeof (list_item_t));
item->instance = strdup (ci->values[0].value.string);
if (item->instance == NULL)
procstat_t *ptr;
int status;
- new = (procstat_t *) malloc (sizeof (procstat_t));
+ new = calloc (1, sizeof (*new));
if (new == NULL)
{
- ERROR ("processes plugin: ps_list_register: malloc failed.");
+ ERROR ("processes plugin: ps_list_register: calloc failed.");
return;
}
- memset (new, 0, sizeof (procstat_t));
sstrncpy (new->name, name, sizeof (new->name));
#if HAVE_REGEX_H
if (regexp != NULL)
{
DEBUG ("ProcessMatch: adding \"%s\" as criteria to process %s.", regexp, name);
- new->re = (regex_t *) malloc (sizeof (regex_t));
+ new->re = malloc (sizeof (*new->re));
if (new->re == NULL)
{
ERROR ("processes plugin: ps_list_register: malloc failed.");
{
procstat_entry_t *new;
- new = (procstat_entry_t *) malloc (sizeof (procstat_entry_t));
+ new = calloc (1, sizeof (*new));
if (new == NULL)
return;
- memset (new, 0, sizeof (procstat_entry_t));
new->id = entry->id;
if (pse == NULL)
/* ------- additional functions for KERNEL_LINUX/HAVE_THREAD_INFO ------- */
#if KERNEL_LINUX
-static procstat_t *ps_read_tasks_status (int pid, procstat_t *ps)
+static procstat_t *ps_read_tasks_status (long pid, procstat_t *ps)
{
char dirname[64];
DIR *dh;
char *fields[8];
int numfields;
- ssnprintf (dirname, sizeof (dirname), "/proc/%i/task", pid);
+ ssnprintf (dirname, sizeof (dirname), "/proc/%li/task", pid);
if ((dh = opendir (dirname)) == NULL)
{
tpid = ent->d_name;
- ssnprintf (filename, sizeof (filename), "/proc/%i/task/%s/status", pid, tpid);
+ ssnprintf (filename, sizeof (filename), "/proc/%li/task/%s/status", pid, tpid);
if ((fh = fopen (filename, "r")) == NULL)
{
DEBUG ("Failed to open file `%s'", filename);
} /* int *ps_read_tasks_status */
/* Read data from /proc/pid/status */
-static procstat_t *ps_read_status (int pid, procstat_t *ps)
+static procstat_t *ps_read_status (long pid, procstat_t *ps)
{
FILE *fh;
char buffer[1024];
char *fields[8];
int numfields;
- ssnprintf (filename, sizeof (filename), "/proc/%i/status", pid);
+ ssnprintf (filename, sizeof (filename), "/proc/%li/status", pid);
if ((fh = fopen (filename, "r")) == NULL)
return (NULL);
return (ps);
} /* procstat_t *ps_read_vmem */
-static procstat_t *ps_read_io (int pid, procstat_t *ps)
+static procstat_t *ps_read_io (long pid, procstat_t *ps)
{
FILE *fh;
char buffer[1024];
char *fields[8];
int numfields;
- ssnprintf (filename, sizeof (filename), "/proc/%i/io", pid);
+ ssnprintf (filename, sizeof (filename), "/proc/%li/io", pid);
if ((fh = fopen (filename, "r")) == NULL)
return (NULL);
return (ps);
} /* procstat_t *ps_read_io */
-int ps_read_process (int pid, procstat_t *ps, char *state)
+static int ps_read_process (long pid, procstat_t *ps, char *state)
{
char filename[64];
char buffer[1024];
memset (ps, 0, sizeof (procstat_t));
- ssnprintf (filename, sizeof (filename), "/proc/%i/stat", pid);
+ ssnprintf (filename, sizeof (filename), "/proc/%li/stat", pid);
status = read_file_contents (filename, buffer, sizeof(buffer) - 1);
if (status <= 0)
* strchr(3) and strrchr(3) to avoid pointer arithmetic which would
* otherwise be required to determine name_len. */
name_start_pos = 0;
- while ((buffer[name_start_pos] != '(')
- && (name_start_pos < buffer_len))
+ while (name_start_pos < buffer_len && buffer[name_start_pos] != '(')
name_start_pos++;
name_end_pos = buffer_len;
- while ((buffer[name_end_pos] != ')')
- && (name_end_pos > 0))
+ while (name_end_pos > 0 && buffer[name_end_pos] != ')')
name_end_pos--;
/* Either '(' or ')' is not found or they are in the wrong order.
fields_len = strsplit (buffer_ptr, fields, STATIC_ARRAY_SIZE (fields));
if (fields_len < 22)
{
- DEBUG ("processes plugin: ps_read_process (pid = %i):"
+ DEBUG ("processes plugin: ps_read_process (pid = %li):"
" `%s' has only %i fields..",
- (int) pid, filename, fields_len);
+ pid, filename, fields_len);
return (-1);
}
/* No VMem data */
ps->vmem_data = -1;
ps->vmem_code = -1;
- DEBUG("ps_read_process: did not get vmem data for pid %i",pid);
+ DEBUG("ps_read_process: did not get vmem data for pid %li", pid);
}
- if (ps->num_lwp <= 0)
+ if (ps->num_lwp == 0)
ps->num_lwp = 1;
ps->num_proc = 1;
}
/* Leave the rest at zero if this is only a zombi */
if (ps->num_proc == 0)
{
- DEBUG ("processes plugin: This is only a zombie: pid = %i; "
+ DEBUG ("processes plugin: This is only a zombie: pid = %li; "
"name = %s;", pid, ps->name);
return (0);
}
ps->io_syscr = -1;
ps->io_syscw = -1;
- DEBUG("ps_read_process: not get io data for pid %i",pid);
+ DEBUG("ps_read_process: not get io data for pid %li", pid);
}
if ( report_ctx_switch )
ps->cswitch_invol = -1;
DEBUG("ps_read_tasks_status: not get context "
- "switch data for pid %i",pid);
+ "switch data for pid %li", pid);
}
}
return (0);
} /* int ps_read_process (...) */
-static char *ps_get_cmdline (pid_t pid, char *name, char *buf, size_t buf_len)
+static char *ps_get_cmdline (long pid, char *name, char *buf, size_t buf_len)
{
char *buf_ptr;
size_t len;
if ((pid < 1) || (NULL == buf) || (buf_len < 2))
return NULL;
- ssnprintf (file, sizeof (file), "/proc/%u/cmdline",
- (unsigned int) pid);
+ ssnprintf (file, sizeof (file), "/proc/%li/cmdline", pid);
errno = 0;
fd = open (file, O_RDONLY);
buf_ptr += status;
len -= status;
- if (len <= 0)
+ if (len == 0)
break;
}
return buf;
} /* char *ps_get_cmdline (...) */
-static int read_fork_rate ()
+static int read_fork_rate (void)
{
FILE *proc_stat;
char buffer[1024];
#endif /*KERNEL_LINUX */
#if KERNEL_SOLARIS
-static char *ps_get_cmdline (pid_t pid, char *name __attribute__((unused)), /* {{{ */
+static char *ps_get_cmdline (long pid, char *name __attribute__((unused)), /* {{{ */
char *buffer, size_t buffer_size)
{
char path[PATH_MAX];
snprintf(f_usage, sizeof (f_usage), "/proc/%li/usage", pid);
- buffer = malloc(sizeof (pstatus_t));
- memset(buffer, 0, sizeof (pstatus_t));
+ buffer = calloc(1, sizeof (pstatus_t));
read_file_contents(filename, buffer, sizeof (pstatus_t));
myStatus = (pstatus_t *) buffer;
- buffer = malloc(sizeof (psinfo_t));
- memset(buffer, 0, sizeof(psinfo_t));
+ buffer = calloc(1, sizeof (psinfo_t));
read_file_contents(f_psinfo, buffer, sizeof (psinfo_t));
myInfo = (psinfo_t *) buffer;
- buffer = malloc(sizeof (prusage_t));
- memset(buffer, 0, sizeof(prusage_t));
+ buffer = calloc(1, sizeof (prusage_t));
read_file_contents(f_usage, buffer, sizeof (prusage_t));
myUsage = (prusage_t *) buffer;
ps->num_proc = 0;
ps->num_lwp = 0;
*state = (char) 'Z';
+
+ sfree(myStatus);
+ sfree(myInfo);
+ sfree(myUsage);
return (0);
} else {
ps->num_proc = 1;
* are retrieved from kstat (module cpu, name sys, class misc, stat nthreads).
* The result is the sum for all the threads created on each cpu
*/
-static int read_fork_rate()
+static int read_fork_rate (void)
{
extern kstat_ctl_t *kc;
kstat_t *ksp_chain = NULL;
struct dirent *ent;
DIR *proc;
- int pid;
+ long pid;
char cmdline[CMDLINE_BUFFER_SIZE];
if (!isdigit (ent->d_name[0]))
continue;
- if ((pid = atoi (ent->d_name)) < 1)
+ if ((pid = atol (ent->d_name)) < 1)
continue;
status = ps_read_process (pid, &ps, &state);
static ignorelist_t *values_list = NULL;
-/*
+/*
* Functions
*/
static void submit (const char *protocol_name,
* DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Sven Trenkel <collectd at semidefinite.de>
+ * Sven Trenkel <collectd at semidefinite.de>
**/
#include <Python.h>
static PyObject *Config_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
Config *self;
-
+
self = (Config *) type->tp_alloc(type, 0);
if (self == NULL)
return NULL;
-
+
self->parent = NULL;
self->key = NULL;
self->values = NULL;
PyObject *key = NULL, *parent = NULL, *values = NULL, *children = NULL, *tmp;
Config *self = (Config *) s;
static char *kwlist[] = {"key", "parent", "values", "children", NULL};
-
+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OOO", kwlist,
&key, &parent, &values, &children))
return -1;
-
+
if (!IS_BYTES_OR_UNICODE(key)) {
PyErr_SetString(PyExc_TypeError, "argument 1 must be str");
Py_XDECREF(parent);
Config *self = (Config *) s;
PyObject *ret = NULL;
static PyObject *node_prefix = NULL, *root_prefix = NULL, *ending = NULL;
-
+
/* This is ok because we have the GIL, so this is thread-save by default. */
if (node_prefix == NULL)
node_prefix = cpy_string_to_unicode_or_bytes("<collectd.Config node ");
ending = cpy_string_to_unicode_or_bytes(">");
if (node_prefix == NULL || root_prefix == NULL || ending == NULL)
return NULL;
-
+
ret = PyObject_Str(self->key);
CPY_SUBSTITUTE(PyObject_Repr, ret, ret);
if (self->parent == NULL || self->parent == Py_None)
else
CPY_STRCAT(&ret, node_prefix);
CPY_STRCAT(&ret, ending);
-
+
return ret;
}
* DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Sven Trenkel <collectd at semidefinite.de>
+ * Sven Trenkel <collectd at semidefinite.de>
**/
#include <Python.h>
static void cpy_build_name(char *buf, size_t size, PyObject *callback, const char *name) {
const char *module = NULL;
PyObject *mod = NULL;
-
+
if (name != NULL) {
snprintf(buf, size, "python.%s", name);
return;
}
-
+
mod = PyObject_GetAttrString(callback, "__module__"); /* New reference. */
if (mod != NULL)
module = cpy_unicode_or_bytes_to_string(&mod);
-
+
if (module != NULL) {
snprintf(buf, size, "python.%s", module);
Py_XDECREF(mod);
return;
}
Py_XDECREF(mod);
-
+
snprintf(buf, size, "python.%p", callback);
PyErr_Clear();
}
int l = 0, i;
const char *typename = NULL, *message = NULL;
PyObject *type, *value, *traceback, *tn, *m, *list;
-
+
PyErr_Fetch(&type, &value, &traceback);
PyErr_NormalizeException(&type, &value, &traceback);
if (type == NULL) return;
}
dict = PyDict_New(); /* New reference. */
if (value_list->meta) {
- int i, num;
+ int num;
char **table;
meta_data_t *meta = value_list->meta;
uint64_t ui;
double d;
_Bool b;
-
+
type = meta_data_type(meta, table[i]);
if (type == MD_TYPE_STRING) {
if (meta_data_get_string(meta, table[i], &string))
char *name = NULL;
PyObject *callback = NULL, *data = NULL, *mod = NULL;
static char *kwlist[] = {"callback", "data", "name", NULL};
-
+
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|Oet", kwlist, &callback, &data, NULL, &name) == 0) return NULL;
if (PyCallable_Check(callback) == 0) {
PyMem_Free(name);
Py_INCREF(callback);
Py_XINCREF(data);
- c = malloc(sizeof(*c));
+ c = calloc(1, sizeof(*c));
if (c == NULL)
return NULL;
- memset (c, 0, sizeof (*c));
c->name = strdup(buf);
c->callback = callback;
int timeout = -1;
char *plugin = NULL, *identifier = NULL;
static char *kwlist[] = {"plugin", "timeout", "identifier", NULL};
-
+
if (PyArg_ParseTupleAndKeywords(args, kwds, "|etiet", kwlist, NULL, &plugin, &timeout, NULL, &identifier) == 0) return NULL;
Py_BEGIN_ALLOW_THREADS
plugin_flush(plugin, timeout, identifier);
char *name = NULL;
PyObject *callback = NULL, *data = NULL;
static char *kwlist[] = {"callback", "data", "name", NULL};
-
+
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|Oet", kwlist, &callback, &data, NULL, &name) == 0) return NULL;
if (PyCallable_Check(callback) == 0) {
PyMem_Free(name);
}
cpy_build_name(buf, sizeof(buf), callback, name);
PyMem_Free(name);
-
+
Py_INCREF(callback);
Py_XINCREF(data);
- c = malloc(sizeof(*c));
+ c = calloc(1, sizeof(*c));
if (c == NULL)
return NULL;
- memset (c, 0, sizeof (*c));
c->name = strdup(buf);
c->callback = callback;
char *name = NULL;
PyObject *callback = NULL, *data = NULL;
static char *kwlist[] = {"callback", "interval", "data", "name", NULL};
-
+
if (PyArg_ParseTupleAndKeywords(args, kwds, "O|dOet", kwlist, &callback, &interval, &data, NULL, &name) == 0) return NULL;
if (PyCallable_Check(callback) == 0) {
PyMem_Free(name);
}
cpy_build_name(buf, sizeof(buf), callback, name);
PyMem_Free(name);
-
+
Py_INCREF(callback);
Py_XINCREF(data);
- c = malloc(sizeof(*c));
+ c = calloc(1, sizeof(*c));
if (c == NULL)
return NULL;
- memset (c, 0, sizeof (*c));
c->name = strdup(buf);
c->callback = callback;
static int cpy_shutdown(void) {
cpy_callback_t *c;
PyObject *ret;
-
+
/* This can happen if the module was loaded but not configured. */
if (state != NULL)
PyEval_RestoreThread(state);
static void *cpy_interactive(void *data) {
sigset_t sigset;
struct sigaction sig_int_action, old;
-
+
/* Signal handler in a plugin? Bad stuff, but the best way to
* handle it I guess. In an interactive session people will
* press Ctrl+C at some time, which will generate a SIGINT.
* This will cause collectd to shutdown, thus killing the
* interactive interpreter, and leaving the terminal in a
* mess. Chances are, this isn't what the user wanted to do.
- *
+ *
* So this is the plan:
* 1. Block SIGINT in the main thread.
* 2. Install our own signal handler that does nothing.
memset (&sig_int_action, '\0', sizeof (sig_int_action));
sig_int_action.sa_handler = cpy_int_handler;
sigaction (SIGINT, &sig_int_action, &old);
-
+
sigemptyset(&sigset);
sigaddset(&sigset, SIGINT);
pthread_sigmask(SIG_UNBLOCK, &sigset, NULL);
PyObject *ret;
static pthread_t thread;
sigset_t sigset;
-
+
if (!Py_IsInitialized()) {
WARNING("python: Plugin loaded but not configured.");
plugin_unregister_shutdown("python");
static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) {
int i;
PyObject *item, *values, *children, *tmp;
-
+
if (parent == NULL)
parent = Py_None;
-
+
values = PyTuple_New(ci->values_num); /* New reference. */
for (i = 0; i < ci->values_num; ++i) {
if (ci->values[i].type == OCONFIG_TYPE_STRING) {
PyTuple_SET_ITEM(values, i, PyBool_FromLong(ci->values[i].value.boolean));
}
}
-
+
tmp = cpy_string_to_unicode_or_bytes(ci->key);
item = PyObject_CallFunction((void *) &ConfigType, "NONO", tmp, parent, values, Py_None);
if (item == NULL)
}
#endif
-static int cpy_init_python() {
+static int cpy_init_python(void) {
PyObject *sys;
PyObject *module;
#else
char *argv = "";
#endif
-
+
Py_Initialize();
-
+
PyType_Ready(&ConfigType);
PyType_Ready(&PluginDataType);
ValuesType.tp_base = &PluginDataType;
for (i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
-
+
if (strcasecmp(item->key, "Interactive") == 0) {
if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN)
continue;
} else if (strcasecmp(item->key, "ModulePath") == 0) {
char *dir = NULL;
PyObject *dir_object;
-
- if (cf_util_get_string(item, &dir) != 0)
+
+ if (cf_util_get_string(item, &dir) != 0)
continue;
dir_object = cpy_string_to_unicode_or_bytes(dir); /* New reference. */
if (dir_object == NULL) {
} else if (strcasecmp(item->key, "Import") == 0) {
char *module_name = NULL;
PyObject *module;
-
- if (cf_util_get_string(item, &module_name) != 0)
+
+ if (cf_util_get_string(item, &module_name) != 0)
continue;
module = PyImport_ImportModule(module_name); /* New reference. */
if (module == NULL) {
char *name = NULL;
cpy_callback_t *c;
PyObject *ret;
-
+
if (cf_util_get_string(item, &name) != 0)
continue;
for (c = cpy_config_callbacks; c; c = c->next) {
* DEALINGS IN THE SOFTWARE.
*
* Authors:
- * Sven Trenkel <collectd at semidefinite.de>
+ * Sven Trenkel <collectd at semidefinite.de>
**/
#include <Python.h>
static PyObject *l_type = NULL, *l_type_instance = NULL, *l_plugin = NULL, *l_plugin_instance = NULL;
static PyObject *l_host = NULL, *l_time = NULL;
PluginData *self = (PluginData *) s;
-
+
if (l_type == NULL)
l_type = cpy_string_to_unicode_or_bytes("(type=");
if (l_type_instance == NULL)
l_host = cpy_string_to_unicode_or_bytes(",host=");
if (l_time == NULL)
l_time = cpy_string_to_unicode_or_bytes(",time=");
-
+
if (!l_type || !l_type_instance || !l_plugin || !l_plugin_instance || !l_host || !l_time)
return NULL;
-
+
ret = cpy_string_to_unicode_or_bytes(s->ob_type->tp_name);
CPY_STRCAT(&ret, l_type);
return ret;
}
-static char time_doc[] = "This is the Unix timestap of the time this value was read.\n"
+static char time_doc[] = "This is the Unix timestamp of the time this value was read.\n"
"For dispatching values this can be set to 0 which means \"now\".\n"
"This means the time the value is actually dispatched, not the time\n"
"it was set to 0.";
static char host_doc[] = "The hostname of the host this value was read from.\n"
"For dispatching this can be set to an empty string which means\n"
- "the local hostname as defined in the collectd.conf.";
+ "the local hostname as defined in collectd.conf.";
static char type_doc[] = "The type of this value. This type has to be defined\n"
- "in your types.db. Attempting to set it to any other value will\n"
- "raise a TypeError exception.\n"
- "Assigning a type is mandetory, calling dispatch without doing\n"
+ "in the types.db file. Attempting to set it to any other value\n"
+ "will raise a TypeError exception.\n"
+ "Assigning a type is mandatory, calling dispatch without doing\n"
"so will raise a RuntimeError exception.";
static char type_instance_doc[] = "";
static char plugin_instance_doc[] = "";
static char PluginData_doc[] = "This is an internal class that is the base for Values\n"
- "and Notification. It is pretty useless by itself and was therefore not\n"
+ "and Notification. It is pretty useless by itself and is therefore not\n"
"exported to the collectd module.";
static PyObject *PluginData_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
PluginData *self;
-
+
self = (PluginData *) type->tp_alloc(type, 0);
if (self == NULL)
return NULL;
-
+
self->time = 0;
self->host[0] = 0;
self->plugin[0] = 0;
char *type = NULL, *plugin_instance = NULL, *type_instance = NULL, *plugin = NULL, *host = NULL;
static char *kwlist[] = {"type", "plugin_instance", "type_instance",
"plugin", "host", "time", NULL};
-
+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etetetetetd", kwlist, NULL, &type,
NULL, &plugin_instance, NULL, &type_instance, NULL, &plugin, NULL, &host, &time))
return -1;
-
+
if (type && plugin_get_ds(type) == NULL) {
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
FreeAll();
static PyObject *PluginData_repr(PyObject *s) {
PyObject *ret;
static PyObject *l_closing = NULL;
-
+
if (l_closing == NULL)
l_closing = cpy_string_to_unicode_or_bytes(")");
-
+
if (l_closing == NULL)
return NULL;
-
+
ret = cpy_common_repr(s);
CPY_STRCAT(&ret, l_closing);
return ret;
static PyObject *PluginData_getstring(PyObject *self, void *data) {
const char *value = ((char *) self) + (intptr_t) data;
-
+
return cpy_string_to_unicode_or_bytes(value);
}
static int PluginData_setstring(PyObject *self, PyObject *value, void *data) {
char *old;
const char *new;
-
+
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute");
return -1;
static int PluginData_settype(PyObject *self, PyObject *value, void *data) {
char *old;
const char *new;
-
+
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute");
return -1;
static char values_doc[] = "These are the actual values that get dispatched to collectd.\n"
"It has to be a sequence (a tuple or list) of numbers.\n"
"The size of the sequence and the type of its content depend on the type\n"
- "member your types.db file. For more information on this read the types.db\n"
- "man page.\n"
+ "member in the types.db file. For more information on this read the\n"
+ "types.db man page.\n"
"\n"
"If the sequence does not have the correct size upon dispatch a RuntimeError\n"
"exception will be raised. If the content of the sequence is not a number,\n"
static char meta_doc[] = "These are the meta data for this Value object.\n"
"It has to be a dictionary of numbers, strings or bools. All keys must be\n"
"strings. int and long objects will be dispatched as signed integers unless\n"
- "they are between 2**63 and 2**64-1, which will result in a unsigned integer.\n"
+ "they are between 2**63 and 2**64-1, which will result in an unsigned integer.\n"
"You can force one of these storage classes by using the classes\n"
"collectd.Signed and collectd.Unsigned. A meta object received by a write\n"
"callback will always contain Signed or Unsigned objects.";
static char write_doc[] = "write([destination][, type][, values][, plugin_instance][, type_instance]"
"[, plugin][, host][, time][, interval]) -> None. Dispatch a value list.\n"
"\n"
- "Write this instance to a single plugin or all plugins if 'destination' is obmitted.\n"
+ "Write this instance to a single plugin or all plugins if 'destination' is omitted.\n"
"This will bypass the main collectd process and all filtering and caching.\n"
"Other than that it works similar to 'dispatch'. In most cases 'dispatch' should be\n"
"used instead of 'write'.\n";
static PyObject *Values_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
Values *self;
-
+
self = (Values *) PluginData_new(type, args, kwds);
if (self == NULL)
return NULL;
-
+
self->values = PyList_New(0);
self->meta = PyDict_New();
self->interval = 0;
char *type = NULL, *plugin_instance = NULL, *type_instance = NULL, *plugin = NULL, *host = NULL;
static char *kwlist[] = {"type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
-
+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etOetetetetddO", kwlist,
NULL, &type, &values, NULL, &plugin_instance, NULL, &type_instance,
NULL, &plugin, NULL, &host, &time, &interval, &meta))
return -1;
-
+
if (type && plugin_get_ds(type) == NULL) {
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
FreeAll();
} else {
Py_INCREF(values);
}
-
+
if (meta == NULL) {
meta = PyDict_New();
PyErr_Clear();
} else {
Py_INCREF(meta);
}
-
+
tmp = self->values;
self->values = values;
Py_XDECREF(tmp);
-
+
tmp = self->meta;
self->meta = meta;
Py_XDECREF(tmp);
int i, s;
meta_data_t *m = NULL;
PyObject *l;
-
+
if ((meta == NULL) || (meta == Py_None))
return NULL;
for (i = 0; i < s; ++i) {
const char *string, *keystring;
PyObject *key, *value, *item, *tmp;
-
+
item = PyList_GET_ITEM(l, i);
key = PyTuple_GET_ITEM(item, 0);
Py_INCREF(key);
PyObject *values = self->values, *meta = self->meta;
double time = self->data.time, interval = self->interval;
char *host = NULL, *plugin = NULL, *plugin_instance = NULL, *type = NULL, *type_instance = NULL;
-
+
static char *kwlist[] = {"type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etOetetetetddO", kwlist,
PyObject *values = self->values, *meta = self->meta;
double time = self->data.time, interval = self->interval;
char *host = NULL, *plugin = NULL, *plugin_instance = NULL, *type = NULL, *type_instance = NULL, *dest = NULL;
-
+
static char *kwlist[] = {"destination", "type", "values", "plugin_instance", "type_instance",
"plugin", "host", "time", "interval", "meta", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "et|etOetetetetdiO", kwlist, NULL, &dest,
value_list.values_len = size;
value_list.time = DOUBLE_TO_CDTIME_T(time);
value_list.interval = DOUBLE_TO_CDTIME_T(interval);
- value_list.meta = cpy_build_meta(meta);;
+ value_list.meta = cpy_build_meta(meta);
if (value_list.host[0] == 0)
sstrncpy(value_list.host, hostname_g, sizeof(value_list.host));
if (value_list.plugin[0] == 0)
PyObject *ret, *tmp;
static PyObject *l_interval = NULL, *l_values = NULL, *l_meta = NULL, *l_closing = NULL;
Values *self = (Values *) s;
-
+
if (l_interval == NULL)
l_interval = cpy_string_to_unicode_or_bytes(",interval=");
if (l_values == NULL)
l_meta = cpy_string_to_unicode_or_bytes(",meta=");
if (l_closing == NULL)
l_closing = cpy_string_to_unicode_or_bytes(")");
-
+
if (l_interval == NULL || l_values == NULL || l_meta == NULL || l_closing == NULL)
return NULL;
-
+
ret = cpy_common_repr(s);
if (self->interval != 0) {
CPY_STRCAT(&ret, l_interval);
char *type = NULL, *plugin_instance = NULL, *type_instance = NULL, *plugin = NULL, *host = NULL;
static char *kwlist[] = {"type", "message", "plugin_instance", "type_instance",
"plugin", "host", "time", "severity", NULL};
-
+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etetetetetetdi", kwlist,
NULL, &type, NULL, &message, NULL, &plugin_instance, NULL, &type_instance,
NULL, &plugin, NULL, &host, &time, &severity))
return -1;
-
+
if (type && plugin_get_ds(type) == NULL) {
PyErr_Format(PyExc_TypeError, "Dataset %s not found", type);
FreeAll();
int severity = self->severity;
char *host = NULL, *plugin = NULL, *plugin_instance = NULL, *type = NULL, *type_instance = NULL;
char *message = NULL;
-
+
static char *kwlist[] = {"type", "message", "plugin_instance", "type_instance",
"plugin", "host", "time", "severity", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|etetetetetetdi", kwlist,
static PyObject *Notification_new(PyTypeObject *type, PyObject *args, PyObject *kwds) {
Notification *self;
-
+
self = (Notification *) PluginData_new(type, args, kwds);
if (self == NULL)
return NULL;
-
+
self->message[0] = 0;
self->severity = 0;
return (PyObject *) self;
static int Notification_setstring(PyObject *self, PyObject *value, void *data) {
char *old;
const char *new;
-
+
if (value == NULL) {
PyErr_SetString(PyExc_TypeError, "Cannot delete this attribute");
return -1;
PyObject *ret, *tmp;
static PyObject *l_severity = NULL, *l_message = NULL, *l_closing = NULL;
Notification *self = (Notification *) s;
-
+
if (l_severity == NULL)
l_severity = cpy_string_to_unicode_or_bytes(",severity=");
if (l_message == NULL)
l_message = cpy_string_to_unicode_or_bytes(",message=");
if (l_closing == NULL)
l_closing = cpy_string_to_unicode_or_bytes(")");
-
+
if (l_severity == NULL || l_message == NULL || l_closing == NULL)
return NULL;
-
+
ret = cpy_common_repr(s);
if (self->severity != 0) {
CPY_STRCAT(&ret, l_severity);
rq = calloc(1, sizeof(*rq));
if (rq == NULL) {
- ERROR("redis plugin: calloca failed adding redis_query.");
+ ERROR("redis plugin: calloc failed adding redis_query.");
return NULL;
}
status = cf_util_get_string_buffer(ci, rq->query, sizeof(rq->query));
return (0);
} /* }}} int redis_init */
-int redis_handle_info (char *node, char const *info_line, char const *type, char const *type_instance, char const *field_name, int ds_type) /* {{{ */
+static int redis_handle_info (char *node, char const *info_line, char const *type, char const *type_instance, char const *field_name, int ds_type) /* {{{ */
{
char *str = strstr (info_line, field_name);
static char buf[MAX_REDIS_VAL_SIZE];
} /* }}} int redis_handle_info */
-int redis_handle_query (redisContext *rh, redis_node_t *rn, redis_query_t *rq) /* {{{ */
+static int redis_handle_query (redisContext *rh, redis_node_t *rn, redis_query_t *rq) /* {{{ */
{
redisReply *rr;
const data_set_t *ds;
redis_submit(rn->name, rq->type, (strlen(rq->instance) >0)?rq->instance:NULL, val);
freeReplyObject (rr);
return 0;
-} /* }}} int redis_handle_info */
+} /* }}} int redis_handle_query */
static int redis_read (void) /* {{{ */
{
if (strlen (rn->passwd) > 0)
{
- DEBUG ("redis plugin: authenticanting node `%s' passwd(%s).", rn->name, rn->passwd);
- rr = redisCommand (rh, "AUTH %s", rn->passwd);
+ DEBUG ("redis plugin: authenticating node `%s' passwd(%s).", rn->name, rn->passwd);
- if (rr == NULL || rr->type != REDIS_REPLY_STATUS)
+ if ((rr = redisCommand (rh, "AUTH %s", rn->passwd)) == NULL)
{
WARNING ("redis plugin: unable to authenticate on node `%s'.", rn->name);
- if (rr != NULL)
- freeReplyObject (rr);
+ goto redis_fail;
+ }
- redisFree (rh);
- continue;
+ if (rr->type != REDIS_REPLY_STATUS)
+ {
+ WARNING ("redis plugin: invalid authentication on node `%s'.", rn->name);
+ goto redis_fail;
}
+
+ freeReplyObject (rr);
}
if ((rr = redisCommand(rh, "INFO")) == NULL)
{
- WARNING ("redis plugin: unable to connect to node `%s'.", rn->name);
- redisFree (rh);
- continue;
+ WARNING ("redis plugin: unable to get info from node `%s'.", rn->name);
+ goto redis_fail;
}
redis_handle_info (rn->name, rr->str, "uptime", NULL, "uptime_in_seconds", DS_TYPE_GAUGE);
redis_handle_info (rn->name, rr->str, "volatile_changes", NULL, "changes_since_last_save", DS_TYPE_GAUGE);
redis_handle_info (rn->name, rr->str, "total_connections", NULL, "total_connections_received", DS_TYPE_DERIVE);
redis_handle_info (rn->name, rr->str, "total_operations", NULL, "total_commands_processed", DS_TYPE_DERIVE);
- redis_handle_info (rn->name, rr->str, "expired_keys", NULL, "expired_keys", DS_TYPE_GAUGE);
+ redis_handle_info (rn->name, rr->str, "expired_keys", NULL, "expired_keys", DS_TYPE_DERIVE);
+ redis_handle_info (rn->name, rr->str, "evicted_keys", NULL, "evicted_keys", DS_TYPE_DERIVE);
redis_handle_info (rn->name, rr->str, "pubsub", "channels", "pubsub_channels", DS_TYPE_GAUGE);
redis_handle_info (rn->name, rr->str, "pubsub", "patterns", "pubsub_patterns", DS_TYPE_GAUGE);
redis_handle_info (rn->name, rr->str, "current_connections", "slaves", "connected_slaves", DS_TYPE_GAUGE);
-
- freeReplyObject (rr);
+ redis_handle_info (rn->name, rr->str, "cache_result", "hits", "keyspace_hits", DS_TYPE_DERIVE);
+ redis_handle_info (rn->name, rr->str, "cache_result", "misses", "keyspace_misses", DS_TYPE_DERIVE);
+ redis_handle_info (rn->name, rr->str, "total_bytes", "input", "total_net_input_bytes", DS_TYPE_DERIVE);
+ redis_handle_info (rn->name, rr->str, "total_bytes", "output", "total_net_output_bytes", DS_TYPE_DERIVE);
for (rq = rn->queries; rq != NULL; rq = rq->next)
redis_handle_query(rh, rn, rq);
+redis_fail:
+ if (rr != NULL)
+ freeReplyObject (rr);
redisFree (rh);
}
+++ /dev/null
-option java_package = "com.aphyr.riemann";
-option java_outer_classname = "Proto";
-
-message State {
- optional int64 time = 1;
- optional string state = 2;
- optional string service = 3;
- optional string host = 4;
- optional string description = 5;
- optional bool once = 6;
- repeated string tags = 7;
- optional float ttl = 8;
-}
-
-message Event {
- optional int64 time = 1;
- optional string state = 2;
- optional string service = 3;
- optional string host = 4;
- optional string description = 5;
- repeated string tags = 7;
- optional float ttl = 8;
- repeated Attribute attributes = 9;
-
- optional sint64 metric_sint64 = 13;
- optional double metric_d = 14;
- optional float metric_f = 15;
-}
-
-message Query {
- optional string string = 1;
-}
-
-message Msg {
- optional bool ok = 2;
- optional string error = 3;
- repeated State states = 4;
- optional Query query = 5;
- repeated Event events = 6;
-}
-
-message Attribute {
- required string key = 1;
- optional string value = 2;
-}
int status;
int i;
- router_data = malloc (sizeof (*router_data));
+ router_data = calloc (1, sizeof (*router_data));
if (router_data == NULL)
return (-1);
- memset (router_data, 0, sizeof (*router_data));
router_data->connection = NULL;
router_data->node = NULL;
router_data->service = NULL;
status = ssnprintf (buffer + offset, buffer_len - offset,
":%llu", vl->values[i].counter);
}
- else if (ds->ds[i].type == DS_TYPE_GAUGE)
+ else if (ds->ds[i].type == DS_TYPE_GAUGE)
{
status = ssnprintf (buffer + offset, buffer_len - offset,
":%f", vl->values[i].gauge);
else /* if (ds->ds[i].type == DS_TYPE_ABSOLUTE) */ {
status = ssnprintf (buffer + offset, buffer_len - offset,
":%"PRIu64, vl->values[i].absolute);
-
+
}
if ((status < 1) || (status >= (buffer_len - offset)))
assert (template == NULL);
new_argc = 2 + argc;
- new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *));
+ new_argv = malloc ((new_argc + 1) * sizeof (*new_argv));
if (new_argv == NULL)
{
ERROR ("rrdtool plugin: malloc failed.");
}
/* Update `tv_next_update' */
- if (write_rate > 0.0)
+ if (write_rate > 0.0)
{
gettimeofday (&tv_now, /* timezone = */ NULL);
tv_next_update.tv_sec = tv_now.tv_sec;
{
rrd_queue_t *queue_entry;
- queue_entry = (rrd_queue_t *) malloc (sizeof (rrd_queue_t));
+ queue_entry = malloc (sizeof (*queue_entry));
if (queue_entry == NULL)
return (-1);
{
if (strcmp (this->filename, filename) == 0)
break;
-
+
prev = this;
this = this->next;
}
}
else /* ancient and no values -> waste of memory */
{
- char **tmp = (char **) realloc ((void *) keys,
+ char **tmp = realloc (keys,
(keys_num + 1) * sizeof (char *));
if (tmp == NULL)
{
}
} /* while (c_avl_iterator_next) */
c_avl_iterator_destroy (iter);
-
+
for (i = 0; i < keys_num; i++)
{
if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
return (-1);
}
- values_new = (char **) realloc ((void *) rc->values,
+ values_new = realloc ((void *) rc->values,
(rc->values_num + 1) * sizeof (char *));
if (values_new == NULL)
{
while ((ptr = strtok_r (dummy, ", \t", &saveptr)) != NULL)
{
dummy = NULL;
-
+
tmp_alloc = realloc (rrdcreate_config.timespans,
sizeof (int) * (rrdcreate_config.timespans_num + 1));
if (tmp_alloc == NULL)
*
* Authors:
* Florian octo Forster <octo at collectd.org>
- *
+ *
* Lubos Stanek <lubek at users.sourceforge.net> Wed Oct 27, 2006
* - config ExtendedSensorNaming option
* - precise sensor feature selection (chip-bus-address/type-feature)
typedef struct sensors_labeltypes_s sensors_labeltypes_t;
/* finite list of known labels extracted from lm_sensors */
-static sensors_labeltypes_t known_features[] =
+static sensors_labeltypes_t known_features[] =
{
{ "fan1", SENSOR_TYPE_FANSPEED },
{ "fan2", SENSOR_TYPE_FANSPEED },
{
"Sensor",
"IgnoreSelected",
- "SensorConfigFile"
+ "SensorConfigFile",
+ "UseLabels"
};
static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
} featurelist_t;
static char *conffile = NULL;
+static _Bool use_labels = 0;
/* #endif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500) */
#else /* if SENSORS_API_VERSION >= 0x500 */
"as bug."
#endif
-featurelist_t *first_feature = NULL;
+static featurelist_t *first_feature = NULL;
static ignorelist_t *sensor_list;
#if SENSORS_API_VERSION < 0x400
if (IS_TRUE (value))
ignorelist_set_invert (sensor_list, 0);
}
+#if (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
+ else if (strcasecmp (key, "UseLabels") == 0)
+ {
+ use_labels = IS_TRUE (value) ? 1 : 0;
+ }
+#endif
else
{
return (-1);
return (0);
}
-void sensors_free_features (void)
+static void sensors_free_features (void)
{
featurelist_t *thisft;
featurelist_t *nextft;
FILE *fh = NULL;
featurelist_t *last_feature = NULL;
-
+
const sensors_chip_name *chip;
int chip_num;
continue;
}
- fl = (featurelist_t *) malloc (sizeof (featurelist_t));
+ fl = calloc (1, sizeof (*fl));
if (fl == NULL)
{
- ERROR ("sensors plugin: malloc failed.");
+ ERROR ("sensors plugin: calloc failed.");
continue;
}
- memset (fl, '\0', sizeof (featurelist_t));
fl->chip = chip;
fl->data = feature;
&& (subfeature->type != SENSORS_SUBFEATURE_POWER_INPUT))
continue;
- fl = (featurelist_t *) malloc (sizeof (featurelist_t));
+ fl = calloc (1, sizeof (*fl));
if (fl == NULL)
{
- ERROR ("sensors plugin: malloc failed.");
+ ERROR ("sensors plugin: calloc failed.");
continue;
}
- memset (fl, '\0', sizeof (featurelist_t));
fl->chip = chip;
fl->feature = feature;
int status;
char plugin_instance[DATA_MAX_NAME_LEN];
char type_instance[DATA_MAX_NAME_LEN];
+ char *sensor_label;
const char *type;
status = sensors_get_value (fl->chip,
if (status < 0)
continue;
- sstrncpy (type_instance, fl->feature->name,
- sizeof (type_instance));
+ if (use_labels)
+ {
+ sensor_label = sensors_get_label (fl->chip, fl->feature);
+ sstrncpy (type_instance, sensor_label, sizeof (type_instance));
+ free (sensor_label);
+ }
+ else
+ {
+ sstrncpy (type_instance, fl->feature->name,
+ sizeof (type_instance));
+ }
if (fl->feature->type == SENSORS_FEATURE_IN)
type = "voltage";
struct config_device *cfdev;
int i;
- if (!(cfdev = malloc(sizeof(struct config_device)))) {
- ERROR("sigrok plugin: malloc() failed.");
+ if (!(cfdev = calloc(1, sizeof(*cfdev)))) {
+ ERROR("sigrok plugin: calloc failed.");
return -1;
}
- memset(cfdev, 0, sizeof(*cfdev));
if (cf_util_get_string(ci, &cfdev->name)) {
free(cfdev);
WARNING("sigrok plugin: Invalid device name.");
return 0;
}
-static char *sigrok_value_type(const struct sr_datafeed_analog *analog)
+static const char *sigrok_value_type(const struct sr_datafeed_analog *analog)
{
- char *s;
+ const char *s;
if (analog->mq == SR_MQ_VOLTAGE)
s = "voltage";
drvopts = NULL;
if (cfdev->conn) {
- if (!(src = malloc(sizeof(struct sr_config))))
+ if (!(src = malloc(sizeof(*src))))
return -1;
src->key = SR_CONF_CONN;
src->data = g_variant_new_string(cfdev->conn);
drvopts = g_slist_append(drvopts, src);
}
if (cfdev->serialcomm) {
- if (!(src = malloc(sizeof(struct sr_config))))
+ if (!(src = malloc(sizeof(*src))))
return -1;
src->key = SR_CONF_SERIALCOMM;
src->data = g_variant_new_string(cfdev->serialcomm);
return (0);
} /* int smart_config */
-static void smart_submit (const char *dev, char *type, char *type_inst, double value)
+static void smart_submit (const char *dev, const char *type,
+ const char *type_inst, double value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
sfree (dd->values);
dd->values_len = 0;
- dd->values = (oid_t *) malloc (sizeof (oid_t) * ci->values_num);
+ dd->values = malloc (sizeof (*dd->values) * ci->values_num);
if (dd->values == NULL)
return (-1);
dd->values_len = (size_t) ci->values_num;
int status = 0;
int i;
- dd = (data_definition_t *) malloc (sizeof (data_definition_t));
+ dd = calloc (1, sizeof (*dd));
if (dd == NULL)
return (-1);
- memset (dd, '\0', sizeof (data_definition_t));
status = cf_util_get_string(ci, &dd->name);
if (status != 0)
}
data_list_len = host->data_list_len + ci->values_num;
- data_list = (data_definition_t **) realloc (host->data_list,
+ data_list = realloc (host->data_list,
sizeof (data_definition_t *) * data_list_len);
if (data_list == NULL)
return (-1);
char cb_name[DATA_MAX_NAME_LEN];
user_data_t cb_data;
- hd = (host_definition_t *) malloc (sizeof (host_definition_t));
+ hd = calloc (1, sizeof (*hd));
if (hd == NULL)
return (-1);
- memset (hd, '\0', sizeof (host_definition_t));
hd->version = 2;
C_COMPLAIN_INIT (&hd->complaint);
csnmp_oid_init (&vb_name, vb->name, vb->name_length);
- il = malloc (sizeof (*il));
+ il = calloc (1, sizeof (*il));
if (il == NULL)
{
- ERROR ("snmp plugin: malloc failed.");
+ ERROR ("snmp plugin: calloc failed.");
return (-1);
}
- memset (il, 0, sizeof (*il));
il->next = NULL;
status = csnmp_oid_suffix (&il->suffix, &vb_name, &dd->instance.oid);
continue;
}
- vt = malloc (sizeof (*vt));
+ vt = calloc (1, sizeof (*vt));
if (vt == NULL)
{
- ERROR ("snmp plugin: malloc failed.");
+ ERROR ("snmp plugin: calloc failed.");
status = -1;
break;
}
- memset (vt, 0, sizeof (*vt));
vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type,
data->scale, data->shift, host->name, data->name);
static int csnmp_read_value (host_definition_t *host, data_definition_t *data)
{
struct snmp_pdu *req;
- struct snmp_pdu *res;
+ struct snmp_pdu *res = NULL;
struct variable_list *vb;
const data_set_t *ds;
}
vl.values_len = ds->ds_num;
- vl.values = (value_t *) malloc (sizeof (value_t) * vl.values_len);
+ vl.values = malloc (sizeof (*vl.values) * vl.values_len);
if (vl.values == NULL)
return (-1);
for (i = 0; i < vl.values_len; i++)
for (i = 0; i < data->values_len; i++)
snmp_add_null_var (req, data->values[i].oid, data->values[i].oid_len);
- res = NULL;
status = snmp_sess_synch_response (host->sess_handle, req, &res);
if ((status != STAT_SUCCESS) || (res == NULL))
if (res != NULL)
snmp_free_pdu (res);
- res = NULL;
sfree (errstr);
sfree (vl.values);
data->scale, data->shift, host->name, data->name);
} /* for (res->variables) */
- if (res != NULL)
- snmp_free_pdu (res);
- res = NULL;
+ snmp_free_pdu (res);
DEBUG ("snmp plugin: -> plugin_dispatch_values (&vl);");
plugin_dispatch_values (&vl);
return (NULL);
}
- metric = malloc (sizeof (*metric));
+ metric = calloc (1, sizeof (*metric));
if (metric == NULL)
{
- ERROR ("statsd plugin: malloc failed.");
+ ERROR ("statsd plugin: calloc failed.");
sfree (key_copy);
return (NULL);
}
- memset (metric, 0, sizeof (*metric));
metric->type = type;
metric->latency = NULL;
static _Bool report_by_device = 0;
/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_TWO_ARGS */
+#elif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS
+/* No global variables */
+/* #endif HAVE_SWAPCTL && HAVE_SWAPCTL_THREE_ARGS */
+
#elif defined(VM_SWAPUSAGE)
/* No global variables */
/* #endif defined(VM_SWAPUSAGE) */
char buf[1024] = "";
size_t offset = 0;
int log_severity;
- char *severity_string;
+ const char *severity_string;
int status;
if (n->severity > notif_severity)
return 1;
}
- res = (tbl_result_t *)realloc (tbl->results,
+ res = realloc (tbl->results,
(tbl->results_num + 1) * sizeof (*tbl->results));
if (res == NULL) {
char errbuf[1024];
return 1;
}
- tbl = (tbl_t *)realloc (tables, (tables_num + 1) * sizeof (*tables));
+ tbl = realloc (tables, (tables_num + 1) * sizeof (*tables));
if (NULL == tbl) {
char errbuf[1024];
log_err ("realloc failed: %s.",
};
typedef struct ctail_config_match_s ctail_config_match_t;
-cu_tail_match_t **tail_match_list = NULL;
-size_t tail_match_list_num = 0;
-cdtime_t tail_match_list_intervals[255];
+static cu_tail_match_t **tail_match_list = NULL;
+static size_t tail_match_list_num = 0;
+static cdtime_t tail_match_list_intervals[255];
static int ctail_config_add_match_dstype (ctail_config_match_t *cm,
oconfig_item_t *ci)
{
cu_tail_match_t **temp;
- temp = (cu_tail_match_t **) realloc (tail_match_list,
+ temp = realloc (tail_match_list,
sizeof (cu_tail_match_t *) * (tail_match_list_num + 1));
if (temp == NULL)
{
static cdtime_t parse_time (char const *tbuf)
{
double t;
- char *endptr = 0;
+ char *endptr = NULL;
errno = 0;
t = strtod (tbuf, &endptr);
int status;
int i;
- md = (metric_definition_t *)malloc(sizeof(*md));
+ md = calloc(1, sizeof(*md));
if (md == NULL)
return (-1);
- memset(md, 0, sizeof(*md));
md->name = NULL;
md->type = NULL;
md->instance = NULL;
char cb_name[DATA_MAX_NAME_LEN];
user_data_t cb_data;
- id = malloc(sizeof(*id));
+ id = calloc(1, sizeof(*id));
if (id == NULL)
return (-1);
- memset(id, 0, sizeof(*id));
id->instance = NULL;
id->path = NULL;
id->metric_list = NULL;
int status;
int i;
- data = (tn_data_t *) malloc (sizeof (*data));
+ data = calloc (1, sizeof (*data));
if (data == NULL)
{
- ERROR ("tn_create: malloc failed.");
+ ERROR ("tn_create: calloc failed.");
return (-ENOMEM);
}
- memset (data, 0, sizeof (*data));
data->message = NULL;
data->severity = 0;
return (NULL);
sz = strlen (orig) + 1;
- dest = (char *) malloc (sz);
+ dest = malloc (sz);
if (dest == NULL)
return (NULL);
return (-1);
}
- act = (tr_action_t *) malloc (sizeof (*act));
+ act = calloc (1, sizeof (*act));
if (act == NULL)
{
- ERROR ("tr_config_add_action: malloc failed.");
+ ERROR ("tr_config_add_action: calloc failed.");
return (-ENOMEM);
}
- memset (act, 0, sizeof (*act));
act->replacement = NULL;
act->may_be_empty = may_be_empty;
int status;
int i;
- data = (tr_data_t *) malloc (sizeof (*data));
+ data = calloc (1, sizeof (*data));
if (data == NULL)
{
- ERROR ("tr_create: malloc failed.");
+ ERROR ("tr_create: calloc failed.");
return (-ENOMEM);
}
- memset (data, 0, sizeof (*data));
data->host = NULL;
data->plugin = NULL;
/* Allocate space for the char pointers */
new_data_sources_num = data->data_sources_num + ((size_t) ci->values_num);
- temp = (char **) realloc (data->data_sources,
+ temp = realloc (data->data_sources,
new_data_sources_num * sizeof (char *));
if (temp == NULL)
{
int status;
int i;
- data = (ts_data_t *) malloc (sizeof (*data));
+ data = calloc (1, sizeof (*data));
if (data == NULL)
{
- ERROR ("ts_create: malloc failed.");
+ ERROR ("ts_create: calloc failed.");
return (-ENOMEM);
}
- memset (data, 0, sizeof (*data));
data->factor = NAN;
data->offset = NAN;
char *plugin_instance;
/* char *type; */
char *type_instance;
+ meta_data_t *meta;
};
typedef struct ts_data_s ts_data_t;
+int ts_util_get_key_and_string_wo_strdup (const oconfig_item_t *ci, char **ret_key, char **ret_string) /* {{{ */
+{
+ if ((ci->values_num != 2)
+ || (ci->values[0].type != OCONFIG_TYPE_STRING)
+ || (ci->values[1].type != OCONFIG_TYPE_STRING))
+ {
+ ERROR ("ts_util_get_key_and_string_wo_strdup: The %s option requires "
+ "exactly two string argument.", ci->key);
+ return (-1);
+ }
+
+ *ret_key = ci->values[0].value.string;
+ *ret_string = ci->values[1].value.string;
+
+ return (0);
+} /* }}} int ts_util_get_key_and_string_wo_strdup */
+
static int ts_config_add_string (char **dest, /* {{{ */
const oconfig_item_t *ci, int may_be_empty)
{
return (0);
} /* }}} int ts_config_add_string */
+static int ts_config_add_meta (meta_data_t **dest, /* {{{ */
+ const oconfig_item_t *ci, int may_be_empty)
+{
+ char *key = NULL;
+ char *string = NULL;
+ int status;
+
+ status = ts_util_get_key_and_string_wo_strdup (ci, &key, &string);
+ if (status != 0)
+ return (status);
+
+ if (strlen (key) == 0)
+ {
+ ERROR ("Target `set': The `%s' option does not accept empty string as first argument.",
+ ci->key);
+ return (-1);
+ }
+
+ if (!may_be_empty && (strlen (string) == 0))
+ {
+ ERROR ("Target `set': The `%s' option does not accept empty string as second argument.",
+ ci->key);
+ return (-1);
+ }
+
+ if ((*dest) == NULL)
+ {
+ // Create a new meta_data_t
+ if ((*dest = meta_data_create()) == NULL)
+ {
+ ERROR ("Target `set': failed to create a meta data for `%s'.", ci->key);
+ return (-1);
+ }
+ }
+
+ return (meta_data_add_string (*dest, key, string));
+} /* }}} int ts_config_add_meta */
+
static int ts_destroy (void **user_data) /* {{{ */
{
ts_data_t *data;
free (data->plugin_instance);
/* free (data->type); */
free (data->type_instance);
+ meta_data_destroy(data->meta);
free (data);
return (0);
int status;
int i;
- data = (ts_data_t *) malloc (sizeof (*data));
+ data = calloc (1, sizeof (*data));
if (data == NULL)
{
- ERROR ("ts_create: malloc failed.");
+ ERROR ("ts_create: calloc failed.");
return (-ENOMEM);
}
- memset (data, 0, sizeof (*data));
data->host = NULL;
data->plugin = NULL;
data->plugin_instance = NULL;
/* data->type = NULL; */
data->type_instance = NULL;
+ data->meta = NULL;
status = 0;
for (i = 0; i < ci->children_num; i++)
else if (strcasecmp ("TypeInstance", child->key) == 0)
status = ts_config_add_string (&data->type_instance, child,
/* may be empty = */ 1);
+ else if (strcasecmp ("MetaDataSet", child->key) == 0)
+ status = ts_config_add_meta (&data->meta, child,
+ /* may be empty = */ 1);
else
{
ERROR ("Target `set': The `%s' configuration option is not understood "
&& (data->plugin == NULL)
&& (data->plugin_instance == NULL)
/* && (data->type == NULL) */
- && (data->type_instance == NULL))
+ && (data->type_instance == NULL)
+ && (data->meta == NULL))
{
ERROR ("Target `set': You need to set at least one of `Host', "
- "`Plugin', `PluginInstance' or `TypeInstance'.");
+ "`Plugin', `PluginInstance', `TypeInstance', "
+ "`MetaDataSet' or `MetaDataEval'.");
status = -1;
}
return (-EINVAL);
}
+ if (data->meta != NULL)
+ {
+ meta_data_clone_merge(&(vl->meta), data->meta);
+ }
+
#define SET_FIELD(f) if (data->f != NULL) { sstrncpy (vl->f, data->f, sizeof (vl->f)); }
SET_FIELD (host);
SET_FIELD (plugin);
static uint32_t sequence_number = 0;
#endif
-enum
+static enum
{
SRC_DUNNO,
SRC_NETLINK,
if ((ret == NULL) && (create != 0))
{
- ret = (port_entry_t *) malloc (sizeof (port_entry_t));
+ ret = calloc (1, sizeof (*ret));
if (ret == NULL)
return (NULL);
- memset (ret, '\0', sizeof (port_entry_t));
ret->port = port;
ret->next = port_list_head;
return (-1);
}
- buffer = (char *) malloc (buffer_len);
+ buffer = malloc (buffer_len);
if (buffer == NULL)
{
ERROR ("tcpconns plugin: malloc failed.");
}
/* Allocate memory */
- entry = (vserver_list_t *) malloc (sizeof (vserver_list_t));
+ entry = calloc (1, sizeof (*entry));
if (entry == NULL)
{
- ERROR ("teamspeak2 plugin: malloc failed.");
+ ERROR ("teamspeak2 plugin: calloc failed.");
return (-1);
}
- memset (entry, 0, sizeof (vserver_list_t));
/* Save data */
entry->port = vserver_port;
if (type_instance != NULL)
sstrncpy (vl.type_instance, type_instance,
sizeof (vl.type_instance));
-
+
plugin_dispatch_values (&vl);
} /* void tss2_submit_gauge */
* Receive a single line from the given file object
*/
char *temp;
-
+
/*
* fgets is blocking but much easier then doing anything else
* TODO: Non-blocking Version would be safer
char buffer[4096];
char *value;
char *endptr = NULL;
-
+
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
return (-1);
}
buffer[sizeof (buffer) - 1] = 0;
-
+
if (strncmp ("average_packet_loss=", buffer,
strlen ("average_packet_loss=")) == 0)
{
}
value++;
}
-
+
value = &buffer[20];
-
+
packet_loss = strtod (value, &endptr);
if (value == endptr)
{
buffer);
}
}
-
+
*ret_value = packet_loss;
return (0);
} /* int tss2_vserver_gapl */
char *key;
char *value;
char *endptr = NULL;
-
+
/* Read one line of the server's answer */
status = tss2_receive_line (read_fh, buffer, sizeof (buffer));
if (status != 0)
{
/* Server variable found */
int status;
-
+
status = tss2_add_vserver (atoi (value));
if (status != 0)
return (1);
continue;
}
}
-
+
if (success == 0)
return (-1);
return (0);
/* Get rid of the configuration */
sfree (config_host);
sfree (config_port);
-
+
return (0);
} /* int tss2_shutdown */
return (0);
} /* int ted_open_device */
-static void ted_submit (char *type, double value)
+static void ted_submit (const char *type, double value)
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
# define DBL_PRECISION 1e-12
#endif
-#define DEF_TEST(func) static int test_##func ()
+#define DEF_TEST(func) static int test_##func (void)
#define RUN_TEST(func) do { \
int status; \
"ForceUseProcfs"
};
-const char *const dirname_sysfs = "/sys/class/thermal";
-const char *const dirname_procfs = "/proc/acpi/thermal_zone";
+static const char *const dirname_sysfs = "/sys/class/thermal";
+static const char *const dirname_procfs = "/proc/acpi/thermal_zone";
static _Bool force_procfs = 0;
static ignorelist_t *device_list;
return (-1);
}
- th_copy = (threshold_t *) malloc (sizeof (threshold_t));
+ th_copy = malloc (sizeof (*th_copy));
if (th_copy == NULL)
{
sfree (name_copy);
return (-1);
}
memcpy (th_copy, th, sizeof (threshold_t));
- th_ptr = NULL;
DEBUG ("ut_threshold_add: Adding entry `%s'", name);
return (0);
} /* }}} int ut_missing */
-int ut_config (oconfig_item_t *ci)
+static int ut_config (oconfig_item_t *ci)
{ /* {{{ */
int i;
int status = 0;
return (0);
}
-static void printerr()
+static void printerr (void)
{
int ecode = tcrdbecode(rdb);
ERROR ("tokyotyrant plugin: error: %d, %s",
static void tt_open_db (void)
{
- char* host = NULL;
- int port = DEFAULT_PORT;
+ const char *host;
+ int port = DEFAULT_PORT;
if (rdb != NULL)
return;
*/
static inline int __attribute__((warn_unused_result))
delta_thread(struct thread_data *delta, const struct thread_data *new, const struct thread_data *old,
- const struct core_data *core_delta)
+ const struct core_data *cdelta)
{
delta->tsc = new->tsc - old->tsc;
* it is possible for mperf's non-halted cycles + idle states
* to exceed TSC's all cycles: show c1 = 0% in that case.
*/
- if ((delta->mperf + core_delta->c3 + core_delta->c6 + core_delta->c7) > delta->tsc)
+ if ((delta->mperf + cdelta->c3 + cdelta->c6 + cdelta->c7) > delta->tsc)
delta->c1 = 0;
else {
/* normal case, derive c1 */
- delta->c1 = delta->tsc - delta->mperf - core_delta->c3
- - core_delta->c6 - core_delta->c7;
+ delta->c1 = delta->tsc - delta->mperf - cdelta->c3
+ - cdelta->c6 - cdelta->c7;
}
if (delta->mperf == 0) {
* Identify the functionality of the CPU
*/
static int __attribute__((warn_unused_result))
-probe_cpu()
+probe_cpu(void)
{
unsigned int eax, ebx, ecx, edx, max_level;
unsigned int fms, family, model;
* Build a local representation of the cpu distribution
*/
static int __attribute__((warn_unused_result))
-topology_probe()
+topology_probe(void)
{
unsigned int i;
int ret;
CPU_FREE(cpu_present_set);
cpu_present_set = NULL;
- cpu_present_set = 0;
+ cpu_present_setsize = 0;
CPU_FREE(cpu_affinity_set);
cpu_affinity_set = NULL;
-absolute value:ABSOLUTE:0:U
-apache_bytes value:DERIVE:0:U
-apache_connections value:GAUGE:0:65535
-apache_idle_workers value:GAUGE:0:65535
-apache_requests value:DERIVE:0:U
-apache_scoreboard value:GAUGE:0:65535
-ath_nodes value:GAUGE:0:65535
-ath_stat value:DERIVE:0:U
-backends value:GAUGE:0:65535
-bitrate value:GAUGE:0:4294967295
-blocked_clients value:GAUGE:0:U
-bytes value:GAUGE:0:U
-cache_eviction value:DERIVE:0:U
-cache_operation value:DERIVE:0:U
-cache_ratio value:GAUGE:0:100
-cache_result value:DERIVE:0:U
-cache_size value:GAUGE:0:1125899906842623
-capacity value:GAUGE:0:U
-ceph_bytes value:GAUGE:U:U
-ceph_latency value:GAUGE:U:U
-ceph_rate value:DERIVE:0:U
-changes_since_last_save value:GAUGE:0:U
-charge value:GAUGE:0:U
-compression_ratio value:GAUGE:0:2
-compression uncompressed:DERIVE:0:U, compressed:DERIVE:0:U
-connections value:DERIVE:0:U
-conntrack value:GAUGE:0:4294967295
-contextswitch value:DERIVE:0:U
-count value:GAUGE:0:U
-counter value:COUNTER:U:U
-cpufreq value:GAUGE:0:U
-cpu value:DERIVE:0:U
-current_connections value:GAUGE:0:U
-current_sessions value:GAUGE:0:U
-current value:GAUGE:U:U
-delay value:GAUGE:-1000000:1000000
-derive value:DERIVE:0:U
-df_complex value:GAUGE:0:U
-df_inodes value:GAUGE:0:U
-df used:GAUGE:0:1125899906842623, free:GAUGE:0:1125899906842623
-disk_latency read:GAUGE:0:U, write:GAUGE:0:U
-disk_merged read:DERIVE:0:U, write:DERIVE:0:U
-disk_octets read:DERIVE:0:U, write:DERIVE:0:U
-disk_ops_complex value:DERIVE:0:U
-disk_ops read:DERIVE:0:U, write:DERIVE:0:U
-disk_time read:DERIVE:0:U, write:DERIVE:0:U
-disk_io_time io_time:DERIVE:0:U, weighted_io_time:DERIVE:0:U
-dns_answer value:DERIVE:0:U
-dns_notify value:DERIVE:0:U
-dns_octets queries:DERIVE:0:U, responses:DERIVE:0:U
-dns_opcode value:DERIVE:0:U
-dns_qtype_cached value:GAUGE:0:4294967295
-dns_qtype value:DERIVE:0:U
-dns_query value:DERIVE:0:U
-dns_question value:DERIVE:0:U
-dns_rcode value:DERIVE:0:U
-dns_reject value:DERIVE:0:U
-dns_request value:DERIVE:0:U
-dns_resolver value:DERIVE:0:U
-dns_response value:DERIVE:0:U
-dns_transfer value:DERIVE:0:U
-dns_update value:DERIVE:0:U
-dns_zops value:DERIVE:0:U
-drbd_resource value:DERIVE:0:U
-duration seconds:GAUGE:0:U
-email_check value:GAUGE:0:U
-email_count value:GAUGE:0:U
-email_size value:GAUGE:0:U
-entropy value:GAUGE:0:4294967295
-expired_keys value:GAUGE:0:U
-fanspeed value:GAUGE:0:U
-file_handles value:GAUGE:0:U
-file_size value:GAUGE:0:U
-files value:GAUGE:0:U
-flow value:GAUGE:0:U
-fork_rate value:DERIVE:0:U
-frequency_offset value:GAUGE:-1000000:1000000
-frequency value:GAUGE:0:U
-fscache_stat value:DERIVE:0:U
-gauge value:GAUGE:U:U
-hash_collisions value:DERIVE:0:U
-http_request_methods value:DERIVE:0:U
-http_requests value:DERIVE:0:U
-http_response_codes value:DERIVE:0:U
-humidity value:GAUGE:0:100
-if_collisions value:DERIVE:0:U
-if_dropped rx:DERIVE:0:U, tx:DERIVE:0:U
-if_errors rx:DERIVE:0:U, tx:DERIVE:0:U
-if_multicast value:DERIVE:0:U
-if_octets rx:DERIVE:0:U, tx:DERIVE:0:U
-if_packets rx:DERIVE:0:U, tx:DERIVE:0:U
-if_rx_errors value:DERIVE:0:U
-if_rx_octets value:DERIVE:0:U
-if_tx_errors value:DERIVE:0:U
-if_tx_octets value:DERIVE:0:U
-invocations value:DERIVE:0:U
-io_octets rx:DERIVE:0:U, tx:DERIVE:0:U
-io_packets rx:DERIVE:0:U, tx:DERIVE:0:U
-ipt_bytes value:DERIVE:0:U
-ipt_packets value:DERIVE:0:U
-irq value:DERIVE:0:U
-latency value:GAUGE:0:U
-links value:GAUGE:0:U
-load shortterm:GAUGE:0:5000, midterm:GAUGE:0:5000, longterm:GAUGE:0:5000
-md_disks value:GAUGE:0:U
-memcached_command value:DERIVE:0:U
-memcached_connections value:GAUGE:0:U
-memcached_items value:GAUGE:0:U
-memcached_octets rx:DERIVE:0:U, tx:DERIVE:0:U
-memcached_ops value:DERIVE:0:U
-memory value:GAUGE:0:281474976710656
-memory_lua value:GAUGE:0:281474976710656
-multimeter value:GAUGE:U:U
-mutex_operations value:DERIVE:0:U
-mysql_commands value:DERIVE:0:U
-mysql_handler value:DERIVE:0:U
-mysql_locks value:DERIVE:0:U
-mysql_log_position value:DERIVE:0:U
-mysql_octets rx:DERIVE:0:U, tx:DERIVE:0:U
-mysql_bpool_pages value:GAUGE:0:U
-mysql_bpool_bytes value:GAUGE:0:U
-mysql_bpool_counters value:DERIVE:0:U
-mysql_innodb_data value:DERIVE:0:U
-mysql_innodb_dblwr value:DERIVE:0:U
-mysql_innodb_log value:DERIVE:0:U
-mysql_innodb_pages value:DERIVE:0:U
-mysql_innodb_row_lock value:DERIVE:0:U
-mysql_innodb_rows value:DERIVE:0:U
-mysql_select value:DERIVE:0:U
-mysql_sort value:DERIVE:0:U
-nfs_procedure value:DERIVE:0:U
-nginx_connections value:GAUGE:0:U
-nginx_requests value:DERIVE:0:U
-node_octets rx:DERIVE:0:U, tx:DERIVE:0:U
-node_rssi value:GAUGE:0:255
-node_stat value:DERIVE:0:U
-node_tx_rate value:GAUGE:0:127
-objects value:GAUGE:0:U
-operations value:DERIVE:0:U
-packets value:DERIVE:0:U
-pending_operations value:GAUGE:0:U
-percent value:GAUGE:0:100.1
-percent_bytes value:GAUGE:0:100.1
-percent_inodes value:GAUGE:0:100.1
-pf_counters value:DERIVE:0:U
-pf_limits value:DERIVE:0:U
-pf_source value:DERIVE:0:U
-pf_states value:GAUGE:0:U
-pf_state value:DERIVE:0:U
-pg_blks value:DERIVE:0:U
-pg_db_size value:GAUGE:0:U
-pg_n_tup_c value:DERIVE:0:U
-pg_n_tup_g value:GAUGE:0:U
-pg_numbackends value:GAUGE:0:U
-pg_scan value:DERIVE:0:U
-pg_xact value:DERIVE:0:U
-ping_droprate value:GAUGE:0:100
-ping_stddev value:GAUGE:0:65535
-ping value:GAUGE:0:65535
-players value:GAUGE:0:1000000
-power value:GAUGE:0:U
-pressure value:GAUGE:0:U
-protocol_counter value:DERIVE:0:U
-ps_code value:GAUGE:0:9223372036854775807
-ps_count processes:GAUGE:0:1000000, threads:GAUGE:0:1000000
-ps_cputime user:DERIVE:0:U, syst:DERIVE:0:U
-ps_data value:GAUGE:0:9223372036854775807
-ps_disk_octets read:DERIVE:0:U, write:DERIVE:0:U
-ps_disk_ops read:DERIVE:0:U, write:DERIVE:0:U
-ps_pagefaults minflt:DERIVE:0:U, majflt:DERIVE:0:U
-ps_rss value:GAUGE:0:9223372036854775807
-ps_stacksize value:GAUGE:0:9223372036854775807
-ps_state value:GAUGE:0:65535
-ps_vm value:GAUGE:0:9223372036854775807
-pubsub value:GAUGE:0:U
-queue_length value:GAUGE:0:U
-records value:GAUGE:0:U
-requests value:GAUGE:0:U
-response_time value:GAUGE:0:U
-response_code value:GAUGE:0:U
-route_etx value:GAUGE:0:U
-route_metric value:GAUGE:0:U
-routes value:GAUGE:0:U
-segments value:GAUGE:0:65535
-serial_octets rx:DERIVE:0:U, tx:DERIVE:0:U
-signal_noise value:GAUGE:U:0
-signal_power value:GAUGE:U:0
-signal_quality value:GAUGE:0:U
-smart_poweron value:GAUGE:0:U
-smart_powercycles value:GAUGE:0:U
-smart_badsectors value:GAUGE:0:U
-smart_temperature value:GAUGE:-300:300
+absolute value:ABSOLUTE:0:U
+apache_bytes value:DERIVE:0:U
+apache_connections value:GAUGE:0:65535
+apache_idle_workers value:GAUGE:0:65535
+apache_requests value:DERIVE:0:U
+apache_scoreboard value:GAUGE:0:65535
+ath_nodes value:GAUGE:0:65535
+ath_stat value:DERIVE:0:U
+backends value:GAUGE:0:65535
+bitrate value:GAUGE:0:4294967295
+blocked_clients value:GAUGE:0:U
+bytes value:GAUGE:0:U
+cache_eviction value:DERIVE:0:U
+cache_operation value:DERIVE:0:U
+cache_ratio value:GAUGE:0:100
+cache_result value:DERIVE:0:U
+cache_size value:GAUGE:0:1125899906842623
+capacity value:GAUGE:0:U
+ceph_bytes value:GAUGE:U:U
+ceph_latency value:GAUGE:U:U
+ceph_rate value:DERIVE:0:U
+changes_since_last_save value:GAUGE:0:U
+charge value:GAUGE:0:U
+compression uncompressed:DERIVE:0:U, compressed:DERIVE:0:U
+compression_ratio value:GAUGE:0:2
+connections value:DERIVE:0:U
+conntrack value:GAUGE:0:4294967295
+contextswitch value:DERIVE:0:U
+count value:GAUGE:0:U
+counter value:COUNTER:U:U
+cpu value:DERIVE:0:U
+cpufreq value:GAUGE:0:U
+current value:GAUGE:U:U
+current_connections value:GAUGE:0:U
+current_sessions value:GAUGE:0:U
+delay value:GAUGE:-1000000:1000000
+derive value:DERIVE:0:U
+df used:GAUGE:0:1125899906842623, free:GAUGE:0:1125899906842623
+df_complex value:GAUGE:0:U
+df_inodes value:GAUGE:0:U
+disk_io_time io_time:DERIVE:0:U, weighted_io_time:DERIVE:0:U
+disk_latency read:GAUGE:0:U, write:GAUGE:0:U
+disk_merged read:DERIVE:0:U, write:DERIVE:0:U
+disk_octets read:DERIVE:0:U, write:DERIVE:0:U
+disk_ops read:DERIVE:0:U, write:DERIVE:0:U
+disk_ops_complex value:DERIVE:0:U
+disk_time read:DERIVE:0:U, write:DERIVE:0:U
+dns_answer value:DERIVE:0:U
+dns_notify value:DERIVE:0:U
+dns_octets queries:DERIVE:0:U, responses:DERIVE:0:U
+dns_opcode value:DERIVE:0:U
+dns_qtype value:DERIVE:0:U
+dns_qtype_cached value:GAUGE:0:4294967295
+dns_query value:DERIVE:0:U
+dns_question value:DERIVE:0:U
+dns_rcode value:DERIVE:0:U
+dns_reject value:DERIVE:0:U
+dns_request value:DERIVE:0:U
+dns_resolver value:DERIVE:0:U
+dns_response value:DERIVE:0:U
+dns_transfer value:DERIVE:0:U
+dns_update value:DERIVE:0:U
+dns_zops value:DERIVE:0:U
+drbd_resource value:DERIVE:0:U
+duration seconds:GAUGE:0:U
+email_check value:GAUGE:0:U
+email_count value:GAUGE:0:U
+email_size value:GAUGE:0:U
+entropy value:GAUGE:0:4294967295
+evicted_keys value:DERIVE:0:U
+expired_keys value:DERIVE:0:U
+fanspeed value:GAUGE:0:U
+file_handles value:GAUGE:0:U
+file_size value:GAUGE:0:U
+files value:GAUGE:0:U
+flow value:GAUGE:0:U
+fork_rate value:DERIVE:0:U
+frequency value:GAUGE:0:U
+frequency_offset value:GAUGE:-1000000:1000000
+fscache_stat value:DERIVE:0:U
+gauge value:GAUGE:U:U
+hash_collisions value:DERIVE:0:U
+http_request_methods value:DERIVE:0:U
+http_requests value:DERIVE:0:U
+http_response_codes value:DERIVE:0:U
+humidity value:GAUGE:0:100
+if_collisions value:DERIVE:0:U
+if_dropped rx:DERIVE:0:U, tx:DERIVE:0:U
+if_errors rx:DERIVE:0:U, tx:DERIVE:0:U
+if_multicast value:DERIVE:0:U
+if_octets rx:DERIVE:0:U, tx:DERIVE:0:U
+if_packets rx:DERIVE:0:U, tx:DERIVE:0:U
+if_rx_errors value:DERIVE:0:U
+if_rx_octets value:DERIVE:0:U
+if_tx_errors value:DERIVE:0:U
+if_tx_octets value:DERIVE:0:U
+invocations value:DERIVE:0:U
+io_octets rx:DERIVE:0:U, tx:DERIVE:0:U
+io_packets rx:DERIVE:0:U, tx:DERIVE:0:U
+ipt_bytes value:DERIVE:0:U
+ipt_packets value:DERIVE:0:U
+irq value:DERIVE:0:U
+latency value:GAUGE:0:U
+links value:GAUGE:0:U
+load shortterm:GAUGE:0:5000, midterm:GAUGE:0:5000, longterm:GAUGE:0:5000
+md_disks value:GAUGE:0:U
+memcached_command value:DERIVE:0:U
+memcached_connections value:GAUGE:0:U
+memcached_items value:GAUGE:0:U
+memcached_octets rx:DERIVE:0:U, tx:DERIVE:0:U
+memcached_ops value:DERIVE:0:U
+memory value:GAUGE:0:281474976710656
+memory_lua value:GAUGE:0:281474976710656
+multimeter value:GAUGE:U:U
+mutex_operations value:DERIVE:0:U
+mysql_bpool_bytes value:GAUGE:0:U
+mysql_bpool_counters value:DERIVE:0:U
+mysql_bpool_pages value:GAUGE:0:U
+mysql_commands value:DERIVE:0:U
+mysql_handler value:DERIVE:0:U
+mysql_innodb_data value:DERIVE:0:U
+mysql_innodb_dblwr value:DERIVE:0:U
+mysql_innodb_log value:DERIVE:0:U
+mysql_innodb_pages value:DERIVE:0:U
+mysql_innodb_row_lock value:DERIVE:0:U
+mysql_innodb_rows value:DERIVE:0:U
+mysql_locks value:DERIVE:0:U
+mysql_log_position value:DERIVE:0:U
+mysql_octets rx:DERIVE:0:U, tx:DERIVE:0:U
+mysql_select value:DERIVE:0:U
+mysql_sort value:DERIVE:0:U
+mysql_sort_merge_passes value:DERIVE:0:U
+mysql_sort_rows value:DERIVE:0:U
+nfs_procedure value:DERIVE:0:U
+nginx_connections value:GAUGE:0:U
+nginx_requests value:DERIVE:0:U
+node_octets rx:DERIVE:0:U, tx:DERIVE:0:U
+node_rssi value:GAUGE:0:255
+node_stat value:DERIVE:0:U
+node_tx_rate value:GAUGE:0:127
+objects value:GAUGE:0:U
+operations value:DERIVE:0:U
+packets value:DERIVE:0:U
+pending_operations value:GAUGE:0:U
+percent value:GAUGE:0:100.1
+percent_bytes value:GAUGE:0:100.1
+percent_inodes value:GAUGE:0:100.1
+pf_counters value:DERIVE:0:U
+pf_limits value:DERIVE:0:U
+pf_source value:DERIVE:0:U
+pf_state value:DERIVE:0:U
+pf_states value:GAUGE:0:U
+pg_blks value:DERIVE:0:U
+pg_db_size value:GAUGE:0:U
+pg_n_tup_c value:DERIVE:0:U
+pg_n_tup_g value:GAUGE:0:U
+pg_numbackends value:GAUGE:0:U
+pg_scan value:DERIVE:0:U
+pg_xact value:DERIVE:0:U
+ping value:GAUGE:0:65535
+ping_droprate value:GAUGE:0:100
+ping_stddev value:GAUGE:0:65535
+players value:GAUGE:0:1000000
+power value:GAUGE:0:U
+pressure value:GAUGE:0:U
+protocol_counter value:DERIVE:0:U
+ps_code value:GAUGE:0:9223372036854775807
+ps_count processes:GAUGE:0:1000000, threads:GAUGE:0:1000000
+ps_cputime user:DERIVE:0:U, syst:DERIVE:0:U
+ps_data value:GAUGE:0:9223372036854775807
+ps_disk_octets read:DERIVE:0:U, write:DERIVE:0:U
+ps_disk_ops read:DERIVE:0:U, write:DERIVE:0:U
+ps_pagefaults minflt:DERIVE:0:U, majflt:DERIVE:0:U
+ps_rss value:GAUGE:0:9223372036854775807
+ps_stacksize value:GAUGE:0:9223372036854775807
+ps_state value:GAUGE:0:65535
+ps_vm value:GAUGE:0:9223372036854775807
+pubsub value:GAUGE:0:U
+queue_length value:GAUGE:0:U
+records value:GAUGE:0:U
+requests value:GAUGE:0:U
+response_code value:GAUGE:0:U
+response_time value:GAUGE:0:U
+route_etx value:GAUGE:0:U
+route_metric value:GAUGE:0:U
+routes value:GAUGE:0:U
+segments value:GAUGE:0:65535
+serial_octets rx:DERIVE:0:U, tx:DERIVE:0:U
+signal_noise value:GAUGE:U:0
+signal_power value:GAUGE:U:0
+signal_quality value:GAUGE:0:U
smart_attribute current:GAUGE:0:255, worst:GAUGE:0:255, threshold:GAUGE:0:255, pretty:GAUGE:0:U
-snr value:GAUGE:0:U
-spam_check value:GAUGE:0:U
-spam_score value:GAUGE:U:U
-spl value:GAUGE:U:U
-swap_io value:DERIVE:0:U
-swap value:GAUGE:0:1099511627776
-tcp_connections value:GAUGE:0:4294967295
-temperature value:GAUGE:U:U
-threads value:GAUGE:0:U
-time_dispersion value:GAUGE:-1000000:1000000
-timeleft value:GAUGE:0:U
-time_offset value:GAUGE:-1000000:1000000
-total_bytes value:DERIVE:0:U
-total_connections value:DERIVE:0:U
-total_objects value:DERIVE:0:U
-total_operations value:DERIVE:0:U
-total_requests value:DERIVE:0:U
-total_sessions value:DERIVE:0:U
-total_threads value:DERIVE:0:U
-total_time_in_ms value:DERIVE:0:U
-total_values value:DERIVE:0:U
-uptime value:GAUGE:0:4294967295
-users value:GAUGE:0:65535
-vcl value:GAUGE:0:65535
-vcpu value:GAUGE:0:U
-virt_cpu_total value:DERIVE:0:U
-virt_vcpu value:DERIVE:0:U
-vmpage_action value:DERIVE:0:U
-vmpage_faults minflt:DERIVE:0:U, majflt:DERIVE:0:U
-vmpage_io in:DERIVE:0:U, out:DERIVE:0:U
-vmpage_number value:GAUGE:0:4294967295
-volatile_changes value:GAUGE:0:U
-voltage_threshold value:GAUGE:U:U, threshold:GAUGE:U:U
-voltage value:GAUGE:U:U
-vs_memory value:GAUGE:0:9223372036854775807
-vs_processes value:GAUGE:0:65535
-vs_threads value:GAUGE:0:65535
+smart_badsectors value:GAUGE:0:U
+smart_powercycles value:GAUGE:0:U
+smart_poweron value:GAUGE:0:U
+smart_temperature value:GAUGE:-300:300
+snr value:GAUGE:0:U
+spam_check value:GAUGE:0:U
+spam_score value:GAUGE:U:U
+spl value:GAUGE:U:U
+swap value:GAUGE:0:1099511627776
+swap_io value:DERIVE:0:U
+tcp_connections value:GAUGE:0:4294967295
+temperature value:GAUGE:U:U
+threads value:GAUGE:0:U
+time_dispersion value:GAUGE:-1000000:1000000
+time_offset value:GAUGE:-1000000:1000000
+timeleft value:GAUGE:0:U
+total_bytes value:DERIVE:0:U
+total_connections value:DERIVE:0:U
+total_objects value:DERIVE:0:U
+total_operations value:DERIVE:0:U
+total_requests value:DERIVE:0:U
+total_sessions value:DERIVE:0:U
+total_threads value:DERIVE:0:U
+total_time_in_ms value:DERIVE:0:U
+total_values value:DERIVE:0:U
+uptime value:GAUGE:0:4294967295
+users value:GAUGE:0:65535
+vcl value:GAUGE:0:65535
+vcpu value:GAUGE:0:U
+virt_cpu_total value:DERIVE:0:U
+virt_vcpu value:DERIVE:0:U
+vmpage_action value:DERIVE:0:U
+vmpage_faults minflt:DERIVE:0:U, majflt:DERIVE:0:U
+vmpage_io in:DERIVE:0:U, out:DERIVE:0:U
+vmpage_number value:GAUGE:0:4294967295
+volatile_changes value:GAUGE:0:U
+voltage value:GAUGE:U:U
+voltage_threshold value:GAUGE:U:U, threshold:GAUGE:U:U
+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
+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
do
{
- char *grpname;
+ const char *grpname;
struct group *g;
struct group sg;
char grbuf[2048];
pthread_exit ((void *) 1);
}
- remote_fd = (int *) malloc (sizeof (int));
+ remote_fd = malloc (sizeof (*remote_fd));
if (remote_fd == NULL)
{
char errbuf[1024];
* Copyright (C) 2005-2007 Sebastian Harl
* Copyright (C) 2005 Niki W. Waibel
* Copyright (C) 2005-2007 Florian octo Forster
- * Copyright (C) 2008 Oleg King
+ * Copyright (C) 2008 Oleg King
*
* 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
users_submit (users);
/* #endif HAVE_GETUTXENT */
-
+
#elif HAVE_GETUTENT
unsigned int users = 0;
struct utmp *entry = NULL;
us = sg_get_user_stats ();
# endif
if (us == NULL)
- return (-1);
+ return (-1);
users_submit ((gauge_t)
# if HAVE_LIBSTATGRAB_0_90
#include "common.h"
#include "plugin.h"
#include "utils_parse_option.h"
+#include "utils_cmd_flush.h"
int handle_flush (FILE *fh, char *buffer)
{
#include "utils_cache.h"
#include "utils_parse_option.h"
+#include "utils_cmd_getval.h"
#define print_to_socket(fh, ...) \
do { \
#include "plugin.h"
#include "utils_parse_option.h"
+#include "utils_cmd_putnotif.h"
#define print_to_socket(fh, ...) \
do { \
#include "plugin.h"
#include "utils_parse_option.h"
+#include "utils_cmd_putval.h"
#define print_to_socket(fh, ...) \
do { \
sfree (identifier_copy);
vl.values_len = ds->ds_num;
- vl.values = (value_t *) malloc (vl.values_len * sizeof (value_t));
+ vl.values = malloc (vl.values_len * sizeof (*vl.values));
if (vl.values == NULL)
{
print_to_socket (fh, "-1 malloc failed.\n");
} /* while (*buffer != 0) */
/* Done parsing the options. */
- print_to_socket (fh, "0 Success: %i %s been dispatched.\n",
+ if (fh!=stdout)
+ print_to_socket (fh, "0 Success: %i %s been dispatched.\n",
values_submitted,
(values_submitted == 1) ? "value has" : "values have");
}
array_len = *ret_array_len;
- array = (char **) realloc (*ret_array,
+ array = realloc (*ret_array,
sizeof (char *) * (array_len + ci->values_num));
if (array == NULL)
{
assert (((size_t) r_area->ds->ds_num) == r->values_num);
assert (r->values_num > 0);
- vl.values = (value_t *) calloc (r->values_num, sizeof (value_t));
+ vl.values = calloc (r->values_num, sizeof (*vl.values));
if (vl.values == NULL)
{
- ERROR ("db query utils: malloc failed.");
+ ERROR ("db query utils: calloc failed.");
return (-1);
}
vl.values_len = r_area->ds->ds_num;
ERROR ("db query utils: udb_result_submit: Parsing `%s' as %s failed.",
value_str, DS_TYPE_TO_STRING (r_area->ds->ds[i].type));
errno = EINVAL;
+ free (vl.values);
return (-1);
}
}
sstrncpy (vl.type, r->type, sizeof (vl.type));
/* Set vl.type_instance {{{ */
- if (r->instances_num <= 0)
+ if (r->instances_num == 0)
{
if (r->instance_prefix == NULL)
vl.type_instance[0] = 0;
= (size_t *) calloc (r->instances_num, sizeof (size_t));
if (prep_area->instances_pos == NULL)
{
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ ERROR ("db query utils: udb_result_prepare_result: calloc failed.");
BAIL_OUT (-ENOMEM);
}
= (char **) calloc (r->instances_num, sizeof (char *));
if (prep_area->instances_buffer == NULL)
{
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ ERROR ("db query utils: udb_result_prepare_result: calloc failed.");
BAIL_OUT (-ENOMEM);
}
} /* if (r->instances_num > 0) */
= (size_t *) calloc (r->values_num, sizeof (size_t));
if (prep_area->values_pos == NULL)
{
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ ERROR ("db query utils: udb_result_prepare_result: calloc failed.");
BAIL_OUT (-ENOMEM);
}
= (char **) calloc (r->values_num, sizeof (char *));
if (prep_area->values_buffer == NULL)
{
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ ERROR ("db query utils: udb_result_prepare_result: calloc failed.");
BAIL_OUT (-ENOMEM);
}
= (size_t *) calloc (r->metadata_num, sizeof (size_t));
if (prep_area->metadata_pos == NULL)
{
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ ERROR ("db query utils: udb_result_prepare_result: calloc failed.");
BAIL_OUT (-ENOMEM);
}
= (char **) calloc (r->metadata_num, sizeof (char *));
if (prep_area->metadata_buffer == NULL)
{
- ERROR ("db query utils: udb_result_prepare_result: malloc failed.");
+ ERROR ("db query utils: udb_result_prepare_result: calloc failed.");
BAIL_OUT (-ENOMEM);
}
ci->values_num, (ci->values_num == 1) ? "" : "s");
}
- r = (udb_result_t *) malloc (sizeof (*r));
+ r = calloc (1, sizeof (*r));
if (r == NULL)
{
- ERROR ("db query utils: malloc failed.");
+ ERROR ("db query utils: calloc failed.");
return (-1);
}
- memset (r, 0, sizeof (*r));
r->type = NULL;
r->instance_prefix = NULL;
r->instances = NULL;
/*
* Query private functions
*/
-void udb_query_free_one (udb_query_t *q) /* {{{ */
+static void udb_query_free_one (udb_query_t *q) /* {{{ */
{
if (q == NULL)
return;
return (-1);
}
- q = (udb_query_t *) malloc (sizeof (*q));
+ q = calloc (1, sizeof (*q));
if (q == NULL)
{
- ERROR ("db query utils: malloc failed.");
+ ERROR ("db query utils: calloc failed.");
return (-1);
}
- memset (q, 0, sizeof (*q));
q->min_version = 0;
q->max_version = UINT_MAX;
{
udb_query_t **temp;
- temp = (udb_query_t **) realloc (query_list,
+ temp = realloc (query_list,
sizeof (*query_list) * (query_list_len + 1));
if (temp == NULL)
{
continue;
tmp_list_len = *dst_list_len;
- tmp_list = (udb_query_t **) realloc (*dst_list, (tmp_list_len + 1)
+ tmp_list = realloc (*dst_list, (tmp_list_len + 1)
* sizeof (udb_query_t *));
if (tmp_list == NULL)
{
udb_result_preparation_area_t **next_r_area;
udb_result_t *r;
- q_area = malloc (sizeof (*q_area));
+ q_area = calloc (1, sizeof (*q_area));
if (q_area == NULL)
return NULL;
- memset (q_area, 0, sizeof (*q_area));
next_r_area = &q_area->result_prep_areas;
for (r = q->results; r != NULL; r = r->next)
{
udb_result_preparation_area_t *r_area;
- r_area = malloc (sizeof (*r_area));
+ r_area = calloc (1, sizeof (*r_area));
if (r_area == NULL)
{
udb_result_preparation_area_t *a = q_area->result_prep_areas;
return NULL;
}
- memset (r_area, 0, sizeof (*r_area));
-
*next_r_area = r_area;
next_r_area = &r_area->next;
}
typedef int (*udb_query_create_callback_t) (udb_query_t *q,
oconfig_item_t *ci);
-/*
+/*
* Public functions
*/
int udb_query_create (udb_query_t ***ret_query_list,
void udb_query_set_user_data (udb_query_t *q, void *user_data);
void *udb_query_get_user_data (udb_query_t *q);
-/*
+/*
* udb_query_check_version
*
* Returns 0 if the query is NOT suitable for `version' and >0 if the
/*
* Global variables
*/
-int qtype_counts[T_MAX];
-int opcode_counts[OP_MAX];
-int qclass_counts[C_MAX];
#if HAVE_PCAP_H
static pcap_t *pcap_obj = NULL;
if (ignore_list_match (addr) != 0)
return;
- new = malloc (sizeof (ip_list_t));
+ new = malloc (sizeof (*new));
if (new == NULL)
{
perror ("malloc");
qh.length = (uint16_t) len;
- /* gather stats */
- qtype_counts[qh.qtype]++;
- qclass_counts[qh.qclass]++;
- opcode_counts[qh.opcode]++;
-
if (Callback != NULL)
Callback (&qh);
* Copyright (C) 2006 Florian octo Forster
* Copyright (C) 2002 The Measurement Factory, Inc.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
- *
+ *
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
#define DNS_MSG_HDR_SZ 12
#define T_MAX 65536
-#define OP_MAX 16
-#define C_MAX 65536
#define MAX_QNAME_SZ 512
struct rfc1035_header_s {
};
typedef struct rfc1035_header_s rfc1035_header_t;
-extern int qtype_counts[T_MAX];
-extern int opcode_counts[OP_MAX];
-extern int qclass_counts[C_MAX];
-
#if HAVE_PCAP_H
void dnstop_set_pcap_obj (pcap_t *po);
#endif
if (file == NULL)
return (NULL);
- h = malloc (sizeof (*h));
+ h = calloc (1, sizeof (*h));
if (h == NULL)
return (NULL);
- memset (h, 0, sizeof (*h));
h->filename = strdup (file);
if (h->filename == NULL)
}
} /* for (keys) */
- if (offset <= 0)
+ if (offset == 0)
return (ENOENT);
buffer[0] = '{'; /* replace leading ',' */
* So, if the required bin width is 300, then new bin width will be 512 as it is
* the next nearest power of 2.
*/
-void change_bin_width (latency_counter_t *lc, cdtime_t latency) /* {{{ */
+static void change_bin_width (latency_counter_t *lc, cdtime_t latency) /* {{{ */
{
/* This function is called because the new value is above histogram's range.
* First find the required bin width:
CDTIME_T_TO_DOUBLE (new_bin_width));
} /* }}} void change_bin_width */
-latency_counter_t *latency_counter_create () /* {{{ */
+latency_counter_t *latency_counter_create (void) /* {{{ */
{
latency_counter_t *lc;
- lc = malloc (sizeof (*lc));
+ lc = calloc (1, sizeof (*lc));
if (lc == NULL)
return (NULL);
- memset (lc, 0, sizeof (*lc));
latency_counter_reset (lc);
lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
struct latency_counter_s;
typedef struct latency_counter_s latency_counter_t;
-latency_counter_t *latency_counter_create ();
+latency_counter_t *latency_counter_create (void);
void latency_counter_destroy (latency_counter_t *lc);
void latency_counter_add (latency_counter_t *lc, cdtime_t latency);
* Niki W. Waibel <niki.waibel@gmx.net>
**/
-#include "collectd.h"
-#include "utils_mount.h"
-
-#include "common.h" /* sstrncpy() et alii */
-#include "plugin.h" /* ERROR() macro */
+#if HAVE_CONFIG_H
+# include "config.h"
+#endif
#if HAVE_XFS_XQM_H
+# define _GNU_SOURCE
# include <xfs/xqm.h>
#define XFS_SUPER_MAGIC_STR "XFSB"
#define XFS_SUPER_MAGIC2_STR "BSFX"
#endif
+#include "collectd.h"
+#include "utils_mount.h"
+
+#include "common.h" /* sstrncpy() et alii */
+#include "plugin.h" /* ERROR() macro */
+
+
#if HAVE_GETVFSSTAT
# if HAVE_SYS_TYPES_H
# include <sys/types.h>
#elif HAVE_GETVFSSTAT || HAVE_GETFSSTAT
static cu_mount_t *cu_mount_getfsstat (void)
{
-#if HAVE_GETVFSSTAT
-# define STRUCT_STATFS struct statvfs
-# define CMD_STATFS getvfsstat
-# define FLAGS_STATFS ST_NOWAIT
-/* #endif HAVE_GETVFSSTAT */
-#elif HAVE_GETFSSTAT
+#if HAVE_GETFSSTAT
# define STRUCT_STATFS struct statfs
# define CMD_STATFS getfsstat
# define FLAGS_STATFS MNT_NOWAIT
-#endif /* HAVE_GETFSSTAT */
+/* #endif HAVE_GETFSSTAT */
+#elif HAVE_GETVFSSTAT
+# define STRUCT_STATFS struct statvfs
+# define CMD_STATFS getvfsstat
+# define FLAGS_STATFS ST_NOWAIT
+#endif /* HAVE_GETVFSSTAT */
int bufsize;
STRUCT_STATFS *buf;
return (NULL);
}
- if ((buf = (STRUCT_STATFS *) malloc (bufsize * sizeof (STRUCT_STATFS)))
- == NULL)
+ if ((buf = calloc (bufsize, sizeof (*buf))) == NULL)
return (NULL);
- memset (buf, '\0', bufsize * sizeof (STRUCT_STATFS));
/* The bufsize needs to be passed in bytes. Really. This is not in the
* manpage.. -octo */
for (i = 0; i < num; i++)
{
- if ((new = malloc (sizeof (cu_mount_t))) == NULL)
+ if ((new = calloc (1, sizeof (*new))) == NULL)
break;
- memset (new, '\0', sizeof (cu_mount_t));
-
+
/* Copy values from `struct mnttab' */
new->dir = sstrdup (buf[i].f_mntonname);
new->spec_device = sstrdup (buf[i].f_mntfromname);
while (getmntent (fp, &mt) == 0)
{
- if ((new = malloc (sizeof (cu_mount_t))) == NULL)
+ if ((new = calloc (1, sizeof (*new))) == NULL)
break;
- memset (new, '\0', sizeof (cu_mount_t));
-
+
/* Copy values from `struct mnttab' */
new->dir = sstrdup (mt.mnt_mountp);
new->spec_device = sstrdup (mt.mnt_special);
while (getmntent_r (fp, &me, mntbuf, sizeof (mntbuf) ))
{
- if ((new = malloc (sizeof (cu_mount_t))) == NULL)
+ if ((new = calloc (1, sizeof (*new))) == NULL)
break;
- memset (new, '\0', sizeof (cu_mount_t));
/* Copy values from `struct mntent *' */
new->dir = sstrdup (me.mnt_dir);
while ((me = getmntent (fp)) != NULL)
{
- if ((new = malloc (sizeof (cu_mount_t))) == NULL)
+ if ((new = calloc (1, sizeof (*new))) == 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);
} /* void cu_mount_freelist(cu_mount_t *list) */
char *
-cu_mount_checkoption(char *line, char *keyword, int full)
+cu_mount_checkoption(char *line, const char *keyword, int full)
{
char *line2, *l2, *p1, *p2;
int l;
} /* char *cu_mount_checkoption(char *line, char *keyword, int full) */
char *
-cu_mount_getoptionvalue(char *line, char *keyword)
+cu_mount_getoptionvalue(char *line, const char *keyword)
{
char *r;
if((p-r) == 1) {
return NULL;
}
- m = (char *)smalloc(p-r+1);
+ m = smalloc(p-r+1);
sstrncpy(m, r, p-r+1);
return m;
}
}
return r;
-} /* char *cu_mount_getoptionvalue(char *line, char *keyword) */
+} /* char *cu_mount_getoptionvalue(char *line, const char *keyword) */
int
cu_mount_type(const char *type)
allocated by *list and *list itself as well.
*/
-char *cu_mount_checkoption(char *line, char *keyword, int full);
+char *cu_mount_checkoption(char *line, const char *keyword, int full);
/*
DESCRIPTION
The cu_mount_checkoption() function is a replacement of
maybe you might want to try cu_mount_getoptionvalue()...
*/
-char *cu_mount_getoptionvalue(char *line, char *keyword);
+char *cu_mount_getoptionvalue(char *line, const char *keyword);
/*
DESCRIPTION
The cu_mount_getoptionvalue() function can be used to grab
buffer++;
}
}
-
+
/* Eat up trailing spaces */
while (isspace ((int) *buffer))
buffer++;
};
static int rra_timespans_num = STATIC_ARRAY_SIZE (rra_timespans);
-static char *rra_types[] =
+static const char *const rra_types[] =
{
"AVERAGE",
"MIN",
};
static int rra_types_num = STATIC_ARRAY_SIZE (rra_types);
-#if !defined(HAVE_THREADSAFE_LIBRRD) || !HAVE_THREADSAFE_LIBRRD
+#if !defined(HAVE_THREADSAFE_LIBRRD)
static pthread_mutex_t librrd_lock = PTHREAD_MUTEX_INITIALIZER;
#endif
{
srrd_create_args_t *args;
- args = malloc (sizeof (*args));
+ args = calloc (1, sizeof (*args));
if (args == NULL)
{
- ERROR ("srrd_create_args_create: malloc failed.");
+ ERROR ("srrd_create_args_create: calloc failed.");
return (NULL);
}
- memset (args, 0, sizeof (*args));
args->filename = NULL;
args->pdp_step = pdp_step;
args->last_up = last_up;
rra_max = rts_num * rra_types_num;
assert (rra_max > 0);
- if ((rra_def = malloc ((rra_max + 1) * sizeof (*rra_def))) == NULL)
+ if ((rra_def = calloc (rra_max + 1, sizeof (*rra_def))) == NULL)
return (-1);
- memset (rra_def, 0, (rra_max + 1) * sizeof (*rra_def));
rra_num = 0;
cdp_len = 0;
assert (ds->ds_num > 0);
- ds_def = malloc (ds->ds_num * sizeof (*ds_def));
+ ds_def = calloc (ds->ds_num, sizeof (*ds_def));
if (ds_def == NULL)
{
char errbuf[1024];
- ERROR ("rrdtool plugin: malloc failed: %s",
+ ERROR ("rrdtool plugin: calloc failed: %s",
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
- memset (ds_def, 0, ds->ds_num * sizeof (*ds_def));
for (ds_num = 0; ds_num < ds->ds_num; ds_num++)
{
data_source_t *d = ds->ds + ds_num;
- char *type;
+ const char *type;
int status;
ds_def[ds_num] = NULL;
return (-1);
}
- if (ds_num <= 0)
+ if (ds_num == 0)
{
sfree (ds_def);
return (0);
char last_up_str[16];
new_argc = 6 + argc;
- new_argv = (char **) malloc ((new_argc + 1) * sizeof (char *));
+ new_argv = malloc ((new_argc + 1) * sizeof (*new_argv));
if (new_argv == NULL)
{
ERROR ("rrdtool plugin: malloc failed.");
argc = ds_num + rra_num;
- if ((argv = (char **) malloc (sizeof (char *) * (argc + 1))) == NULL)
+ if ((argv = malloc (sizeof (*argv) * (argc + 1))) == NULL)
{
char errbuf[1024];
ERROR ("cu_rrd_create_file failed: %s",
assert (sizeof (match_part->str) > len);
/* strip trailing slash */
match_part->str[len - 2] = 0;
-
+
status = regcomp (&match_part->regex, match_part->str,
/* flags = */ REG_EXTENDED);
if (status != 0)
return (EINVAL);
}
match_part->is_regex = 1;
-
+
return (0);
} /* }}} int lu_copy_ident_to_match_part */
{
user_obj_t *user_obj;
- user_obj = malloc (sizeof (*user_obj));
+ user_obj = calloc (1, sizeof (*user_obj));
if (user_obj == NULL)
{
- ERROR ("utils_vl_lookup: malloc failed.");
+ ERROR ("utils_vl_lookup: calloc failed.");
return (NULL);
}
- memset (user_obj, 0, sizeof (*user_obj));
user_obj->next = NULL;
user_obj->user_obj = obj->cb_user_class (ds, vl, user_class->user_class);
{
user_class_list_t *ptr;
int retval = 0;
-
+
for (ptr = user_class_list; ptr != NULL; ptr = ptr->next)
{
int status;
return (NULL);
}
- by_type = malloc (sizeof (*by_type));
+ by_type = calloc (1, sizeof (*by_type));
if (by_type == NULL)
{
- ERROR ("utils_vl_lookup: malloc failed.");
+ ERROR ("utils_vl_lookup: calloc failed.");
sfree (type_copy);
return (NULL);
}
- memset (by_type, 0, sizeof (*by_type));
by_type->wildcard_plugin_list = NULL;
-
+
by_type->by_plugin_tree = c_avl_create ((void *) strcmp);
if (by_type->by_plugin_tree == NULL)
{
sfree (type_copy);
return (NULL);
}
-
+
return (by_type);
} /* }}} by_type_entry_t *lu_search_by_type */
static void lu_destroy_by_type (lookup_t *obj, /* {{{ */
by_type_entry_t *by_type)
{
-
+
while (42)
{
char *plugin = NULL;
lookup_free_class_callback_t cb_free_class,
lookup_free_obj_callback_t cb_free_obj)
{
- lookup_t *obj = malloc (sizeof (*obj));
+ lookup_t *obj = calloc (1, sizeof (*obj));
if (obj == NULL)
{
- ERROR ("utils_vl_lookup: malloc failed.");
+ ERROR ("utils_vl_lookup: calloc failed.");
return (NULL);
}
- memset (obj, 0, sizeof (*obj));
obj->by_type_tree = c_avl_create ((void *) strcmp);
if (obj->by_type_tree == NULL)
if (by_type == NULL)
return (-1);
- user_class_obj = malloc (sizeof (*user_class_obj));
+ user_class_obj = calloc (1, sizeof (*user_class_obj));
if (user_class_obj == NULL)
{
- ERROR ("utils_vl_lookup: malloc failed.");
+ ERROR ("utils_vl_lookup: calloc failed.");
return (ENOMEM);
}
- memset (user_class_obj, 0, sizeof (*user_class_obj));
pthread_mutex_init (&user_class_obj->entry.lock, /* attr = */ NULL);
user_class_obj->entry.user_class = user_class;
lu_copy_ident_to_match (&user_class_obj->entry.match, ident, group_by);
return (status);
retval += status;
}
-
+
return (retval);
} /* }}} lookup_search */
assert (expect_new_obj);
memcpy (&last_class_ident, class, sizeof (last_class_ident));
-
+
obj = malloc (sizeof (*obj));
strncpy (obj->host, vl->host, sizeof (obj->host));
strncpy (obj->plugin, vl->plugin, sizeof (obj->plugin));
if (!dmidecode) {
return NULL;
}
-
+
uuid = uuid_parse_dmidecode(dmidecode);
pclose(dmidecode);
if (have_instance)
return (0);
- conf = malloc (sizeof (*conf));
+ conf = calloc (1, sizeof (*conf));
if (conf == NULL)
return (ENOMEM);
- memset (conf, 0, sizeof (*conf));
/* Default settings: */
conf->instance = NULL;
char callback_name[DATA_MAX_NAME_LEN];
int i;
- conf = malloc (sizeof (*conf));
+ conf = calloc (1, sizeof (*conf));
if (conf == NULL)
return (ENOMEM);
- memset (conf, 0, sizeof (*conf));
conf->instance = NULL;
varnish_config_apply_default (conf);
int *domids;
/* Get list of domains. */
- domids = malloc (sizeof (int) * n);
- if (domids == 0) {
+ domids = malloc (sizeof (*domids) * n);
+ if (domids == NULL) {
ERROR (PLUGIN_NAME " plugin: malloc failed.");
return -1;
}
}
static void
-free_domains ()
+free_domains (void)
{
int i;
}
static void
-free_block_devices ()
+free_block_devices (void)
{
int i;
}
static void
-free_interface_devices ()
+free_interface_devices (void)
{
int i;
if (fields[1] == endptr)
continue;
- /*
+ /*
* Number of pages
*
* The total number of {inst} pages, e. g dirty pages.
}
}
- /*
+ /*
* Page in and page outs. For memory and swap.
*/
else if (strcmp ("pgpgin", key) == 0)
if (proc == NULL)
{
char errbuf[1024];
- ERROR ("vserver plugin: fopen (%s): %s", PROCDIR,
+ ERROR ("vserver plugin: fopen (%s): %s", PROCDIR,
sstrerror (errno, errbuf, sizeof (errbuf)));
return (-1);
}
len = ssnprintf (file, sizeof (file), PROCDIR "/%s", dent->d_name);
if ((len < 0) || (len >= BUFSIZE))
continue;
-
+
status = stat (file, &statbuf);
if (status != 0)
{
file, sstrerror (errno, errbuf, sizeof (errbuf)));
continue;
}
-
+
if (!S_ISDIR (statbuf.st_mode))
continue;
{
derive_t rx;
derive_t tx;
- char *type_instance;
+ const char *type_instance;
if (strsplit (buffer, cols, 4) < 4)
continue;
if (2 == n)
{
- char *type_instance;
+ const char *type_instance;
gauge_t value;
if (0 == strcmp (cols[0], "nr_threads:"))
while ((fh != NULL) && (NULL != fgets (buffer, BUFSIZE, fh)))
{
- char *type = "vs_memory";
- char *type_instance;
+ const char *type = "vs_memory";
+ const char *type_instance;
gauge_t value;
if (strsplit (buffer, cols, 2) < 2)
/*
* dbm = 10 * log_{10} (1000 * power / W)
- * power = 10^(dbm/10) * W/1000
+ * power = 10^(dbm/10) * W/1000
*/
watt = pow (10.0, (dbm / 10.0)) / 1000.0;
double quality;
double power;
double noise;
-
+
char *fields[8];
int numfields;
return (0);
}
- if (cb->send_buf_fill <= 0)
+ if (cb->send_buf_fill == 0)
{
cb->send_buf_init_time = cdtime ();
return (0);
int i;
int status = 0;
- cb = malloc (sizeof (*cb));
+ cb = calloc (1, sizeof (*cb));
if (cb == NULL)
{
- ERROR ("write_graphite plugin: malloc failed.");
+ ERROR ("write_graphite plugin: calloc failed.");
return (-1);
}
- memset (cb, 0, sizeof (*cb));
cb->sock_fd = -1;
cb->name = NULL;
cb->node = strdup (WG_DEFAULT_NODE);
int format;
CURL *curl;
+ struct curl_slist *headers;
char curl_errbuf[CURL_ERROR_SIZE];
char *send_buffer;
static int wh_callback_init (wh_callback_t *cb) /* {{{ */
{
- struct curl_slist *headers;
-
if (cb->curl != NULL)
return (0);
curl_easy_setopt (cb->curl, CURLOPT_NOSIGNAL, 1L);
curl_easy_setopt (cb->curl, CURLOPT_USERAGENT, COLLECTD_USERAGENT);
- headers = NULL;
- headers = curl_slist_append (headers, "Accept: */*");
+ cb->headers = curl_slist_append (cb->headers, "Accept: */*");
if (cb->format == WH_FORMAT_JSON)
- headers = curl_slist_append (headers, "Content-Type: application/json");
+ cb->headers = curl_slist_append (cb->headers, "Content-Type: application/json");
else
- headers = curl_slist_append (headers, "Content-Type: text/plain");
- headers = curl_slist_append (headers, "Expect:");
- curl_easy_setopt (cb->curl, CURLOPT_HTTPHEADER, headers);
+ cb->headers = curl_slist_append (cb->headers, "Content-Type: text/plain");
+ cb->headers = curl_slist_append (cb->headers, "Expect:");
+ curl_easy_setopt (cb->curl, CURLOPT_HTTPHEADER, cb->headers);
curl_easy_setopt (cb->curl, CURLOPT_ERRORBUFFER, cb->curl_errbuf);
curl_easy_setopt (cb->curl, CURLOPT_URL, cb->location);
if (cb->pass != NULL)
credentials_size += strlen (cb->pass);
- cb->credentials = (char *) malloc (credentials_size);
+ cb->credentials = malloc (credentials_size);
if (cb->credentials == NULL)
{
ERROR ("curl plugin: malloc failed.");
if (cb->format == WH_FORMAT_COMMAND)
{
- if (cb->send_buffer_fill <= 0)
+ if (cb->send_buffer_fill == 0)
{
cb->send_buffer_init_time = cdtime ();
return (0);
curl_easy_cleanup (cb->curl);
cb->curl = NULL;
}
+
+ if (cb->headers != NULL)
+ {
+ curl_slist_free_all (cb->headers);
+ cb->headers = NULL;
+ }
+
sfree (cb->name);
sfree (cb->location);
sfree (cb->user);
return (0);
} /* }}} int config_set_format */
+static int wh_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */
+ oconfig_item_t *ci)
+{
+ struct curl_slist *temp = NULL;
+ if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
+ {
+ WARNING ("write_http plugin: `%s' needs exactly one string argument.", name);
+ return (-1);
+ }
+
+ temp = curl_slist_append(*dest, ci->values[0].value.string);
+ if (temp == NULL)
+ return (-1);
+
+ *dest = temp;
+
+ return (0);
+} /* }}} int wh_config_append_string */
+
static int wh_config_node (oconfig_item_t *ci) /* {{{ */
{
wh_callback_t *cb;
int status = 0;
int i;
- cb = malloc (sizeof (*cb));
+ cb = calloc (1, sizeof (*cb));
if (cb == NULL)
{
- ERROR ("write_http plugin: malloc failed.");
+ ERROR ("write_http plugin: calloc failed.");
return (-1);
}
- memset (cb, 0, sizeof (*cb));
cb->verify_peer = 1;
cb->verify_host = 1;
cb->format = WH_FORMAT_COMMAND;
cb->low_speed_limit = 0;
cb->timeout = 0;
cb->log_http_error = 0;
+ cb->headers = NULL;
+
pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
status = cf_util_get_int (child, &cb->timeout);
else if (strcasecmp ("LogHttpError", child->key) == 0)
status = cf_util_get_boolean (child, &cb->log_http_error);
+ else if (strcasecmp ("Header", child->key) == 0)
+ status = wh_config_append_string ("Header", &cb->headers, child);
else
{
ERROR ("write_http plugin: Invalid configuration "
INFO ("write_kafka plugin: created KAFKA handle : %s", rd_kafka_name(ctx->kafka));
-#ifdef HAVE_LIBRDKAFKA_LOGGER
+#if defined(HAVE_LIBRDKAFKA_LOGGER) && !defined(HAVE_LIBRDKAFKA_LOG_CB)
rd_kafka_set_logger(ctx->kafka, kafka_log);
#endif
}
{
plugin_register_complex_config ("write_kafka", kafka_config);
}
-
int status;
int i;
- node = malloc (sizeof (*node));
+ node = calloc (1, sizeof (*node));
if (node == NULL)
return (ENOMEM);
- memset (node, 0, sizeof (*node));
mongo_init (node->conn);
node->host = NULL;
node->store_rates = 1;
int status;
int i;
- node = malloc (sizeof (*node));
+ node = calloc (1, sizeof (*node));
if (node == NULL)
return (ENOMEM);
- memset (node, 0, sizeof (*node));
node->host = NULL;
node->port = 0;
node->timeout.tv_sec = 0;
* collectd - src/write_riemann.c
* Copyright (C) 2012,2013 Pierre-Yves Ritschard
* Copyright (C) 2013 Florian octo Forster
+ * Copyright (C) 2015,2016 Gergely Nagy
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* Authors:
* Pierre-Yves Ritschard <pyr at spootnik.org>
* Florian octo Forster <octo at collectd.org>
+ * Gergely Nagy <algernon at madhouse-project.org>
*/
+#include <riemann/riemann-client.h>
+#include <errno.h>
+#include <pthread.h>
+
#include "collectd.h"
#include "plugin.h"
#include "common.h"
#include "configfile.h"
#include "utils_cache.h"
-#include "riemann.pb-c.h"
-
-#include <arpa/inet.h>
-#include <errno.h>
-#include <netdb.h>
-#include <inttypes.h>
-#include <pthread.h>
+#include "utils_complain.h"
+#include "write_riemann_threshold.h"
#define RIEMANN_HOST "localhost"
-#define RIEMANN_PORT "5555"
+#define RIEMANN_PORT 5555
#define RIEMANN_TTL_FACTOR 2.0
#define RIEMANN_BATCH_MAX 8192
-int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *);
-
struct riemann_host {
+ c_complain_t init_complaint;
char *name;
char *event_service_prefix;
-#define F_CONNECT 0x01
- uint8_t flags;
pthread_mutex_t lock;
_Bool batch_mode;
_Bool notifications;
_Bool store_rates;
_Bool always_append_ds;
char *node;
- char *service;
- _Bool use_tcp;
- int s;
+ int port;
+ riemann_client_type_t client_type;
+ riemann_client_t *client;
double ttl_factor;
- Msg *batch_msg;
cdtime_t batch_init;
int batch_max;
+ int batch_timeout;
int reference_count;
+ riemann_message_t *batch_msg;
+ char *tls_ca_file;
+ char *tls_cert_file;
+ char *tls_key_file;
+ struct timeval timeout;
};
static char **riemann_tags;
static char **riemann_attrs;
static size_t riemann_attrs_num;
-static void riemann_event_protobuf_free (Event *event) /* {{{ */
-{
- size_t i;
-
- if (event == NULL)
- return;
-
- sfree (event->state);
- sfree (event->service);
- sfree (event->host);
- sfree (event->description);
-
- strarray_free (event->tags, event->n_tags);
- event->tags = NULL;
- event->n_tags = 0;
-
- for (i = 0; i < event->n_attributes; i++)
- {
- sfree (event->attributes[i]->key);
- sfree (event->attributes[i]->value);
- sfree (event->attributes[i]);
- }
- sfree (event->attributes);
- event->n_attributes = 0;
-
- sfree (event);
-} /* }}} void riemann_event_protobuf_free */
-
-static void riemann_msg_protobuf_free(Msg *msg) /* {{{ */
-{
- size_t i;
-
- if (msg == NULL)
- return;
-
- for (i = 0; i < msg->n_events; i++)
- {
- riemann_event_protobuf_free (msg->events[i]);
- msg->events[i] = NULL;
- }
-
- sfree (msg->events);
- msg->n_events = 0;
-
- sfree (msg);
-} /* }}} void riemann_msg_protobuf_free */
-
/* host->lock must be held when calling this function. */
-static int riemann_connect(struct riemann_host *host) /* {{{ */
+static int wrr_connect(struct riemann_host *host) /* {{{ */
{
- int e;
- struct addrinfo *ai, *res, hints;
char const *node;
- char const *service;
+ int port;
- if (host->flags & F_CONNECT)
+ if (host->client)
return 0;
- memset(&hints, 0, sizeof(hints));
- memset(&service, 0, sizeof(service));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = host->use_tcp ? SOCK_STREAM : SOCK_DGRAM;
-#ifdef AI_ADDRCONFIG
- hints.ai_flags |= AI_ADDRCONFIG;
-#endif
-
node = (host->node != NULL) ? host->node : RIEMANN_HOST;
- service = (host->service != NULL) ? host->service : RIEMANN_PORT;
-
- if ((e = getaddrinfo(node, service, &hints, &res)) != 0) {
- ERROR ("write_riemann plugin: Unable to resolve host \"%s\": %s",
- node, gai_strerror(e));
+ port = (host->port) ? host->port : RIEMANN_PORT;
+
+ host->client = NULL;
+
+ host->client = riemann_client_create(host->client_type, node, port,
+ RIEMANN_CLIENT_OPTION_TLS_CA_FILE, host->tls_ca_file,
+ RIEMANN_CLIENT_OPTION_TLS_CERT_FILE, host->tls_cert_file,
+ RIEMANN_CLIENT_OPTION_TLS_KEY_FILE, host->tls_key_file,
+ RIEMANN_CLIENT_OPTION_NONE);
+ if (host->client == NULL) {
+ c_complain (LOG_ERR, &host->init_complaint,
+ "write_riemann plugin: Unable to connect to Riemann at %s:%d",
+ node, port);
return -1;
}
-
- host->s = -1;
- for (ai = res; ai != NULL; ai = ai->ai_next) {
- if ((host->s = socket(ai->ai_family,
- ai->ai_socktype,
- ai->ai_protocol)) == -1) {
- continue;
- }
-
- if (connect(host->s, ai->ai_addr, ai->ai_addrlen) != 0) {
- close(host->s);
- host->s = -1;
- continue;
+ if (host->timeout.tv_sec != 0) {
+ if (riemann_client_set_timeout(host->client, &host->timeout) != 0) {
+ riemann_client_free(host->client);
+ host->client = NULL;
+ c_complain (LOG_ERR, &host->init_complaint,
+ "write_riemann plugin: Unable to connect to Riemann at %s:%d",
+ node, port);
+ return -1;
}
-
- host->flags |= F_CONNECT;
- DEBUG("write_riemann plugin: got a successful connection for: %s:%s",
- node, service);
- break;
}
- freeaddrinfo(res);
+ c_release (LOG_INFO, &host->init_complaint,
+ "write_riemann plugin: Successfully connected to %s:%d",
+ node, port);
- if (host->s < 0) {
- WARNING("write_riemann plugin: Unable to connect to Riemann at %s:%s",
- node, service);
- return -1;
- }
return 0;
-} /* }}} int riemann_connect */
+} /* }}} int wrr_connect */
/* host->lock must be held when calling this function. */
-static int riemann_disconnect (struct riemann_host *host) /* {{{ */
+static int wrr_disconnect(struct riemann_host *host) /* {{{ */
{
- if ((host->flags & F_CONNECT) == 0)
+ if (!host->client)
return (0);
- close (host->s);
- host->s = -1;
- host->flags &= ~F_CONNECT;
+ riemann_client_free(host->client);
+ host->client = NULL;
return (0);
-} /* }}} int riemann_disconnect */
-
-static int riemann_send_msg (struct riemann_host *host, const Msg *msg) /* {{{ */
-{
- int status = 0;
- u_char *buffer = NULL;
- size_t buffer_len;
-
- status = riemann_connect (host);
- if (status != 0)
- return status;
-
- buffer_len = msg__get_packed_size(msg);
-
- if (host->use_tcp)
- buffer_len += 4;
-
- buffer = malloc (buffer_len);
- if (buffer == NULL) {
- ERROR ("write_riemann plugin: malloc failed.");
- return ENOMEM;
- }
- memset (buffer, 0, buffer_len);
-
- if (host->use_tcp)
- {
- uint32_t length = htonl ((uint32_t) (buffer_len - 4));
- memcpy (buffer, &length, 4);
- msg__pack(msg, buffer + 4);
- }
- else
- {
- msg__pack(msg, buffer);
- }
-
- status = (int) swrite (host->s, buffer, buffer_len);
- if (status != 0)
- {
- char errbuf[1024];
- ERROR ("write_riemann plugin: Sending to Riemann at %s:%s failed: %s",
- (host->node != NULL) ? host->node : RIEMANN_HOST,
- (host->service != NULL) ? host->service : RIEMANN_PORT,
- sstrerror (errno, errbuf, sizeof (errbuf)));
- sfree (buffer);
- return -1;
- }
-
- sfree (buffer);
- return 0;
-} /* }}} int riemann_send_msg */
-
-static int riemann_recv_ack(struct riemann_host *host) /* {{{ */
-{
- int status = 0;
- Msg *msg = NULL;
- uint32_t header;
-
- status = (int) sread (host->s, &header, 4);
-
- if (status != 0)
- return -1;
-
- size_t size = ntohl(header);
-
- // Buffer on the stack since acknowledges are typically small.
- u_char buffer[size];
- memset (buffer, 0, size);
-
- status = (int) sread (host->s, buffer, size);
-
- if (status != 0)
- return status;
-
- msg = msg__unpack (NULL, size, buffer);
-
- if (msg == NULL)
- return -1;
-
- if (!msg->ok)
- {
- ERROR ("write_riemann plugin: Sending to Riemann at %s:%s acknowledgement message reported error: %s",
- (host->node != NULL) ? host->node : RIEMANN_HOST,
- (host->service != NULL) ? host->service : RIEMANN_PORT,
- msg->error);
-
- msg__free_unpacked(msg, NULL);
- return -1;
- }
-
- msg__free_unpacked (msg, NULL);
- return 0;
-} /* }}} int riemann_recv_ack */
+} /* }}} int wrr_disconnect */
/**
- * Function to send messages (Msg) to riemann.
+ * Function to send messages to riemann.
*
* Acquires the host lock, disconnects on errors.
*/
-static int riemann_send(struct riemann_host *host, Msg const *msg) /* {{{ */
+static int wrr_send_nolock(struct riemann_host *host, riemann_message_t *msg) /* {{{ */
{
int status = 0;
- pthread_mutex_lock (&host->lock);
- status = riemann_send_msg(host, msg);
+ status = wrr_connect(host);
if (status != 0) {
- riemann_disconnect (host);
- pthread_mutex_unlock (&host->lock);
+ return status;
+ }
+
+ status = riemann_client_send_message(host->client, msg);
+ if (status != 0) {
+ wrr_disconnect(host);
return status;
}
/*
* For TCP we need to receive message acknowledgemenent.
*/
- if (host->use_tcp)
+ if (host->client_type != RIEMANN_CLIENT_UDP)
{
- status = riemann_recv_ack(host);
+ riemann_message_t *response;
- if (status != 0)
+ response = riemann_client_recv_message(host->client);
+
+ if (response == NULL)
{
- riemann_disconnect (host);
- pthread_mutex_unlock (&host->lock);
- return status;
+ wrr_disconnect(host);
+ return errno;
}
+ riemann_message_free(response);
}
- pthread_mutex_unlock (&host->lock);
return 0;
-} /* }}} int riemann_send */
+} /* }}} int wrr_send */
-static int riemann_event_add_tag (Event *event, char const *tag) /* {{{ */
+static int wrr_send(struct riemann_host *host, riemann_message_t *msg)
{
- return (strarray_add (&event->tags, &event->n_tags, tag));
-} /* }}} int riemann_event_add_tag */
+ int status = 0;
-static int riemann_event_add_attribute(Event *event, /* {{{ */
- char const *key, char const *value)
-{
- Attribute **new_attributes;
- Attribute *a;
-
- new_attributes = realloc (event->attributes,
- sizeof (*event->attributes) * (event->n_attributes + 1));
- if (new_attributes == NULL)
- {
- ERROR ("write_riemann plugin: realloc failed.");
- return (ENOMEM);
- }
- event->attributes = new_attributes;
-
- a = malloc (sizeof (*a));
- if (a == NULL)
- {
- ERROR ("write_riemann plugin: malloc failed.");
- return (ENOMEM);
- }
- attribute__init (a);
-
- a->key = strdup (key);
- if (value != NULL)
- a->value = strdup (value);
-
- event->attributes[event->n_attributes] = a;
- event->n_attributes++;
-
- return (0);
-} /* }}} int riemann_event_add_attribute */
+ pthread_mutex_lock (&host->lock);
+ status = wrr_send_nolock(host, msg);
+ pthread_mutex_unlock (&host->lock);
+ return status;
+}
-static Msg *riemann_notification_to_protobuf(struct riemann_host *host, /* {{{ */
+static riemann_message_t *wrr_notification_to_message(struct riemann_host *host, /* {{{ */
notification_t const *n)
{
- Msg *msg;
- Event *event;
+ riemann_message_t *msg;
+ riemann_event_t *event;
char service_buffer[6 * DATA_MAX_NAME_LEN];
char const *severity;
notification_meta_t *meta;
size_t i;
- msg = malloc (sizeof (*msg));
- if (msg == NULL)
- {
- ERROR ("write_riemann plugin: malloc failed.");
- return (NULL);
- }
- memset (msg, 0, sizeof (*msg));
- msg__init (msg);
-
- msg->events = malloc (sizeof (*msg->events));
- if (msg->events == NULL)
- {
- ERROR ("write_riemann plugin: malloc failed.");
- sfree (msg);
- return (NULL);
- }
-
- event = malloc (sizeof (*event));
- if (event == NULL)
- {
- ERROR ("write_riemann plugin: malloc failed.");
- sfree (msg->events);
- sfree (msg);
- return (NULL);
- }
- memset (event, 0, sizeof (*event));
- event__init (event);
-
- msg->events[0] = event;
- msg->n_events = 1;
-
- event->host = strdup (n->host);
- event->time = CDTIME_T_TO_TIME_T (n->time);
- event->has_time = 1;
-
switch (n->severity)
{
case NOTIF_OKAY: severity = "ok"; break;
case NOTIF_FAILURE: severity = "critical"; break;
default: severity = "unknown";
}
- event->state = strdup (severity);
- riemann_event_add_tag (event, "notification");
+ format_name(service_buffer, sizeof(service_buffer),
+ /* host = */ "", n->plugin, n->plugin_instance,
+ n->type, n->type_instance);
+
+ event = riemann_event_create(RIEMANN_EVENT_FIELD_HOST, n->host,
+ RIEMANN_EVENT_FIELD_TIME, (int64_t) CDTIME_T_TO_TIME_T(n->time),
+ RIEMANN_EVENT_FIELD_TAGS, "notification", NULL,
+ RIEMANN_EVENT_FIELD_STATE, severity,
+ RIEMANN_EVENT_FIELD_SERVICE, &service_buffer[1],
+ RIEMANN_EVENT_FIELD_NONE);
+
if (n->host[0] != 0)
- riemann_event_add_attribute (event, "host", n->host);
+ riemann_event_string_attribute_add(event, "host", n->host);
if (n->plugin[0] != 0)
- riemann_event_add_attribute (event, "plugin", n->plugin);
+ riemann_event_string_attribute_add(event, "plugin", n->plugin);
if (n->plugin_instance[0] != 0)
- riemann_event_add_attribute (event, "plugin_instance",
- n->plugin_instance);
+ riemann_event_string_attribute_add(event, "plugin_instance", n->plugin_instance);
if (n->type[0] != 0)
- riemann_event_add_attribute (event, "type", n->type);
+ riemann_event_string_attribute_add(event, "type", n->type);
if (n->type_instance[0] != 0)
- riemann_event_add_attribute (event, "type_instance",
- n->type_instance);
+ riemann_event_string_attribute_add(event, "type_instance", n->type_instance);
for (i = 0; i < riemann_attrs_num; i += 2)
- riemann_event_add_attribute(event,
- riemann_attrs[i],
- riemann_attrs[i +1]);
+ riemann_event_string_attribute_add(event, riemann_attrs[i], riemann_attrs[i+1]);
for (i = 0; i < riemann_tags_num; i++)
- riemann_event_add_tag (event, riemann_tags[i]);
-
- format_name (service_buffer, sizeof (service_buffer),
- /* host = */ "", n->plugin, n->plugin_instance,
- n->type, n->type_instance);
- event->service = strdup (&service_buffer[1]);
+ riemann_event_tag_add(event, riemann_tags[i]);
if (n->message[0] != 0)
- riemann_event_add_attribute (event, "description", n->message);
+ riemann_event_string_attribute_add(event, "description", n->message);
/* Pull in values from threshold and add extra attributes */
for (meta = n->meta; meta != NULL; meta = meta->next)
{
- if (strcasecmp ("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
+ if (strcasecmp("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE)
{
- event->metric_d = meta->nm_value.nm_double;
- event->has_metric_d = 1;
+ riemann_event_set(event,
+ RIEMANN_EVENT_FIELD_METRIC_D,
+ (double) meta->nm_value.nm_double,
+ RIEMANN_EVENT_FIELD_NONE);
continue;
}
if (meta->type == NM_TYPE_STRING) {
- riemann_event_add_attribute (event, meta->name, meta->nm_value.nm_string);
+ riemann_event_string_attribute_add(event, meta->name, meta->nm_value.nm_string);
continue;
}
}
- DEBUG ("write_riemann plugin: Successfully created protobuf for notification: "
- "host = \"%s\", service = \"%s\", state = \"%s\"",
- event->host, event->service, event->state);
+ msg = riemann_message_create_with_events(event, NULL);
+ if (msg == NULL)
+ {
+ ERROR("write_riemann plugin: riemann_message_create_with_events() failed.");
+ riemann_event_free (event);
+ return (NULL);
+ }
+
+ DEBUG("write_riemann plugin: Successfully created message for notification: "
+ "host = \"%s\", service = \"%s\", state = \"%s\"",
+ event->host, event->service, event->state);
return (msg);
-} /* }}} Msg *riemann_notification_to_protobuf */
+} /* }}} riemann_message_t *wrr_notification_to_message */
-static Event *riemann_value_to_protobuf(struct riemann_host const *host, /* {{{ */
- data_set_t const *ds,
- value_list_t const *vl, size_t index,
- gauge_t const *rates,
- int status)
+static riemann_event_t *wrr_value_to_event(struct riemann_host const *host, /* {{{ */
+ data_set_t const *ds,
+ value_list_t const *vl, size_t index,
+ gauge_t const *rates,
+ int status)
{
- Event *event;
+ riemann_event_t *event;
char name_buffer[5 * DATA_MAX_NAME_LEN];
char service_buffer[6 * DATA_MAX_NAME_LEN];
- double ttl;
size_t i;
- event = malloc (sizeof (*event));
+ event = riemann_event_new();
if (event == NULL)
{
- ERROR ("write_riemann plugin: malloc failed.");
+ ERROR("write_riemann plugin: riemann_event_new() failed.");
return (NULL);
}
- memset (event, 0, sizeof (*event));
- event__init (event);
- event->host = strdup (vl->host);
- event->time = CDTIME_T_TO_TIME_T (vl->time);
- event->has_time = 1;
+ format_name(name_buffer, sizeof(name_buffer),
+ /* host = */ "", vl->plugin, vl->plugin_instance,
+ vl->type, vl->type_instance);
+ if (host->always_append_ds || (ds->ds_num > 1))
+ {
+ if (host->event_service_prefix == NULL)
+ ssnprintf(service_buffer, sizeof(service_buffer), "%s/%s",
+ &name_buffer[1], ds->ds[index].name);
+ else
+ ssnprintf(service_buffer, sizeof(service_buffer), "%s%s/%s",
+ host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
+ }
+ else
+ {
+ if (host->event_service_prefix == NULL)
+ sstrncpy(service_buffer, &name_buffer[1], sizeof(service_buffer));
+ else
+ ssnprintf(service_buffer, sizeof(service_buffer), "%s%s",
+ host->event_service_prefix, &name_buffer[1]);
+ }
+
+ riemann_event_set(event,
+ RIEMANN_EVENT_FIELD_HOST, vl->host,
+ RIEMANN_EVENT_FIELD_TIME, (int64_t) CDTIME_T_TO_TIME_T(vl->time),
+ RIEMANN_EVENT_FIELD_TTL, (float) CDTIME_T_TO_DOUBLE(vl->interval) * host->ttl_factor,
+ RIEMANN_EVENT_FIELD_STRING_ATTRIBUTES,
+ "plugin", vl->plugin,
+ "type", vl->type,
+ "ds_name", ds->ds[index].name,
+ NULL,
+ RIEMANN_EVENT_FIELD_SERVICE, service_buffer,
+ RIEMANN_EVENT_FIELD_NONE);
if (host->check_thresholds) {
+ const char *state = NULL;
+
switch (status) {
case STATE_OKAY:
- event->state = strdup("ok");
+ state = "ok";
break;
case STATE_ERROR:
- event->state = strdup("critical");
+ state = "critical";
break;
case STATE_WARNING:
- event->state = strdup("warning");
+ state = "warning";
break;
case STATE_MISSING:
- event->state = strdup("unknown");
+ state = "unknown";
break;
}
+ if (state)
+ riemann_event_set(event, RIEMANN_EVENT_FIELD_STATE, state,
+ RIEMANN_EVENT_FIELD_NONE);
}
- ttl = CDTIME_T_TO_DOUBLE (vl->interval) * host->ttl_factor;
- event->ttl = (float) ttl;
- event->has_ttl = 1;
-
- riemann_event_add_attribute (event, "plugin", vl->plugin);
if (vl->plugin_instance[0] != 0)
- riemann_event_add_attribute (event, "plugin_instance",
- vl->plugin_instance);
-
- riemann_event_add_attribute (event, "type", vl->type);
+ riemann_event_string_attribute_add(event, "plugin_instance", vl->plugin_instance);
if (vl->type_instance[0] != 0)
- riemann_event_add_attribute (event, "type_instance",
- vl->type_instance);
+ riemann_event_string_attribute_add(event, "type_instance", vl->type_instance);
if ((ds->ds[index].type != DS_TYPE_GAUGE) && (rates != NULL))
{
char ds_type[DATA_MAX_NAME_LEN];
- ssnprintf (ds_type, sizeof (ds_type), "%s:rate",
- DS_TYPE_TO_STRING(ds->ds[index].type));
- riemann_event_add_attribute (event, "ds_type", ds_type);
+ ssnprintf(ds_type, sizeof(ds_type), "%s:rate",
+ DS_TYPE_TO_STRING(ds->ds[index].type));
+ riemann_event_string_attribute_add(event, "ds_type", ds_type);
}
else
{
- riemann_event_add_attribute (event, "ds_type",
- DS_TYPE_TO_STRING(ds->ds[index].type));
+ riemann_event_string_attribute_add(event, "ds_type",
+ DS_TYPE_TO_STRING(ds->ds[index].type));
}
- riemann_event_add_attribute (event, "ds_name", ds->ds[index].name);
+
{
char ds_index[DATA_MAX_NAME_LEN];
- ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
- riemann_event_add_attribute (event, "ds_index", ds_index);
+ ssnprintf(ds_index, sizeof(ds_index), "%zu", index);
+ riemann_event_string_attribute_add(event, "ds_index", ds_index);
}
for (i = 0; i < riemann_attrs_num; i += 2)
- riemann_event_add_attribute(event,
- riemann_attrs[i],
- riemann_attrs[i +1]);
+ riemann_event_string_attribute_add(event, riemann_attrs[i], riemann_attrs[i +1]);
for (i = 0; i < riemann_tags_num; i++)
- riemann_event_add_tag (event, riemann_tags[i]);
+ riemann_event_tag_add(event, riemann_tags[i]);
if (ds->ds[index].type == DS_TYPE_GAUGE)
{
- event->has_metric_d = 1;
- event->metric_d = (double) vl->values[index].gauge;
+ riemann_event_set(event,
+ RIEMANN_EVENT_FIELD_METRIC_D,
+ (double) vl->values[index].gauge,
+ RIEMANN_EVENT_FIELD_NONE);
}
else if (rates != NULL)
{
- event->has_metric_d = 1;
- event->metric_d = (double) rates[index];
+ riemann_event_set(event,
+ RIEMANN_EVENT_FIELD_METRIC_D,
+ (double) rates[index],
+ RIEMANN_EVENT_FIELD_NONE);
}
else
{
- event->has_metric_sint64 = 1;
+ int64_t metric;
+
if (ds->ds[index].type == DS_TYPE_DERIVE)
- event->metric_sint64 = (int64_t) vl->values[index].derive;
+ metric = (int64_t) vl->values[index].derive;
else if (ds->ds[index].type == DS_TYPE_ABSOLUTE)
- event->metric_sint64 = (int64_t) vl->values[index].absolute;
+ metric = (int64_t) vl->values[index].absolute;
else
- event->metric_sint64 = (int64_t) vl->values[index].counter;
- }
+ metric = (int64_t) vl->values[index].counter;
- format_name (name_buffer, sizeof (name_buffer),
- /* host = */ "", vl->plugin, vl->plugin_instance,
- vl->type, vl->type_instance);
- if (host->always_append_ds || (ds->ds_num > 1))
- {
- if (host->event_service_prefix == NULL)
- ssnprintf (service_buffer, sizeof (service_buffer), "%s/%s",
- &name_buffer[1], ds->ds[index].name);
- else
- ssnprintf (service_buffer, sizeof (service_buffer), "%s%s/%s",
- host->event_service_prefix, &name_buffer[1], ds->ds[index].name);
- }
- else
- {
- if (host->event_service_prefix == NULL)
- sstrncpy (service_buffer, &name_buffer[1], sizeof (service_buffer));
- else
- ssnprintf (service_buffer, sizeof (service_buffer), "%s%s",
- host->event_service_prefix, &name_buffer[1]);
+ riemann_event_set(event,
+ RIEMANN_EVENT_FIELD_METRIC_S64,
+ (int64_t) metric,
+ RIEMANN_EVENT_FIELD_NONE);
}
- event->service = strdup (service_buffer);
-
- DEBUG ("write_riemann plugin: Successfully created protobuf for metric: "
- "host = \"%s\", service = \"%s\"",
- event->host, event->service);
+ DEBUG("write_riemann plugin: Successfully created message for metric: "
+ "host = \"%s\", service = \"%s\"",
+ event->host, event->service);
return (event);
-} /* }}} Event *riemann_value_to_protobuf */
+} /* }}} riemann_event_t *wrr_value_to_event */
-static Msg *riemann_value_list_to_protobuf (struct riemann_host const *host, /* {{{ */
- data_set_t const *ds,
- value_list_t const *vl,
- int *statuses)
+static riemann_message_t *wrr_value_list_to_message(struct riemann_host const *host, /* {{{ */
+ data_set_t const *ds,
+ value_list_t const *vl,
+ int *statuses)
{
- Msg *msg;
+ riemann_message_t *msg;
size_t i;
gauge_t *rates = NULL;
/* Initialize the Msg structure. */
- msg = malloc (sizeof (*msg));
+ msg = riemann_message_new();
if (msg == NULL)
{
- ERROR ("write_riemann plugin: malloc failed.");
- return (NULL);
- }
- memset (msg, 0, sizeof (*msg));
- msg__init (msg);
-
- /* Set up events. First, the list of pointers. */
- msg->n_events = vl->values_len;
- msg->events = calloc (msg->n_events, sizeof (*msg->events));
- if (msg->events == NULL)
- {
- ERROR ("write_riemann plugin: calloc failed.");
- riemann_msg_protobuf_free (msg);
+ ERROR ("write_riemann plugin: riemann_message_new failed.");
return (NULL);
}
if (host->store_rates)
{
- rates = uc_get_rate (ds, vl);
+ rates = uc_get_rate(ds, vl);
if (rates == NULL)
{
- ERROR ("write_riemann plugin: uc_get_rate failed.");
- riemann_msg_protobuf_free (msg);
+ ERROR("write_riemann plugin: uc_get_rate failed.");
+ riemann_message_free(msg);
return (NULL);
}
}
- for (i = 0; i < msg->n_events; i++)
+ for (i = 0; i < vl->values_len; i++)
{
- msg->events[i] = riemann_value_to_protobuf (host, ds, vl,
- (int) i, rates, statuses[i]);
- if (msg->events[i] == NULL)
+ riemann_event_t *event;
+
+ event = wrr_value_to_event(host, ds, vl,
+ (int) i, rates, statuses[i]);
+ if (event == NULL)
{
- riemann_msg_protobuf_free (msg);
- sfree (rates);
+ riemann_message_free(msg);
+ sfree(rates);
return (NULL);
}
+ riemann_message_append_events(msg, event, NULL);
}
- sfree (rates);
+ sfree(rates);
return (msg);
-} /* }}} Msg *riemann_value_list_to_protobuf */
-
+} /* }}} riemann_message_t *wrr_value_list_to_message */
/*
* Always call while holding host->lock !
*/
-static int riemann_batch_flush_nolock (cdtime_t timeout,
- struct riemann_host *host)
+static int wrr_batch_flush_nolock(cdtime_t timeout,
+ struct riemann_host *host)
{
- cdtime_t now;
- int status = 0;
+ cdtime_t now;
+ int status = 0;
- if (timeout > 0) {
- now = cdtime ();
- if ((host->batch_init + timeout) > now)
- return status;
- }
- riemann_send_msg(host, host->batch_msg);
- riemann_msg_protobuf_free(host->batch_msg);
-
- if (host->use_tcp && ((status = riemann_recv_ack(host)) != 0))
- riemann_disconnect (host);
+ now = cdtime();
+ if (timeout > 0) {
+ if ((host->batch_init + timeout) > now) {
+ return status;
+ }
+ }
+ wrr_send_nolock(host, host->batch_msg);
+ riemann_message_free(host->batch_msg);
- host->batch_init = cdtime();
- host->batch_msg = NULL;
- return status;
+ host->batch_init = now;
+ host->batch_msg = NULL;
+ return status;
}
-static int riemann_batch_flush (cdtime_t timeout,
+static int wrr_batch_flush(cdtime_t timeout,
const char *identifier __attribute__((unused)),
user_data_t *user_data)
{
- struct riemann_host *host;
- int status;
+ struct riemann_host *host;
+ int status;
- if (user_data == NULL)
- return (-EINVAL);
+ if (user_data == NULL)
+ return (-EINVAL);
- host = user_data->data;
- pthread_mutex_lock (&host->lock);
- status = riemann_batch_flush_nolock (timeout, host);
- if (status != 0)
- ERROR ("write_riemann plugin: riemann_send failed with status %i",
- status);
+ host = user_data->data;
+ pthread_mutex_lock(&host->lock);
+ status = wrr_batch_flush_nolock(timeout, host);
+ if (status != 0)
+ c_complain (LOG_ERR, &host->init_complaint,
+ "write_riemann plugin: riemann_client_send failed with status %i",
+ status);
+ else
+ c_release (LOG_DEBUG, &host->init_complaint, "write_riemann plugin: batch sent.");
- pthread_mutex_unlock(&host->lock);
- return status;
+ pthread_mutex_unlock(&host->lock);
+ return status;
}
-static int riemann_batch_add_value_list (struct riemann_host *host, /* {{{ */
- data_set_t const *ds,
- value_list_t const *vl,
- int *statuses)
+static int wrr_batch_add_value_list(struct riemann_host *host, /* {{{ */
+ data_set_t const *ds,
+ value_list_t const *vl,
+ int *statuses)
{
- size_t i;
- Event **events;
- Msg *msg;
- size_t len;
- int ret;
+ riemann_message_t *msg;
+ size_t len;
+ int ret;
+ cdtime_t timeout;
- msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
- if (msg == NULL)
- return -1;
+ msg = wrr_value_list_to_message(host, ds, vl, statuses);
+ if (msg == NULL)
+ return -1;
- pthread_mutex_lock(&host->lock);
+ pthread_mutex_lock(&host->lock);
- if (host->batch_msg == NULL) {
- host->batch_msg = msg;
- } else {
- len = msg->n_events + host->batch_msg->n_events;
- events = realloc(host->batch_msg->events,
- (len * sizeof(*host->batch_msg->events)));
- if (events == NULL) {
- pthread_mutex_unlock(&host->lock);
- ERROR ("write_riemann plugin: out of memory");
- riemann_msg_protobuf_free (msg);
- return -1;
- }
- host->batch_msg->events = events;
+ if (host->batch_msg == NULL) {
+ host->batch_msg = msg;
+ } else {
+ int status;
- for (i = host->batch_msg->n_events; i < len; i++)
- host->batch_msg->events[i] = msg->events[i - host->batch_msg->n_events];
+ status = riemann_message_append_events_n(host->batch_msg,
+ msg->n_events,
+ msg->events);
+ msg->n_events = 0;
+ msg->events = NULL;
- host->batch_msg->n_events = len;
- sfree (msg->events);
- msg->n_events = 0;
- sfree (msg);
- }
+ riemann_message_free(msg);
+
+ if (status != 0) {
+ pthread_mutex_unlock(&host->lock);
+ ERROR("write_riemann plugin: out of memory");
+ return -1;
+ }
+ }
- len = msg__get_packed_size(host->batch_msg);
- ret = 0;
- if ((host->batch_max < 0) || (((size_t) host->batch_max) <= len)) {
- ret = riemann_batch_flush_nolock(0, host);
+ len = riemann_message_get_packed_size(host->batch_msg);
+ ret = 0;
+ if ((host->batch_max < 0) || (((size_t) host->batch_max) <= len)) {
+ ret = wrr_batch_flush_nolock(0, host);
+ } else {
+ if (host->batch_timeout > 0) {
+ timeout = TIME_T_TO_CDTIME_T((time_t)host->batch_timeout);
+ ret = wrr_batch_flush_nolock(timeout, host);
+ }
}
- pthread_mutex_unlock(&host->lock);
- return ret;
-} /* }}} Msg *riemann_batch_add_value_list */
+ pthread_mutex_unlock(&host->lock);
+ return ret;
+} /* }}} riemann_message_t *wrr_batch_add_value_list */
-static int riemann_notification(const notification_t *n, user_data_t *ud) /* {{{ */
+static int wrr_notification(const notification_t *n, user_data_t *ud) /* {{{ */
{
int status;
struct riemann_host *host = ud->data;
- Msg *msg;
+ riemann_message_t *msg;
if (!host->notifications)
return 0;
/*
* Never batch for notifications, send them ASAP
*/
- msg = riemann_notification_to_protobuf (host, n);
+ msg = wrr_notification_to_message(host, n);
if (msg == NULL)
return (-1);
- status = riemann_send (host, msg);
+ status = wrr_send(host, msg);
if (status != 0)
- ERROR ("write_riemann plugin: riemann_send failed with status %i",
- status);
-
- riemann_msg_protobuf_free (msg);
+ c_complain (LOG_ERR, &host->init_complaint,
+ "write_riemann plugin: riemann_client_send failed with status %i",
+ status);
+ else
+ c_release (LOG_DEBUG, &host->init_complaint,
+ "write_riemann plugin: riemann_client_send succeeded");
+
+ riemann_message_free(msg);
return (status);
-} /* }}} int riemann_notification */
+} /* }}} int wrr_notification */
-static int riemann_write(const data_set_t *ds, /* {{{ */
- const value_list_t *vl,
- user_data_t *ud)
+static int wrr_write(const data_set_t *ds, /* {{{ */
+ const value_list_t *vl,
+ user_data_t *ud)
{
int status = 0;
int statuses[vl->values_len];
struct riemann_host *host = ud->data;
+ riemann_message_t *msg;
if (host->check_thresholds) {
status = write_riemann_threshold_check(ds, vl, statuses);
- if (status != 0)
- return status;
- } else {
- memset (statuses, 0, sizeof (statuses));
- }
-
- if (host->use_tcp == 1 && host->batch_mode) {
- riemann_batch_add_value_list (host, ds, vl, statuses);
- } else {
- Msg *msg = riemann_value_list_to_protobuf (host, ds, vl, statuses);
- if (msg == NULL)
- return (-1);
+ if (status != 0)
+ return status;
+ } else {
+ memset (statuses, 0, sizeof (statuses));
+ }
+
+ if (host->client_type != RIEMANN_CLIENT_UDP && host->batch_mode) {
+ wrr_batch_add_value_list(host, ds, vl, statuses);
+ } else {
+ msg = wrr_value_list_to_message(host, ds, vl, statuses);
+ if (msg == NULL)
+ return (-1);
- status = riemann_send (host, msg);
- if (status != 0)
- ERROR ("write_riemann plugin: riemann_send failed with status %i", status);
+ status = wrr_send(host, msg);
- riemann_msg_protobuf_free (msg);
- }
+ riemann_message_free(msg);
+ }
+ return status;
+} /* }}} int wrr_write */
- return status;
-} /* }}} int riemann_write */
-
-static void riemann_free(void *p) /* {{{ */
+static void wrr_free(void *p) /* {{{ */
{
- struct riemann_host *host = p;
+ struct riemann_host *host = p;
- if (host == NULL)
- return;
+ if (host == NULL)
+ return;
- pthread_mutex_lock (&host->lock);
+ pthread_mutex_lock(&host->lock);
- host->reference_count--;
- if (host->reference_count > 0)
- {
- pthread_mutex_unlock (&host->lock);
- return;
- }
+ host->reference_count--;
+ if (host->reference_count > 0)
+ {
+ pthread_mutex_unlock(&host->lock);
+ return;
+ }
- riemann_disconnect (host);
+ wrr_disconnect(host);
- sfree(host->service);
- pthread_mutex_destroy (&host->lock);
- sfree(host);
-} /* }}} void riemann_free */
+ pthread_mutex_destroy(&host->lock);
+ sfree(host);
+} /* }}} void wrr_free */
-static int riemann_config_node(oconfig_item_t *ci) /* {{{ */
+static int wrr_config_node(oconfig_item_t *ci) /* {{{ */
{
- struct riemann_host *host = NULL;
- int status = 0;
- int i;
- oconfig_item_t *child;
- char callback_name[DATA_MAX_NAME_LEN];
- user_data_t ud;
-
- if ((host = calloc(1, sizeof (*host))) == NULL) {
- ERROR ("write_riemann plugin: calloc failed.");
- return ENOMEM;
- }
- pthread_mutex_init (&host->lock, NULL);
- host->reference_count = 1;
- host->node = NULL;
- host->service = NULL;
- host->notifications = 1;
- host->check_thresholds = 0;
- host->store_rates = 1;
- host->always_append_ds = 0;
- host->use_tcp = 1;
- host->batch_mode = 1;
- host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
- host->batch_init = cdtime();
- host->ttl_factor = RIEMANN_TTL_FACTOR;
-
- status = cf_util_get_string (ci, &host->name);
- if (status != 0) {
- WARNING("write_riemann plugin: Required host name is missing.");
- riemann_free (host);
- return -1;
- }
-
- for (i = 0; i < ci->children_num; i++) {
- /*
- * The code here could be simplified but makes room
- * for easy adding of new options later on.
- */
- child = &ci->children[i];
- status = 0;
-
- if (strcasecmp ("Host", child->key) == 0) {
- status = cf_util_get_string (child, &host->node);
- if (status != 0)
- break;
- } else if (strcasecmp ("Notifications", child->key) == 0) {
- status = cf_util_get_boolean(child, &host->notifications);
- if (status != 0)
- break;
- } else if (strcasecmp ("EventServicePrefix", child->key) == 0) {
- status = cf_util_get_string (child, &host->event_service_prefix);
- if (status != 0)
- break;
- } else if (strcasecmp ("CheckThresholds", child->key) == 0) {
- status = cf_util_get_boolean(child, &host->check_thresholds);
- if (status != 0)
- break;
- } else if (strcasecmp ("Batch", child->key) == 0) {
- status = cf_util_get_boolean(child, &host->batch_mode);
- if (status != 0)
- break;
- } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
- status = cf_util_get_int(child, &host->batch_max);
- if (status != 0)
- break;
- } else if (strcasecmp ("Port", child->key) == 0) {
- status = cf_util_get_service (child, &host->service);
- if (status != 0) {
- ERROR ("write_riemann plugin: Invalid argument "
- "configured for the \"Port\" "
- "option.");
- break;
- }
- } else if (strcasecmp ("Protocol", child->key) == 0) {
- char tmp[16];
- status = cf_util_get_string_buffer (child,
- tmp, sizeof (tmp));
- if (status != 0)
- {
- ERROR ("write_riemann plugin: cf_util_get_"
- "string_buffer failed with "
- "status %i.", status);
- break;
- }
-
- if (strcasecmp ("UDP", tmp) == 0)
- host->use_tcp = 0;
- else if (strcasecmp ("TCP", tmp) == 0)
- host->use_tcp = 1;
- else
- WARNING ("write_riemann plugin: The value "
- "\"%s\" is not valid for the "
- "\"Protocol\" option. Use "
- "either \"UDP\" or \"TCP\".",
- tmp);
- } else if (strcasecmp ("StoreRates", child->key) == 0) {
- status = cf_util_get_boolean (child, &host->store_rates);
- if (status != 0)
- break;
- } else if (strcasecmp ("AlwaysAppendDS", child->key) == 0) {
- status = cf_util_get_boolean (child,
- &host->always_append_ds);
- if (status != 0)
- break;
- } else if (strcasecmp ("TTLFactor", child->key) == 0) {
- double tmp = NAN;
- status = cf_util_get_double (child, &tmp);
- if (status != 0)
- break;
- if (tmp >= 2.0) {
- host->ttl_factor = tmp;
- } else if (tmp >= 1.0) {
- NOTICE ("write_riemann plugin: The configured "
- "TTLFactor is very small "
- "(%.1f). A value of 2.0 or "
- "greater is recommended.",
- tmp);
- host->ttl_factor = tmp;
- } else if (tmp > 0.0) {
- WARNING ("write_riemann plugin: The configured "
- "TTLFactor is too small to be "
- "useful (%.1f). I'll use it "
- "since the user knows best, "
- "but under protest.",
- tmp);
- host->ttl_factor = tmp;
- } else { /* zero, negative and NAN */
- ERROR ("write_riemann plugin: The configured "
- "TTLFactor is invalid (%.1f).",
- tmp);
- }
- } else {
- WARNING("write_riemann plugin: ignoring unknown config "
- "option: \"%s\"", child->key);
- }
- }
- if (status != 0) {
- riemann_free (host);
- return status;
- }
-
- ssnprintf (callback_name, sizeof (callback_name), "write_riemann/%s",
- host->name);
- ud.data = host;
- ud.free_func = riemann_free;
-
- pthread_mutex_lock (&host->lock);
-
- status = plugin_register_write (callback_name, riemann_write, &ud);
+ struct riemann_host *host = NULL;
+ int status = 0;
+ int i;
+ oconfig_item_t *child;
+ char callback_name[DATA_MAX_NAME_LEN];
+ user_data_t ud;
+
+ if ((host = calloc(1, sizeof(*host))) == NULL) {
+ ERROR ("write_riemann plugin: calloc failed.");
+ return ENOMEM;
+ }
+ pthread_mutex_init(&host->lock, NULL);
+ C_COMPLAIN_INIT (&host->init_complaint);
+ host->reference_count = 1;
+ host->node = NULL;
+ host->port = 0;
+ host->notifications = 1;
+ host->check_thresholds = 0;
+ host->store_rates = 1;
+ host->always_append_ds = 0;
+ host->batch_mode = 1;
+ host->batch_max = RIEMANN_BATCH_MAX; /* typical MSS */
+ host->batch_init = cdtime();
+ host->batch_timeout = 0;
+ host->ttl_factor = RIEMANN_TTL_FACTOR;
+ host->client = NULL;
+ host->client_type = RIEMANN_CLIENT_TCP;
+ host->timeout.tv_sec = 0;
+ host->timeout.tv_usec = 0;
+
+ status = cf_util_get_string(ci, &host->name);
+ if (status != 0) {
+ WARNING("write_riemann plugin: Required host name is missing.");
+ wrr_free(host);
+ return -1;
+ }
+
+ for (i = 0; i < ci->children_num; i++) {
+ /*
+ * The code here could be simplified but makes room
+ * for easy adding of new options later on.
+ */
+ child = &ci->children[i];
+ status = 0;
+
+ if (strcasecmp("Host", child->key) == 0) {
+ status = cf_util_get_string(child, &host->node);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("Notifications", child->key) == 0) {
+ status = cf_util_get_boolean(child, &host->notifications);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("EventServicePrefix", child->key) == 0) {
+ status = cf_util_get_string(child, &host->event_service_prefix);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("CheckThresholds", child->key) == 0) {
+ status = cf_util_get_boolean(child, &host->check_thresholds);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("Batch", child->key) == 0) {
+ status = cf_util_get_boolean(child, &host->batch_mode);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("BatchMaxSize", child->key) == 0) {
+ status = cf_util_get_int(child, &host->batch_max);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("BatchFlushTimeout", child->key) == 0) {
+ status = cf_util_get_int(child, &host->batch_timeout);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("Timeout", child->key) == 0) {
+ status = cf_util_get_int(child, (int *)&host->timeout.tv_sec);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("Port", child->key) == 0) {
+ host->port = cf_util_get_port_number(child);
+ if (host->port == -1) {
+ ERROR("write_riemann plugin: Invalid argument "
+ "configured for the \"Port\" "
+ "option.");
+ break;
+ }
+ } else if (strcasecmp("Protocol", child->key) == 0) {
+ char tmp[16];
+ status = cf_util_get_string_buffer(child,
+ tmp, sizeof(tmp));
+ if (status != 0)
+ {
+ ERROR("write_riemann plugin: cf_util_get_"
+ "string_buffer failed with "
+ "status %i.", status);
+ break;
+ }
- if (host->use_tcp == 1 && host->batch_mode) {
- ud.free_func = NULL;
- plugin_register_flush(callback_name, riemann_batch_flush, &ud);
+ if (strcasecmp("UDP", tmp) == 0)
+ host->client_type = RIEMANN_CLIENT_UDP;
+ else if (strcasecmp("TCP", tmp) == 0)
+ host->client_type = RIEMANN_CLIENT_TCP;
+ else if (strcasecmp("TLS", tmp) == 0)
+ host->client_type = RIEMANN_CLIENT_TLS;
+ else
+ WARNING("write_riemann plugin: The value "
+ "\"%s\" is not valid for the "
+ "\"Protocol\" option. Use "
+ "either \"UDP\", \"TCP\" or \"TLS\".",
+ tmp);
+ } else if (strcasecmp("TLSCAFile", child->key) == 0) {
+ status = cf_util_get_string(child, &host->tls_ca_file);
+ if (status != 0)
+ {
+ ERROR("write_riemann plugin: cf_util_get_"
+ "string_buffer failed with "
+ "status %i.", status);
+ break;
+ }
+ } else if (strcasecmp("TLSCertFile", child->key) == 0) {
+ status = cf_util_get_string(child, &host->tls_cert_file);
+ if (status != 0)
+ {
+ ERROR("write_riemann plugin: cf_util_get_"
+ "string_buffer failed with "
+ "status %i.", status);
+ break;
+ }
+ } else if (strcasecmp("TLSKeyFile", child->key) == 0) {
+ status = cf_util_get_string(child, &host->tls_key_file);
+ if (status != 0)
+ {
+ ERROR("write_riemann plugin: cf_util_get_"
+ "string_buffer failed with "
+ "status %i.", status);
+ break;
+ }
+ } else if (strcasecmp("StoreRates", child->key) == 0) {
+ status = cf_util_get_boolean(child, &host->store_rates);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("AlwaysAppendDS", child->key) == 0) {
+ status = cf_util_get_boolean(child,
+ &host->always_append_ds);
+ if (status != 0)
+ break;
+ } else if (strcasecmp("TTLFactor", child->key) == 0) {
+ double tmp = NAN;
+ status = cf_util_get_double(child, &tmp);
+ if (status != 0)
+ break;
+ if (tmp >= 2.0) {
+ host->ttl_factor = tmp;
+ } else if (tmp >= 1.0) {
+ NOTICE("write_riemann plugin: The configured "
+ "TTLFactor is very small "
+ "(%.1f). A value of 2.0 or "
+ "greater is recommended.",
+ tmp);
+ host->ttl_factor = tmp;
+ } else if (tmp > 0.0) {
+ WARNING("write_riemann plugin: The configured "
+ "TTLFactor is too small to be "
+ "useful (%.1f). I'll use it "
+ "since the user knows best, "
+ "but under protest.",
+ tmp);
+ host->ttl_factor = tmp;
+ } else { /* zero, negative and NAN */
+ ERROR("write_riemann plugin: The configured "
+ "TTLFactor is invalid (%.1f).",
+ tmp);
+ }
+ } else {
+ WARNING("write_riemann plugin: ignoring unknown config "
+ "option: \"%s\"", child->key);
+ }
+ }
+ if (status != 0) {
+ wrr_free(host);
+ return status;
+ }
+
+ ssnprintf(callback_name, sizeof(callback_name), "write_riemann/%s",
+ host->name);
+ ud.data = host;
+ ud.free_func = wrr_free;
+
+ pthread_mutex_lock(&host->lock);
+
+ status = plugin_register_write(callback_name, wrr_write, &ud);
+
+ if (host->client_type != RIEMANN_CLIENT_UDP && host->batch_mode) {
+ ud.free_func = NULL;
+ plugin_register_flush(callback_name, wrr_batch_flush, &ud);
+ }
+ if (status != 0)
+ WARNING("write_riemann plugin: plugin_register_write (\"%s\") "
+ "failed with status %i.",
+ callback_name, status);
+ else /* success */
+ host->reference_count++;
+
+ status = plugin_register_notification(callback_name,
+ wrr_notification, &ud);
+ if (status != 0)
+ WARNING("write_riemann plugin: plugin_register_notification (\"%s\") "
+ "failed with status %i.",
+ callback_name, status);
+ else /* success */
+ host->reference_count++;
+
+ if (host->reference_count <= 1)
+ {
+ /* Both callbacks failed => free memory.
+ * We need to unlock here, because riemann_free() will lock.
+ * This is not a race condition, because we're the only one
+ * holding a reference. */
+ pthread_mutex_unlock(&host->lock);
+ wrr_free(host);
+ return (-1);
}
- if (status != 0)
- WARNING ("write_riemann plugin: plugin_register_write (\"%s\") "
- "failed with status %i.",
- callback_name, status);
- else /* success */
- host->reference_count++;
-
- status = plugin_register_notification (callback_name,
- riemann_notification, &ud);
- if (status != 0)
- WARNING ("write_riemann plugin: plugin_register_notification (\"%s\") "
- "failed with status %i.",
- callback_name, status);
- else /* success */
- host->reference_count++;
-
- if (host->reference_count <= 1)
- {
- /* Both callbacks failed => free memory.
- * We need to unlock here, because riemann_free() will lock.
- * This is not a race condition, because we're the only one
- * holding a reference. */
- pthread_mutex_unlock (&host->lock);
- riemann_free (host);
- return (-1);
- }
- host->reference_count--;
- pthread_mutex_unlock (&host->lock);
+ host->reference_count--;
+ pthread_mutex_unlock(&host->lock);
- return status;
-} /* }}} int riemann_config_node */
+ return status;
+} /* }}} int wrr_config_node */
-static int riemann_config(oconfig_item_t *ci) /* {{{ */
+static int wrr_config(oconfig_item_t *ci) /* {{{ */
{
- int i;
- oconfig_item_t *child;
- int status;
-
- for (i = 0; i < ci->children_num; i++) {
- child = &ci->children[i];
-
- if (strcasecmp("Node", child->key) == 0) {
- riemann_config_node (child);
- } else if (strcasecmp(child->key, "attribute") == 0) {
- char *key = NULL;
- char *val = NULL;
-
- if (child->values_num != 2) {
- WARNING("riemann attributes need both a key and a value.");
- return (-1);
- }
- if (child->values[0].type != OCONFIG_TYPE_STRING ||
- child->values[1].type != OCONFIG_TYPE_STRING) {
- WARNING("riemann attribute needs string arguments.");
- return (-1);
- }
- if ((key = strdup(child->values[0].value.string)) == NULL) {
- WARNING("cannot allocate memory for attribute key.");
- return (-1);
- }
- if ((val = strdup(child->values[1].value.string)) == NULL) {
- WARNING("cannot allocate memory for attribute value.");
- sfree (key);
- return (-1);
- }
- strarray_add(&riemann_attrs, &riemann_attrs_num, key);
- strarray_add(&riemann_attrs, &riemann_attrs_num, val);
- DEBUG("write_riemann: got attr: %s => %s", key, val);
- sfree(key);
- sfree(val);
- } else if (strcasecmp(child->key, "tag") == 0) {
- char *tmp = NULL;
- status = cf_util_get_string(child, &tmp);
- if (status != 0)
- continue;
-
- strarray_add (&riemann_tags, &riemann_tags_num, tmp);
- DEBUG("write_riemann plugin: Got tag: %s", tmp);
- sfree (tmp);
- } else {
- WARNING ("write_riemann plugin: Ignoring unknown "
- "configuration option \"%s\" at top level.",
- child->key);
- }
- }
- return (0);
-} /* }}} int riemann_config */
+ int i;
+ oconfig_item_t *child;
+ int status;
+
+ for (i = 0; i < ci->children_num; i++) {
+ child = &ci->children[i];
+
+ if (strcasecmp("Node", child->key) == 0) {
+ wrr_config_node (child);
+ } else if (strcasecmp(child->key, "attribute") == 0) {
+ char *key = NULL;
+ char *val = NULL;
+
+ if (child->values_num != 2) {
+ WARNING("riemann attributes need both a key and a value.");
+ return (-1);
+ }
+ if (child->values[0].type != OCONFIG_TYPE_STRING ||
+ child->values[1].type != OCONFIG_TYPE_STRING) {
+ WARNING("riemann attribute needs string arguments.");
+ return (-1);
+ }
+ if ((key = strdup(child->values[0].value.string)) == NULL) {
+ WARNING("cannot allocate memory for attribute key.");
+ return (-1);
+ }
+ if ((val = strdup(child->values[1].value.string)) == NULL) {
+ WARNING("cannot allocate memory for attribute value.");
+ sfree(key);
+ return (-1);
+ }
+ strarray_add(&riemann_attrs, &riemann_attrs_num, key);
+ strarray_add(&riemann_attrs, &riemann_attrs_num, val);
+ DEBUG("write_riemann: got attr: %s => %s", key, val);
+ sfree(key);
+ sfree(val);
+ } else if (strcasecmp(child->key, "tag") == 0) {
+ char *tmp = NULL;
+ status = cf_util_get_string(child, &tmp);
+ if (status != 0)
+ continue;
+
+ strarray_add(&riemann_tags, &riemann_tags_num, tmp);
+ DEBUG("write_riemann plugin: Got tag: %s", tmp);
+ sfree(tmp);
+ } else {
+ WARNING("write_riemann plugin: Ignoring unknown "
+ "configuration option \"%s\" at top level.",
+ child->key);
+ }
+ }
+ return (0);
+} /* }}} int wrr_config */
void module_register(void)
{
- plugin_register_complex_config ("write_riemann", riemann_config);
+ plugin_register_complex_config("write_riemann", wrr_config);
}
/* vim: set sw=8 sts=8 ts=8 noet : */
* Andrés J. Díaz <ajdiaz at connectical.com>
**/
+#include <assert.h>
+#include <ltdl.h>
+#include <pthread.h>
+
#include "collectd.h"
#include "common.h"
#include "plugin.h"
#include "utils_avltree.h"
#include "utils_cache.h"
#include "utils_threshold.h"
-
-#include <assert.h>
-#include <pthread.h>
+#include "write_riemann_threshold.h"
/*
* Threshold management
--- /dev/null
+#ifndef WRITE_RIEMANN_THRESHOLD_H
+#define WRITE_RIEMANN_THRESHOLD_H
+
+int write_riemann_threshold_check(const data_set_t *, const value_list_t *, int *);
+
+#endif
* Fabrice A. Marie <fabrice at kibinlabs.com>
*/
+#define _GNU_SOURCE
+
#include "collectd.h"
#include "plugin.h"
#include "common.h"
#include <stddef.h>
#include <stdlib.h>
-#ifndef HAVE_ASPRINTF
-/*
- * Uses asprintf() portable implementation from
- * https://github.com/littlstar/asprintf.c/blob/master/
- * copyright (c) 2014 joseph werle <joseph.werle@gmail.com> under MIT license.
- */
-#include <stdio.h>
-#include <stdarg.h>
-
-int vasprintf(char **str, const char *fmt, va_list args) {
- int size = 0;
- va_list tmpa;
- // copy
- va_copy(tmpa, args);
- // apply variadic arguments to
- // sprintf with format to get size
- size = vsnprintf(NULL, size, fmt, tmpa);
- // toss args
- va_end(tmpa);
- // return -1 to be compliant if
- // size is less than 0
- if (size < 0) { return -1; }
- // alloc with size plus 1 for `\0'
- *str = (char *) malloc(size + 1);
- // return -1 to be compliant
- // if pointer is `NULL'
- if (NULL == *str) { return -1; }
- // format string with original
- // variadic arguments and set new size
- size = vsprintf(*str, fmt, args);
- return size;
-}
-
-int asprintf(char **str, const char *fmt, ...) {
- int size = 0;
- va_list args;
- // init variadic argumens
- va_start(args, fmt);
- // format and get size
- size = vasprintf(str, fmt, args);
- // toss args
- va_end(args);
- return size;
-}
-
-#endif
-
#define SENSU_HOST "localhost"
#define SENSU_PORT "3030"
static char *build_json_str_list(const char *tag, struct str_list const *list) /* {{{ */
{
int res;
- char *ret_str;
+ char *ret_str = NULL;
char *temp_str;
int i;
if (list->nb_strs == 0) {
res = asprintf(&temp_str, "\"%s\": [\"%s\"", tag, list->strs[0]);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
+ free(ret_str);
return NULL;
}
for (i=1; i<list->nb_strs; i++) {
return ret_str;
} /* }}} char *build_json_str_list*/
-int sensu_format_name2(char *ret, int ret_len,
+static int sensu_format_name2(char *ret, int ret_len,
const char *hostname,
const char *plugin, const char *plugin_instance,
const char *type, const char *type_instance,
* http://creativeandcritical.net/str-replace-c/
* copyright (c) Laird Shaw, under public domain.
*/
-char *replace_str(const char *str, const char *old, /* {{{ */
+static char *replace_str(const char *str, const char *old, /* {{{ */
const char *new)
{
char *ret, *r;
} else
retlen = strlen(str);
- ret = malloc(retlen + 1);
+ ret = calloc(1, retlen + 1);
if (ret == NULL)
return NULL;
// added to original: not optimized, but keeps valgrind happy.
- memset(ret, 0, retlen + 1);
r = ret;
p = str;
return 0;
}
- if (cb->send_buf_fill <= 0)
+ if (cb->send_buf_fill == 0)
{
cb->send_buf_init_time = cdtime();
return 0;
{
int status;
char *temp = NULL;
- char *prefix = "";
+ const char *prefix = "";
const char *meta_prefix = "tsdb_prefix";
if (vl->meta) {
int status;
size_t message_len;
char *temp = NULL;
- char *tags = "";
+ const char *tags = "";
char message[1024];
- char *host_tags = cb->host_tags ? cb->host_tags : "";
+ const char *host_tags = cb->host_tags ? cb->host_tags : "";
const char *meta_tsdb = "tsdb_tags";
/* skip if value is NaN */
char callback_name[DATA_MAX_NAME_LEN];
int i;
- cb = malloc(sizeof(*cb));
+ cb = calloc(1, sizeof(*cb));
if (cb == NULL)
{
- ERROR("write_tsdb plugin: malloc failed.");
+ ERROR("write_tsdb plugin: calloc failed.");
return -1;
}
- memset(cb, 0, sizeof(*cb));
cb->sock_fd = -1;
cb->node = NULL;
cb->service = NULL;
--- /dev/null
+/**
+ * collectd - src/xencpu.c
+ * Copyright (C) 2016 Pavel Rochnyak
+ *
+ * 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:
+ * Pavel Rochnyak <pavel2000 ngs.ru>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+
+#include <xenctrl.h>
+
+#ifdef XENCTRL_HAS_XC_INTERFACE
+
+//Xen-4.1+
+#define XC_INTERFACE_INIT_ARGS NULL,NULL,0
+xc_interface *xc_handle;
+
+#else /* XENCTRL_HAS_XC_INTERFACE */
+
+//For xen-3.4/xen-4.0
+#include <string.h>
+#define xc_strerror(xc_interface, errcode) strerror(errcode)
+#define XC_INTERFACE_INIT_ARGS
+typedef int xc_interface;
+xc_interface xc_handle = 0;
+
+#endif /* XENCTRL_HAS_XC_INTERFACE */
+
+uint32_t num_cpus = 0;
+xc_cpuinfo_t *cpu_info;
+static value_to_rate_state_t *cpu_states;
+
+static int xencpu_init (void)
+{
+ xc_handle = xc_interface_open(XC_INTERFACE_INIT_ARGS);
+ if (!xc_handle)
+ {
+ ERROR ("xencpu: xc_interface_open() failed");
+ return (-1);
+ };
+
+ xc_physinfo_t *physinfo;
+
+ physinfo = calloc(1, sizeof(xc_physinfo_t));
+ if (physinfo == NULL)
+ {
+ ERROR ("xencpu plugin: calloc() for physinfo failed.");
+ xc_interface_close(xc_handle);
+ return (ENOMEM);
+ }
+
+ if (xc_physinfo(xc_handle, physinfo) < 0)
+ {
+ ERROR ("xencpu plugin: xc_physinfo() failed");
+ xc_interface_close(xc_handle);
+ free(physinfo);
+ return (-1);
+ };
+
+ num_cpus = physinfo->nr_cpus;
+ free(physinfo);
+
+ INFO ("xencpu plugin: Found %"PRIu32" processors.", num_cpus);
+
+ cpu_info = calloc(num_cpus, sizeof(xc_cpuinfo_t));
+ if (cpu_info == NULL)
+ {
+ ERROR ("xencpu plugin: calloc() for num_cpus failed.");
+ xc_interface_close(xc_handle);
+ return (ENOMEM);
+ }
+
+ cpu_states = calloc (num_cpus, sizeof (value_to_rate_state_t));
+ if (cpu_states == NULL)
+ {
+ ERROR ("xencpu plugin: calloc() for cpu_states failed.");
+ xc_interface_close(xc_handle);
+ free(cpu_info);
+ return (ENOMEM);
+ }
+
+ return (0);
+} /* static int xencpu_init */
+
+static int xencpu_shutdown (void)
+{
+ free(cpu_states);
+ free(cpu_info);
+ xc_interface_close(xc_handle);
+
+ return 0;
+} /* static int xencpu_shutdown */
+
+static void submit_value (int cpu_num, gauge_t percent)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].gauge = percent;
+
+ vl.values = values;
+ vl.values_len = 1;
+
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "xencpu", sizeof (vl.plugin));
+ sstrncpy (vl.type, "percent", sizeof (vl.type));
+ sstrncpy (vl.type_instance, "load", sizeof (vl.type_instance));
+
+ if (cpu_num >= 0) {
+ ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
+ "%i", cpu_num);
+ }
+ plugin_dispatch_values (&vl);
+} /* static void submit_value */
+
+static int xencpu_read (void)
+{
+ cdtime_t now = cdtime ();
+
+ int rc, nr_cpus;
+
+ rc = xc_getcpuinfo(xc_handle, num_cpus, cpu_info, &nr_cpus);
+ if (rc < 0) {
+ ERROR ("xencpu: xc_getcpuinfo() Failed: %d %s\n", rc, xc_strerror(xc_handle,errno));
+ return (-1);
+ }
+
+ int cpu, status;
+ for (cpu = 0; cpu < nr_cpus; cpu++) {
+ gauge_t rate = NAN;
+ value_t value = {.derive = cpu_info[cpu].idletime};
+
+ status = value_to_rate (&rate, value, DS_TYPE_DERIVE, now, &cpu_states[cpu]);
+ if (status == 0) {
+ submit_value(cpu, 100 - rate/10000000);
+ }
+ }
+
+ return (0);
+} /* static int xencpu_read */
+
+void module_register (void)
+{
+ plugin_register_init ("xencpu", xencpu_init);
+ plugin_register_read ("xencpu", xencpu_read);
+ plugin_register_shutdown ("xencpu", xencpu_shutdown);
+} /* void module_register */
plugin_dispatch_values (&vl);
} /* void cxmms_submit */
-int cxmms_read (void)
+static int cxmms_read (void)
{
gint rate;
gint freq;
return 0;
}
-static long long get_zfs_value(kstat_t *ksp, char *key)
+static long long get_zfs_value(kstat_t *ksp, const char *key)
{
llentry_t *e;
value_t *v;
za_read_derive (ksp, "deleted", "cache_operation", "deleted");
#if __FreeBSD__
za_read_derive (ksp, "allocated","cache_operation", "allocated");
+#if defined(__FreeBSD_version) && (__FreeBSD_version < 1002501)
+ /* stolen removed from sysctl kstat.zfs.misc.arcstats on FreeBSD 10.2+ */
za_read_derive (ksp, "stolen", "cache_operation", "stolen");
#endif
+#endif
/* Issue indicators */
za_read_derive (ksp, "mutex_miss", "mutex_operations", "miss");
zoneid_t *key = NULL;
if (c_avl_get(tree, (void **)&zoneid, (void **)&ret)) {
- if (!(ret = malloc(sizeof(zone_stats_t)))) {
+ if (!(ret = malloc(sizeof(*ret)))) {
WARNING("zone plugin: no memory");
return(NULL);
}
- if (!(key = malloc(sizeof(zoneid_t)))) {
+ if (!(key = malloc(sizeof(*key)))) {
WARNING("zone plugin: no memory");
+ free(ret);
return(NULL);
}
*key = zoneid;
struct addrinfo ai_hints;
struct addrinfo *ai;
struct addrinfo *ai_list;
- char *host;
- char *port;
+ const char *host;
+ const char *port;
memset ((void *) &ai_hints, '\0', sizeof (ai_hints));
ai_hints.ai_family = AF_UNSPEC;
static int zookeeper_query (char *buffer, size_t buffer_size)
{
- int sk = -1;
- int status;
+ int sk, status;
size_t buffer_fill;
sk = zookeeper_connect();