author | Sebastian Harl <sh@tokkee.org> | |
Thu, 11 Aug 2016 20:51:50 +0000 (22:51 +0200) | ||
committer | GitHub <noreply@github.com> | |
Thu, 11 Aug 2016 20:51:50 +0000 (22:51 +0200) |
grpc plugin: Refactor plugin.
224 files changed:
diff --git a/.gitignore b/.gitignore
index d74238957e438cfc15b2494c58bc9c50b4451fb7..8154d73329ba87a31d90b4182d815f447ddabe21 100644 (file)
--- a/.gitignore
+++ b/.gitignore
# lint stuff
*.ln
+#ide stuff
+.vscode
+
+# cscope stuff
+cscope.*
+
# Unit tests
src/daemon/test-suite.log
src/tests/
index bdffa923657169fbcac21a44e46511f8d342e17d..f5f6db0eeb84c386fe6be619e30a4d1abd2e3d12 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
- Normalization in the CPU plugin.
- Relative values in the Load plugin.
-Ruben Kerkhof <ruben@rubenkerkhof.com>
+Ruben Kerkhof <ruben at rubenkerkhof.com>
- Bugfixes and enhancements in many places all around the project.
- - Fedora package.
+ - Fedora and EPEL packages.
Sebastian "tokkee" Harl <sh at tokkee.org>
- Bugfixes and enhancements in many places all around the project.
- - gprc plugin.
+ - grpc plugin.
- perl plugin.
- postgresql plugin.
- users plugin.
Mirko Buffoni <briareos at eswat.org>
- Port/Socket selection in the MySQL plugin.
+Nicolas Jourden <nicolas.jourden at laposte.net>
+ - gps plugin.
+
Niki W. Waibel <niki.waibel at newlogic.com>
- Initial autotools fixes.
- libltdl code.
index 1c3af7a4baa251640ac45a21a96cd04b7236b6a1..f2df12cdd34c253dc31d15a30533d90204d64ad9 100644 (file)
--- a/README
+++ b/README
- cpufreq
CPU frequency (For laptops with speed step or a similar technology)
+ - cpusleep
+ CPU sleep: Time spent in suspend (For mobile devices which enter suspend automatically)
+
- curl
Parse statistics from websites using regular expressions.
- gmond
Receive multicast traffic from Ganglia instances.
+ - gps
+ Monitor gps related data through gpsd.
+
- grpc
Receive values over the network using the gRPC framework.
Used by the `network' plugin for encryption and authentication.
<http://www.gnupg.org/>
+ * libgps (optional)
+ Used by the `gps' plugin.
+ <http://developer.berlios.de/projects/gpsd/>
+
* libhal (optional)
If present, the `uuid' plugin will check for UUID from HAL.
<http://hal.freedesktop.org/>
diff --git a/configure.ac b/configure.ac
index 15b42d5944ebd61021c2f2bf0fa7c9a9241ca236..8dda7104514bd760b0f8373004c09bb99b5b4162 100644 (file)
--- a/configure.ac
+++ b/configure.ac
dnl Process this file with autoconf to produce a configure script.
+AC_PREREQ([2.60])
AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)])
AC_CONFIG_SRCDIR(src/target_set.c)
AC_CONFIG_HEADERS(src/config.h)
#
# Checks for programs.
#
-AC_PROG_CC
+AC_PROG_CC_C99([],
+ [AC_MSG_ERROR([No compiler found that supports C99])]
+)
AC_PROG_CXX
AC_PROG_CPP
AC_PROG_EGREP
have_protoc3="no"
if test "x$PROTOC" != "x"; then
AC_MSG_CHECKING([for protoc 3.0.0+])
- if $PROTOC --version | grep -q libprotoc.3; then
+ if $PROTOC --version | $EGREP libprotoc.3 >/dev/null; then
protoc3="yes (`$PROTOC --version`)"
have_protoc3="yes"
else
#include <linux/major.h>
#include <linux/types.h>
])
+ AC_CHECK_HEADERS([sys/sysmacros.h])
else
have_linux_raid_md_u_h="no"
fi
have_termios_h="no"
AC_CHECK_HEADERS(termios.h, [have_termios_h="yes"])
+# For cpusleep plugin
+AC_CACHE_CHECK([whether clock_boottime and clock_monotonic are supported],
+ [c_cv_have_clock_boottime_monotonic],
+ AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+[[
+#include <time.h>
+]],
+[[
+ struct timespec b, m;
+ clock_gettime(CLOCK_BOOTTIME, &b );
+ clock_gettime(CLOCK_MONOTONIC, &m );
+]]
+ )],
+ [c_cv_have_clock_boottime_monotonic="yes"],
+ [c_cv_have_clock_boottime_monotonic="no"]))
+
+
# For the turbostat plugin
have_asm_msrindex_h="no"
AC_CHECK_HEADERS(asm/msr-index.h, [have_asm_msrindex_h="yes"])
#
# Checks for library functions.
#
-AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale)
+AC_CHECK_FUNCS(gettimeofday select strdup strtol getaddrinfo getnameinfo strchr memcpy strstr strcmp strncmp strncpy strlen strncasecmp strcasecmp openlog closelog sysconf setenv if_indextoname setlocale asprintf)
AC_FUNC_STRERROR_R
@@ -1350,6 +1371,20 @@ AC_ARG_WITH(useragent, [AS_HELP_STRING([--with-useragent@<:@=AGENT@:>@], [User a
# }}}
+# --with-data-max-name-len {{{
+AC_ARG_WITH(data-max-name-len, [AS_HELP_STRING([--with-data-max-name-len@<:@=VALUE@:>@], [Maximum length of data buffers])],
+[
+ if test "x$withval" != "x" && test $withval -gt 0
+ then
+ AC_DEFINE_UNQUOTED(DATA_MAX_NAME_LEN, [$withval], [Maximum length of data buffers])
+ else
+ AC_MSG_ERROR([DATA_MAX_NAME_LEN must be a positive integer -- $withval given])
+ fi
+],
+[ AC_DEFINE(DATA_MAX_NAME_LEN, 128, [Maximum length of data buffers])]
+)
+# }}}
+
have_getfsstat="no"
AC_CHECK_FUNCS(getfsstat, [have_getfsstat="yes"])
have_getvfsstat="no"
fi
if test "x$have_getmntent" = "xsun"; then
AC_DEFINE(HAVE_SUN_GETMNTENT, 1,
- [Define if the function getmntent exists. It's the version from libsun.])
+ [Define if the function getmntent exists. It is the version from libsun.])
fi
if test "x$have_getmntent" = "xseq"; then
AC_DEFINE(HAVE_SEQ_GETMNTENT, 1,
- [Define if the function getmntent exists. It's the version from libseq.])
+ [Define if the function getmntent exists. It is the version from libseq.])
fi
if test "x$have_getmntent" = "xgen"; then
AC_DEFINE(HAVE_GEN_GETMNTENT, 1,
- [Define if the function getmntent exists. It's the version from libgen.])
+ [Define if the function getmntent exists. It is the version from libgen.])
fi
# Check for htonll
AM_CONDITIONAL(BUILD_WITH_LIBGCRYPT, test "x$with_libgcrypt" = "xyes")
# }}}
+# --with-libgps {{{
+with_libgps_cflags=""
+with_libgps_ldflags=""
+AC_ARG_WITH(libgps, [AS_HELP_STRING([--with-libgps@<:@=PREFIX@:>@], [Path to libgps.])],
+[
+ if test "x$withval" != "xno" && test "x$withval" != "xyes"
+ then
+ with_libgps_cflags="-I$withval/include"
+ with_libgps_ldflags="-L$withval/lib"
+ with_libgps="yes"
+ else
+ with_libgps="$withval"
+ fi
+],
+[
+ with_libgps="yes"
+])
+if test "x$with_libgps" = "xyes"
+then
+ SAVE_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $with_libgps_cflags"
+
+ AC_CHECK_HEADERS(gps.h, [with_libgps="yes"], [with_libgps="no (gps.h not found)"])
+
+ CFLAGS="$SAVE_CFLAGS"
+fi
+if test "x$with_libgps" = "xyes"
+then
+ SAVE_CFLAGS="$CFLAGS"
+ SAVE_LDFLAGS="$LDFLAGS"
+ CFLAGS="$CFLAGS $with_libgps_cflags"
+ LDFLAGS="$LDFLAGS $with_libgps_ldflags"
+
+ AC_CHECK_LIB(gps, gps_open, [with_libgps="yes"], [with_libgps="no (symbol gps_open not found)"])
+
+ CFLAGS="$SAVE_CFLAGS"
+ LDFLAGS="$SAVE_LDFLAGS"
+fi
+if test "x$with_libgps" = "xyes"
+then
+ BUILD_WITH_LIBGPS_CFLAGS="$with_libgps_cflags"
+ BUILD_WITH_LIBGPS_LDFLAGS="$with_libgps_ldflags"
+ BUILD_WITH_LIBGPS_LIBS="-lgps"
+ AC_SUBST(BUILD_WITH_LIBGPS_CFLAGS)
+ AC_SUBST(BUILD_WITH_LIBGPS_LDFLAGS)
+ AC_SUBST(BUILD_WITH_LIBGPS_LIBS)
+fi
+AM_CONDITIONAL(BUILD_WITH_LIBGPS, test "x$with_libgps" = "xyes")
+# }}}
+
# --with-libgrpc++ {{{
with_libgrpcpp_cppflags=""
with_libgrpcpp_ldflags=""
then
AC_LANG_PUSH(C++)
SAVE_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS -std=c++11"
+ CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS"
AC_CHECK_HEADERS([grpc++/grpc++.h], [],
[with_libgrpcpp="no (<grpc++/grpc++.h> not found)"]
)
if test "x$with_libgrpcpp" = "xyes"
then
AC_LANG_PUSH(C++)
+ SAVE_CPPFLAGS="$CPPFLAGS"
SAVE_LDFLAGS="$LDFLAGS"
SAVE_LIBS="$LIBS"
+ CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS"
LDFLAGS="$with_libgrpcpp_ldflags"
if test "x$GRPCPP_LIBS" = "x"
then
],
[with_libgrpcpp="no (libgrpc++ not found)"]
)
+ CPPFLAGS="$SAVE_CPPFLAGS"
LDFLAGS="$SAVE_LDFLAGS"
LIBS="$SAVE_LIBS"
AC_LANG_POP(C++)
@@ -2361,11 +2449,6 @@ AC_ARG_WITH(libiptc, [AS_HELP_STRING([--with-libiptc@<:@=PREFIX@:>@], [Path to l
fi
])
-if test "x$with_libiptc" = "xpkgconfig" && test "x$PKG_CONFIG" = "x"
-then
- with_libiptc="no (Don't have pkg-config)"
-fi
-
if test "x$with_libiptc" = "xpkgconfig"
then
$PKG_CONFIG --exists 'libiptc' 2>/dev/null
@@ -2802,13 +2885,6 @@ AC_ARG_WITH(libmodbus, [AS_HELP_STRING([--with-libmodbus@<:@=PREFIX@:>@], [Path
# configure using pkg-config
if test "x$with_libmodbus" = "xuse_pkgconfig"
-then
- if test "x$PKG_CONFIG" = "x"
- then
- with_libmodbus="no (Don't have pkg-config)"
- fi
-fi
-if test "x$with_libmodbus" = "xuse_pkgconfig"
then
AC_MSG_NOTICE([Checking for libmodbus using $PKG_CONFIG])
$PKG_CONFIG --exists 'libmodbus' 2>/dev/null
@@ -3100,10 +3176,6 @@ AC_ARG_WITH(libmnl, [AS_HELP_STRING([--with-libmnl@<:@=PREFIX@:>@], [Path to lib
with_libmnl="no (Linux only library)"
fi
])
-if test "x$PKG_CONFIG" = "x"
-then
- with_libmnl="no (Don't have pkg-config)"
-fi
if test "x$with_libmnl" = "xyes"
then
if $PKG_CONFIG --exists libmnl 2>/dev/null; then
SAVE_CFLAGS="$CFLAGS"
SAVE_LIBS="$LIBS"
dnl ARCHFLAGS="" -> disable multi -arch on OSX (see Config_heavy.pl:fetch_string)
- PERL_CFLAGS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e ccopts`
+ PERL_CFLAGS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e perl_inc`
PERL_LIBS=`ARCHFLAGS="" $perl_interpreter -MExtUtils::Embed -e ldopts`
CFLAGS="$CFLAGS $PERL_CFLAGS"
LIBS="$LIBS $PERL_LIBS"
AC_SUBST([BUILD_WITH_LIBPROTOBUF_C_LIBS])
# }}}
-# --with-python {{{
-with_python_prog=""
-with_python_path="$PATH"
-AC_ARG_WITH(python, [AS_HELP_STRING([--with-python@<:@=PREFIX@:>@], [Path to the python interpreter.])],
-[
- if test "x$withval" = "xyes" || test "x$withval" = "xno"
- then
- with_python="$withval"
- else if test -x "$withval"
- then
- with_python_prog="$withval"
- with_python_path="`dirname \"$withval\"`$PATH_SEPARATOR$with_python_path"
- with_python="yes"
- else if test -d "$withval"
- then
- with_python_path="$withval$PATH_SEPARATOR$with_python_path"
- with_python="yes"
- else
- AC_MSG_WARN([Argument not recognized: $withval])
- fi; fi; fi
-], [with_python="yes"])
-
-SAVE_PATH="$PATH"
-SAVE_CPPFLAGS="$CPPFLAGS"
-SAVE_LDFLAGS="$LDFLAGS"
-SAVE_LIBS="$LIBS"
-
-PATH="$with_python_path"
-
-if test "x$with_python" = "xyes" && test "x$with_python_prog" = "x"
-then
- AC_PATH_PROG([PYTHON], [python])
- if test "x$PYTHON" = "x"
- then
- with_python="no (interpreter not found)"
- else
- with_python_prog="$PYTHON"
- fi
-fi
+# --with-libpython {{{
+AC_ARG_VAR([LIBPYTHON_CPPFLAGS], [Preprocessor flags for libpython])
+AC_ARG_VAR([LIBPYTHON_LDFLAGS], [Linker flags for libpython])
+AC_ARG_VAR([LIBPYTHON_LIBS], [Libraries for libpython])
-if test "x$with_python" = "xyes"
-then
- AC_MSG_CHECKING([for Python CPPFLAGS])
- python_include_path=`echo "import distutils.sysconfig;import sys;sys.stdout.write(distutils.sysconfig.get_python_inc())" | "$with_python_prog" 2>&1`
- python_config_status=$?
-
- if test "$python_config_status" -ne 0 || test "x$python_include_path" = "x"
- then
- AC_MSG_RESULT([failed with status $python_config_status (output: $python_include_path)])
- with_python="no"
- else
- AC_MSG_RESULT([$python_include_path])
- fi
-fi
-
-if test "x$with_python" = "xyes"
-then
- CPPFLAGS="-I$python_include_path $CPPFLAGS"
- AC_CHECK_HEADERS(Python.h,
- [with_python="yes"],
- [with_python="no ('Python.h' not found)"])
-fi
-
-if test "x$with_python" = "xyes"
-then
- AC_MSG_CHECKING([for Python LDFLAGS])
- python_library_path=`echo "import distutils.sysconfig;import sys;sys.stdout.write(distutils.sysconfig.get_config_vars(\"LIBDIR\").__getitem__(0))" | "$with_python_prog" 2>&1`
- python_config_status=$?
-
- if test "$python_config_status" -ne 0 || test "x$python_library_path" = "x"
- then
- AC_MSG_RESULT([failed with status $python_config_status (output: $python_library_path)])
- with_python="no"
- else
- AC_MSG_RESULT([$python_library_path])
- fi
-fi
-
-if test "x$with_python" = "xyes"
-then
- AC_MSG_CHECKING([for Python LIBS])
- python_library_flags=`echo "import distutils.sysconfig;import sys;sys.stdout.write(distutils.sysconfig.get_config_vars(\"BLDLIBRARY\").__getitem__(0))" | "$with_python_prog" 2>&1`
- python_config_status=$?
-
- if test "$python_config_status" -ne 0 || test "x$python_library_flags" = "x"
- then
- AC_MSG_RESULT([failed with status $python_config_status (output: $python_library_flags)])
- with_python="no"
- else
- AC_MSG_RESULT([$python_library_flags])
- fi
+AC_ARG_WITH([libpython],
+ [AS_HELP_STRING([--with-libpython],
+ [if we should build with libpython @<:@default=yes@:>@])
+ ],
+ [with_libpython="$withval"],
+ [with_libpython="check"]
+)
+if test "$with_libpython" != "no"; then
+ if test "$LIBPYTHON_CPPFLAGS" = "" && test "$LIBPYTHON_LDFLAGS" = ""; then
+ AC_ARG_VAR([PYTHON_CONFIG], [path to python-config])
+ AC_PATH_PROGS([PYTHON_CONFIG],
+ [python3-config python2-config python-config]
+ )
+ if test "$PYTHON_CONFIG" = ""; then
+ if test "$with_libpython" = "yes"; then
+ AC_MSG_ERROR([Unable to find python-config])
+ fi
+ with_libpython="no"
+ fi
+ fi
fi
-if test "x$with_python" = "xyes"
-then
- LDFLAGS="-L$python_library_path $LDFLAGS"
- LIBS="$python_library_flags $LIBS"
-
- AC_CHECK_FUNC(PyObject_CallFunction,
- [with_python="yes"],
- [with_python="no (Symbol 'PyObject_CallFunction' not found)"])
+if test "$PYTHON_CONFIG" != ""; then
+ LIBPYTHON_CPPFLAGS="`${PYTHON_CONFIG} --includes`"
+ if test $? -ne 0; then
+ with_libpython="no"
+ fi
+ LIBPYTHON_LDFLAGS="`${PYTHON_CONFIG} --ldflags`"
+ if test $? -ne 0; then
+ with_libpython="no"
+ fi
+ LIBPYTHON_LIBS="`${PYTHON_CONFIG} --libs`"
+ if test $? -ne 0; then
+ with_libpython="no"
+ fi
fi
-PATH="$SAVE_PATH"
-CPPFLAGS="$SAVE_CPPFLAGS"
-LDFLAGS="$SAVE_LDFLAGS"
-LIBS="$SAVE_LIBS"
-
-if test "x$with_python" = "xyes"
-then
- BUILD_WITH_PYTHON_CPPFLAGS="-I$python_include_path"
- BUILD_WITH_PYTHON_LDFLAGS="-L$python_library_path"
- BUILD_WITH_PYTHON_LIBS="$python_library_flags"
- AC_SUBST(BUILD_WITH_PYTHON_CPPFLAGS)
- AC_SUBST(BUILD_WITH_PYTHON_LDFLAGS)
- AC_SUBST(BUILD_WITH_PYTHON_LIBS)
+if test "$with_libpython" != "xno"; then
+ SAVE_CPPFLAGS="$CPPFLAGS"
+ SAVE_LDFLAGS="$LDFLAGS"
+ SAVE_LIBS="$LIBS"
+ CPPFLAGS="$LIBPYTHON_CPPFLAGS $CPPFLAGS"
+ LDFLAGS="$LIBPYTHON_LDFLAGS $LDFLAGS"
+ LIBS="$LIBPYTHON_LIBS $LIBS"
+ AC_CHECK_HEADERS([Python.h],
+ [
+ AC_MSG_CHECKING([for libpython])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM(
+ [[#include <Python.h>]],
+ [[Py_Initialize();]])
+ ],
+ [with_libpython="yes"],
+ [with_libpython="no"]
+ )
+ AC_MSG_RESULT([$with_libpython])
+ ],
+ [with_libpython="no"]
+ )
+ CPPFLAGS="$SAVE_CPPFLAGS"
+ LDFLAGS="$SAVE_LDFLAGS"
+ LIBS="$SAVE_LIBS"
fi
-# }}} --with-python
+# }}} --with-libpython
# --with-librabbitmq {{{
with_librabbitmq_cppflags=""
AM_CONDITIONAL(BUILD_WITH_LM_SENSORS, test "x$with_libsensors" = "xyes")
# }}}
-# --with-libsigrok {{{
-with_libsigrok_cflags=""
-with_libsigrok_ldflags=""
-AC_ARG_WITH(libsigrok, [AS_HELP_STRING([--with-libsigrok@<:@=PREFIX@:>@], [Path to libsigrok.])],
-[
- if test "x$withval" = "xno"
- then
- with_libsigrok="no"
- else
- with_libsigrok="yes"
- if test "x$withval" != "xyes"
- then
- with_libsigrok_cflags="-I$withval/include"
- with_libsigrok_ldflags="-L$withval/lib"
- fi
- fi
-],[with_libsigrok="yes"])
-
-# libsigrok has a glib dependency
-if test "x$with_libsigrok" = "xyes"
-then
-m4_ifdef([AM_PATH_GLIB_2_0],
- [
- AM_PATH_GLIB_2_0([2.28.0],
- [with_libsigrok_cflags="$with_libsigrok_cflags $GLIB_CFLAGS"; with_libsigrok_ldflags="$with_libsigrok_ldflags $GLIB_LIBS"])
- ],
- [
- with_libsigrok="no (glib not available)"
- ]
+# libsigrok {{{
+AC_SUBST([LIBSIGROK_CFLAGS])
+AC_SUBST([LIBSIGROK_LIBS])
+PKG_CHECK_MODULES([LIBSIGROK], [libsigrok < 0.4],
+ [with_libsigrok="yes"],
+ [with_libsigrok="no (pkg-config could not find libsigrok)"]
)
-fi
-
-# libsigrok headers
-if test "x$with_libsigrok" = "xyes"
-then
- SAVE_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $with_libsigrok_cflags"
-
- AC_CHECK_HEADERS(libsigrok/libsigrok.h, [], [with_libsigrok="no (libsigrok/libsigrok.h not found)"])
-
- CPPFLAGS="$SAVE_CPPFLAGS"
-fi
-
-# libsigrok library
-if test "x$with_libsigrok" = "xyes"
-then
- SAVE_CPPFLAGS="$CPPFLAGS"
- SAVE_LDFLAGS="$LDFLAGS"
- CPPFLAGS="$CPPFLAGS $with_libsigrok_cflags"
- LDFLAGS="$LDFLAGS $with_libsigrok_ldflags"
-
- AC_CHECK_LIB(sigrok, sr_init,
- [
- AC_DEFINE(HAVE_LIBSIGROK, 1, [Define to 1 if you have the sigrok library (-lsigrok).])
- ],
- [with_libsigrok="no (libsigrok not found)"])
-
- CPPFLAGS="$SAVE_CPPFLAGS"
- LDFLAGS="$SAVE_LDFLAGS"
-fi
-if test "x$with_libsigrok" = "xyes"
-then
- BUILD_WITH_LIBSIGROK_CFLAGS="$with_libsigrok_cflags"
- BUILD_WITH_LIBSIGROK_LDFLAGS="$with_libsigrok_ldflags"
- AC_SUBST(BUILD_WITH_LIBSIGROK_CFLAGS)
- AC_SUBST(BUILD_WITH_LIBSIGROK_LDFLAGS)
-fi
-AM_CONDITIONAL(BUILD_WITH_LIBSIGROK, test "x$with_libsigrok" = "xyes")
# }}}
# --with-libstatgrab {{{
@@ -4591,23 +4552,16 @@ AC_ARG_WITH(libstatgrab, [AS_HELP_STRING([--with-libstatgrab@<:@=PREFIX@:>@], [P
if test "x$with_libstatgrab" = "xyes" \
&& test "x$with_libstatgrab_pkg_config" = "xyes"
then
- if test "x$PKG_CONFIG" != "x"
+ AC_MSG_CHECKING([pkg-config for libstatgrab])
+ temp_result="found"
+ $PKG_CONFIG --exists libstatgrab 2>/dev/null
+ if test "$?" != "0"
then
- AC_MSG_CHECKING([pkg-config for libstatgrab])
- temp_result="found"
- $PKG_CONFIG --exists libstatgrab 2>/dev/null
- if test "$?" != "0"
- then
- with_libstatgrab_pkg_config="no"
- with_libstatgrab="no (pkg-config doesn't know libstatgrab)"
- temp_result="not found"
- fi
- AC_MSG_RESULT([$temp_result])
- else
- AC_MSG_NOTICE([pkg-config not available, trying to guess flags for the statgrab library.])
with_libstatgrab_pkg_config="no"
- with_libstatgrab_ldflags="$with_libstatgrab_ldflags -lstatgrab"
+ with_libstatgrab="no (pkg-config doesn't know libstatgrab)"
+ temp_result="not found"
fi
+ AC_MSG_RESULT([$temp_result])
fi
if test "x$with_libstatgrab" = "xyes" \
# configure using pkg-config
if test "x$with_libupsclient" = "xuse_pkgconfig"
-then
- if test "x$PKG_CONFIG" = "x"
- then
- with_libupsclient="no (Don't have pkg-config)"
- fi
-fi
-if test "x$with_libupsclient" = "xuse_pkgconfig"
then
AC_MSG_NOTICE([Checking for libupsclient using $PKG_CONFIG])
$PKG_CONFIG --exists 'libupsclient' 2>/dev/null
@@ -5233,13 +5180,6 @@ AC_ARG_WITH(libvarnish, [AS_HELP_STRING([--with-libvarnish@<:@=PREFIX@:>@], [Pat
# configure using pkg-config
if test "x$with_libvarnish" = "xuse_pkgconfig"
-then
- if test "x$PKG_CONFIG" = "x"
- then
- with_libvarnish="no (Don't have pkg-config)"
- fi
-fi
-if test "x$with_libvarnish" = "xuse_pkgconfig"
then
AC_MSG_NOTICE([Checking for varnishapi using $PKG_CONFIG])
$PKG_CONFIG --exists 'varnishapi' 2>/dev/null
with_libvirt="no (pkg-config isn't available)"
with_libvirt_cflags=""
with_libvirt_ldflags=""
-if test "x$PKG_CONFIG" != "x"
+$PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null
+if test "$?" = "0"
then
- $PKG_CONFIG --exists 'libxml-2.0' 2>/dev/null
- if test "$?" = "0"
- then
- with_libxml2="yes"
- else
- with_libxml2="no (pkg-config doesn't know libxml-2.0)"
- fi
+ with_libxml2="yes"
+else
+ with_libxml2="no (pkg-config doesn't know libxml-2.0)"
+fi
- $PKG_CONFIG --exists libvirt 2>/dev/null
- if test "$?" = "0"
- then
- with_libvirt="yes"
- else
- with_libvirt="no (pkg-config doesn't know libvirt)"
- fi
+$PKG_CONFIG --exists libvirt 2>/dev/null
+if test "$?" = "0"
+then
+ with_libvirt="yes"
+else
+ with_libvirt="no (pkg-config doesn't know libvirt)"
fi
if test "x$with_libxml2" = "xyes"
then
with_libopenipmipthread_cflags=""
with_libopenipmipthread_libs=""
-AC_MSG_CHECKING([for pkg-config])
-temp_result="no"
-if test "x$PKG_CONFIG" = "x"
-then
- with_libopenipmipthread="no"
- temp_result="no"
-else
- temp_result="$PKG_CONFIG"
-fi
-AC_MSG_RESULT([$temp_result])
-
if test "x$with_libopenipmipthread" = "xyes"
then
AC_MSG_CHECKING([for libOpenIPMIpthread])
plugin_contextswitch="no"
plugin_cpu="no"
plugin_cpufreq="no"
+plugin_cpusleep="no"
plugin_curl_json="no"
plugin_curl_xml="no"
plugin_df="no"
plugin_ethstat="no"
plugin_fhcount="no"
plugin_fscache="no"
+plugin_gps="no"
plugin_grpc="no"
plugin_interface="no"
plugin_ipmi="no"
plugin_pinba="no"
plugin_processes="no"
plugin_protocols="no"
+plugin_python="no"
plugin_serial="no"
plugin_smart="no"
plugin_swap="no"
then
plugin_turbostat="yes"
fi
+
+ if test "x$c_cv_have_clock_boottime_monotonic" = "xyes"
+ then
+ plugin_cpusleep="yes"
+ fi
fi
if test "x$ac_system" = "xOpenBSD"
plugin_interface="yes"
fi
+if test "x$with_libgps" = "xyes"
+then
+ plugin_gps="yes"
+fi
+
if test "x$have_getloadavg" = "xyes"
then
plugin_load="yes"
plugin_processes="yes"
fi
+if test "x$with_libpython" != "xno"
+then
+ plugin_python="yes"
+fi
+
if test "x$with_libatasmart" = "xyes" && test "x$with_libudev" = "xyes"
then
plugin_smart="yes"
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([cpusleep], [$plugin_cpusleep], [CPU sleep 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([filecount], [yes], [Count files in directories])
AC_PLUGIN([fscache], [$plugin_fscache], [fscache statistics])
AC_PLUGIN([gmond], [$with_libganglia], [Ganglia plugin])
+AC_PLUGIN([gps], [$plugin_gps], [GPS plugin])
AC_PLUGIN([grpc], [$plugin_grpc], [gRPC plugin])
AC_PLUGIN([hddtemp], [yes], [Query hddtempd])
AC_PLUGIN([interface], [$plugin_interface], [Interface traffic 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([python], [$plugin_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_MSG_RESULT([ libesmtp . . . . . . $with_libesmtp])
AC_MSG_RESULT([ libganglia . . . . . $with_libganglia])
AC_MSG_RESULT([ libgcrypt . . . . . . $with_libgcrypt])
+AC_MSG_RESULT([ libgps . . . . . . . $with_libgps])
AC_MSG_RESULT([ libgrpc++ . . . . . . $with_libgrpcpp])
AC_MSG_RESULT([ libhal . . . . . . . $with_libhal])
AC_MSG_RESULT([ libhiredis . . . . . $with_libhiredis])
AC_MSG_RESULT([ libpq . . . . . . . . $with_libpq])
AC_MSG_RESULT([ libprotobuf . . . . . $with_libprotobuf])
AC_MSG_RESULT([ libprotobuf-c . . . . $with_libprotobuf_c])
+AC_MSG_RESULT([ libpython . . . . . . $with_libpython])
AC_MSG_RESULT([ librabbitmq . . . . . $with_librabbitmq])
AC_MSG_RESULT([ libriemann-client . . $with_libriemann_client])
AC_MSG_RESULT([ librdkafka . . . . . $with_librdkafka])
AC_MSG_RESULT([ oracle . . . . . . . $with_oracle])
AC_MSG_RESULT([ protobuf-c . . . . . $have_protoc_c])
AC_MSG_RESULT([ protoc 3 . . . . . . $have_protoc3])
-AC_MSG_RESULT([ python . . . . . . . $with_python])
AC_MSG_RESULT()
AC_MSG_RESULT([ Features:])
AC_MSG_RESULT([ daemon mode . . . . . $enable_daemon])
AC_MSG_RESULT([ contextswitch . . . . $enable_contextswitch])
AC_MSG_RESULT([ cpu . . . . . . . . . $enable_cpu])
AC_MSG_RESULT([ cpufreq . . . . . . . $enable_cpufreq])
+AC_MSG_RESULT([ cpusleep . . . . . . $enable_cpusleep])
AC_MSG_RESULT([ csv . . . . . . . . . $enable_csv])
AC_MSG_RESULT([ curl . . . . . . . . $enable_curl])
AC_MSG_RESULT([ curl_json . . . . . . $enable_curl_json])
AC_MSG_RESULT([ filecount . . . . . . $enable_filecount])
AC_MSG_RESULT([ fscache . . . . . . . $enable_fscache])
AC_MSG_RESULT([ gmond . . . . . . . . $enable_gmond])
+AC_MSG_RESULT([ gps . . . . . . . . . $enable_gps])
AC_MSG_RESULT([ grpc . . . . . . . . $enable_grpc])
AC_MSG_RESULT([ hddtemp . . . . . . . $enable_hddtemp])
AC_MSG_RESULT([ interface . . . . . . $enable_interface])
index 9539062c9383b88ace7e06954ec60e6bb9fa6684..e1b89f6c110c2953d37dae987690310a804c10a3 100644 (file)
#endif /* ! HAVE_CONFIG */
#include <collectd/collectd.h>
+
#include <collectd/common.h>
#include <collectd/plugin.h>
index 5b018f8a85073d6f1dc045da285b0cf3ec40fe9c..355c9e3d9a39f6c3e7772445c08e4dc27760d0b1 100644 (file)
%define with_contextswitch 0%{!?_without_contextswitch:1}
%define with_cpu 0%{!?_without_cpu:1}
%define with_cpufreq 0%{!?_without_cpufreq:1}
+%define with_cpusleep 0%{!?_without_cpusleep:1}
%define with_csv 0%{!?_without_csv:1}
%define with_curl 0%{!?_without_curl:1}
%define with_curl_json 0%{!?_without_curl_json:1}
%define with_filecount 0%{!?_without_filecount:1}
%define with_fscache 0%{!?_without_fscache:1}
%define with_gmond 0%{!?_without_gmond:1}
+%define with_gps 0%{!?_without_gps:1}
%define with_hddtemp 0%{!?_without_hddtemp:1}
%define with_interface 0%{!?_without_interface:1}
%define with_ipc 0%{!?_without_ipc:1}
# Plugins not buildable on RHEL < 7
%if 0%{?rhel} && 0%{?rhel} < 7
+%define with_cpusleep 0
+%define with_gps 0
%define with_mqtt 0
%define with_rrdcached 0
%define with_xmms 0
the client daemon of the Ganglia project.
%endif
+%if %{with_gps}
+%package gps
+Summary: GPS plugin for collectd
+Group: System Environment/Daemons
+Requires: %{name}%{?_isa} = %{version}-%{release}
+BuildRequires: gpsd-devel
+%description gps
+This plugin monitor gps related data through gpsd.
+%endif
+
%if %{with_grpc}
%package grpc
Summary: GRPC plugin for collectd
%define _with_cpufreq --disable-cpufreq
%endif
+%if %{with_cpusleep}
+%define _with_cpusleep --enable-cpusleep
+%else
+%define _with_cpusleep --disable-cpusleep
+%endif
+
%if %{with_csv}
%define _with_csv --enable-csv
%else
%define _with_gmond --disable-gmond
%endif
+%if %{with_gps}
+%define _with_gps --enable-gps
+%else
+%define _with_gps --disable-gps
+%endif
+
%if %{with_grpc}
%define _with_grpc --enable-grpc
%else
%if %{with_python}
%if 0%{?rhel} && 0%{?rhel} < 6
%define _with_python --enable-python --with-python=%{_bindir}/python2.6
+%define _python_config PYTHON_CONFIG="%{_bindir}/python2.6-config"
%else
%define _with_python --enable-python
%endif
%endif
%configure CFLAGS="%{optflags} -DLT_LAZY_OR_NOW=\"RTLD_LAZY|RTLD_GLOBAL\"" \
+ %{?_python_config} \
--disable-static \
--without-included-ltdl \
--enable-all-plugins=yes \
%{?_with_conntrack} \
%{?_with_contextswitch} \
%{?_with_cpufreq} \
+ %{?_with_cpusleep} \
%{?_with_cpu} \
%{?_with_csv} \
%{?_with_curl_json} \
%{?_with_filecount} \
%{?_with_fscache} \
%{?_with_gmond} \
+ %{?_with_gps} \
%{?_with_grpc} \
%{?_with_hddtemp} \
%{?_with_interface} \
%if %{with_cpufreq}
%{_libdir}/%{name}/cpufreq.so
%endif
+%if %{with_cpusleep}
+%{_libdir}/%{name}/cpusleep.so
+%endif
%if %{with_csv}
%{_libdir}/%{name}/csv.so
%endif
%{_libdir}/%{name}/gmond.so
%endif
+%if %{with_gps}
+%files gps
+%{_libdir}/%{name}/gps.so
+%endif
+
%if %{with_grpc}
%files grpc
%{_libdir}/%{name}/grpc.so
diff --git a/src/Makefile.am b/src/Makefile.am
index a4ca01e795658749fdc399e8b9c7bd1f6b94ab46..12c7730cc95a5779a170ec9eb42de0a6b492bfe3 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
check_PROGRAMS =
TESTS =
+noinst_LTLIBRARIES += libformat_json.la
+libformat_json_la_SOURCES = utils_format_json.c utils_format_json.h
+libformat_json_la_CPPFLAGS = $(AM_CPPFLAGS)
+libformat_json_la_LDFLAGS = $(AM_LDFLAGS)
+libformat_json_la_LIBADD =
+if BUILD_WITH_LIBYAJL
+libformat_json_la_CPPFLAGS += $(BUILD_WITH_LIBYAJL_CPPFLAGS)
+libformat_json_la_LDFLAGS += $(BUILD_WITH_LIBYAJL_LDFLAGS)
+libformat_json_la_LIBADD += $(BUILD_WITH_LIBYAJL_LIBS)
+check_PROGRAMS += test_format_json
+TESTS += test_format_json
+test_format_json_SOURCES = utils_format_json_test.c testing.h
+test_format_json_LDADD = libformat_json.la daemon/libmetadata.la daemon/libplugin_mock.la -lm
+endif
+
noinst_LTLIBRARIES += liblatency.la
liblatency_la_SOURCES = utils_latency.c utils_latency.h
check_PROGRAMS += test_utils_latency
amqp_la_SOURCES = amqp.c \
utils_cmd_putval.c utils_cmd_putval.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
+ utils_format_graphite.c utils_format_graphite.h
amqp_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRABBITMQ_LDFLAGS)
amqp_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRABBITMQ_CPPFLAGS)
-amqp_la_LIBADD = $(BUILD_WITH_LIBRABBITMQ_LIBS)
+amqp_la_LIBADD = $(BUILD_WITH_LIBRABBITMQ_LIBS) libformat_json.la
endif
if BUILD_PLUGIN_APACHE
cpufreq_la_LDFLAGS = $(PLUGIN_LDFLAGS)
endif
+if BUILD_PLUGIN_CPUSLEEP
+pkglib_LTLIBRARIES += cpusleep.la
+cpusleep_la_SOURCES = cpusleep.c
+cpusleep_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+endif
+
if BUILD_PLUGIN_CSV
pkglib_LTLIBRARIES += csv.la
csv_la_SOURCES = csv.c
gmond_la_LIBADD = $(GANGLIA_LIBS)
endif
+if BUILD_PLUGIN_GPS
+pkglib_LTLIBRARIES += gps.la
+gps_la_SOURCES = gps.c
+gps_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBGPS_CFLAGS)
+gps_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBGPS_LDFLAGS)
+gps_la_LIBADD = -lpthread $(BUILD_WITH_LIBGPS_LIBS)
+endif
+
if BUILD_PLUGIN_GRPC
pkglib_LTLIBRARIES += grpc.la
grpc_la_SOURCES = grpc.cc
# Despite C99 providing the "bool" type thru stdbool.h, Perl defines its own
# version of that type if HAS_BOOL is not defined... *sigh*
perl_la_CPPFLAGS = $(AM_CPPFLAGS) -DHAS_BOOL=1
+# Despite off_t being 64 bit wide on 64 bit platforms, Perl insist on using
+# off64_t which is only exposed when _LARGEFILE64_SOURCE is defined... *sigh*
+# On older platforms we also need _REENTRANT. _GNU_SOURCE sets both of these.
+perl_la_CPPFLAGS += -D_GNU_SOURCE
perl_la_CFLAGS = $(AM_CFLAGS) \
$(PERL_CFLAGS) \
-DXS_VERSION=\"$(VERSION)\" -DVERSION=\"$(VERSION)\"
if BUILD_PLUGIN_PYTHON
pkglib_LTLIBRARIES += python.la
python_la_SOURCES = python.c pyconfig.c pyvalues.c cpython.h
-python_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_PYTHON_CPPFLAGS)
-python_la_CFLAGS = $(AM_CFLAGS)
+python_la_CPPFLAGS = $(AM_CPPFLAGS) $(LIBPYTHON_CPPFLAGS)
if COMPILER_IS_GCC
-python_la_CFLAGS += -fno-strict-aliasing -Wno-strict-aliasing
+python_la_CPPFLAGS += -fno-strict-aliasing -Wno-strict-aliasing
endif
-python_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_PYTHON_LDFLAGS)
-python_la_LIBADD = $(BUILD_WITH_PYTHON_LIBS)
+python_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(LIBPYTHON_LDFLAGS)
endif
if BUILD_PLUGIN_PROCESSES
if BUILD_PLUGIN_SIGROK
pkglib_LTLIBRARIES += sigrok.la
sigrok_la_SOURCES = sigrok.c
-sigrok_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBSIGROK_CFLAGS)
-sigrok_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBSIGROK_LDFLAGS)
-sigrok_la_LIBADD = -lsigrok
+sigrok_la_CFLAGS = $(AM_CFLAGS) $(LIBSIGROK_CFLAGS)
+sigrok_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+sigrok_la_LIBADD = $(LIBSIGROK_LIBS)
endif
if BUILD_PLUGIN_SMART
if BUILD_PLUGIN_WRITE_GRAPHITE
pkglib_LTLIBRARIES += write_graphite.la
write_graphite_la_SOURCES = write_graphite.c \
- utils_format_graphite.c utils_format_graphite.h \
- utils_format_json.c utils_format_json.h
+ utils_format_graphite.c utils_format_graphite.h
write_graphite_la_LDFLAGS = $(PLUGIN_LDFLAGS)
+write_graphite_la_LIBADD = libformat_json.la
endif
if BUILD_PLUGIN_WRITE_HTTP
pkglib_LTLIBRARIES += write_http.la
write_http_la_SOURCES = write_http.c \
- utils_format_json.c utils_format_json.h \
utils_format_kairosdb.c utils_format_kairosdb.h
-write_http_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS)
write_http_la_LDFLAGS = $(PLUGIN_LDFLAGS)
-write_http_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS)
+write_http_la_CFLAGS = $(AM_CFLAGS) $(BUILD_WITH_LIBCURL_CFLAGS)
+write_http_la_LIBADD = $(BUILD_WITH_LIBCURL_LIBS) libformat_json.la
endif
if BUILD_PLUGIN_WRITE_KAFKA
pkglib_LTLIBRARIES += write_kafka.la
write_kafka_la_SOURCES = write_kafka.c \
utils_format_graphite.c utils_format_graphite.h \
- utils_format_json.c utils_format_json.h \
utils_cmd_putval.c utils_cmd_putval.h \
utils_crc32.c utils_crc32.h
write_kafka_la_CPPFLAGS = $(AM_CPPFLAGS) $(BUILD_WITH_LIBRDKAFKA_CPPFLAGS)
write_kafka_la_LDFLAGS = $(PLUGIN_LDFLAGS) $(BUILD_WITH_LIBRDKAFKA_LDFLAGS)
-write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS)
+write_kafka_la_LIBADD = $(BUILD_WITH_LIBRDKAFKA_LIBS) libformat_json.la
endif
if BUILD_PLUGIN_WRITE_LOG
diff --git a/src/aggregation.c b/src/aggregation.c
index 92f34bc3d3fecde099037cde685db6cddf595947..b9db500b188f17eb7a0a478d07f136feaae9d774 100644 (file)
--- a/src/aggregation.c
+++ b/src/aggregation.c
static int agg_config_handle_group_by (oconfig_item_t const *ci, /* {{{ */
aggregation_t *agg)
{
- int i;
-
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
char const *value;
aggregation_t *agg;
_Bool is_valid;
int status;
- int i;
agg = calloc (1, sizeof (*agg));
if (agg == NULL)
sstrncpy (agg->ident.type_instance, "/.*/",
sizeof (agg->ident.type_instance));
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int agg_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
pthread_mutex_lock (&agg_instance_list_lock);
if (lookup == NULL)
}
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int agg_read (void) /* {{{ */
{
- agg_instance_t *this;
cdtime_t t;
int success;
return (0);
}
- for (this = agg_instance_list_head; this != NULL; this = this->next)
+ for (agg_instance_t *this = agg_instance_list_head; this != NULL; this = this->next)
{
int status;
diff --git a/src/amqp.c b/src/amqp.c
index 9bc3175cebaf0dd25c5a1188f4099e10426ccaac..89f051e81960668c957abfe72239c542ed4681d2 100644 (file)
--- a/src/amqp.c
+++ b/src/amqp.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_cmd_putval.h"
static int camqp_shutdown (void) /* {{{ */
{
- size_t i;
-
DEBUG ("amqp plugin: Shutting down %zu subscriber threads.",
subscriber_threads_num);
subscriber_threads_running = 0;
- for (i = 0; i < subscriber_threads_num; i++)
+ for (size_t i = 0; i < subscriber_threads_num; i++)
{
/* FIXME: Sending a signal is not very elegant here. Maybe find out how
* to use a timeout in the thread and check for the variable in regular
}
else
{
- size_t i;
ssnprintf (routing_key, sizeof (routing_key), "collectd/%s/%s/%s/%s/%s",
vl->host,
vl->plugin, vl->plugin_instance,
/* Switch slashes (the only character forbidden by collectd) and dots
* (the separation character used by AMQP). */
- for (i = 0; routing_key[i] != 0; i++)
+ for (size_t i = 0; routing_key[i] != 0; i++)
{
if (routing_key[i] == '.')
routing_key[i] = '/';
{
camqp_config_t *conf;
int status;
- int i;
conf = calloc (1, sizeof (*conf));
if (conf == NULL)
return (status);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int camqp_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/apache.c b/src/apache.c
index afdeda4ec2eb02a8e5296546102d5e1bfdf9574a..650d67889724d208c5d12cac80910119e7b0bfad 100644 (file)
--- a/src/apache.c
+++ b/src/apache.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int config_add (oconfig_item_t *ci)
{
apache_t *st;
- int i;
int status;
st = calloc (1, sizeof (*st));
}
assert (st->name != NULL);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int config (oconfig_item_t *ci)
{
int status = 0;
- int i;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
long long response_start = 0LL;
long long response_end = 0LL;
- int i;
- for (i = 0; buf[i] != '\0'; i++)
+ for (int i = 0; buf[i] != '\0'; i++)
{
if (buf[i] == '.') open++;
else if (buf[i] == '_') waiting++;
diff --git a/src/apcups.c b/src/apcups.c
index 84249339a2261f7f7f6ca4f429f1d7911687c1f8..cc2035787ea8fb1a595ad4a0ba9e2e52fabef50e 100644 (file)
--- a/src/apcups.c
+++ b/src/apcups.c
**/
#include "collectd.h"
+
#include "common.h" /* rrd_update_file */
#include "plugin.h" /* plugin_register, plugin_submit */
#include "configfile.h" /* cf_register */
{
int sd;
int status;
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_return;
struct addrinfo *ai_list;
/* TODO: Change this to `AF_UNSPEC' if apcupsd can handle IPv6 */
- ai_hints.ai_family = AF_INET;
- ai_hints.ai_socktype = SOCK_STREAM;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_INET,
+ .ai_socktype = SOCK_STREAM
+ };
status = getaddrinfo (node, service, &ai_hints, &ai_return);
if (status != 0)
static int apcups_config (oconfig_item_t *ci)
{
- int i;
_Bool persistent_conn_set = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/apple_sensors.c b/src/apple_sensors.c
index 7ed2016f2a3bee68fffd04c41d106fdf8034b143..48fbcb91e53117832fc26160df4f8ecd4fa96947 100644 (file)
--- a/src/apple_sensors.c
+++ b/src/apple_sensors.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
char inst[128];
int value_int;
double value_double;
- int i;
-
if (!io_master_port || (io_master_port == MACH_PORT_NULL))
return (-1);
kCFStringEncodingASCII))
continue;
inst[sizeof (inst) - 1] = '\0';
- for (i = 0; i < 128; i++)
+ for (int i = 0; i < 128; i++)
{
if (inst[i] == '\0')
break;
diff --git a/src/aquaero.c b/src/aquaero.c
index 5db988e60663f56c39c796596176ff587088c046..81a4efd4337257865dd78d293d065572c3aa7b7e 100644 (file)
--- a/src/aquaero.c
+++ b/src/aquaero.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int aquaero_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
const char *type_instance_prefix, double *value_array, int len)
{
char type_instance[DATA_MAX_NAME_LEN];
- int i;
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
{
if (value_array[i] == AQ5_FLOAT_UNDEF)
continue;
aq5_settings_t aq_sett;
char *err_msg = NULL;
char type_instance[DATA_MAX_NAME_LEN];
- int i;
if (libaquaero5_poll(conf_device, &aq_data, &err_msg) < 0)
{
AQ5_NUM_OTHER_SENSORS);
/* Fans */
- for (i = 0; i < AQ5_NUM_FAN; i++)
+ for (int i = 0; i < AQ5_NUM_FAN; i++)
{
if ((aq_sett.fan_data_source[i] == NONE)
|| (aq_data.fan_vrm_temp[i] != AQ5_FLOAT_UNDEF))
diff --git a/src/ascent.c b/src/ascent.c
index a947bce942ee0e045fe3a77aeadb0802fa41a725..20fef656c1e9acbd989aa29699512c32f023ab52 100644 (file)
--- a/src/ascent.c
+++ b/src/ascent.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
@@ -181,20 +182,19 @@ static size_t ascent_curl_callback (void *buf, size_t size, size_t nmemb, /* {{{
static int ascent_submit_players (player_stats_t *ps) /* {{{ */
{
- size_t i;
gauge_t value;
- for (i = 0; i < RACES_LIST_LENGTH; i++)
+ for (size_t i = 0; i < RACES_LIST_LENGTH; i++)
if (races_list[i] != NULL)
ascent_submit_gauge ("by-race", "players", races_list[i],
(gauge_t) ps->races[i]);
- for (i = 0; i < CLASSES_LIST_LENGTH; i++)
+ for (size_t i = 0; i < CLASSES_LIST_LENGTH; i++)
if (classes_list[i] != NULL)
ascent_submit_gauge ("by-class", "players", classes_list[i],
(gauge_t) ps->classes[i]);
- for (i = 0; i < GENDERS_LIST_LENGTH; i++)
+ for (size_t i = 0; i < GENDERS_LIST_LENGTH; i++)
if (genders_list[i] != NULL)
ascent_submit_gauge ("by-gender", "players", genders_list[i],
(gauge_t) ps->genders[i]);
static int ascent_xml_sessions_plr (xmlDoc *doc, xmlNode *node, /* {{{ */
player_info_t *pi)
{
- xmlNode *child;
-
- for (child = node->xmlChildrenNode; child != NULL; child = child->next)
+ for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next)
{
if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0)
|| (xmlStrcmp ((const xmlChar *) "text", child->name) == 0))
static int ascent_xml_sessions (xmlDoc *doc, xmlNode *node) /* {{{ */
{
- xmlNode *child;
player_stats_t ps = {
.level_sum = 0
};
- for (child = node->xmlChildrenNode; child != NULL; child = child->next)
+ for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next)
{
if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0)
|| (xmlStrcmp ((const xmlChar *) "text", child->name) == 0))
static int ascent_xml_status (xmlDoc *doc, xmlNode *node) /* {{{ */
{
- xmlNode *child;
-
- for (child = node->xmlChildrenNode; child != NULL; child = child->next)
+ for (xmlNode *child = node->xmlChildrenNode; child != NULL; child = child->next)
{
if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0)
|| (xmlStrcmp ((const xmlChar *) "text", child->name) == 0))
{
xmlDoc *doc;
xmlNode *cur;
- xmlNode *child;
#if 0
doc = xmlParseMemory (data, strlen (data),
return (-1);
}
- for (child = cur->xmlChildrenNode; child != NULL; child = child->next)
+ for (xmlNode *child = cur->xmlChildrenNode; child != NULL; child = child->next)
{
if ((xmlStrcmp ((const xmlChar *) "comment", child->name) == 0)
|| (xmlStrcmp ((const xmlChar *) "text", child->name) == 0))
diff --git a/src/barometer.c b/src/barometer.c
index f14ac049dab29ada5279a01d9388d621f5962eb6..fba3450a2aed5db5331cb6e82484916b54a29999 100644 (file)
--- a/src/barometer.c
+++ b/src/barometer.c
**/
#include "collectd.h"
+
#include "common.h"
#include "utils_cache.h"
#include "plugin.h"
gauge_t * values = NULL; /**< rate values */
size_t values_num = 0; /**< number of rate values */
- size_t i;
gauge_t values_history[REF_TEMP_AVG_NUM];
list->initialized = 1;
list->num_values = values_num;
- for(i=0; i<values_num; ++i)
+ for(size_t i=0; i<values_num; ++i)
{
DEBUG ("barometer: get_reference_temperature - rate %zu: %lf **",
i, values[i]);
continue;
}
- for(i=0; i<REF_TEMP_AVG_NUM*list->num_values; ++i)
+ for(size_t i=0; i<REF_TEMP_AVG_NUM*list->num_values; ++i)
{
DEBUG ("barometer: get_reference_temperature - history %zu: %lf",
i, values_history[i]);
continue;
}
- for(i=0; i<values_num; ++i)
+ for(size_t i=0; i<values_num; ++i)
{
DEBUG ("barometer: get_reference_temperature - rate last %zu: %lf **",
i, values[i]);
already available. */
if(!avg_initialized)
{
- int i;
- for(i=0; i<config_oversample-1; ++i)
+ for(int i=0; i<config_oversample-1; ++i)
{
result = MPL115_read_averaged(&pressure, &temperature);
if(result)
diff --git a/src/battery.c b/src/battery.c
index 4e0c06fdb0d4e5ab567cb47ec5deeef78a087d60..a0843196a302c55c8647dd64b67ae2038d05fa00 100644 (file)
--- a/src/battery.c
+++ b/src/battery.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
CFTypeRef ps_obj;
double temp_double;
- int i;
ps_raw = IOPSCopyPowerSourcesInfo ();
ps_array = IOPSCopyPowerSourcesList (ps_raw);
DEBUG ("ps_array_len == %i", ps_array_len);
- for (i = 0; i < ps_array_len; i++)
+ for (int i = 0; i < ps_array_len; i++)
{
ps_obj = CFArrayGetValueAtIndex (ps_array, i);
ps_dict = IOPSGetPowerSourceDescription (ps_raw, ps_obj);
CFDictionaryRef bat_root_dict;
CFArrayRef bat_info_arry;
CFIndex bat_info_arry_len;
- CFIndex bat_info_arry_pos;
CFDictionaryRef bat_info_dict;
double temp_double;
}
bat_info_arry_len = CFArrayGetCount (bat_info_arry);
- for (bat_info_arry_pos = 0;
+ for (CFIndex bat_info_arry_pos = 0;
bat_info_arry_pos < bat_info_arry_len;
bat_info_arry_pos++)
{
static int read_pmu (void) /* {{{ */
{
- int i;
-
+ int i = 0;
/* The upper limit here is just a safeguard. If there is a system with
* more than 100 batteries, this can easily be increased. */
- for (i = 0; i < 100; i++)
+ for (; i < 100; i++)
{
FILE *fh;
static int battery_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/bind.c b/src/bind.c
index d46d4967caf1d9f5be590b5d383abe477daacc8d..7fda034968ffe5217a3a24bd493974c271124db7 100644 (file)
--- a/src/bind.c
+++ b/src/bind.c
#endif /* STRPTIME_NEEDS_STANDARDS */
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
@@ -309,12 +310,11 @@ static int bind_xml_table_callback (const char *name, value_t value, /* {{{ */
time_t current_time, void *user_data)
{
translation_table_ptr_t *table = (translation_table_ptr_t *) user_data;
- size_t i;
if (table == NULL)
return (-1);
- for (i = 0; i < table->table_length; i++)
+ for (size_t i = 0; i < table->table_length; i++)
{
if (strcmp (table->table[i].xml_name, name) != 0)
continue;
@@ -490,7 +490,6 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ *
{
xmlXPathObject *xpathObj = NULL;
int num_entries;
- int i;
xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
if (xpathObj == NULL)
@@ -502,19 +501,18 @@ static int bind_parse_generic_name_value (const char *xpath_expression, /* {{{ *
num_entries = 0;
/* Iterate over all matching nodes. */
- for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
+ for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
{
xmlNode *name_node = NULL;
xmlNode *counter = NULL;
xmlNode *parent;
- xmlNode *child;
parent = xpathObj->nodesetval->nodeTab[i];
DEBUG ("bind plugin: bind_parse_generic_name_value: parent->name = %s;",
(char *) parent->name);
/* Iterate over all child nodes. */
- for (child = parent->xmlChildrenNode;
+ for (xmlNode *child = parent->xmlChildrenNode;
child != NULL;
child = child->next)
{
@@ -577,7 +575,6 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ *
{
xmlXPathObject *xpathObj = NULL;
int num_entries;
- int i;
xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
if (xpathObj == NULL)
@@ -589,12 +586,10 @@ static int bind_parse_generic_value_list (const char *xpath_expression, /* {{{ *
num_entries = 0;
/* Iterate over all matching nodes. */
- for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
+ for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
{
- xmlNode *child;
-
/* Iterate over all child nodes. */
- for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
+ for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
child != NULL;
child = child->next)
{
@@ -648,7 +643,6 @@ static int bind_parse_generic_name_attr_value_list (const char *xpath_expression
{
xmlXPathObject *xpathObj = NULL;
int num_entries;
- int i;
xpathObj = xmlXPathEvalExpression(BAD_CAST xpath_expression, xpathCtx);
if (xpathObj == NULL)
@@ -660,12 +654,10 @@ static int bind_parse_generic_name_attr_value_list (const char *xpath_expression
num_entries = 0;
/* Iterate over all matching nodes. */
- for (i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
+ for (int i = 0; xpathObj->nodesetval && (i < xpathObj->nodesetval->nodeNr); i++)
{
- xmlNode *child;
-
/* Iterate over all child nodes. */
- for (child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
+ for (xmlNode *child = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
child != NULL;
child = child->next)
{
{
xmlXPathObject *path_obj;
char *zone_name = NULL;
- int i;
size_t j;
if (version >= 3)
return (-1);
}
- for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+ for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
{
zone_name = (char *) xmlNodeListGetString (doc,
path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
{
xmlXPathObject *zone_nodes = NULL;
xmlXPathContext *zone_path_context;
- int i;
zone_path_context = xmlXPathNewContext (doc);
if (zone_path_context == NULL)
return (-1);
}
- for (i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
+ for (int i = 0; i < zone_nodes->nodesetval->nodeNr; i++)
{
node = zone_nodes->nodesetval->nodeTab[i];
assert (node != NULL);
{
char *view_name = NULL;
cb_view_t *view;
- int i;
size_t j;
if (version == 3)
return (-1);
}
- for (i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
+ for (int i = 0; path_obj->nodesetval && (i < path_obj->nodesetval->nodeNr); i++)
{
view_name = (char *) xmlNodeListGetString (doc,
path_obj->nodesetval->nodeTab[i]->xmlChildrenNode, 1);
{
xmlXPathObject *view_nodes = NULL;
xmlXPathContext *view_path_context;
- int i;
view_path_context = xmlXPathNewContext (doc);
if (view_path_context == NULL)
return (-1);
}
- for (i = 0; i < view_nodes->nodesetval->nodeNr; i++)
+ for (int i = 0; i < view_nodes->nodesetval->nodeNr; i++)
{
xmlNode *node;
xmlXPathContext *xpathCtx = NULL;
xmlXPathObject *xpathObj = NULL;
int ret = -1;
- int i;
doc = xmlParseMemory (data, strlen (data));
if (doc == NULL)
}
else
{
- for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
+ for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
{
xmlNode *node;
char *attr_version;
return (-1);
}
- for (i = 0; i < xpathObj->nodesetval->nodeNr; i++)
+ for (int i = 0; i < xpathObj->nodesetval->nodeNr; i++)
{
xmlNode *node;
char *attr_version;
static int bind_config_add_view (oconfig_item_t *ci) /* {{{ */
{
cb_view_t *tmp;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
return (-1);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int bind_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/ceph.c b/src/ceph.c
index 34aa7b1679324e832acdd1ad65e84f715fe477c4..5248a1ac55f48e5409a8a001686a04d09875d5f2 100644 (file)
--- a/src/ceph.c
+++ b/src/ceph.c
#define _BSD_SOURCE
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#if HAVE_YAJL_YAJL_VERSION_H
#include <yajl/yajl_version.h>
#endif
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
#include <limits.h>
#include <poll.h>
char buffer[number_len+1];
char key[2 * DATA_MAX_NAME_LEN];
_Bool latency_type = 0;
- size_t i;
int status;
key[0] = '\0';
memcpy(buffer, number_val, number_len);
buffer[sizeof(buffer) - 1] = '\0';
- for (i = 0; i < state->depth; i++)
+ for (size_t i = 0; i < state->depth; i++)
{
if (state->stack[i] == NULL)
continue;
static void ceph_daemons_print(void)
{
- int i;
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
ceph_daemon_print(g_daemons[i]);
}
static void ceph_daemon_free(struct ceph_daemon *d)
{
- int i = 0;
- for(; i < d->last_idx; i++)
+ for(int i = 0; i < d->last_idx; i++)
{
sfree(d->last_poll_data[i]);
}
sfree(d->last_poll_data);
d->last_poll_data = NULL;
d->last_idx = 0;
- for(i = 0; i < d->ds_num; i++)
+
+ for(int i = 0; i < d->ds_num; i++)
{
sfree(d->ds_names[i]);
}
/* count_parts returns the number of elements a "foo.bar.baz" style key has. */
static size_t count_parts (char const *key)
{
- char const *ptr;
size_t parts_num = 0;
- for (ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.'))
+ for (const char *ptr = key; ptr != NULL; ptr = strchr (ptr + 1, '.'))
parts_num++;
return parts_num;
static int cc_add_daemon_config(oconfig_item_t *ci)
{
- int ret, i;
+ int ret;
struct ceph_daemon *nd, cd = { 0 };
struct ceph_daemon **tmp;
return ret;
}
- for(i=0; i < ci->children_num; i++)
+ for(int i=0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int ceph_config(oconfig_item_t *ci)
{
- int ret, i;
+ int ret;
- for(i = 0; i < ci->children_num; ++i)
+ for(int i = 0; i < ci->children_num; ++i)
{
oconfig_item_t *child = ci->children + i;
if(strcasecmp("Daemon", child->key) == 0)
*/
static int backup_search_for_last_avg(struct ceph_daemon *d, const char *ds_n)
{
- int i = 0;
- for(; i < d->last_idx; i++)
+ for(int i = 0; i < d->last_idx; i++)
{
if(strcmp(d->last_poll_data[i]->ds_name, ds_n) == 0)
{
@@ -957,12 +957,11 @@ static double get_last_avg(struct ceph_daemon *d, const char *ds_n, int index,
*/
static uint32_t backup_search_for_type(struct ceph_daemon *d, char *ds_name)
{
- int idx = 0;
- for(; idx < d->ds_num; idx++)
+ for(int i = 0; i < d->ds_num; i++)
{
- if(strcmp(d->ds_names[idx], ds_name) == 0)
+ if(strcmp(d->ds_names[i], ds_name) == 0)
{
- return d->ds_types[idx];
+ return d->ds_types[i];
}
}
return DSET_TYPE_UNFOUND;
*/
static int cconn_main_loop(uint32_t request_type)
{
- int i, ret, some_unreachable = 0;
+ int ret, some_unreachable = 0;
struct timeval end_tv;
struct cconn io_array[g_num_daemons];
/* create cconn array */
memset(io_array, 0, sizeof(io_array));
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
io_array[i].d = g_daemons[i];
io_array[i].request_type = request_type;
struct pollfd fds[g_num_daemons];
memset(fds, 0, sizeof(fds));
nfds = 0;
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
struct cconn *io = io_array + i;
ret = cconn_prepare(io, fds + nfds);
ERROR("ceph plugin: poll(2) error: %d", ret);
goto done;
}
- for(i = 0; i < nfds; ++i)
+ for(int i = 0; i < nfds; ++i)
{
struct cconn *io = polled_io_array[i];
int revents = fds[i].revents;
}
}
}
- done: for(i = 0; i < g_num_daemons; ++i)
+ done: for(int i = 0; i < g_num_daemons; ++i)
{
cconn_close(io_array + i);
}
static int ceph_init(void)
{
int ret;
+
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_DAC_OVERRIDE)
+ if (check_capability (CAP_DAC_OVERRIDE) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("ceph plugin: Running collectd as root, but the "
+ "CAP_DAC_OVERRIDE capability is missing. The plugin's read "
+ "function will probably fail. Is your init system dropping "
+ "capabilities?");
+ else
+ WARNING ("ceph plugin: collectd doesn't have the CAP_DAC_OVERRIDE "
+ "capability. If you don't want to run collectd as root, try running "
+ "\"setcap cap_dac_override=ep\" on the collectd binary.");
+ }
+#endif
+
ceph_daemons_print();
ret = cconn_main_loop(ASOK_REQ_VERSION);
static int ceph_shutdown(void)
{
- int i;
- for(i = 0; i < g_num_daemons; ++i)
+ for(int i = 0; i < g_num_daemons; ++i)
{
ceph_daemon_free(g_daemons[i]);
}
diff --git a/src/ceph_test.c b/src/ceph_test.c
index 199d40ec9a429d8c5fac6fb99b48b7968bd59db2..91f084f7be9fb618fb44432f096279895704f564 100644 (file)
--- a/src/ceph_test.c
+++ b/src/ceph_test.c
for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
{
- char got[DATA_MAX_NAME_LEN];
+ char got[64];
CHECK_ZERO (parse_keys (got, sizeof (got), cases[i].str));
EXPECT_EQ_STR (cases[i].want, got);
diff --git a/src/cgroups.c b/src/cgroups.c
index 6d419722b7ef385ea0b8607f2b5b5056c849a408..3a59ec4c02e299a7368ac8dd53c8adeda45a7b1e 100644 (file)
--- a/src/cgroups.c
+++ b/src/cgroups.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int cgroups_read (void)
{
- cu_mount_t *mnt_list;
- cu_mount_t *mnt_ptr;
+ cu_mount_t *mnt_list = NULL;
_Bool cgroup_found = 0;
- mnt_list = NULL;
if (cu_mount_getlist (&mnt_list) == NULL)
{
ERROR ("cgroups plugin: cu_mount_getlist failed.");
return (-1);
}
- for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
+ for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
{
/* Find the cgroup mountpoint which contains the cpuacct
* controller. */
diff --git a/src/chrony.c b/src/chrony.c
index 4a09753ffc3ee2b3ee151b5841ad670dc6b86e5a..f6294e49112dabdcf70a0c84c78e96e40b2a5945 100644 (file)
--- a/src/chrony.c
+++ b/src/chrony.c
*/
#include "collectd.h"
+
#include "common.h" /* auxiliary functions */
#include "plugin.h" /* plugin_register_*, plugin_dispatch_values */
connect_client(const char *p_hostname,
const char *p_service, int p_family, int p_socktype)
{
- struct addrinfo hints = { 0 };
- struct addrinfo *res = NULL, *ressave = NULL;
+ struct addrinfo *res, *ressave;
int n, sockfd;
- hints.ai_family = p_family;
- hints.ai_socktype = p_socktype;
+ struct addrinfo ai_hints = {
+ .ai_family = p_family,
+ .ai_socktype = p_socktype
+ };
- n = getaddrinfo(p_hostname, p_service, &hints, &res);
+ n = getaddrinfo(p_hostname, p_service, &ai_hints, &res);
if (n < 0)
{
if (chrony_set_timeout())
{
- ERROR(PLUGIN_NAME ": Error setting timeout to %lds. Errno = %d",
- g_chrony_timeout, errno);
+ ERROR(PLUGIN_NAME ": Error setting timeout to %llds. Errno = %d",
+ (long long)g_chrony_timeout, errno);
return CHRONY_RC_FAIL;
}
return CHRONY_RC_OK;
{
/* collectd read callback: Perform data acquisition */
int rc;
- unsigned int now_src, n_sources;
+ unsigned int n_sources;
if (g_chrony_seq_is_initialized == 0)
{
if (rc != CHRONY_RC_OK)
return rc;
- for (now_src = 0; now_src < n_sources; ++now_src)
+ for (unsigned int now_src = 0; now_src < n_sources; ++now_src)
{
int is_reachable;
rc = chrony_request_source_data(now_src, &is_reachable);
diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c
index c1a851568a9aa419d63980ce685c4506ce4dc42d..12187f3070de63fb551929daa93a50a2985d1251 100644 (file)
--- a/src/collectd-nagios.c
+++ b/src/collectd-nagios.c
gauge_t *new_values;
char **new_names;
- size_t i;
-
if (match_ds_g == NULL)
return (RET_OKAY);
return (RET_UNKNOWN);
}
- for (i = 0; i < match_ds_num_g; i++)
+ for (size_t i = 0; i < match_ds_num_g; i++)
{
size_t j;
}
free (*values);
- for (i = 0; i < *values_num; i++)
+ for (size_t i = 0; i < *values_num; i++)
free ((*values_names)[i]);
free (*values_names);
char *hostname = NULL;
int status;
- size_t i;
status = lcc_listval (connection, &ret_ident, &ret_ident_num);
if (status != 0) {
return (RET_UNKNOWN);
}
- for (i = 0; i < ret_ident_num; ++i) {
+ for (size_t i = 0; i < ret_ident_num; ++i) {
char id[1024];
if ((hostname_g != NULL) && (strcasecmp (hostname_g, ret_ident[i].host)))
int num_okay = 0;
const char *status_str = "UNKNOWN";
int status_code = RET_UNKNOWN;
- size_t i;
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
if (values_num > 0)
{
printf (" |");
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%f;;;;", values_names[i], values[i]);
}
printf ("\n");
static int do_check_con_average (size_t values_num,
double *values, char **values_names)
{
- size_t i;
double total;
int total_num;
double average;
total = 0.0;
total_num = 0;
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
}
printf ("%s: %g average |", status_str, average);
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%f;;;;", values_names[i], values[i]);
printf ("\n");
static int do_check_con_sum (size_t values_num,
double *values, char **values_names)
{
- size_t i;
double total;
int total_num;
const char *status_str = "UNKNOWN";
total = 0.0;
total_num = 0;
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
}
printf ("%s: %g sum |", status_str, total);
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%f;;;;", values_names[i], values[i]);
printf ("\n");
static int do_check_con_percentage (size_t values_num,
double *values, char **values_names)
{
- size_t i;
double sum = 0.0;
double percentage;
return (RET_WARNING);
}
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
if (isnan (values[i]))
{
}
printf ("%s: %lf percent |", status_str, percentage);
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
printf (" %s=%lf;;;;", values_names[i], values[i]);
return (status_code);
} /* int do_check_con_percentage */
size_t values_num;
char ident_str[1024];
lcc_identifier_t ident;
- size_t i;
int status;
snprintf (ident_str, sizeof (ident_str), "%s/%s",
free (values);
if (values_names != NULL)
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
free (values_names[i]);
free (values_names);
index 773a6cd4b7919b1d950794c63b49dc401e43a4c1..16b26afad1af0a820059656fd0d1d10d89d39b35 100644 (file)
--- a/src/collectd-python.pod
+++ b/src/collectd-python.pod
Python-script every time you want to read a value with the C<exec plugin> (see
L<collectd-exec(5)>) and provides a lot more functionality, too.
-The minimum required Python version is I<2.3>.
+The minimum required Python version is I<2.6>.
=head1 CONFIGURATION
=item *
-B<2.> collectd will block I<SIGINT>. Pressing I<Ctrl+C> will usually cause
+B<2.> Python will be handling I<SIGINT>. Pressing I<Ctrl+C> will usually cause
collectd to shut down. This would be problematic in an interactive session,
-therefore this signal will be blocked. You can still use it to interrupt
-syscalls like sleep and pause but it won't generate a I<KeyboardInterrupt>
-exception either.
+therefore Python will be handling it in interactive sessions. This allows you
+to use I<Ctrl+C> to interrupt Python code without killing collectd. This also
+means you can catch I<KeyboardInterrupt> exceptions which does not work during
+normal operation.
To quit collectd send I<EOF> (press I<Ctrl+D> at the beginning of a new line).
A very simple read function might look like:
+ import random
+
def read(data=None):
vl = collectd.Values(type='gauge')
vl.plugin='python.spam'
To register those functions with collectd:
- collectd.register_read(read);
- collectd.register_write(write);
+ collectd.register_read(read)
+ collectd.register_write(write)
See the section L<"CLASSES"> above for a complete documentation of the data
types used by the read, write and match functions.
-=head1 NOTES
-
-=over 4
-
-=item *
-
-Please feel free to send in new plugins to collectd's mailing list at
-E<lt>collectdE<nbsp>atE<nbsp>collectd.orgE<gt> for review and, possibly,
-inclusion in the main distribution. In the latter case, we will take care of
-keeping the plugin up to date and adapting it to new versions of collectd.
-
-Before submitting your plugin, please take a look at
-L<http://collectd.org/dev-info.shtml>.
-
-=back
-
=head1 CAVEATS
=over 4
diff --git a/src/collectd-tg.c b/src/collectd-tg.c
index 513d4ffcc0d3e0ccca9faba8df0bc8cd25015246..7db9fe713ee2dcde8674e2f69aa3827f28295fa2 100644 (file)
--- a/src/collectd-tg.c
+++ b/src/collectd-tg.c
int main (int argc, char **argv) /* {{{ */
{
- int i;
double last_time;
int values_sent = 0;
fprintf (stdout, "Creating %i values ... ", conf_num_values);
fflush (stdout);
- for (i = 0; i < conf_num_values; i++)
+ for (int i = 0; i < conf_num_values; i++)
{
lcc_value_list_t *vl;
diff --git a/src/collectd.conf.in b/src/collectd.conf.in
index 9375202b80b2ccc57dd11a712df4c928c6cf88d9..e06465bf44ac82c256c1303abb41df3dd3bb49e8 100644 (file)
--- a/src/collectd.conf.in
+++ b/src/collectd.conf.in
#@BUILD_PLUGIN_CONTEXTSWITCH_TRUE@LoadPlugin contextswitch
@BUILD_PLUGIN_CPU_TRUE@@BUILD_PLUGIN_CPU_TRUE@LoadPlugin cpu
#@BUILD_PLUGIN_CPUFREQ_TRUE@LoadPlugin cpufreq
+#@BUILD_PLUGIN_CPUSLEEP_TRUE@LoadPlugin cpusleep
@LOAD_PLUGIN_CSV@LoadPlugin csv
#@BUILD_PLUGIN_CURL_TRUE@LoadPlugin curl
#@BUILD_PLUGIN_CURL_JSON_TRUE@LoadPlugin curl_json
#@BUILD_PLUGIN_FILECOUNT_TRUE@LoadPlugin filecount
#@BUILD_PLUGIN_FSCACHE_TRUE@LoadPlugin fscache
#@BUILD_PLUGIN_GMOND_TRUE@LoadPlugin gmond
+#@BUILD_PLUGIN_GPS_TRUE@LoadPlugin gps
#@BUILD_PLUGIN_GRPC_TRUE@LoadPlugin grpc
#@BUILD_PLUGIN_HDDTEMP_TRUE@LoadPlugin hddtemp
@BUILD_PLUGIN_INTERFACE_TRUE@@BUILD_PLUGIN_INTERFACE_TRUE@LoadPlugin interface
# </Metric>
#</Plugin>
+#<Plugin gps>
+# Host "127.0.0.1"
+# Port "2947"
+# Timeout 0.015
+# PauseConnect 5
+#</Plugin>
+
#<Plugin grpc>
# <Listen "0.0.0.0" "50051">
# EnableSSL true
# User "db_user"
# Password "secret"
# Database "db_name"
+# SSLKey "/path/to/key.pem"
+# SSLCert "/path/to/cert.pem"
+# SSLCA "/path/to/ca.pem"
+# SSLCAPath "/path/to/cas/"
+# SSLCipher "DHE-RSA-AES256-SHA"
# MasterStats true
# ConnectTimeout 10
# InnodbStats true
# SlaveStats true
# SlaveNotifications true
# </Database>
+# <Database galera>
+# Alias "galera"
+# Host "localhost"
+# Socket "/var/run/mysql/mysqld.sock"
+# WsrepStats true
+# </Database>
#</Plugin>
#<Plugin netapp>
# Header "X-Custom-Header: custom_value"
# SSLVersion "TLSv1"
# Format "Command"
+# Metrics true
+# Notifications false
# StoreRates false
# BufferSize 4096
# LowSpeedLimit 0
diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod
index 381d67292986f75ce71ddb5a62108c8918fa5de7..9ae73106de75ac1a445f60799ff3f71f3a115bd4 100644 (file)
--- a/src/collectd.conf.pod
+++ b/src/collectd.conf.pod
@@ -1457,6 +1457,16 @@ installed) to get the current CPU frequency. If this file does not exist make
sure B<cpufreqd> (L<http://cpufreqd.sourceforge.net/>) or a similar tool is
installed and an "cpu governor" (that's a kernel module) is loaded.
+=head2 Plugin C<cpusleep>
+
+This plugin doesn't have any options. It reads CLOCK_BOOTTIME and
+CLOCK_MONOTONIC and reports the difference between these clocks. Since
+BOOTTIME clock increments while device is suspended and MONOTONIC
+clock does not, the derivative of the difference between these clocks
+gives the relative amount of time the device has spent in suspend
+state. The recorded value is in milliseconds of sleep per seconds of
+wall clock.
+
=head2 Plugin C<csv>
=over 4
=item B<MappedOnly> B<true>|B<false>
-When set to B<true>, only metrics that can be mapped to to a I<type> will be
+When set to B<true>, only metrics that can be mapped to a I<type> will be
collected, all other metrics will be ignored. Defaults to B<false>.
=back
=back
+=head2 Plugin C<gps>
+
+The C<gps plugin> connects to gpsd on the host machine.
+The host, port, timeout and pause are configurable.
+
+This is useful if you run an NTP server using a GPS for source and you want to
+monitor it.
+
+Mind your GPS must send $--GSA for having the data reported!
+
+The following elements are collected:
+
+=over 4
+
+=item B<satellites>
+
+Number of satellites used for fix (type instance "used") and in view (type
+instance "visible"). 0 means no GPS satellites are visible.
+
+=item B<dilution_of_precision>
+
+Vertical and horizontal dilution (type instance "horizontal" or "vertical").
+It should be between 0 and 3.
+Look at the documentation of your GPS to know more.
+
+=back
+
+Synopsis:
+
+ LoadPlugin gps
+ <Plugin "gps">
+ # Connect to localhost on gpsd regular port:
+ Host "127.0.0.1"
+ Port "2947"
+ # 15 ms timeout
+ Timeout 0.015
+ # PauseConnect of 5 sec. between connection attempts.
+ PauseConnect 5
+ </Plugin>
+
+Available configuration options:
+
+=over 4
+
+=item B<Host> I<Host>
+
+The host on which gpsd daemon runs. Defaults to B<localhost>.
+
+=item B<Port> I<Port>
+
+Port to connect to gpsd on the host machine. Defaults to B<2947>.
+
+=item B<Timeout> I<Seconds>
+
+Timeout in seconds (default 0.015 sec).
+
+The GPS data stream is fetch by the plugin form the daemon.
+It waits for data to be available, if none arrives it times out
+and loop for another reading.
+Mind to put a low value gpsd expects value in the micro-seconds area
+(recommended is 500 us) since the waiting function is blocking.
+Value must be between 500 us and 5 sec., if outside that range the
+default value is applied.
+
+This only applies from gpsd release-2.95.
+
+=item B<PauseConnect> I<Seconds>
+
+Pause to apply between attempts of connection to gpsd in seconds (default 5 sec).
+
+=back
+
=head2 Plugin C<grpc>
The I<grpc> plugin provides an RPC interface to submit values to or query
Port "3306"
MasterStats true
ConnectTimeout 10
+ SSLKey "/path/to/key.pem"
+ SSLCert "/path/to/cert.pem"
+ SSLCA "/path/to/ca.pem"
+ SSLCAPath "/path/to/cas/"
+ SSLCipher "DHE-RSA-AES256-SHA"
</Database>
<Database bar>
SlaveStats true
SlaveNotifications true
</Database>
+
+ <Database galera>
+ Alias "galera"
+ Host "localhost"
+ Socket "/var/run/mysql/mysqld.sock"
+ WsrepStats true
+ </Database>
</Plugin>
A B<Database> block defines one connection to a MySQL database. It accepts a
single argument which specifies the name of the database. None of the other
options are required. MySQL will use default values as documented in the
-section "mysql_real_connect()" in the B<MySQL reference manual>.
+"mysql_real_connect()" and "mysql_ssl_set()" sections in the
+B<MySQL reference manual>.
=over 4
If enabled, the plugin sends a notification if the replication slave I/O and /
or SQL threads are not running. Defaults to B<false>.
+=item B<WsrepStats> I<true|false>
+
+ Enable the collection of wsrep plugin statistics, used in Master-Master
+ replication setups like in MySQL Galera/Percona XtraDB Cluster.
+ User needs only privileges to execute 'SHOW GLOBAL STATUS'
+
=item B<ConnectTimeout> I<Seconds>
Sets the connect timeout for the MySQL client.
+=item B<SSLKey> I<Path>
+
+If provided, the X509 key in PEM format.
+
+=item B<SSLCert> I<Path>
+
+If provided, the X509 cert in PEM format.
+
+=item B<SSLCA> I<Path>
+
+If provided, the CA file in PEM format (check OpenSSL docs).
+
+=item B<SSLCAPath> I<Path>
+
+If provided, the CA directory (check OpenSSL docs).
+
+=item B<SSLCipher> I<String>
+
+If provided, the SSL cipher to use.
+
=back
=head2 Plugin C<netapp>
=item B<AllPortsSummary> I<true>|I<false>
If this option is set to I<true> a summary of statistics from all connections
-are collectd. This option defaults to I<false>.
+are collected. This option defaults to I<false>.
=back
@@ -7825,6 +7946,14 @@ create output in the I<JavaScript Object Notation> (JSON). When set to KAIROSDB
Defaults to B<Command>.
+=item B<Metrics> B<true>|B<false>
+
+Controls whether I<metrics> are POSTed to this location. Defaults to B<true>.
+
+=item B<Notifications> B<false>|B<true>
+
+Controls whether I<notifications> are POSTed to this location. Defaults to B<false>.
+
=item B<StoreRates> B<true|false>
If set to B<true>, convert counter values to rates. If set to B<false> (the
diff --git a/src/collectdctl.c b/src/collectdctl.c
index 8ca0559d0728eebf5dafabb57fb0c47e556e29aa..31183b1c8b83b37963fb4b34052d400cffdc96f4 100644 (file)
--- a/src/collectdctl.c
+++ b/src/collectdctl.c
char **ret_values_names = NULL;
int status;
- size_t i;
assert (strcasecmp (argv[0], "getval") == 0);
if (ret_values != NULL) \
free (ret_values); \
if (ret_values_names != NULL) { \
- for (i = 0; i < ret_values_num; ++i) \
+ for (size_t i = 0; i < ret_values_num; ++i) \
free (ret_values_names[i]); \
free (ret_values_names); \
} \
BAIL_OUT (-1);
}
- for (i = 0; i < ret_values_num; ++i)
+ for (size_t i = 0; i < ret_values_num; ++i)
printf ("%s=%e\n", ret_values_names[i], ret_values[i]);
BAIL_OUT (0);
#undef BAIL_OUT
size_t plugins_num = 0;
int status;
- int i;
assert (strcasecmp (argv[0], "flush") == 0);
return (s); \
} while (0)
- for (i = 1; i < argc; ++i) {
+ for (int i = 1; i < argc; ++i) {
char *key, *value;
key = argv[i];
plugins[0] = NULL;
}
- for (i = 0; i < plugins_num; ++i) {
+ for (size_t i = 0; i < plugins_num; ++i) {
if (identifiers_num == 0) {
status = lcc_flush (c, plugins[i], NULL, timeout);
if (status != 0)
(plugins[i] == NULL) ? "(all)" : plugins[i], lcc_strerror (c));
}
else {
- int j;
-
- for (j = 0; j < identifiers_num; ++j) {
+ for (size_t j = 0; j < identifiers_num; ++j) {
status = lcc_flush (c, plugins[i], identifiers + j, timeout);
if (status != 0) {
char id[1024];
size_t ret_ident_num = 0;
int status;
- size_t i;
assert (strcasecmp (argv[0], "listval") == 0);
BAIL_OUT (status);
}
- for (i = 0; i < ret_ident_num; ++i) {
+ for (size_t i = 0; i < ret_ident_num; ++i) {
char id[1024];
status = lcc_identifier_to_string (c, id, sizeof (id), ret_ident + i);
size_t values_len = 0;
int status;
- int i;
assert (strcasecmp (argv[0], "putval") == 0);
if (status != 0)
return (status);
- for (i = 2; i < argc; ++i) {
+ for (int i = 2; i < argc; ++i) {
char *tmp;
tmp = strchr (argv[i], (int)'=');
diff --git a/src/conntrack.c b/src/conntrack.c
index 123ff5431c9d1b27eb27718d5a612c70243aee41..ce90ede34749e5e30b4014e99193539119f5ea68 100644 (file)
--- a/src/conntrack.c
+++ b/src/conntrack.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/contextswitch.c b/src/contextswitch.c
index 344f76e76f0c29242ac20821d8efb25f83f12871..76e2a6c0b935c9225d50e96e7c2405554f459476 100644 (file)
--- a/src/contextswitch.c
+++ b/src/contextswitch.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/cpu.c b/src/cpu.c
index 9c432d1791d0090191842aa364c48d761b5da72e..80029667af80d39950fe06f1d0482455f70ff92c 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
* array. */
static void aggregate (gauge_t *sum_by_state) /* {{{ */
{
- size_t cpu_num;
- size_t state;
-
- for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
+ for (size_t state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
sum_by_state[state] = NAN;
- for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+ for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
{
cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0);
this_cpu_states[COLLECTD_CPU_STATE_ACTIVE].rate = NAN;
- for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
+ for (size_t state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
{
if (!this_cpu_states[state].has_value)
continue;
static void cpu_commit_one (int cpu_num, /* {{{ */
gauge_t rates[static COLLECTD_CPU_STATE_MAX])
{
- size_t state;
gauge_t sum;
sum = rates[COLLECTD_CPU_STATE_ACTIVE];
return;
}
- for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
+ for (size_t state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
{
gauge_t percent = 100.0 * rates[state] / sum;
submit_percent (cpu_num, state, percent);
* each iteration / after each call to cpu_commit(). */
static void cpu_reset (void) /* {{{ */
{
- size_t i;
-
- for (i = 0; i < cpu_states_num; i++)
+ for (size_t i = 0; i < cpu_states_num; i++)
cpu_states[i].has_value = 0;
global_cpu_num = 0;
/* Legacy behavior: Dispatches the raw derive values without any aggregation. */
static void cpu_commit_without_aggregation (void) /* {{{ */
{
- int state;
-
- for (state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
+ for (int state = 0; state < COLLECTD_CPU_STATE_ACTIVE; state++)
{
- size_t cpu_num;
-
- for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+ for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
{
cpu_state_t *s = get_cpu_state (cpu_num, state);
gauge_t global_rates[COLLECTD_CPU_STATE_MAX] = {
NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN /* Batman! */
};
- size_t cpu_num;
if (report_by_state && report_by_cpu && !report_percent)
{
return;
}
- for (cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
+ for (size_t cpu_num = 0; cpu_num < global_cpu_num; cpu_num++)
{
cpu_state_t *this_cpu_states = get_cpu_state (cpu_num, 0);
gauge_t local_rates[COLLECTD_CPU_STATE_MAX] = {
NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN
};
- size_t state;
- for (state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
+ for (size_t state = 0; state < COLLECTD_CPU_STATE_MAX; state++)
if (this_cpu_states[state].has_value)
local_rates[state] = this_cpu_states[state].rate;
cdtime_t now = cdtime ();
#if PROCESSOR_CPU_LOAD_INFO /* {{{ */
- int cpu;
-
kern_return_t status;
processor_cpu_load_info_data_t cpu_info;
host_t cpu_host;
- for (cpu = 0; cpu < cpu_list_len; cpu++)
+ for (int cpu = 0; cpu < cpu_list_len; cpu++)
{
cpu_host = 0;
cpu_info_len = PROCESSOR_BASIC_INFO_COUNT;
/* }}} #endif defined(KERNEL_LINUX) */
#elif defined(HAVE_LIBKSTAT) /* {{{ */
- int cpu;
static cpu_stat_t cs;
if (kc == NULL)
return (-1);
- for (cpu = 0; cpu < numcpu; cpu++)
+ for (int cpu = 0; cpu < numcpu; cpu++)
{
if (kstat_read (kc, ksp[cpu], &cs) == -1)
continue; /* error message? */
uint64_t cpuinfo[numcpu][CPUSTATES];
size_t cpuinfo_size;
int status;
- int i;
if (numcpu < 1)
{
#if defined(KERN_CPTIME2)
if (numcpu > 1) {
- for (i = 0; i < numcpu; i++) {
+ for (int i = 0; i < numcpu; i++) {
int mib[] = {CTL_KERN, KERN_CPTIME2, i};
cpuinfo_size = sizeof (cpuinfo[0]);
return (-1);
}
- for(i = 0; i < CPUSTATES; i++) {
+ for(int i = 0; i < CPUSTATES; i++) {
cpuinfo[0][i] = cpuinfo_tmp[i];
}
}
- for (i = 0; i < numcpu; i++) {
+ for (int i = 0; i < numcpu; i++) {
cpu_stage (i, COLLECTD_CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now);
cpu_stage (i, COLLECTD_CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now);
cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now);
#elif defined(HAVE_SYSCTLBYNAME) && defined(HAVE_SYSCTL_KERN_CP_TIMES) /* {{{ */
long cpuinfo[maxcpu][CPUSTATES];
size_t cpuinfo_size;
- int i;
memset (cpuinfo, 0, sizeof (cpuinfo));
return (-1);
}
- for (i = 0; i < numcpu; i++) {
+ for (int i = 0; i < numcpu; i++) {
cpu_stage (i, COLLECTD_CPU_STATE_USER, (derive_t) cpuinfo[i][CP_USER], now);
cpu_stage (i, COLLECTD_CPU_STATE_NICE, (derive_t) cpuinfo[i][CP_NICE], now);
cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) cpuinfo[i][CP_SYS], now);
#elif defined(HAVE_PERFSTAT) /* {{{ */
perfstat_id_t id;
- int i, cpus;
+ int cpus;
numcpu = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0);
if(numcpu == -1)
return (-1);
}
- for (i = 0; i < cpus; i++)
+ for (int i = 0; i < cpus; i++)
{
cpu_stage (i, COLLECTD_CPU_STATE_IDLE, (derive_t) perfcpu[i].idle, now);
cpu_stage (i, COLLECTD_CPU_STATE_SYSTEM, (derive_t) perfcpu[i].sys, now);
diff --git a/src/cpufreq.c b/src/cpufreq.c
index b92b1d095226c6a9deea13fa6731d5a68b213478..1e9e857980c68c3ebcb19af9e9b8c15d3f83ddcc 100644 (file)
--- a/src/cpufreq.c
+++ b/src/cpufreq.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
{
int status;
unsigned long long val;
- int i = 0;
FILE *fp;
char filename[256];
char buffer[16];
- for (i = 0; i < num_cpu; i++)
+ for (int i = 0; i < num_cpu; i++)
{
status = ssnprintf (filename, sizeof (filename),
"/sys/devices/system/cpu/cpu%d/cpufreq/"
diff --git a/src/cpusleep.c b/src/cpusleep.c
--- /dev/null
+++ b/src/cpusleep.c
@@ -0,0 +1,79 @@
+/**
+ * collectd - src/cpusleep.c
+ * Copyright (C) 2016 rinigus
+ *
+ * The MIT License (MIT)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors:
+ * rinigus <http://github.com/rinigus>
+ *
+ * CPU sleep is reported in milliseconds of sleep per second of wall
+ * time. For that, the time difference between BOOT and MONOTONIC clocks
+ * is reported using derive type.
+**/
+
+#include "collectd.h"
+
+#include "common.h"
+#include "plugin.h"
+#include <time.h>
+
+static void cpusleep_submit(derive_t cpu_sleep) {
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].derive = cpu_sleep;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy(vl.host, hostname_g, sizeof(vl.host));
+ sstrncpy(vl.plugin, "cpusleep", sizeof(vl.plugin));
+ sstrncpy(vl.type, "total_time_in_ms", sizeof(vl.type));
+
+ plugin_dispatch_values(&vl);
+}
+
+static int cpusleep_read(void) {
+ struct timespec b, m;
+ if (clock_gettime(CLOCK_BOOTTIME, &b) < 0) {
+ ERROR("cpusleep plugin: clock_boottime failed");
+ return (-1);
+ }
+
+ if (clock_gettime(CLOCK_MONOTONIC, &m) < 0) {
+ ERROR("cpusleep plugin: clock_monotonic failed");
+ return (-1);
+ }
+
+ // to avoid false positives in counter overflow due to reboot,
+ // derive is used. Sleep is calculated in milliseconds
+ derive_t diffsec = b.tv_sec - m.tv_sec;
+ derive_t diffnsec = b.tv_nsec - m.tv_nsec;
+ derive_t sleep = diffsec * 1000 + diffnsec / 1000000;
+
+ cpusleep_submit(sleep);
+
+ return (0);
+}
+
+void module_register(void) {
+ plugin_register_read("cpusleep", cpusleep_read);
+} /* void module_register */
diff --git a/src/cpython.h b/src/cpython.h
index 880fa4ce29adb8333e1c0576480dfa292affe0da..070d33af9e61df3a6abe968a223bc5533985f227 100644 (file)
--- a/src/cpython.h
+++ b/src/cpython.h
PyGILState_Release(gil_state);\
}
-/* Python 2.4 has this macro, older versions do not. */
-#ifndef Py_VISIT
-#define Py_VISIT(o) do {\
- int _vret;\
- if ((o) != NULL) {\
- _vret = visit((o), arg);\
- if (_vret != 0)\
- return _vret;\
- }\
-} while (0)
-#endif
-
-/* Python 2.4 has this macro, older versions do not. */
-#ifndef Py_CLEAR
-#define Py_CLEAR(o) do {\
- PyObject *tmp = o;\
- (o) = NULL;\
- Py_XDECREF(tmp);\
-} while (0)
-#endif
-
-/* Python 2.4 has this macro, older versions do not. */
-#ifndef Py_RETURN_NONE
-# define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
-#endif
-
/* This macro is a shortcut for calls like
* x = PyObject_Repr(x);
* This can't be done like this example because this would leak
PyObject *values; /* Sequence */
PyObject *children; /* Sequence */
} Config;
-PyTypeObject ConfigType;
+extern PyTypeObject ConfigType;
typedef struct {
PyObject_HEAD /* No semicolon! */
char type[DATA_MAX_NAME_LEN];
char type_instance[DATA_MAX_NAME_LEN];
} PluginData;
-PyTypeObject PluginDataType;
+extern PyTypeObject PluginDataType;
#define PluginData_New() PyObject_CallFunctionObjArgs((PyObject *) &PluginDataType, (void *) 0)
typedef struct {
PyObject *meta; /* dict */
double interval;
} Values;
-PyTypeObject ValuesType;
+extern PyTypeObject ValuesType;
#define Values_New() PyObject_CallFunctionObjArgs((PyObject *) &ValuesType, (void *) 0)
typedef struct {
int severity;
char message[NOTIF_MAX_MSG_LEN];
} Notification;
-PyTypeObject NotificationType;
+extern PyTypeObject NotificationType;
#define Notification_New() PyObject_CallFunctionObjArgs((PyObject *) &NotificationType, (void *) 0)
typedef PyLongObject Signed;
-PyTypeObject SignedType;
+extern PyTypeObject SignedType;
typedef PyLongObject Unsigned;
-PyTypeObject UnsignedType;
+extern PyTypeObject UnsignedType;
diff --git a/src/csv.c b/src/csv.c
index 0cb9bc1a319f9e33f1903f601266e6954c720f44..e008ecfe0f6fdeafe10caa20b9d7ca2eaf44c2f6 100644 (file)
--- a/src/csv.c
+++ b/src/csv.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "utils_cache.h"
{
int offset;
int status;
- size_t i;
gauge_t *rates = NULL;
assert (0 == strcmp (ds->type, vl->type));
return (-1);
offset = status;
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_COUNTER)
&& (ds->ds[i].type != DS_TYPE_GAUGE)
static int csv_create_file (const char *filename, const data_set_t *ds)
{
FILE *csv;
- size_t i;
if (check_create_dir (filename))
return (-1);
}
fprintf (csv, "epoch");
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
fprintf (csv, ",%s", ds->ds[i].name);
fprintf (csv, "\n");
if (use_stdio)
{
- size_t i;
-
escape_string (filename, sizeof (filename));
/* Replace commas by colons for PUTVAL compatible output. */
- for (i = 0; i < sizeof (values); i++)
+ for (size_t i = 0; i < sizeof (values); i++)
{
if (values[i] == 0)
break;
diff --git a/src/curl.c b/src/curl.c
index d9ced60dc0416edbb8112d12dae35f61148fb385..8d7baa51a16116c3d0b6925224b92f92f85d9e41 100644 (file)
--- a/src/curl.c
+++ b/src/curl.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
web_match_t *match;
int status;
- int i;
if (ci->values_num != 0)
{
}
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
web_page_t *page;
int status;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
/* Process all children */
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
int success;
int errors;
int status;
- int i;
success = 0;
errors = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int cc_read_page (web_page_t *wp) /* {{{ */
{
- web_match_t *wm;
int status;
cdtime_t start = 0;
}
}
- for (wm = wp->matches; wm != NULL; wm = wm->next)
+ for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next)
{
cu_match_value_t *mv;
static int cc_read (void) /* {{{ */
{
- web_page_t *wp;
-
- for (wp = pages_g; wp != NULL; wp = wp->next)
+ for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next)
cc_read_page (wp);
return (0);
diff --git a/src/curl_json.c b/src/curl_json.c
index 2dac7479308df41485226c947d03739d2c394d4f..d4e78039e3ab264c08cffeb95d3b4256789412b8 100644 (file)
--- a/src/curl_json.c
+++ b/src/curl_json.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
cj_key_t *key;
int status;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
}
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
cj_t *db;
int status = 0;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
}
/* Fill the `cj_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
int success;
int errors;
int status;
- int i;
success = 0;
errors = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (key->instance == NULL)
{
- int i, len = 0;
- for (i = 0; i < db->depth; i++)
+ int len = 0;
+ for (int i = 0; i < db->depth; i++)
len += ssnprintf(vl.type_instance+len, sizeof(vl.type_instance)-len,
i ? "-%s" : "%s", db->state[i+1].name);
}
diff --git a/src/curl_xml.c b/src/curl_xml.c
index 05d75c670b60d4419e0657bd26d9567bc80af528..f3aa2d9af432fe33345c755b74e5475ce9c2c76b 100644 (file)
--- a/src/curl_xml.c
+++ b/src/curl_xml.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static void cx_free (void *arg) /* {{{ */
{
cx_t *db;
- size_t i;
DEBUG ("curl_xml plugin: cx_free (arg = %p);", arg);
curl_slist_free_all (db->headers);
curl_stats_destroy (db->stats);
- for (i = 0; i < db->namespaces_num; i++)
+ for (size_t i = 0; i < db->namespaces_num; i++)
{
sfree (db->namespaces[i].prefix);
sfree (db->namespaces[i].url);
@@ -368,14 +368,13 @@ static int cx_handle_all_value_xpaths (xmlXPathContextPtr xpath_ctx, /* {{{ */
{
value_t values[xpath->values_len];
int status;
- size_t i;
assert (xpath->values_len > 0);
assert (xpath->values_len == vl->values_len);
assert (xpath->values_len == ds->ds_num);
vl->values = values;
- for (i = 0; i < xpath->values_len; i++)
+ for (size_t i = 0; i < xpath->values_len; i++)
{
status = cx_handle_single_value_xpath (xpath_ctx, xpath, ds, vl, i);
if (status != 0)
char *base_xpath, cx_xpath_t *xpath)
{
int total_nodes;
- int i;
xmlXPathObjectPtr base_node_obj = NULL;
xmlNodeSetPtr base_nodes = NULL;
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- for (i = 0; i < total_nodes; i++)
+ for (int i = 0; i < total_nodes; i++)
{
int status;
int status;
xmlDocPtr doc;
xmlXPathContextPtr xpath_ctx;
- size_t i;
/* Load the XML */
doc = xmlParseDoc(xml);
return (-1);
}
- for (i = 0; i < db->namespaces_num; i++)
+ for (size_t i = 0; i < db->namespaces_num; i++)
{
cx_namespace_t const *ns = db->namespaces + i;
status = xmlXPathRegisterNs (xpath_ctx,
static int cx_config_add_values (const char *name, cx_xpath_t *xpath, /* {{{ */
oconfig_item_t *ci)
{
- int i;
-
if (ci->values_num < 1)
{
WARNING ("curl_xml plugin: `ValuesFrom' needs at least one argument.");
return (-1);
}
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
WARNING ("curl_xml plugin: `ValuesFrom' needs only string argument.");
xpath->values_len = (size_t) ci->values_num;
/* populate cx_values_t structure */
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
xpath->values[i].path_len = sizeof (ci->values[i].value.string);
sstrncpy (xpath->values[i].path, ci->values[i].value.string, sizeof (xpath->values[i].path));
char *name;
llentry_t *le;
int status;
- int i;
xpath = calloc (1, sizeof (*xpath));
if (xpath == NULL)
}
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
cx_t *db;
int status = 0;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
}
/* Fill the `cx_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
int success;
int errors;
int status;
- int i;
success = 0;
errors = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c
index 840520887b3352a70dc19d6243b9c8fe58f81430..8573579166ab7e0aa13078d934ec92ffbf30324e 100644 (file)
--- a/src/daemon/collectd.c
+++ b/src/daemon/collectd.c
**/
#include "collectd.h"
-#include "common.h"
+#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
const char *str;
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
int status;
str = global_option_get ("Hostname");
if (IS_FALSE (str))
return (0);
- ai_hints.ai_flags = AI_CANONNAME;
+ struct addrinfo ai_hints = {
+ .ai_flags = AI_CANONNAME
+ };
status = getaddrinfo (hostname_g, NULL, &ai_hints, &ai_list);
if (status != 0)
return (-1);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
if (ai_ptr->ai_canonname == NULL)
continue;
diff --git a/src/daemon/common.c b/src/daemon/common.c
index 9da47755034038ebc0025343b9e3b55a6b2f1796..05b119901ce2bf9a606a4e07c1ed45b7c2d78ce7 100644 (file)
--- a/src/daemon/common.c
+++ b/src/daemon/common.c
#endif
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_cache.h"
# include <netinet/in.h>
#endif
+#if HAVE_NETINET_TCP_H
+# include <netinet/tcp.h>
+#endif
+
/* for ntohl and htonl */
#if HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
#ifdef HAVE_LIBKSTAT
extern kstat_ctl_t *kc;
#endif
size_t avail;
char *ptr;
size_t sep_len;
- size_t i;
if ((buffer_size < 1) || (fields_num == 0))
return (-1);
if (sep != NULL)
sep_len = strlen (sep);
- for (i = 0; i < fields_num; i++)
+ for (size_t i = 0; i < fields_num; i++)
{
size_t field_len;
int escape_string (char *buffer, size_t buffer_size)
{
char *temp;
- size_t i;
size_t j;
/* Check if we need to escape at all first */
temp[0] = '"';
j = 1;
- for (i = 0; i < buffer_size; i++)
+ for (size_t i = 0; i < buffer_size; i++)
{
if (buffer[i] == 0)
{
int strunescape (char *buf, size_t buf_len)
{
- size_t i;
-
- for (i = 0; (i < buf_len) && (buf[i] != '\0'); ++i)
+ for (size_t i = 0; (i < buf_len) && (buf[i] != '\0'); ++i)
{
if (buf[i] != '\\')
continue;
int escape_slashes (char *buffer, size_t buffer_size)
{
size_t buffer_len;
- size_t i;
buffer_len = strlen (buffer);
buffer_len--;
}
- for (i = 0; i < buffer_len; i++)
+ for (size_t i = 0; i < buffer_len; i++)
{
if (buffer[i] == '/')
buffer[i] = '_';
void replace_special (char *buffer, size_t buffer_size)
{
- size_t i;
-
- for (i = 0; i < buffer_size; i++)
+ for (size_t i = 0; i < buffer_size; i++)
{
if (buffer[i] == 0)
return;
int last_is_file = 1;
int path_is_absolute = 0;
size_t len;
- int i;
/*
* Sanity checks first
/*
* For each component, do..
*/
- for (i = 0; i < (fields_num - last_is_file); i++)
+ for (int i = 0; i < (fields_num - last_is_file); i++)
{
/*
* Do not create directories that start with a dot. This
{
size_t offset = 0;
int status;
- size_t i;
gauge_t *rates = NULL;
assert (0 == strcmp (ds->type, vl->type));
BUFFER_ADD ("%.3f", CDTIME_T_TO_DOUBLE (vl->time));
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if (ds->ds[i].type == DS_TYPE_GAUGE)
BUFFER_ADD (":"GAUGE_FORMAT, vl->values[i].gauge);
int service_name_to_port_number (const char *service_name)
{
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
- struct addrinfo ai_hints = { 0 };
int status;
int service_number;
if (service_name == NULL)
return (-1);
- ai_list = NULL;
- ai_hints.ai_family = AF_UNSPEC;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC
+ };
status = getaddrinfo (/* node = */ NULL, service_name,
&ai_hints, &ai_list);
}
service_number = -1;
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
if (ai_ptr->ai_family == AF_INET)
{
return (-1);
} /* int service_name_to_port_number */
+void set_sock_opts (int sockfd) /* {{{ */
+{
+ int status;
+ int socktype;
+
+ socklen_t socklen = sizeof (socklen_t);
+ int so_keepalive = 1;
+
+ status = getsockopt (sockfd, SOL_SOCKET, SO_TYPE, &socktype, &socklen);
+ if (status != 0)
+ {
+ WARNING ("set_sock_opts: failed to determine socket type");
+ return;
+ }
+
+ if (socktype == SOCK_STREAM)
+ {
+ status = setsockopt(sockfd, SOL_SOCKET, SO_KEEPALIVE,
+ &so_keepalive, sizeof (so_keepalive));
+ if (status != 0)
+ WARNING ("set_sock_opts: failed to set socket keepalive flag");
+
+#ifdef TCP_KEEPIDLE
+ int tcp_keepidle = ((CDTIME_T_TO_MS(plugin_get_interval()) - 1) / 100 + 1);
+ status = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE,
+ &tcp_keepidle, sizeof (tcp_keepidle));
+ if (status != 0)
+ WARNING ("set_sock_opts: failed to set socket tcp keepalive time");
+#endif
+
+#ifdef TCP_KEEPINTVL
+ int tcp_keepintvl = ((CDTIME_T_TO_MS(plugin_get_interval()) - 1) / 1000 + 1);
+ status = setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPINTVL,
+ &tcp_keepintvl, sizeof (tcp_keepintvl));
+ if (status != 0)
+ WARNING ("set_sock_opts: failed to set socket tcp keepalive interval");
+#endif
+ }
+} /* }}} void set_sock_opts */
+
int strtoderive (const char *string, derive_t *ret_value) /* {{{ */
{
derive_t tmp;
@@ -1629,9 +1668,56 @@ int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str) /*
void strarray_free (char **array, size_t array_len) /* {{{ */
{
- size_t i;
-
- for (i = 0; i < array_len; i++)
+ for (size_t i = 0; i < array_len; i++)
sfree (array[i]);
sfree (array);
} /* }}} void strarray_free */
+
+#ifdef HAVE_SYS_CAPABILITY_H
+int check_capability (int capability) /* {{{ */
+{
+#ifdef _LINUX_CAPABILITY_VERSION_3
+ cap_user_header_t cap_header = calloc(1, sizeof (*cap_header));
+ if (cap_header == NULL)
+ {
+ ERROR("check_capability: calloc failed");
+ return (-1);
+ }
+
+ cap_user_data_t cap_data = calloc(1, sizeof (*cap_data));
+ if (cap_data == NULL)
+ {
+ ERROR("check_capability: calloc failed");
+ sfree(cap_header);
+ return (-1);
+ }
+
+ cap_header->pid = getpid();
+ cap_header->version = _LINUX_CAPABILITY_VERSION;
+ if (capget(cap_header, cap_data) < 0)
+ {
+ ERROR("check_capability: capget failed");
+ sfree(cap_header);
+ sfree(cap_data);
+ return (-1);
+ }
+
+ if ((cap_data->effective & (1 << capability)) == 0)
+ {
+ sfree(cap_header);
+ sfree(cap_data);
+ return (-1);
+ }
+ else
+ {
+ sfree(cap_header);
+ sfree(cap_data);
+ return (0);
+ }
+#else
+ WARNING ("check_capability: unsupported capability implementation. "
+ "Some plugin(s) may require elevated privileges to work properly.");
+ return (0);
+#endif /* _LINUX_CAPABILITY_VERSION_3 */
+} /* }}} int check_capability */
+#endif /* HAVE_SYS_CAPABILITY_H */
diff --git a/src/daemon/common.h b/src/daemon/common.h
index 6981d21d7aad6371fafda10f2ae7a68616ccaa7d..720e5f1bc0a408f097fe1d586b5bbb26dda9bcce 100644 (file)
--- a/src/daemon/common.h
+++ b/src/daemon/common.h
#define COMMON_H
#include "collectd.h"
+
#include "plugin.h"
#if HAVE_PWD_H
* (in the range [1-65535]). Returns less than zero on error. */
int service_name_to_port_number (const char *service_name);
+/* Sets various, non-default, socket options */
+void set_sock_opts (int sockfd);
+
/** Parse a string to a derive_t value. Returns zero on success or non-zero on
* failure. If failure is returned, ret_value is not touched. */
int strtoderive (const char *string, derive_t *ret_value);
int strarray_add (char ***ret_array, size_t *ret_array_len, char const *str);
void strarray_free (char **array, size_t array_len);
+#ifdef HAVE_SYS_CAPABILITY_H
+/** Check if the current process benefits from the capability passed in
+ * argument. Returns zero if it does, less than zero if it doesn't or on error.
+ * See capabilities(7) for the list of possible capabilities.
+ * */
+int check_capability (int capability);
+#endif /* HAVE_SYS_CAPABILITY_H */
+
#endif /* COMMON_H */
index 68958f3f15271db5b66c64dd189e12e2f1c50073..202ddf6cd3ab82aa0af180edf40a44e794908376 100644 (file)
--- a/src/daemon/common_test.c
+++ b/src/daemon/common_test.c
{"trailing/slash/", "trailing_slash_"},
{"foo//bar", "foo__bar"},
};
- size_t i;
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
char buffer[32];
strncpy (buffer, cases[i].str, sizeof (buffer));
{"012345 78901234", "\"012345 789012\""},
{"012345 78901\"34", "\"012345 78901\""},
};
- size_t i;
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
char buffer[16];
strncpy (buffer, cases[i].str, sizeof (buffer));
{"T:42.0", -1, NAN},
};
- size_t i;
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
{
data_source_t dsrc = {
.name = "value",
/* 64bit wrap-around. */
{30, 40, DS_TYPE_COUNTER, {.counter = 18446744073709551558ULL}, {.counter = 42}, 10.0},
};
- size_t i;
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
value_to_rate_state_t state = { cases[i].v0, TIME_T_TO_CDTIME_T (cases[i].t0) };
gauge_t got;
index 0654ad7edf825839dc702a98d28d5fd2b6da92fe..a31fb64d17781854d015236155c6a833eae8c186 100644 (file)
--- a/src/daemon/configfile.c
+++ b/src/daemon/configfile.c
char *key;
char *value;
int ret;
- int i;
+ int i = 0;
if (orig_key == NULL)
return (EINVAL);
static int dispatch_value_typesdb (oconfig_item_t *ci)
{
- int i = 0;
-
assert (strcasecmp (ci->key, "TypesDB") == 0);
cf_default_typesdb = 0;
return (-1);
}
- for (i = 0; i < ci->values_num; ++i)
+ for (int i = 0; i < ci->values_num; ++i)
{
if (OCONFIG_TYPE_STRING != ci->values[i].type) {
WARNING ("configfile: TypesDB: Skipping %i. argument which "
static int dispatch_loadplugin (oconfig_item_t *ci)
{
- int i;
const char *name;
unsigned int flags = 0;
plugin_ctx_t ctx = { 0 };
ctx.flush_interval = 0;
ctx.flush_timeout = 0;
- for (i = 0; i < ci->children_num; ++i)
+ for (int i = 0; i < ci->children_num; ++i)
{
oconfig_item_t *child = ci->children + i;
char buffer[4096];
char *buffer_ptr;
int buffer_free;
- int i;
buffer_ptr = buffer;
buffer_free = sizeof (buffer);
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
int status = -1;
static int dispatch_value (oconfig_item_t *ci)
{
int ret = 0;
- int i;
- for (i = 0; i < cf_value_map_num; i++)
+ for (int i = 0; i < cf_value_map_num; i++)
if (strcasecmp (cf_value_map[i].key, ci->key) == 0)
{
ret = cf_value_map[i].func (ci);
break;
}
- for (i = 0; i < cf_global_options_num; i++)
+ for (int i = 0; i < cf_global_options_num; i++)
if (strcasecmp (cf_global_options[i].key, ci->key) == 0)
{
ret = dispatch_global_option (ci);
static int dispatch_block_plugin (oconfig_item_t *ci)
{
- int i;
const char *name;
- cf_complex_callback_t *cb;
-
if (strcasecmp (ci->key, "Plugin") != 0)
return (-1);
if (ci->values_num < 1)
}
/* Check for a complex callback first */
- for (cb = complex_callback_head; cb != NULL; cb = cb->next)
+ for (cf_complex_callback_t *cb = complex_callback_head; cb != NULL; cb = cb->next)
{
if (strcasecmp (name, cb->type) == 0)
{
}
/* Hm, no complex plugin found. Dispatch the values one by one */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
if (ci->children[i].children == NULL)
dispatch_value_plugin (name, ci->children + i);
int offset)
{
oconfig_item_t *temp;
- int i;
assert (offset >= 0);
assert (dst->children_num > offset);
/* Free the memory used by the replaced child. Usually that's the
* `Include "blah"' statement. */
temp = dst->children + offset;
- for (i = 0; i < temp->values_num; i++)
+ for (int i = 0; i < temp->values_num; i++)
{
if (temp->values[i].type == OCONFIG_TYPE_STRING)
{
static int cf_include_all (oconfig_item_t *root, int depth)
{
- int i;
-
- for (i = 0; i < root->children_num; i++)
+ for (int i = 0; i < root->children_num; i++)
{
oconfig_item_t *new;
oconfig_item_t *old;
char *pattern = NULL;
- int j;
-
if (strcasecmp (root->children[i].key, "Include") != 0)
continue;
continue;
}
- for (j = 0; j < old->children_num; ++j)
+ for (int j = 0; j < old->children_num; ++j)
{
oconfig_item_t *child = old->children + j;
char **filenames = NULL;
int filenames_num = 0;
int status;
- int i;
assert (depth < CF_MAX_DEPTH);
" name is too long.",
dir, de->d_name);
closedir (dh);
- for (i = 0; i < filenames_num; ++i)
+ for (int i = 0; i < filenames_num; ++i)
free (filenames[i]);
free (filenames);
free (root);
if (tmp == NULL) {
ERROR ("configfile: realloc failed.");
closedir (dh);
- for (i = 0; i < filenames_num - 1; ++i)
+ for (int i = 0; i < filenames_num - 1; ++i)
free (filenames[i]);
free (filenames);
free (root);
qsort ((void *) filenames, filenames_num, sizeof (*filenames),
cf_compare_string);
- for (i = 0; i < filenames_num; ++i)
+ for (int i = 0; i < filenames_num; ++i)
{
oconfig_item_t *temp;
char *name = filenames[i];
*
* There are two versions of this function: If `wordexp' exists shell wildcards
* will be expanded and the function will include all matches found. If
- * `wordexp' (or, more precisely, it's header file) is not available the
+ * `wordexp' (or, more precisely, its header file) is not available the
* simpler function is used which does not do any such expansion.
*/
#if HAVE_WORDEXP_H
int status;
const char *path_ptr;
wordexp_t we;
- size_t i;
if (depth >= CF_MAX_DEPTH)
{
qsort ((void *) we.we_wordv, we.we_wordc, sizeof (*we.we_wordv),
cf_compare_string);
- for (i = 0; i < we.we_wordc; i++)
+ for (size_t i = 0; i < we.we_wordc; i++)
{
oconfig_item_t *temp;
struct stat statbuf;
int global_option_set (const char *option, const char *value, _Bool from_cli)
{
int i;
-
DEBUG ("option = %s; value = %s;", option, value);
for (i = 0; i < cf_global_options_num; i++)
const char *global_option_get (const char *option)
{
int i;
-
for (i = 0; i < cf_global_options_num; i++)
if (strcasecmp (cf_global_options[i].key, option) == 0)
break;
void cf_unregister (const char *type)
{
- cf_callback_t *this, *prev;
-
- for (prev = NULL, this = first_callback;
+ for (cf_callback_t *prev = NULL, *this = first_callback;
this != NULL;
prev = this, this = this->next)
if (strcasecmp (this->type, type) == 0)
void cf_unregister_complex (const char *type)
{
- cf_complex_callback_t *this, *prev;
-
- for (prev = NULL, this = complex_callback_head;
+ for (cf_complex_callback_t *prev = NULL, *this = complex_callback_head;
this != NULL;
prev = this, this = this->next)
if (strcasecmp (this->type, type) == 0)
@@ -1124,7 +1103,6 @@ int cf_register_complex (const char *type, int (*callback) (oconfig_item_t *))
int cf_read (const char *filename)
{
oconfig_item_t *conf;
- int i;
int ret = 0;
conf = cf_read_generic (filename, /* pattern = */ NULL, /* depth = */ 0);
return (-1);
}
- for (i = 0; i < conf->children_num; i++)
+ for (int i = 0; i < conf->children_num; i++)
{
if (conf->children[i].children == NULL)
{
index 924d97c5395b00ce3c373cf94c665c0c928b073d..ae2c6c0fac27970d4058abbf91aced19c5ef859e 100644 (file)
--- a/src/daemon/configfile.h
+++ b/src/daemon/configfile.h
#define CONFIGFILE_H
#include "collectd.h"
+
#include "utils_time.h"
#include "liboconfig/oconfig.h"
index c10525de37f21694e13c118208c4cf2084420d40..cee479a832406988ecb8ccd155a7ff737a083e26 100644 (file)
**/
#include "collectd.h"
+
#include "configfile.h"
#include "plugin.h"
#include "utils_complain.h"
fc_rule_t *rule;
char rule_name[2*DATA_MAX_NAME_LEN] = "Unnamed rule";
int status = 0;
- int i;
if (ci->values_num > 1)
{
ci->values[0].value.string);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
fc_chain_t *chain = NULL;
int status = 0;
- int i;
int new_chain = 1;
if ((ci->values_num != 1)
sstrncpy (chain->name, ci->values[0].value.string, sizeof (chain->name));
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
@@ -624,16 +623,13 @@ static int fc_bit_return_invoke (const data_set_t __attribute__((unused)) *ds, /
static int fc_bit_write_create (const oconfig_item_t *ci, /* {{{ */
void **user_data)
{
- int i;
-
fc_writer_t *plugin_list = NULL;
size_t plugin_list_len = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
fc_writer_t *temp;
- int j;
if (strcasecmp ("Plugin", child->key) != 0)
{
continue;
}
- for (j = 0; j < child->values_num; j++)
+ for (int j = 0; j < child->values_num; j++)
{
char *plugin;
static int fc_bit_write_destroy (void **user_data) /* {{{ */
{
fc_writer_t *plugin_list;
- size_t i;
if ((user_data == NULL) || (*user_data == NULL))
return (0);
plugin_list = *user_data;
- for (i = 0; plugin_list[i].plugin != NULL; i++)
+ for (size_t i = 0; plugin_list[i].plugin != NULL; i++)
free (plugin_list[i].plugin);
free (plugin_list);
}
else
{
- size_t i;
-
- for (i = 0; plugin_list[i].plugin != NULL; i++)
+ for (size_t i = 0; plugin_list[i].plugin != NULL; i++)
{
status = plugin_write (plugin_list[i].plugin, ds, vl);
if (status != 0)
fc_chain_t *fc_chain_get_by_name (const char *chain_name) /* {{{ */
{
- fc_chain_t *chain;
-
if (chain_name == NULL)
return (NULL);
- for (chain = chain_list_head; chain != NULL; chain = chain->next)
+ for (fc_chain_t *chain = chain_list_head; chain != NULL; chain = chain->next)
if (strcasecmp (chain_name, chain->name) == 0)
return (chain);
int fc_process_chain (const data_set_t *ds, value_list_t *vl, /* {{{ */
fc_chain_t *chain)
{
- fc_rule_t *rule;
fc_target_t *target;
int status = FC_TARGET_CONTINUE;
DEBUG ("fc_process_chain (chain = %s);", chain->name);
- for (rule = chain->rules; rule != NULL; rule = rule->next)
+ for (fc_rule_t *rule = chain->rules; rule != NULL; rule = rule->next)
{
fc_match_t *match;
status = FC_TARGET_CONTINUE;
index dbf4b833fb55882f900b77a58574045e976285c6..2d280f89ec0e399e7e2855ee538ea99141071388 100644 (file)
#define FILTER_CHAIN_H 1
#include "collectd.h"
+
#include "plugin.h"
#define FC_MATCH_NO_MATCH 0
diff --git a/src/daemon/meta_data.c b/src/daemon/meta_data.c
index f4a340cb1a41013b50a1c0506afc84214cb28e07..9e4fd07ecfdf99716a11e64532a8ccb6d5654041 100644 (file)
--- a/src/daemon/meta_data.c
+++ b/src/daemon/meta_data.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "meta_data.h"
int meta_data_clone_merge (meta_data_t **dest, meta_data_t *orig) /* {{{ */
{
- meta_entry_t *e;
-
if (orig == NULL)
return (0);
}
pthread_mutex_lock (&orig->lock);
- for (e=orig->head; e != NULL; e = e->next)
+ for (meta_entry_t *e=orig->head; e != NULL; e = e->next)
{
md_entry_insert_clone((*dest), e);
}
int meta_data_exists (meta_data_t *md, const char *key) /* {{{ */
{
- meta_entry_t *e;
-
if ((md == NULL) || (key == NULL))
return (-EINVAL);
pthread_mutex_lock (&md->lock);
- for (e = md->head; e != NULL; e = e->next)
+ for (meta_entry_t *e = md->head; e != NULL; e = e->next)
{
if (strcasecmp (key, e->key) == 0)
{
int meta_data_type (meta_data_t *md, const char *key) /* {{{ */
{
- meta_entry_t *e;
-
if ((md == NULL) || (key == NULL))
return -EINVAL;
pthread_mutex_lock (&md->lock);
- for (e = md->head; e != NULL; e = e->next)
+ for (meta_entry_t *e = md->head; e != NULL; e = e->next)
{
if (strcasecmp (key, e->key) == 0)
{
int meta_data_toc (meta_data_t *md, char ***toc) /* {{{ */
{
int i = 0, count = 0;
- meta_entry_t *e;
if ((md == NULL) || (toc == NULL))
return -EINVAL;
pthread_mutex_lock (&md->lock);
- for (e = md->head; e != NULL; e = e->next)
+ for (meta_entry_t *e = md->head; e != NULL; e = e->next)
++count;
if (count == 0)
}
*toc = calloc(count, sizeof(**toc));
- for (e = md->head; e != NULL; e = e->next)
+ for (meta_entry_t *e = md->head; e != NULL; e = e->next)
(*toc)[i++] = strdup(e->key);
pthread_mutex_unlock (&md->lock);
diff --git a/src/daemon/meta_data.h b/src/daemon/meta_data.h
index 9e448e55db1085ae24dbb330f1618171344bef2a..0398c5460715fa9dd877d3f8209242a8d92cf2f1 100644 (file)
--- a/src/daemon/meta_data.h
+++ b/src/daemon/meta_data.h
#include "collectd.h"
+
/*
* Defines
*/
index 48760d648645811c875071b69c01f29e8fb859f7..35cfe715ae23e984aa66e5dce21eaca7d77935c7 100644 (file)
#include "common.h" /* for STATIC_ARRAY_SIZE */
#include "collectd.h"
+
#include "testing.h"
#include "meta_data.h"
diff --git a/src/daemon/plugin.c b/src/daemon/plugin.c
index 9258b885159072d6a9921bf71e9261f4afd3e9df..1bee8cdd48693da128558e7579af53b37a370106 100644 (file)
--- a/src/daemon/plugin.c
+++ b/src/daemon/plugin.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
char *str;
int len;
- llentry_t *le;
int i;
+ llentry_t *le;
int n;
char **keys;
static void start_read_threads (int num)
{
- int i;
-
if (read_threads != NULL)
return;
}
read_threads_num = 0;
- for (i = 0; i < num; i++)
+ for (int i = 0; i < num; i++)
{
if (pthread_create (read_threads + read_threads_num, NULL,
plugin_read_thread, NULL) == 0)
static void stop_read_threads (void)
{
- int i;
-
if (read_threads == NULL)
return;
pthread_cond_broadcast (&read_cond);
pthread_mutex_unlock (&read_lock);
- for (i = 0; i < read_threads_num; i++)
+ for (int i = 0; i < read_threads_num; i++)
{
if (pthread_join (read_threads[i], NULL) != 0)
{
static void start_write_threads (size_t num) /* {{{ */
{
- size_t i;
-
if (write_threads != NULL)
return;
}
write_threads_num = 0;
- for (i = 0; i < num; i++)
+ for (size_t i = 0; i < num; i++)
{
int status;
int plugin_register_data_set (const data_set_t *ds)
{
data_set_t *ds_copy;
- size_t i;
if ((data_sets != NULL)
&& (c_avl_get (data_sets, ds->type, NULL) == 0))
return (-1);
}
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
memcpy (ds_copy->ds + i, ds->ds + i, sizeof (data_source_t));
return (c_avl_insert (data_sets, (void *) ds_copy->type, (void *) ds_copy));
llentry_t *le;
int ret = 0; // Assume success.
- stop_read_threads ();
-
destroy_all_callbacks (&list_init);
+ stop_read_threads ();
+
pthread_mutex_lock (&read_lock);
llist_destroy (read_list);
read_list = NULL;
destroy_read_heap ();
+ /* blocks until all write threads have shut down. */
+ stop_write_threads ();
+
+ /* ask all plugins to write out the state they kept. */
plugin_flush (/* plugin = */ NULL,
/* timeout = */ 0,
/* identifier = */ NULL);
plugin_set_ctx (old_ctx);
}
- stop_write_threads ();
-
/* Write plugins which use the `user_data' pointer usually need the
* same data available to the flush callback. If this is the case, set
* the free_function to NULL when registering the flush callback and to
int plugin_notification_meta_copy (notification_t *dst,
const notification_t *src)
{
- notification_meta_t *meta;
-
assert (dst != NULL);
assert (src != NULL);
assert (dst != src);
assert ((src->meta == NULL) || (src->meta != dst->meta));
- for (meta = src->meta; meta != NULL; meta = meta->next)
+ for (notification_meta_t *meta = src->meta; meta != NULL; meta = meta->next)
{
if (meta->type == NM_TYPE_STRING)
plugin_notification_meta_add_string (dst, meta->name,
diff --git a/src/daemon/plugin.h b/src/daemon/plugin.h
index 75498c8aa4398293c603a71126092d24d0be9935..49edba254ea13f5742864f24eb62d4048e9a1258 100644 (file)
--- a/src/daemon/plugin.h
+++ b/src/daemon/plugin.h
#define PLUGIN_H
#include "collectd.h"
+
#include "configfile.h"
#include "meta_data.h"
#include "utils_time.h"
#define PLUGIN_FLAGS_GLOBAL 0x0001
#ifndef DATA_MAX_NAME_LEN
-# define DATA_MAX_NAME_LEN 64
+# define DATA_MAX_NAME_LEN 128
#endif
#define DS_TYPE_COUNTER 0
index de6fce3eed11e6251aed251041694484072e7e62..34c222c7870dab6f0bb0a96bd3714910435fdae2 100644 (file)
--- a/src/daemon/types_list.c
+++ b/src/daemon/types_list.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
char *fields[64];
size_t fields_num;
data_set_t *ds;
- size_t i;
fields_num = strsplit (buf, fields, 64);
if (fields_num < 2)
return;
}
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
if (parse_ds (ds->ds + i, fields[i + 1], strlen (fields[i + 1])) != 0)
{
ERROR ("types_list: parse_line: Cannot parse data source #%zu "
index 1e0f271fc187ce4e35f8bb015dbedc4bbe947448..43e94cfb64dd359dddb5db258dcdeb379e28a060 100644 (file)
*
* PARAMETERS
* `compare' The function-pointer `compare' is used to compare two keys. It
- * has to return less than zero if it's first argument is smaller
+ * has to return less than zero if its first argument is smaller
* then the second argument, more than zero if the first argument
* is bigger than the second argument and zero if they are equal.
* If your keys are char-pointers, you can use the `strcmp'
* c_avl_pick
*
* DESCRIPTION
- * Remove a (pseudo-)random element from the tree and return it's `key' and
+ * Remove a (pseudo-)random element from the tree and return its `key' and
* `value'. Entries are not returned in any particular order. This function
* is intended for cache-flushes that don't care about the order but simply
* want to remove all elements, one at a time.
index 489d60faa2b0cd3602857d8d2b543c4c61bf7b07..150dd1b5b8a8476c98a6fefdc01e9c5761ca02b7 100644 (file)
#include "common.h" /* STATIC_ARRAY_SIZE */
#include "collectd.h"
+
#include "testing.h"
#include "utils_avltree.h"
};
c_avl_tree_t *t;
- size_t i;
RESET_COUNTS ();
CHECK_NOT_NULL (t = c_avl_create (compare_callback));
/* insert */
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
{
char *key;
char *value;
}
/* Key already exists. */
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
EXPECT_EQ_INT (1, c_avl_insert (t, cases[i].key, cases[i].value));
/* get */
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++)
{
char *value_ret = NULL;
}
/* remove half */
- for (i = 0; i < STATIC_ARRAY_SIZE (cases) / 2; i++)
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases) / 2; i++)
{
char *key = NULL;
char *value = NULL;
}
/* pick the other half */
- for (i = STATIC_ARRAY_SIZE (cases) / 2; i < STATIC_ARRAY_SIZE (cases); i++)
+ for (size_t i = STATIC_ARRAY_SIZE (cases) / 2; i < STATIC_ARRAY_SIZE (cases); i++)
{
char *key = NULL;
char *value = NULL;
index fa592f0901a6150449877b6597403e3ac39b0165..7c1fa41e42638593b322368442810c6a96574690 100644 (file)
--- a/src/daemon/utils_cache.c
+++ b/src/daemon/utils_cache.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_avltree.h"
static void uc_check_range (const data_set_t *ds, cache_entry_t *ce)
{
- size_t i;
-
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if (isnan (ce->values_gauge[i]))
continue;
{
char *key_copy;
cache_entry_t *ce;
- size_t i;
/* `cache_lock' has been locked by `uc_update' */
sstrncpy (ce->name, key, sizeof (ce->name));
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
switch (ds->ds[i].type)
{
c_avl_iterator_t *iter;
int status;
- int i;
pthread_mutex_lock (&cache_lock);
* including plugin specific meta data, rates, history, …. This must be done
* without holding the lock, otherwise we will run into a deadlock if a
* plugin calls the cache interface. */
- for (i = 0; i < keys_len; i++)
+ for (int i = 0; i < keys_len; i++)
{
value_list_t vl = VALUE_LIST_INIT;
* the timestamp again, so in theory it is possible we remove a value after
* it is updated here. */
pthread_mutex_lock (&cache_lock);
- for (i = 0; i < keys_len; i++)
+ for (int i = 0; i < keys_len; i++)
{
key = NULL;
ce = NULL;
char name[6 * DATA_MAX_NAME_LEN];
cache_entry_t *ce = NULL;
int status;
- size_t i;
if (FORMAT_VL (name, sizeof (name), vl) != 0)
{
return (-1);
}
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
switch (ds->ds[i].type)
{
if (ce->history != NULL)
{
assert (ce->history_index < ce->history_length);
- for (i = 0; i < ce->values_num; i++)
+ for (size_t i = 0; i < ce->values_num; i++)
{
size_t hist_idx = (ce->values_num * ce->history_index) + i;
ce->history[hist_idx] = ce->values_gauge[i];
if (status != 0)
{
- size_t i;
-
- for (i = 0; i < number; i++)
+ for (size_t i = 0; i < number; i++)
{
sfree (names[i]);
}
gauge_t *ret_history, size_t num_steps, size_t num_ds)
{
cache_entry_t *ce = NULL;
- size_t i;
int status = 0;
pthread_mutex_lock (&cache_lock);
return (-ENOMEM);
}
- for (i = ce->history_length * ce->values_num;
+ for (size_t i = ce->history_length * ce->values_num;
i < (num_steps * ce->values_num);
i++)
tmp[i] = NAN;
} /* if (ce->history_length < num_steps) */
/* Copy the values to the output buffer. */
- for (i = 0; i < num_steps; i++)
+ for (size_t i = 0; i < num_steps; i++)
{
size_t src_index;
size_t dst_index;
int uc_iterator_get_values (uc_iter_t *iter, value_t **ret_values, size_t *ret_num)
{
- size_t i;
-
if ((iter == NULL) || (iter->entry == NULL)
|| (ret_values == NULL) || (ret_num == NULL))
return (-1);
@@ -956,7 +947,7 @@ int uc_iterator_get_values (uc_iter_t *iter, value_t **ret_values, size_t *ret_n
*ret_values = calloc (iter->entry->values_num, sizeof(*iter->entry->values_raw));
if (*ret_values == NULL)
return (-1);
- for (i = 0; i < iter->entry->values_num; ++i)
+ for (size_t i = 0; i < iter->entry->values_num; ++i)
*ret_values[i] = iter->entry->values_raw[i];
*ret_num = iter->entry->values_num;
index 1cf6c3aa14aed420bca416b9dfb1e9c41a3c9f84..d028c06735cdb17843b8d6fb72ff89476021adb4 100644 (file)
**/
#include "collectd.h"
+
#include "utils_complain.h"
#include "plugin.h"
index 6d71c43a13feb371af92033ee949a826e4cba67e..243554c63dba8afba2da304c1f09ec1bf2a00143 100644 (file)
--- a/src/daemon/utils_heap.h
+++ b/src/daemon/utils_heap.h
*
* PARAMETERS
* `compare' The function-pointer `compare' is used to compare two keys. It
- * has to return less than zero if it's first argument is smaller
+ * has to return less than zero if its first argument is smaller
* then the second argument, more than zero if the first argument
* is bigger than the second argument and zero if they are equal.
* If your keys are char-pointers, you can use the `strcmp'
index 6ef80475c0bde77931173b0d50231561a84934af..54a9613abecac1bd5da1f2a3f8de9e7d777bb3cd 100644 (file)
*/
#include "collectd.h"
+
#include "testing.h"
#include "utils_heap.h"
DEF_TEST(simple)
{
int values[] = { 9, 5, 6, 1, 3, 4, 0, 8, 2, 7 };
- int i;
c_heap_t *h;
CHECK_NOT_NULL(h = c_heap_create (compare));
- for (i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++)
CHECK_ZERO(c_heap_insert (h, &values[i]));
- for (i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++)
{
int *ret = NULL;
CHECK_NOT_NULL(ret = c_heap_get_root(h));
CHECK_ZERO(c_heap_insert (h, &values[4] /* = 3 */));
CHECK_ZERO(c_heap_insert (h, &values[5] /* = 4 */));
- for (i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++)
{
int *ret = NULL;
CHECK_NOT_NULL(ret = c_heap_get_root(h));
index 311cb07bf4c68c007ee9bde15d128dfa13e16d99..ff73ad74a4b3ed2cfb9690710fe917902778bd3c 100644 (file)
*/
int ignorelist_match (ignorelist_t *il, const char *entry)
{
- ignorelist_item_t *traverse;
-
/* if no entries, collect all */
if ((il == NULL) || (il->head == NULL))
return (0);
return (0);
/* traverse list and check entries */
- for (traverse = il->head; traverse != NULL; traverse = traverse->next)
+ for (ignorelist_item_t *traverse = il->head; traverse != NULL; traverse = traverse->next)
{
#if HAVE_REGEX_H
if (traverse->rmatch != NULL)
index b4cd5171c1a573a095fa605216b994ac5d9e0534..914b6e278c746c1dd04e44a603894377f3991c0c 100644 (file)
--- a/src/daemon/utils_match.c
+++ b/src/daemon/utils_match.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
if (data->ds_type & UTILS_MATCH_CF_DERIVE_INC)
{
- data->value.counter++;
+ data->value.derive++;
data->values_num++;
return (0);
}
regmatch_t re_match[32];
char *matches[32] = { 0 };
size_t matches_num;
- size_t i;
if ((obj == NULL) || (str == NULL))
return (-1);
}
}
- for (i = 0; i < matches_num; i++)
+ for (size_t i = 0; i < matches_num; i++)
{
sfree (matches[i]);
}
index fee08717a7d464c809be8f23685117654d6bdab0..0488f913644a69ff26887a2a85073b0facd7ccf9 100644 (file)
**/
#include "collectd.h"
+
#include "utils_time.h"
#include "utils_random.h"
index 9284f7330bac4ad8aa272cf213b545c26000815f..1bc28f724ea22e927e6981b09d28fd0d8de2bf8c 100644 (file)
--- a/src/daemon/utils_subst.c
+++ b/src/daemon/utils_subst.c
*/
#include "collectd.h"
+
#include "common.h"
#include "utils_subst.h"
index 953ccc4c3b18505073eb134f31d77e0bf9614197..c6caba20f29293883c81a4eaa3895ff38247f6dd 100644 (file)
#include "common.h" /* for STATIC_ARRAY_SIZE */
#include "collectd.h"
+
#include "testing.h"
#include "utils_subst.h"
{"foo bar", 4, 3, "_", NULL}, /* off1 > off2 */
{"foo bar", 3, 4, NULL, NULL}, /* no replacement */
};
- size_t i;
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
char buffer[16] = "!!!!!!!!!!!!!!!";
if (cases[i].want == NULL) {
{"foo bar", "oo", "oo", "foo bar"},
{"sixteen chars", "chars", "characters", "sixteen charact"},
};
- size_t i;
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
char buffer[16];
if (cases[i].want == NULL) {
index a6fb600597d98621619af2451caca31e54675add..0d8ed7c177fcb2aa12e1c7cf9d9dc3fb88108a50 100644 (file)
--- a/src/daemon/utils_tail.c
+++ b/src/daemon/utils_tail.c
**/
#include "collectd.h"
+
#include "common.h"
#include "utils_tail.h"
index 1aeb814a08398ca961db75e33e87d6d38667dfd2..ffcaa90a118a131e7d727c46e68844670227f2e3 100644 (file)
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_match.h"
int __attribute__((unused)) buflen)
{
cu_tail_match_t *obj = (cu_tail_match_t *) data;
- size_t i;
- for (i = 0; i < obj->matches_num; i++)
+ for (size_t i = 0; i < obj->matches_num; i++)
match_apply (obj->matches[i].match, buf);
return (0);
void tail_match_destroy (cu_tail_match_t *obj)
{
- size_t i;
-
if (obj == NULL)
return;
obj->tail = NULL;
}
- for (i = 0; i < obj->matches_num; i++)
+ for (size_t i = 0; i < obj->matches_num; i++)
{
cu_tail_match_match_t *match = obj->matches + i;
if (match->match != NULL)
{
char buffer[4096];
int status;
- size_t i;
status = cu_tail_read (obj->tail, buffer, sizeof (buffer), tail_callback,
(void *) obj);
return (status);
}
- for (i = 0; i < obj->matches_num; i++)
+ for (size_t i = 0; i < obj->matches_num; i++)
{
cu_tail_match_match_t *lt_match = obj->matches + i;
index cb1ea34a16f25851dd397c30bb07477b6f09ae1d..784e109484a2725d82b3660b8abc996fa7ffe856 100644 (file)
**/
#include "collectd.h"
+
#include "common.h"
#include "utils_avltree.h"
#include "utils_threshold.h"
index 56c250cdbb6479b2a1f07297dc2e5f9800243675..86476ea63b4cd95728cfd843a48b52d26859d979 100644 (file)
--- a/src/daemon/utils_time.c
+++ b/src/daemon/utils_time.c
**/
#include "collectd.h"
+
#include "utils_time.h"
#include "plugin.h"
#include "common.h"
index 4d64991b94a4652e59b22c999a6ca96a366fc258..9f043683e701dd772ce1d2433222c79618ab5251 100644 (file)
#define DBL_PRECISION 1e-3
#include "collectd.h"
+
#include "testing.h"
#include "utils_time.h"
// 1546167986577716567 / 2^30 = 1439981150.0475896215...
{1546167986577716567ULL, 1439981150.048, 1439981150, 1439981150048ULL, {1439981150, 47590}, {1439981150, 47589622}},
};
- size_t i;
- for (i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) {
+ for (size_t i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) {
struct timeval tv;
struct timespec ts;
// 1439981880053705608 * 2^30 / 10^9 = 1546168770415815077.4
{1439981880053705608ULL, 1546168770415815077ULL},
};
- size_t i;
- for (i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) {
+ for (size_t i = 0; i < (sizeof (cases) / sizeof (cases[0])); i++) {
EXPECT_EQ_UINT64 (cases[i].want, NS_TO_CDTIME_T (cases[i].ns));
}
diff --git a/src/dbi.c b/src/dbi.c
index d5a6c603161b4a12743e70e3f9fe72a7781d56b2..b93aa51e39f440cd8cbd3fb1f4646948b67563ba 100644 (file)
--- a/src/dbi.c
+++ b/src/dbi.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static void cdbi_database_free (cdbi_database_t *db) /* {{{ */
{
- size_t i;
-
if (db == NULL)
return;
sfree (db->name);
sfree (db->driver);
- for (i = 0; i < db->driver_options_num; i++)
+ for (size_t i = 0; i < db->driver_options_num; i++)
{
sfree (db->driver_options[i].key);
if (!db->driver_options[i].is_numeric)
sfree (db->driver_options);
if (db->q_prep_areas)
- for (i = 0; i < db->queries_num; ++i)
+ for (size_t i = 0; i < db->queries_num; ++i)
udb_query_delete_preparation_area (db->q_prep_areas[i]);
free (db->q_prep_areas);
{
cdbi_database_t *db;
int status;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
}
/* Fill the `cdbi_database_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
while ((status == 0) && (db->queries_num > 0))
{
- size_t j;
-
db->q_prep_areas = calloc (db->queries_num, sizeof (*db->q_prep_areas));
if (db->q_prep_areas == NULL)
{
break;
}
- for (j = 0; j < db->queries_num; ++j)
+ for (size_t i = 0; i < db->queries_num; ++i)
{
- db->q_prep_areas[j]
- = udb_query_allocate_preparation_area (db->queries[j]);
+ db->q_prep_areas[i]
+ = udb_query_allocate_preparation_area (db->queries[i]);
- if (db->q_prep_areas[j] == NULL)
+ if (db->q_prep_areas[i] == NULL)
{
WARNING ("dbi plugin: udb_query_allocate_preparation_area failed");
status = -1;
static int cdbi_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Query", child->key) == 0)
char **column_names;
char **column_values;
int status;
- size_t i;
/* Macro that cleans up dynamically allocated memory and returns the
* specified status. */
ERROR ("dbi plugin: calloc failed.");
BAIL_OUT (-1);
}
- for (i = 1; i < column_num; i++)
+ for (size_t i = 1; i < column_num; i++)
column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
column_values = calloc (column_num, sizeof (*column_values));
ERROR ("dbi plugin: calloc failed.");
BAIL_OUT (-1);
}
- for (i = 1; i < column_num; i++)
+ for (size_t i = 1; i < column_num; i++)
column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
/* }}} */
/* Copy the field names to `column_names' */
- for (i = 0; i < column_num; i++) /* {{{ */
+ for (size_t i = 0; i < column_num; i++) /* {{{ */
{
const char *column_name;
{
status = 0;
/* Copy the value of the columns to `column_values' */
- for (i = 0; i < column_num; i++) /* {{{ */
+ for (size_t i = 0; i < column_num; i++) /* {{{ */
{
status = cdbi_result_get_field (res, (unsigned int) (i + 1),
column_values[i], DATA_MAX_NAME_LEN);
{
dbi_driver driver;
dbi_conn connection;
- size_t i;
int status;
if (db->connection != NULL)
* encountered, it will get a list of options understood by the driver and
* report that as `INFO'. This way, users hopefully don't have too much
* trouble finding out how to configure the plugin correctly.. */
- for (i = 0; i < db->driver_options_num; i++)
+ for (size_t i = 0; i < db->driver_options_num; i++)
{
if (db->driver_options[i].is_numeric)
{
if (status != 0)
{
- char const *opt;
-
INFO ("dbi plugin: This is a list of all options understood "
"by the `%s' driver:", db->driver);
- for (opt = dbi_conn_get_option_list (connection, NULL);
+ for (const char *opt = dbi_conn_get_option_list (connection, NULL);
opt != NULL;
opt = dbi_conn_get_option_list (connection, opt))
{
static int cdbi_read_database (user_data_t *ud) /* {{{ */
{
cdbi_database_t *db = (cdbi_database_t *) ud->data;
- size_t i;
int success;
int status;
/* TODO: Complain if `db_version == 0' */
success = 0;
- for (i = 0; i < db->queries_num; i++)
+ for (size_t i = 0; i < db->queries_num; i++)
{
/* Check if we know the database's version and if so, if this query applies
* to that version. */
static int cdbi_shutdown (void) /* {{{ */
{
- size_t i;
-
- for (i = 0; i < databases_num; i++)
+ for (size_t i = 0; i < databases_num; i++)
{
if (databases[i]->connection != NULL)
{
diff --git a/src/df.c b/src/df.c
index ff701725f42dc80b3084754503966eb0ca5613ab..83be176469556f53fa627cc682521ffb4db367ff 100644 (file)
--- a/src/df.c
+++ b/src/df.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
#endif
/* struct STATANYFS statbuf; */
cu_mount_t *mnt_list;
- cu_mount_t *mnt_ptr;
mnt_list = NULL;
if (cu_mount_getlist (&mnt_list) == NULL)
return (-1);
}
- for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
+ for (cu_mount_t *mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
{
unsigned long long blocksize;
char disk_name[256];
sstrncpy (disk_name, "root", sizeof (disk_name));
else
{
- int i, len;
+ int len;
sstrncpy (disk_name, mnt_ptr->dir + 1, sizeof (disk_name));
len = strlen (disk_name);
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
if (disk_name[i] == '/')
disk_name[i] = '-';
}
diff --git a/src/disk.c b/src/disk.c
index 9965bca7da17176a114e1532fdbbacb63e8abaae..d7eb0a5c407011c9789ee2fe43e4d46f938e2414 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
# error "kstat_io_t does not have the required members"
# endif
static kstat_io_t kio;
- int i;
if (kc == NULL)
return (-1);
- for (i = 0; i < numdisk; i++)
+ for (int i = 0; i < numdisk; i++)
{
if (kstat_read (kc, ksp[i], &kio) == -1)
continue;
# else
int disks;
#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++) {
+ for (int counter = 0; counter < disks; counter++) {
strncpy(name, ds->disk_name, sizeof(name));
name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
derive_t write_ops;
perfstat_id_t firstpath;
int rnumdisk;
- int i;
if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0)
{
return (-1);
}
- for (i = 0; i < rnumdisk; i++)
+ for (int i = 0; i < rnumdisk; i++)
{
if (ignorelist_match (ignorelist, stat_disk[i].name) != 0)
continue;
diff --git a/src/dns.c b/src/dns.c
index 5930dc5033ad85e74ae0f01a5d592a0086f71ad0..a2a4667a119587f2e56b48e894b58d48d7296f96 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
#define _BSD_SOURCE
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include <pcap.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
/*
* Private data types
*/
listen_thread_init = 1;
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_RAW)
+ if (check_capability (CAP_NET_RAW) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("dns plugin: Running collectd as root, but the CAP_NET_RAW "
+ "capability is missing. The plugin's read function will probably "
+ "fail. Is your init system dropping capabilities?");
+ else
+ WARNING ("dns plugin: collectd doesn't have the CAP_NET_RAW capability. "
+ "If you don't want to run collectd as root, try running \"setcap "
+ "cap_net_raw=ep\" on the collectd binary.");
+ }
+#endif
+
return (0);
} /* int dns_init */
unsigned int keys[T_MAX];
unsigned int values[T_MAX];
int len;
- int i;
counter_list_t *ptr;
}
pthread_mutex_unlock (&qtype_mutex);
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
{
DEBUG ("dns plugin: qtype = %u; counter = %u;", keys[i], values[i]);
submit_derive ("dns_qtype", qtype_str (keys[i]), values[i]);
}
pthread_mutex_unlock (&opcode_mutex);
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
{
DEBUG ("dns plugin: opcode = %u; counter = %u;", keys[i], values[i]);
submit_derive ("dns_opcode", opcode_str (keys[i]), values[i]);
}
pthread_mutex_unlock (&rcode_mutex);
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
{
DEBUG ("dns plugin: rcode = %u; counter = %u;", keys[i], values[i]);
submit_derive ("dns_rcode", rcode_str (keys[i]), values[i]);
diff --git a/src/drbd.c b/src/drbd.c
index f0298943e5aaad07d6b015597f408e7527dff619..70f03cab280ce8426cbaaa99ea8c2f20d244fa4b 100644 (file)
--- a/src/drbd.c
+++ b/src/drbd.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
char plugin_instance[DATA_MAX_NAME_LEN];
value_t values[fields_num];
value_list_t vl = VALUE_LIST_INIT;
- size_t i;
if (resource < 0)
{
ssnprintf (plugin_instance, sizeof (plugin_instance), "r%ld",
resource);
- for (i = 0; i < drbd_names_num; i++)
+ for (size_t i = 0; i < drbd_names_num; i++)
{
char *data;
/* skip non numeric wo */
sizeof (vl.plugin_instance));
sstrncpy (vl.type, "drbd_resource", sizeof (vl.type));
- for (i = 0; i < fields_num; i++)
+ for (size_t i = 0; i < fields_num; i++)
{
if (drbd_names[i] == NULL)
continue;
diff --git a/src/email.c b/src/email.c
index db6dd414bc824edffb89602fcca683f1788d4710..9dce34c430f69ab285e95676dcabd32a1810d49f 100644 (file)
--- a/src/email.c
+++ b/src/email.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
}
{ /* initialize collector threads */
- int i = 0;
-
pthread_attr_t ptattr;
conns.head = NULL;
collectors =
smalloc (max_conns * sizeof (*collectors));
- for (i = 0; i < max_conns; ++i) {
+ for (int i = 0; i < max_conns; ++i) {
collectors[i] = smalloc (sizeof (*collectors[i]));
collectors[i]->socket = NULL;
static int email_shutdown (void)
{
- int i = 0;
-
if (connector != ((pthread_t) 0)) {
pthread_kill (connector, SIGTERM);
connector = (pthread_t) 0;
available_collectors = 0;
if (collectors != NULL) {
- for (i = 0; i < max_conns; ++i) {
+ for (int i = 0; i < max_conns; ++i) {
if (collectors[i] == NULL)
continue;
@@ -679,12 +676,9 @@ static void email_submit (const char *type, const char *type_instance, gauge_t v
* after they have been copied to l2. */
static void copy_type_list (type_list_t *l1, type_list_t *l2)
{
- type_t *ptr1;
- type_t *ptr2;
-
type_t *last = NULL;
- for (ptr1 = l1->head, ptr2 = l2->head; NULL != ptr1;
+ for (type_t *ptr1 = l1->head, *ptr2 = l2->head; NULL != ptr1;
ptr1 = ptr1->next, last = ptr2, ptr2 = ptr2->next) {
if (NULL == ptr2) {
ptr2 = smalloc (sizeof (*ptr2));
static int email_read (void)
{
- type_t *ptr;
-
double score_old;
int score_count_old;
pthread_mutex_unlock (&count_mutex);
- for (ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) {
+ for (type_t *ptr = list_count_copy.head; NULL != ptr; ptr = ptr->next) {
email_submit ("email_count", ptr->name, ptr->value);
}
pthread_mutex_unlock (&size_mutex);
- for (ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) {
+ for (type_t *ptr = list_size_copy.head; NULL != ptr; ptr = ptr->next) {
email_submit ("email_size", ptr->name, ptr->value);
}
pthread_mutex_unlock (&check_mutex);
- for (ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next)
+ for (type_t *ptr = list_check_copy.head; NULL != ptr; ptr = ptr->next)
email_submit ("spam_check", ptr->name, ptr->value);
return (0);
diff --git a/src/entropy.c b/src/entropy.c
index 03de9efb48175dccecf7bdd6ab3a53ddf730e33d..f4f4ac4a916c2952ba92ab94af2a890660c72de6 100644 (file)
--- a/src/entropy.c
+++ b/src/entropy.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/ethstat.c b/src/ethstat.c
index b30f614eab93460d7db4cc87d68d67c71d046b7f..a213b60a684a0b5652328912957ab797dc2e8737 100644 (file)
--- a/src/ethstat.c
+++ b/src/ethstat.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int ethstat_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
size_t n_stats;
size_t strings_size;
size_t stats_size;
- size_t i;
int status;
fd = socket(AF_INET, SOCK_DGRAM, /* protocol = */ 0);
return (-1);
}
- for (i = 0; i < n_stats; i++)
+ for (size_t i = 0; i < n_stats; i++)
{
char *stat_name;
static int ethstat_read(void)
{
- size_t i;
-
- for (i = 0; i < interfaces_num; i++)
+ for (size_t i = 0; i < interfaces_num; i++)
ethstat_read_interface (interfaces[i]);
return 0;
diff --git a/src/exec.c b/src/exec.c
index 71a49181b781ad2d9240263084b33fa6b07b0ee8..dfd4b05f59a95fc5409ab8b6a86aaba00b49df59 100644 (file)
--- a/src/exec.c
+++ b/src/exec.c
#define _BSD_SOURCE /* For setgroups */
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include <grp.h>
#include <signal.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
#define PL_NORMAL 0x01
#define PL_NOTIF_ACTION 0x02
static int exec_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if ((strcasecmp ("Exec", child->key) == 0)
@@ -470,11 +473,10 @@ static int fork_child (program_list_t *pl, int *fd_in, int *fd_out, int *fd_err)
else if (pid == 0)
{
int fd_num;
- int fd;
/* Close all file descriptors but the pipe end we need. */
fd_num = getdtablesize ();
- for (fd = 0; fd < fd_num; fd++)
+ for (int fd = 0; fd < fd_num; fd++)
{
if ((fd == fd_pipe_in[0])
|| (fd == fd_pipe_out[1])
{
program_list_t *pl = ((program_list_and_notification_t *) arg)->pl;
notification_t *n = &((program_list_and_notification_t *) arg)->n;
- notification_meta_t *meta;
int fd;
FILE *fh;
int pid;
if (strlen (n->type_instance) > 0)
fprintf (fh, "TypeInstance: %s\n", n->type_instance);
- for (meta = n->meta; meta != NULL; meta = meta->next)
+ for (notification_meta_t *meta = n->meta; meta != NULL; meta = meta->next)
{
if (meta->type == NM_TYPE_STRING)
fprintf (fh, "%s: %s\n", meta->name, meta->nm_value.nm_string);
sigaction (SIGCHLD, &sa, NULL);
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_SETUID) && defined(CAP_SETGID)
+ if ((check_capability (CAP_SETUID) != 0) ||
+ (check_capability (CAP_SETGID) != 0))
+ {
+ if (getuid () == 0)
+ WARNING ("exec plugin: Running collectd as root, but the CAP_SETUID "
+ "or CAP_SETGID capabilities are missing. The plugin's read function "
+ "will probably fail. Is your init system dropping capabilities?");
+ else
+ WARNING ("exec plugin: collectd doesn't have the CAP_SETUID or "
+ "CAP_SETGID capabilities. If you don't want to run collectd as root, "
+ "try running \"setcap 'cap_setuid=ep cap_setgid=ep'\" on the "
+ "collectd binary.");
+ }
+#endif
+
return (0);
} /* int exec_init }}} */
static int exec_read (void) /* {{{ */
{
- program_list_t *pl;
-
- for (pl = pl_head; pl != NULL; pl = pl->next)
+ for (program_list_t *pl = pl_head; pl != NULL; pl = pl->next)
{
pthread_t t;
pthread_attr_t attr;
static int exec_notification (const notification_t *n, /* {{{ */
user_data_t __attribute__((unused)) *user_data)
{
- program_list_t *pl;
program_list_and_notification_t *pln;
- for (pl = pl_head; pl != NULL; pl = pl->next)
+ for (program_list_t *pl = pl_head; pl != NULL; pl = pl->next)
{
pthread_t t;
pthread_attr_t attr;
diff --git a/src/fhcount.c b/src/fhcount.c
index 666dacc09db1b6e876cf5b11e769c37f97f05626..c7603c7dc06ca519256eba9d190f54e24ad7f5e1 100644 (file)
--- a/src/fhcount.c
+++ b/src/fhcount.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
diff --git a/src/filecount.c b/src/filecount.c
index c81fdc250c9840901cafeb2f7a09098963bed105..9de9e6c53a5fced05d2d8ead5c1297a29195476a 100644 (file)
--- a/src/filecount.c
+++ b/src/filecount.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
{
fc_directory_conf_t *dir;
int status;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
dir->size = 0;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
static int fc_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Directory", child->key) == 0)
static int fc_read (void)
{
- size_t i;
-
- for (i = 0; i < directories_num; i++)
+ for (size_t i = 0; i < directories_num; i++)
fc_read_dir (directories[i]);
return (0);
diff --git a/src/fscache.c b/src/fscache.c
index 68f5c79c98006c37585770b0674bd3b32611b9c7..33633d63247db02deb1c7a909d228557b90184c2 100644 (file)
--- a/src/fscache.c
+++ b/src/fscache.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include <stdio.h> /* a header needed for FILE */
char *lineptr;
char *fields[32];
int fields_num;
- int i;
/* Find the colon and replace it with a null byte */
lineptr = strchr (linebuffer, ':');
if (fields_num <= 0)
continue;
- for (i = 0; i < fields_num; i++)
+ for (int i = 0; i < fields_num; i++)
{
char *field_name;
char *field_value_str;
diff --git a/src/gmond.c b/src/gmond.c
index 47158c975b800b823926e325200a85a18de4fa4d..2b299ca0d149674e067958c4b03ee133d5d1eb5f 100644 (file)
--- a/src/gmond.c
+++ b/src/gmond.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
size_t *ret_sockets_num,
const char *node, const char *service, int listen)
{
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
int ai_return;
socket_entry_t *sockets = NULL;
if (*ret_sockets != NULL)
return (EINVAL);
-#ifdef AI_PASSIVE
- ai_hints.ai_flags |= AI_PASSIVE;
-#endif
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
- ai_hints.ai_protocol = IPPROTO_UDP;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG | AI_PASSIVE,
+ .ai_protocol = IPPROTO_UDP,
+ .ai_socktype = SOCK_DGRAM
+ };
ai_return = getaddrinfo (node, service, &ai_hints, &ai_list);
if (ai_return != 0)
return (-1);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) /* {{{ */
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next) /* {{{ */
{
socket_entry_t *tmp;
char buffer[BUFF_SIZE] = { 0 };
unsigned int buffer_size;
XDR xdr;
- size_t i;
msg.id = gmetadata_request;
msg.Ganglia_metadata_msg_u.grequest.metric_id.host = strdup (host);
host, name);
pthread_mutex_lock (&mc_send_sockets_lock);
- for (i = 0; i < mc_send_sockets_num; i++)
+ for (size_t i = 0; i < mc_send_sockets_num; i++)
{
ssize_t status = sendto (mc_send_sockets[i].fd, buffer, (size_t) buffer_size,
/* flags = */ 0,
{
socket_entry_t *mc_receive_socket_entries;
int status;
- size_t i;
mc_receive_socket_entries = NULL;
status = create_sockets (&mc_receive_socket_entries, &mc_receive_sockets_num,
if (mc_receive_sockets == NULL)
{
ERROR ("gmond plugin: calloc failed.");
- for (i = 0; i < mc_receive_sockets_num; i++)
+ for (size_t i = 0; i < mc_receive_sockets_num; i++)
close (mc_receive_socket_entries[i].fd);
free (mc_receive_socket_entries);
mc_receive_socket_entries = NULL;
return ((void *) -1);
}
- for (i = 0; i < mc_receive_sockets_num; i++)
+ for (size_t i = 0; i < mc_receive_sockets_num; i++)
{
mc_receive_sockets[i].fd = mc_receive_socket_entries[i].fd;
mc_receive_sockets[i].events = POLLIN | POLLPRI;
break;
}
- for (i = 0; i < mc_receive_sockets_num; i++)
+ for (size_t i = 0; i < mc_receive_sockets_num; i++)
{
if (mc_receive_sockets[i].revents != 0)
mc_handle_socket (mc_receive_sockets + i);
static int gmond_config_add_metric (oconfig_item_t *ci) /* {{{ */
{
metric_map_t *map;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
return (-1);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Type", child->key) == 0)
static int gmond_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("MCReceiveFrom", child->key) == 0)
static int gmond_shutdown (void) /* {{{ */
{
- size_t i;
-
mc_receive_thread_stop ();
pthread_mutex_lock (&mc_send_sockets_lock);
- for (i = 0; i < mc_send_sockets_num; i++)
+ for (size_t i = 0; i < mc_send_sockets_num; i++)
{
close (mc_send_sockets[i].fd);
mc_send_sockets[i].fd = -1;
diff --git a/src/gps.c b/src/gps.c
--- /dev/null
+++ b/src/gps.c
@@ -0,0 +1,368 @@
+/**
+ * collectd - src/gps.c
+ * Copyright (C) 2015 Nicolas JOURDEN
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Nicolas JOURDEN <nicolas.jourden at laposte.net>
+ * Florian octo Forster <octo at collectd.org>
+ * Marc Fournier <marc.fournier at camptocamp.com>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_time.h"
+#include "configfile.h"
+
+#define CGPS_TRUE 1
+#define CGPS_FALSE 0
+#define CGPS_DEFAULT_HOST "localhost"
+#define CGPS_DEFAULT_PORT "2947" /* DEFAULT_GPSD_PORT */
+#define CGPS_DEFAULT_TIMEOUT MS_TO_CDTIME_T (15)
+#define CGPS_DEFAULT_PAUSE_CONNECT TIME_T_TO_CDTIME_T (5)
+#define CGPS_MAX_ERROR 100
+#define CGPS_CONFIG "?WATCH={\"enable\":true,\"json\":true,\"nmea\":false}\r\n"
+
+#include <gps.h>
+#include <pthread.h>
+
+typedef struct {
+ char *host;
+ char *port;
+ cdtime_t timeout;
+ cdtime_t pause_connect;
+} cgps_config_t;
+
+typedef struct {
+ gauge_t sats_used;
+ gauge_t sats_visible;
+ gauge_t hdop;
+ gauge_t vdop;
+} cgps_data_t;
+
+static cgps_config_t cgps_config_data;
+
+static cgps_data_t cgps_data = {NAN, NAN, NAN, NAN};
+
+static pthread_t cgps_thread_id;
+static pthread_mutex_t cgps_data_lock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t cgps_thread_lock = PTHREAD_MUTEX_INITIALIZER;
+static int cgps_thread_shutdown = CGPS_FALSE;
+static int cgps_thread_running = CGPS_FALSE;
+
+/**
+ * Non blocking pause for the thread.
+ */
+static int cgps_thread_pause(cdtime_t pTime)
+{
+ cdtime_t now;
+ now = cdtime ();
+ struct timespec pause_th;
+ CDTIME_T_TO_TIMESPEC (MS_TO_CDTIME_T(10), &pause_th);
+ while (CGPS_TRUE)
+ {
+ if ( (cdtime () - now) > pTime )
+ {
+ break;
+ }
+
+ pthread_mutex_lock (&cgps_thread_lock);
+ if (cgps_thread_shutdown == CGPS_TRUE)
+ {
+ return CGPS_FALSE;
+ }
+ pthread_mutex_unlock (&cgps_thread_lock);
+ nanosleep (&pause_th, NULL);
+ }
+
+ return CGPS_TRUE;
+}
+
+/**
+ * Thread reading from gpsd.
+ */
+static void * cgps_thread (void * pData)
+{
+ struct gps_data_t gpsd_conn;
+ unsigned int err_count;
+ cgps_thread_running = CGPS_TRUE;
+
+ while (CGPS_TRUE)
+ {
+ pthread_mutex_lock (&cgps_thread_lock);
+ if (cgps_thread_shutdown == CGPS_TRUE)
+ {
+ goto quit;
+ }
+ pthread_mutex_unlock (&cgps_thread_lock);
+
+ err_count = 0;
+
+#if GPSD_API_MAJOR_VERSION > 4
+ int status = gps_open (cgps_config_data.host, cgps_config_data.port, &gpsd_conn);
+#else
+ int status = gps_open_r (cgps_config_data.host, cgps_config_data.port, &gpsd_conn);
+#endif
+ if (status < 0)
+ {
+ WARNING ("gps plugin: connecting to %s:%s failed: %s",
+ cgps_config_data.host, cgps_config_data.port, gps_errstr (status));
+
+ // Here we make a pause until a new tentative to connect, we check also if
+ // the thread does not need to stop.
+ if (cgps_thread_pause(cgps_config_data.pause_connect) == CGPS_FALSE)
+ {
+ goto quit;
+ }
+
+ continue;
+ }
+
+ gps_stream (&gpsd_conn, WATCH_ENABLE | WATCH_JSON | WATCH_NEWSTYLE, NULL);
+ gps_send (&gpsd_conn, CGPS_CONFIG);
+
+ while (CGPS_TRUE)
+ {
+ pthread_mutex_lock (&cgps_thread_lock);
+ if (cgps_thread_shutdown == CGPS_TRUE)
+ {
+ goto stop;
+ }
+ pthread_mutex_unlock (&cgps_thread_lock);
+
+#if GPSD_API_MAJOR_VERSION > 4
+ long timeout_us = CDTIME_T_TO_US (cgps_config_data.timeout);
+ if (!gps_waiting (&gpsd_conn, (int) timeout_us ))
+#else
+ if (!gps_waiting (&gpsd_conn))
+#endif
+ {
+ continue;
+ }
+
+ if (gps_read (&gpsd_conn) == -1)
+ {
+ WARNING ("gps plugin: incorrect data! (err_count: %d)", err_count);
+ err_count++;
+
+ if (err_count > CGPS_MAX_ERROR)
+ {
+ // Server is not responding ...
+ if (gps_send (&gpsd_conn, CGPS_CONFIG) == -1)
+ {
+ WARNING ("gps plugin: gpsd seems to be down, reconnecting");
+ gps_close (&gpsd_conn);
+ break;
+ }
+ // Server is responding ...
+ else
+ {
+ err_count = 0;
+ }
+ }
+
+ continue;
+ }
+
+ pthread_mutex_lock (&cgps_data_lock);
+
+ // Number of sats in view:
+ cgps_data.sats_used = (gauge_t) gpsd_conn.satellites_used;
+ cgps_data.sats_visible = (gauge_t) gpsd_conn.satellites_visible;
+
+ // dilution of precision:
+ cgps_data.vdop = NAN;
+ cgps_data.hdop = NAN;
+ if (cgps_data.sats_used > 0)
+ {
+ cgps_data.hdop = gpsd_conn.dop.hdop;
+ cgps_data.vdop = gpsd_conn.dop.vdop;
+ }
+
+ DEBUG ("gps plugin: %.0f sats used (of %.0f visible), hdop = %.3f, vdop = %.3f",
+ cgps_data.sats_used, cgps_data.sats_visible, cgps_data.hdop, cgps_data.vdop);
+
+ pthread_mutex_unlock (&cgps_data_lock);
+ }
+ }
+
+stop:
+ DEBUG ("gps plugin: thread closing gpsd connection ... ");
+ gps_stream (&gpsd_conn, WATCH_DISABLE, NULL);
+ gps_close (&gpsd_conn);
+quit:
+ DEBUG ("gps plugin: thread shutting down ... ");
+ cgps_thread_running = CGPS_FALSE;
+ pthread_mutex_unlock (&cgps_thread_lock);
+ pthread_exit (NULL);
+}
+
+
+/**
+ * Submit a piece of the data.
+ */
+static void cgps_submit (const char *type, gauge_t value, const char *type_instance)
+{
+ value_t values[1];
+ value_list_t vl = VALUE_LIST_INIT;
+
+ values[0].gauge = value;
+
+ vl.values = values;
+ vl.values_len = 1;
+ sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+ sstrncpy (vl.plugin, "gps", sizeof (vl.plugin));
+ sstrncpy (vl.type, type, sizeof (vl.type));
+ sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+
+ plugin_dispatch_values (&vl);
+}
+
+/**
+ * Read the data and submit by piece.
+ */
+static int cgps_read (void)
+{
+ cgps_data_t data_copy;
+
+ pthread_mutex_lock (&cgps_data_lock);
+ data_copy = cgps_data;
+ pthread_mutex_unlock (&cgps_data_lock);
+
+ cgps_submit ("dilution_of_precision", data_copy.hdop, "horizontal");
+ cgps_submit ("dilution_of_precision", data_copy.vdop, "vertical");
+ cgps_submit ("satellites", data_copy.sats_used, "used");
+ cgps_submit ("satellites", data_copy.sats_visible, "visible");
+
+ return (0);
+}
+
+/**
+ * Read configuration.
+ */
+static int cgps_config (oconfig_item_t *ci)
+{
+ int i;
+
+ for (i = 0; i < ci->children_num; i++)
+ {
+ oconfig_item_t *child = ci->children + i;
+
+ if (strcasecmp ("Host", child->key) == 0)
+ cf_util_get_string (child, &cgps_config_data.host);
+ else if (strcasecmp ("Port", child->key) == 0)
+ cf_util_get_service (child, &cgps_config_data.port);
+ else if (strcasecmp ("Timeout", child->key) == 0)
+ cf_util_get_cdtime (child, &cgps_config_data.timeout);
+ else if (strcasecmp ("PauseConnect", child->key) == 0)
+ cf_util_get_cdtime (child, &cgps_config_data.pause_connect);
+ else
+ WARNING ("gps plugin: Ignoring unknown config option \"%s\".", child->key);
+ }
+
+ // Controlling the value for timeout:
+ // If set too high it blocks the reading (> 5 s), too low it gets not reading (< 500 us).
+ // To avoid any issues we replace "out of range" value by the default value.
+ if (
+ cgps_config_data.timeout > TIME_T_TO_CDTIME_T(5)
+ ||
+ cgps_config_data.timeout < US_TO_CDTIME_T(500)
+ )
+ {
+ WARNING ("gps plugin: timeout set to %.6f sec. setting to default (%.6f).",
+ CDTIME_T_TO_DOUBLE(cgps_config_data.timeout),
+ CDTIME_T_TO_DOUBLE(CGPS_DEFAULT_TIMEOUT)
+ );
+ cgps_config_data.timeout = CGPS_DEFAULT_TIMEOUT;
+ }
+
+ return (0);
+}
+
+/**
+ * Init.
+ */
+static int cgps_init (void)
+{
+ int status;
+
+ if (cgps_thread_running == CGPS_TRUE)
+ {
+ DEBUG ("gps plugin: error gps thread already running ... ");
+ return 0;
+ }
+
+ DEBUG ("gps plugin: config{host: \"%s\", port: \"%s\", timeout: %.6f sec., pause connect: %.3f sec.}",
+ cgps_config_data.host, cgps_config_data.port,
+ CDTIME_T_TO_DOUBLE (cgps_config_data.timeout),
+ CDTIME_T_TO_DOUBLE (cgps_config_data.pause_connect));
+
+ status = plugin_thread_create (&cgps_thread_id, NULL, cgps_thread, NULL);
+ if (status != 0)
+ {
+ ERROR ("gps plugin: pthread_create() failed.");
+ return (-1);
+ }
+
+ return (0);
+}
+
+/**
+ * Shutdown.
+ */
+static int cgps_shutdown (void)
+{
+ void * res;
+
+ pthread_mutex_lock (&cgps_thread_lock);
+ cgps_thread_shutdown = CGPS_TRUE;
+ pthread_mutex_unlock (&cgps_thread_lock);
+
+ pthread_join(cgps_thread_id, &res);
+ free(res);
+
+ // Clean mutex:
+ pthread_mutex_unlock(&cgps_thread_lock);
+ pthread_mutex_destroy(&cgps_thread_lock);
+ pthread_mutex_unlock(&cgps_data_lock);
+ pthread_mutex_destroy(&cgps_data_lock);
+
+ sfree (cgps_config_data.port);
+ sfree (cgps_config_data.host);
+
+ return (0);
+}
+
+/**
+ * Register the module.
+ */
+void module_register (void)
+{
+ cgps_config_data.host = sstrdup (CGPS_DEFAULT_HOST);
+ cgps_config_data.port = sstrdup (CGPS_DEFAULT_PORT);
+ cgps_config_data.timeout = CGPS_DEFAULT_TIMEOUT;
+ cgps_config_data.pause_connect = CGPS_DEFAULT_PAUSE_CONNECT;
+
+ plugin_register_complex_config ("gps", cgps_config);
+ plugin_register_init ("gps", cgps_init);
+ plugin_register_read ("gps", cgps_read);
+ plugin_register_shutdown ("gps", cgps_shutdown);
+}
diff --git a/src/hddtemp.c b/src/hddtemp.c
index c32aa35827744f433fe6280854b3e658c5c170ff..8213e9724525886a908f7e94966173e1b5d20150 100644 (file)
--- a/src/hddtemp.c
+++ b/src/hddtemp.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
const char *host;
const char *port;
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list, *ai_ptr;
+ struct addrinfo *ai_list;
int ai_return;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = PF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
- ai_hints.ai_protocol = IPPROTO_TCP;
-
host = hddtemp_host;
if (host == NULL)
host = HDDTEMP_DEF_HOST;
if (strlen (port) == 0)
port = HDDTEMP_DEF_PORT;
+ struct addrinfo ai_hints = {
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_family = AF_UNSPEC,
+ .ai_protocol = IPPROTO_TCP,
+ .ai_socktype = SOCK_STREAM
+ };
+
if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
{
char errbuf[1024];
}
fd = -1;
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
/* create our socket descriptor */
fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
char *saveptr;
int num_fields;
int num_disks;
- int i;
/* get data from daemon */
if (hddtemp_query_daemon (buf, sizeof (buf)) < 0)
num_disks = num_fields / 4;
- for (i = 0; i < num_disks; i++)
+ for (int i = 0; i < num_disks; i++)
{
char *name;
double temperature;
diff --git a/src/interface.c b/src/interface.c
index 548832258d329bc270118ef92e94a31b6acd403e..a74699ee85d18b9688b2716fc448e86e3ffbbc75 100644 (file)
--- a/src/interface.c
+++ b/src/interface.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
#if HAVE_GETIFADDRS
struct ifaddrs *if_list;
- struct ifaddrs *if_ptr;
/* Darwin/Mac OS X and possible other *BSDs */
#if HAVE_STRUCT_IF_DATA
if (getifaddrs (&if_list) != 0)
return (-1);
- for (if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next)
+ for (struct ifaddrs *if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next)
{
if (if_ptr->ifa_addr != NULL && if_ptr->ifa_addr->sa_family == AF_LINK) {
if_data = (struct IFA_DATA *) if_ptr->ifa_data;
/* #endif KERNEL_LINUX */
#elif HAVE_LIBKSTAT
- int i;
derive_t rx;
derive_t tx;
char iname[DATA_MAX_NAME_LEN];
if (kc == NULL)
return (-1);
- for (i = 0; i < numif; i++)
+ for (int i = 0; i < numif; i++)
{
if (kstat_read (kc, ksp[i], NULL) == -1)
continue;
#elif defined(HAVE_LIBSTATGRAB)
sg_network_io_stats *ios;
- int i, num;
+ int num;
ios = sg_get_network_io_stats (&num);
- for (i = 0; i < num; i++) {
+ for (int i = 0; i < num; i++) {
if (!report_inactive && ios[i].rx == 0 && ios[i].tx == 0)
continue;
if_submit (ios[i].interface_name, "if_octets", ios[i].rx, ios[i].tx);
#elif defined(HAVE_PERFSTAT)
perfstat_id_t id;
- int i, ifs;
+ int ifs;
if ((nif = perfstat_netinterface(NULL, NULL, sizeof(perfstat_netinterface_t), 0)) < 0)
{
return (-1);
}
- for (i = 0; i < ifs; i++)
+ for (int i = 0; i < ifs; i++)
{
if (!report_inactive && ifstat[i].ipackets == 0 && ifstat[i].opackets == 0)
continue;
diff --git a/src/ipc.c b/src/ipc.c
index 00b3a5f8657a0e8d32ab76a41acbd43502368eb0..70c55dc1c7a42a8764761e1afa21581dcfcb61c4 100644 (file)
--- a/src/ipc.c
+++ b/src/ipc.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
ipcinfo_sem_t *ipcinfo_sem;
unsigned short sem_nsems=0;
unsigned short sems=0;
- int i,n;
+ int n;
ipcinfo_sem = (ipcinfo_sem_t *)ipc_get_info(0,
GET_IPCINFO_SEM_ALL, IPCINFO_SEM_VERSION, sizeof(ipcinfo_sem_t), &n);
if (ipcinfo_sem == NULL)
return -1;
- for (i=0; i<n; i++) {
+ for (int i=0; i<n; i++) {
sem_nsems += ipcinfo_sem[i].sem_nsems;
sems++;
}
ipcinfo_shm_t *pshm;
unsigned int shm_segments=0;
size64_t shm_bytes=0;
- int i,n;
+ int n;
ipcinfo_shm = (ipcinfo_shm_t *)ipc_get_info(0,
GET_IPCINFO_SHM_ALL, IPCINFO_SHM_VERSION, sizeof(ipcinfo_shm_t), &n);
if (ipcinfo_shm == NULL)
return -1;
- for (i=0, pshm=ipcinfo_shm; i<n; i++, pshm++) {
+ for (int i=0, pshm=ipcinfo_shm; i<n; i++, pshm++) {
shm_segments++;
shm_bytes += pshm->shm_segsz;
}
uint32_t msg_used_space=0;
uint32_t msg_alloc_queues=0;
msgqnum32_t msg_qnum=0;
- int i,n;
+ int n;
ipcinfo_msg = (ipcinfo_msg_t *)ipc_get_info(0,
GET_IPCINFO_MSG_ALL, IPCINFO_MSG_VERSION, sizeof(ipcinfo_msg_t), &n);
if (ipcinfo_msg == NULL)
return -1;
- for (i=0; i<n; i++) {
+ for (int i=0; i<n; i++) {
msg_alloc_queues++;
msg_used_space += ipcinfo_msg[i].msg_cbytes;
msg_qnum += ipcinfo_msg[i].msg_qnum;
diff --git a/src/ipmi.c b/src/ipmi.c
index 93f2486cfd386ee797d5c627abf01a5c085378d1..ad62299e3390bba91aedf9c5656f711643962e44 100644 (file)
--- a/src/ipmi.c
+++ b/src/ipmi.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
static int sensor_list_read_all (void)
{
- c_ipmi_sensor_list_t *list_item;
-
pthread_mutex_lock (&sensor_list_lock);
- for (list_item = sensor_list;
+ for (c_ipmi_sensor_list_t *list_item = sensor_list;
list_item != NULL;
list_item = list_item->next)
{
diff --git a/src/iptables.c b/src/iptables.c
index 20dce658b95e4edd1767a4b36e341e1308ea7759..35c93f4e1c1939d796a4df518b06554b31388d6c 100644 (file)
--- a/src/iptables.c
+++ b/src/iptables.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
#include <libiptc/libiptc.h>
#include <libiptc/libip6tc.h>
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
/*
* iptc_handle_t was available before libiptc was officially available as a
* shared library. Note, that when the shared lib was introduced, the API and
static int iptables_read (void)
{
- int i;
int num_failures = 0;
ip_chain_t *chain;
/* Init the iptc handle structure and query the correct table */
- for (i = 0; i < chain_num; i++)
+ for (int i = 0; i < chain_num; i++)
{
chain = chain_list[i];
static int iptables_shutdown (void)
{
- int i;
-
- for (i = 0; i < chain_num; i++)
+ for (int i = 0; i < chain_num; i++)
{
if ((chain_list[i] != NULL) && (chain_list[i]->rule_type == RTYPE_COMMENT))
sfree (chain_list[i]->rule.comment);
return (0);
} /* int iptables_shutdown */
+static int iptables_init (void)
+{
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_ADMIN)
+ if (check_capability (CAP_NET_ADMIN) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("iptables plugin: Running collectd as root, but the "
+ "CAP_NET_ADMIN capability is missing. The plugin's read "
+ "function will probably fail. Is your init system dropping "
+ "capabilities?");
+ else
+ WARNING ("iptables plugin: collectd doesn't have the CAP_NET_ADMIN "
+ "capability. If you don't want to run collectd as root, try "
+ "running \"setcap cap_net_admin=ep\" on the collectd binary.");
+ }
+#endif
+ return (0);
+} /* int iptables_init */
+
void module_register (void)
{
plugin_register_config ("iptables", iptables_config,
config_keys, config_keys_num);
+ plugin_register_init ("iptables", iptables_init);
plugin_register_read ("iptables", iptables_read);
plugin_register_shutdown ("iptables", iptables_shutdown);
} /* void module_register */
diff --git a/src/ipvs.c b/src/ipvs.c
index 760aa3c5598af6a8a96785ec5a83137ae7e484e2..92690e88e0098635a8cc56fe9c6191116b81082e 100644 (file)
--- a/src/ipvs.c
+++ b/src/ipvs.c
*/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
char pi[DATA_MAX_NAME_LEN];
- size_t i;
-
if (0 != get_pi (se, pi, sizeof (pi)))
{
free (dests);
cipvs_submit_if (pi, "if_packets", NULL, stats.inpkts, stats.outpkts);
cipvs_submit_if (pi, "if_octets", NULL, stats.inbytes, stats.outbytes);
- for (i = 0; i < dests->num_dests; ++i)
+ for (size_t i = 0; i < dests->num_dests; ++i)
cipvs_submit_dest (pi, &dests->entrytable[i]);
free (dests);
static int cipvs_read (void)
{
struct ip_vs_get_services *services = NULL;
- size_t i;
if (sockfd < 0)
return (-1);
if (NULL == (services = ipvs_get_services ()))
return -1;
- for (i = 0; i < services->num_services; ++i)
+ for (size_t i = 0; i < services->num_services; ++i)
cipvs_submit_service (&services->entrytable[i]);
free (services);
diff --git a/src/irq.c b/src/irq.c
index 93f3f53bea09b964db1f32109c88faf685465e15..0c363795c8e46a3d308799113431aafaa3db499f 100644 (file)
--- a/src/irq.c
+++ b/src/irq.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
diff --git a/src/java.c b/src/java.c
index 33d0504c129e7aebd23e08c93efc0ad27470ce07..47f4cd36cf0e396c81f6eef3125a23679b7f808a 100644 (file)
--- a/src/java.c
+++ b/src/java.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "filter_chain.h"
jmethodID m_addchild;
jobject o_key;
jobject o_ocitem;
- int i;
c_ocitem = (*jvm_env)->FindClass (jvm_env, "org/collectd/api/OConfigItem");
if (c_ocitem == NULL)
(*jvm_env)->DeleteLocalRef (jvm_env, o_key);
/* Call OConfigItem.addValue for each value */
- for (i = 0; i < ci->values_num; i++) /* {{{ */
+ for (int i = 0; i < ci->values_num; i++) /* {{{ */
{
jobject o_value;
} /* }}} for (i = 0; i < ci->values_num; i++) */
/* Call OConfigItem.addChild for each child */
- for (i = 0; i < ci->children_num; i++) /* {{{ */
+ for (int i = 0; i < ci->children_num; i++) /* {{{ */
{
jobject o_child;
jmethodID m_add;
jobject o_type;
jobject o_dataset;
- size_t i;
/* Look up the org/collectd/api/DataSet class */
c_dataset = (*jvm_env)->FindClass (jvm_env, "org/collectd/api/DataSet");
/* Decrease reference counter on the java.lang.String object. */
(*jvm_env)->DeleteLocalRef (jvm_env, o_type);
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
jobject o_datasource;
jmethodID m_valuelist_constructor;
jobject o_valuelist;
int status;
- size_t i;
/* First, create a new ValueList instance..
* Look up the class.. */
return (NULL);
}
- for (i = 0; i < vl->values_len; i++)
+ for (size_t i = 0; i < vl->values_len; i++)
{
status = ctoj_value_list_add_value (jvm_env, vl->values[i], ds->ds[i].type,
c_valuelist, o_valuelist);
value_t *values;
int values_num;
- int i;
values_num = ds->ds_num;
BAIL_OUT (-1);
}
- for (i = 0; i < values_num; i++)
+ for (int i = 0; i < values_num; i++)
{
jobject o_number;
int status;
JavaVMOption vm_options[jvm_argc];
int status;
- size_t i;
if (jvm != NULL)
return (0);
vm_args.options = vm_options;
vm_args.nOptions = (jint) jvm_argc;
- for (i = 0; i < jvm_argc; i++)
+ for (size_t i = 0; i < jvm_argc; i++)
{
DEBUG ("java plugin: cjni_create_jvm: jvm_argv[%zu] = %s",
i, jvm_argv[i]);
{ /* Replace all dots ('.') with slashes ('/'). Dots are usually used
thorough the Java community, but (Sun's) `FindClass' and friends need
slashes. */
- size_t i;
- for (i = 0; class->name[i] != 0; i++)
+ for (size_t i = 0; class->name[i] != 0; i++)
if (class->name[i] == '.')
class->name[i] = '/';
}
cjni_callback_info_t *cbi;
jobject o_ocitem;
const char *name;
- size_t i;
jclass class;
jmethodID method;
name = ci->values[0].value.string;
cbi = NULL;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != CB_TYPE_CONFIG)
continue;
int success;
int errors;
int status;
- int i;
success = 0;
errors = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
jobject o_ci;
jobject o_tmp;
int type;
- size_t i;
cbi_ret = NULL;
o_ci = NULL;
/* Lets see if we have a matching factory here.. */
cbi_factory = NULL;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != type)
continue;
static int cjni_init_plugins (JNIEnv *jvm_env) /* {{{ */
{
int status;
- size_t i;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != CB_TYPE_INIT)
continue;
static int cjni_shutdown_plugins (JNIEnv *jvm_env) /* {{{ */
{
int status;
- size_t i;
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].type != CB_TYPE_SHUTDOWN)
continue;
JNIEnv *jvm_env;
JavaVMAttachArgs args = { 0 };
int status;
- size_t i;
if (jvm == NULL)
return (0);
cjni_shutdown_plugins (jvm_env);
/* Release all the global references to callback functions */
- for (i = 0; i < java_callbacks_num; i++)
+ for (size_t i = 0; i < java_callbacks_num; i++)
{
if (java_callbacks[i].object != NULL)
{
sfree (java_callbacks);
/* Release all the global references to directly loaded classes. */
- for (i = 0; i < java_classes_list_len; i++)
+ for (size_t i = 0; i < java_classes_list_len; i++)
{
if (java_classes_list[i].object != NULL)
{
pthread_key_delete (jvm_env_key);
/* Free the JVM argument list */
- for (i = 0; i < jvm_argc; i++)
+ for (size_t i = 0; i < jvm_argc; i++)
sfree (jvm_argv[i]);
jvm_argc = 0;
sfree (jvm_argv);
index f5eda6d2222957400258ada8e353422997ddd2b0..a15e0aacc1c21e363f57b23842b1eab21e9b73d3 100644 (file)
#include <stdlib.h>
#include <stdio.h>
+#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
(c)->errbuf[sizeof ((c)->errbuf) - 1] = 0; \
} while (0)
-#if COLLECT_DEBUG
-# define LCC_DEBUG(...) printf (__VA_ARGS__)
-#else
-# define LCC_DEBUG(...) /**/
-#endif
-
/*
* Types
*/
/*
* Private functions
*/
+static int lcc_tracef(char const *format, ...)
+{
+ va_list ap;
+ int status;
+
+ char const *trace = getenv (LCC_TRACE_ENV);
+ if (!trace || (strcmp ("", trace) == 0) || (strcmp ("0", trace) == 0))
+ return 0;
+
+ va_start (ap, format);
+ status = vprintf (format, ap);
+ va_end (ap);
+
+ return status;
+}
+
/* Even though Posix requires "strerror_r" to return an "int",
* some systems (e.g. the GNU libc) return a "char *" _and_
* ignore the second argument ... -tokkee */
static void lcc_response_free (lcc_response_t *res) /* {{{ */
{
- size_t i;
-
if (res == NULL)
return;
- for (i = 0; i < res->lines_num; i++)
+ for (size_t i = 0; i < res->lines_num; i++)
free (res->lines[i]);
free (res->lines);
res->lines = NULL;
{
int status;
- LCC_DEBUG ("send: --> %s\n", command);
+ lcc_tracef ("send: --> %s\n", command);
status = fprintf (c->fh, "%s\r\n", command);
if (status < 0)
return (-1);
}
lcc_chomp (buffer);
- LCC_DEBUG ("receive: <-- %s\n", buffer);
+ lcc_tracef ("receive: <-- %s\n", buffer);
/* Convert the leading status to an integer and make `ptr' to point to the
* beginning of the message. */
break;
}
lcc_chomp (buffer);
- LCC_DEBUG ("receive: <-- %s\n", buffer);
+ lcc_tracef ("receive: <-- %s\n", buffer);
res.lines[i] = strdup (buffer);
if (res.lines[i] == NULL)
@@ -420,9 +429,7 @@ static int lcc_open_unixsocket (lcc_connection_t *c, const char *path) /* {{{ */
static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */
const char *addr_orig)
{
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_res;
- struct addrinfo *ai_ptr;
char addr_copy[NI_MAXHOST];
char *addr;
char *port;
addr_copy[sizeof(addr_copy) - 1] = '\0';
addr = addr_copy;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
-
port = NULL;
if (*addr == '[') /* IPv6+port format */
{
}
}
- ai_res = NULL;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM
+ };
+
status = getaddrinfo (addr,
port == NULL ? LCC_DEFAULT_PORT : port,
&ai_hints, &ai_res);
return (-1);
}
- for (ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_res; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (fd < 0)
char command[1024] = "";
lcc_response_t res;
int status;
- size_t i;
if ((c == NULL) || (vl == NULL) || (vl->values_len < 1)
|| (vl->values == NULL) || (vl->values_types == NULL))
else
SSTRCAT (command, " N");
- for (i = 0; i < vl->values_len; i++)
+ for (size_t i = 0; i < vl->values_len; i++)
{
if (vl->values_types[i] == LCC_TYPE_COUNTER)
SSTRCATF (command, ":%"PRIu64, vl->values[i].counter);
lcc_identifier_t **ret_ident, size_t *ret_ident_num)
{
lcc_response_t res;
- size_t i;
int status;
lcc_identifier_t *ident;
return (-1);
}
- for (i = 0; i < res.lines_num; i++)
+ for (size_t i = 0; i < res.lines_num; i++)
{
char *time_str;
char *ident_str;
index ac26b848e0cbec863f21aaf59a34cef495a0cc2f..47462a6ba7884b70385f45d1e275cfed064448e6 100644 (file)
#include "lcc_features.h"
+/* COLLECTD_TRACE is the environment variable used to control trace output. When
+ * set to something non-zero, all lines sent to / received from the daemon are
+ * printed to STDOUT. */
+#ifndef LCC_TRACE_ENV
+# define LCC_TRACE_ENV "COLLECTD_TRACE"
+#endif
+
/*
* Includes (for data types)
*/
index 8e6bab86823efd3c6a4b23aa6d794681d999baa4..16293ca09c59a64973b497605d11d23166e7746f 100644 (file)
static int server_open_socket (lcc_server_t *srv) /* {{{ */
{
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list = NULL;
- struct addrinfo *ai_ptr;
+ struct addrinfo *ai_list;
int status;
if (srv == NULL)
if (srv->fd >= 0)
server_close_socket (srv);
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_DGRAM
+ };
status = getaddrinfo (srv->node, srv->service, &ai_hints, &ai_list);
if (status != 0)
return (status);
assert (ai_list != NULL);
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
srv->fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
if (srv->fd < 0)
int lcc_network_values_send (lcc_network_t *net, /* {{{ */
const lcc_value_list_t *vl)
{
- lcc_server_t *srv;
-
if ((net == NULL) || (vl == NULL))
return (EINVAL);
- for (srv = net->servers; srv != NULL; srv = srv->next)
+ for (lcc_server_t *srv = net->servers; srv != NULL; srv = srv->next)
server_value_add (srv, vl);
return (0);
index 9a9c89acccd763e2f46812eb45a8fdb844091272..2c6277c856b24eb82dd319cf64a14c7798cad4d3 100644 (file)
value_t pkg_values[vl->values_len];
size_t offset;
- size_t i;
packet_len = sizeof (pkg_type) + sizeof (pkg_length)
+ sizeof (pkg_num_values)
pkg_length = htons ((uint16_t) packet_len);
pkg_num_values = htons ((uint16_t) vl->values_len);
- for (i = 0; i < vl->values_len; i++)
+ for (size_t i = 0; i < vl->values_len; i++)
{
pkg_values_types[i] = (uint8_t) vl->values_types[i];
switch (vl->values_types[i])
index cfe9c5a1450fb5588c341fca56aadcc8a1f35a2f..319aae850898f259fd236b36327304029ffe089a 100644 (file)
--- a/src/liboconfig/oconfig.c
+++ b/src/liboconfig/oconfig.c
if (ci_orig->values_num > 0) /* {{{ */
{
- int i;
-
ci_copy->values = (oconfig_value_t *) calloc ((size_t) ci_orig->values_num,
sizeof (*ci_copy->values));
if (ci_copy->values == NULL)
}
ci_copy->values_num = ci_orig->values_num;
- for (i = 0; i < ci_copy->values_num; i++)
+ for (int i = 0; i < ci_copy->values_num; i++)
{
ci_copy->values[i].type = ci_orig->values[i].type;
if (ci_copy->values[i].type == OCONFIG_TYPE_STRING)
if (ci_orig->children_num > 0) /* {{{ */
{
- int i;
-
ci_copy->children = (oconfig_item_t *) calloc ((size_t) ci_orig->children_num,
sizeof (*ci_copy->children));
if (ci_copy->children == NULL)
}
ci_copy->children_num = ci_orig->children_num;
- for (i = 0; i < ci_copy->children_num; i++)
+ for (int i = 0; i < ci_copy->children_num; i++)
{
oconfig_item_t *child;
static void oconfig_free_all (oconfig_item_t *ci)
{
- int i;
-
if (ci == NULL)
return;
if (ci->key != NULL)
free (ci->key);
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
if ((ci->values[i].type == OCONFIG_TYPE_STRING)
&& (NULL != ci->values[i].value.string))
free (ci->values[i].value.string);
if (ci->values != NULL)
free (ci->values);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
oconfig_free_all (ci->children + i);
if (ci->children != NULL)
index 1eb7aecee0cade45c59f34a001d110caaa26093e..4a550b32a1c8e6fa9ad89ec338a1c11c282cd25d 100644 (file)
--- a/src/liboconfig/parser.y
+++ b/src/liboconfig/parser.y
{
char *ret = strdup (orig);
int len;
- int i;
if (ret == NULL)
return (NULL);
memmove (ret, ret + 1, len);
ret[len] = '\0';
- for (i = 0; i < len; i++)
+ for (int i = 0; i < len; i++)
{
if (ret[i] == '\\')
{
diff --git a/src/load.c b/src/load.c
index 18b5f8e87457b2f9dbdc9e723e9f6b6da9967843..cc3be37e03fa4e508ccd3f067f109fbef8dd88cf 100644 (file)
--- a/src/load.c
+++ b/src/load.c
#define _BSD_SOURCE
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/log_logstash.c b/src/log_logstash.c
index 3cf636e501b1891adc4584befa99fd995d10a613..08868409d2b575edfd080f0cf81ffb8d1ada5740 100644 (file)
--- a/src/log_logstash.c
+++ b/src/log_logstash.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/logfile.c b/src/logfile.c
index 334226ba5ef3adaf27a87c3a2b1383c0180a2a15..d18a5365556a67f9cd0be54595d3cfa3d0883588 100644 (file)
--- a/src/logfile.c
+++ b/src/logfile.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/lpar.c b/src/lpar.c
index 4d534476f62c76754433b2c73d313967595e5843..5b0bd13d0cd1ea5881d2da1477311189664dc3e2 100644 (file)
--- a/src/lpar.c
+++ b/src/lpar.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/lvm.c b/src/lvm.c
index 9e245423fef2c829d842619a3a77ee8213864ae4..6b9a0317c2124eb78fe4c81ed485a319b85f8336 100644 (file)
--- a/src/lvm.c
+++ b/src/lvm.c
#include <lvm2app.h>
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/madwifi.c b/src/madwifi.c
index ffc815da70a95f8def3a6bca994824cc23decc4d..728fcd8cc9f22d30395fe77f2ecf570ec6091c48 100644 (file)
--- a/src/madwifi.c
+++ b/src/madwifi.c
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static inline void watchlist_set (uint32_t *wl, uint32_t val)
{
- int i;
- for (i = 0; i < WL_LEN; i++)
+ for (int i = 0; i < WL_LEN; i++)
wl[i] = val;
}
static int watchitem_find (const char *name)
{
int max = STATIC_ARRAY_SIZE (specs);
- int i;
- for (i = 0; i < max; i++)
+ for (int i = 0; i < max; i++)
if (strcasecmp (name, specs[i].name) == 0)
return i;
static int madwifi_real_init (void)
{
size_t max = STATIC_ARRAY_SIZE (specs);
- size_t i;
- for (i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
bounds[i] = 0;
watchlist_set(watch_items, 0);
watchlist_set(misc_items, 0);
- for (i = 0; i < max; i++)
+ for (size_t i = 0; i < max; i++)
{
bounds[specs[i].flags & SRC_MASK] = i;
misc_items[i / 32] |= FLAG (i);
}
- for (i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (bounds); i++)
bounds[i]++;
return (0);
u_int32_t *vals, int vals_num)
{
char ti2[16];
- int i;
- for (i = 0; i < vals_num; i++)
+ for (int i = 0; i < vals_num; i++)
{
if (vals[i] == 0)
continue;
@@ -614,12 +611,11 @@ process_stat_struct (int which, const void *ptr, const char *dev, const char *ma
const char *type_name, const char *misc_name)
{
uint32_t misc = 0;
- int i;
assert (which >= 1);
assert (((size_t) which) < STATIC_ARRAY_SIZE (bounds));
- for (i = bounds[which - 1]; i < bounds[which]; i++)
+ for (int i = bounds[which - 1]; i < bounds[which]; i++)
{
uint32_t val = *(uint32_t *)(((char *) ptr) + specs[i].offset) ;
static int
process_stations (int sk, const char *dev)
{
- uint8_t buf[24*1024];
+ uint8_t buf[24*1024] = { 0 };
uint8_t *cp;
int nodes;
size_t len;
index bff9448a7e7dc273ad14931f8f2f01021f64e944..80a29ac7b467db7f1f25f842b893011e2bf526aa 100644 (file)
**/
#include "collectd.h"
+
#include "common.h"
#include "filter_chain.h"
{
int num_counters = 0;
int num_empty = 0;
- size_t i;
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_DERIVE)
&& (ds->ds[i].type != DS_TYPE_COUNTER))
diff --git a/src/match_hashed.c b/src/match_hashed.c
index a42439c04bea05c0734a45e58188869f9e7ef279..c4983c2ed056a0a455dc38131a3174876c1fb085 100644 (file)
--- a/src/match_hashed.c
+++ b/src/match_hashed.c
**/
#include "collectd.h"
+
#include "common.h"
#include "filter_chain.h"
static int mh_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
{
mh_match_t *m;
- int i;
m = calloc (1, sizeof (*m));
if (m == NULL)
return (-ENOMEM);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
mh_match_t *m;
uint32_t hash_val;
- const char *host_ptr;
- size_t i;
if ((user_data == NULL) || (*user_data == NULL))
return (-1);
hash_val = 0;
- for (host_ptr = vl->host; *host_ptr != 0; host_ptr++)
+ for (const char *host_ptr = vl->host; *host_ptr != 0; host_ptr++)
{
/* 2184401929 is some appropriately sized prime number. */
hash_val = (hash_val * UINT32_C (2184401929)) + ((uint32_t) *host_ptr);
}
DEBUG ("hashed match: host = %s; hash_val = %"PRIu32";", vl->host, hash_val);
- for (i = 0; i < m->matches_num; i++)
+ for (size_t i = 0; i < m->matches_num; i++)
if ((hash_val % m->matches[i].total) == m->matches[i].match)
return (FC_MATCH_MATCHES);
diff --git a/src/match_regex.c b/src/match_regex.c
index 2dee9a8fc39b4afa59c7a5dfadaed0c7ecf36632..cd6301673a1a3673b8912375554da3a32bfd8bb1 100644 (file)
--- a/src/match_regex.c
+++ b/src/match_regex.c
*/
#include "collectd.h"
+
#include "filter_chain.h"
#include <sys/types.h>
static int mr_match_regexen (mr_regex_t *re_head, /* {{{ */
const char *string)
{
- mr_regex_t *re;
-
if (re_head == NULL)
return (FC_MATCH_MATCHES);
- for (re = re_head; re != NULL; re = re->next)
+ for (mr_regex_t *re = re_head; re != NULL; re = re->next)
{
int status;
{
mr_match_t *m;
int status;
- int i;
m = calloc (1, sizeof (*m));
if (m == NULL)
m->invert = 0;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/match_timediff.c b/src/match_timediff.c
index 3b154150aac1aae6c06f491bc7ab3a32e89d808e..00fdd0c1971bb4d044afc293d1d21d1e6a904e63 100644 (file)
--- a/src/match_timediff.c
+++ b/src/match_timediff.c
**/
#include "collectd.h"
+
#include "common.h"
#include "filter_chain.h"
{
mt_match_t *m;
int status;
- int i;
m = calloc (1, sizeof (*m));
if (m == NULL)
m->past = 0;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/match_value.c b/src/match_value.c
index 3b269c8c9c061ff77a7ddf7b7bc9a53af3c58dc4..54ddba28e6cdea3a32af5fe3328cf5a3bd029839 100644 (file)
--- a/src/match_value.c
+++ b/src/match_value.c
*/
#include "collectd.h"
+
#include "common.h"
#include "utils_cache.h"
#include "filter_chain.h"
*/
static void mv_free_match (mv_match_t *m) /* {{{ */
{
- size_t i;
-
if (m == NULL)
return;
if (m->data_sources != NULL)
{
- for (i = 0; i < m->data_sources_num; ++i)
+ for (size_t i = 0; i < m->data_sources_num; ++i)
free(m->data_sources[i]);
free(m->data_sources);
}
{
size_t new_data_sources_num;
char **temp;
- int i;
/* Check number of arbuments. */
if (ci->values_num < 1)
}
/* Check type of arguments */
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
if (ci->values[i].type == OCONFIG_TYPE_STRING)
continue;
m->data_sources = temp;
/* Copy the strings, allocating memory as needed. */
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
- size_t j;
-
/* If we get here, there better be memory for us to write to. */
assert (m->data_sources_num < new_data_sources_num);
- j = m->data_sources_num;
+ size_t j = m->data_sources_num;
m->data_sources[j] = sstrdup (ci->values[i].value.string);
if (m->data_sources[j] == NULL)
{
{
mv_match_t *m;
int status;
- int i;
m = calloc (1, sizeof (*m));
if (m == NULL)
m->data_sources_num = 0;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
mv_match_t *m;
gauge_t *values;
int status;
- size_t i;
if ((user_data == NULL) || (*user_data == NULL))
return (-1);
status = FC_MATCH_NO_MATCH;
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
int value_matches = 0;
diff --git a/src/mbmon.c b/src/mbmon.c
index ccececd758b3971756c999c231dad971e923d27a..184bb9942a7b32f62c2a74a56499b6b1e1a87166 100644 (file)
--- a/src/mbmon.c
+++ b/src/mbmon.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
const char *host;
const char *port;
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list, *ai_ptr;
+ struct addrinfo *ai_list;
int ai_return;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = PF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
- ai_hints.ai_protocol = IPPROTO_TCP;
-
host = mbmon_host;
if (host == NULL)
host = MBMON_DEF_HOST;
if (port == NULL)
port = MBMON_DEF_PORT;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_protocol = IPPROTO_TCP,
+ .ai_socktype = SOCK_STREAM
+ };
+
if ((ai_return = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
{
char errbuf[1024];
}
fd = -1;
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
/* create our socket descriptor */
if ((fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol)) < 0)
/* Trim trailing whitespace from a string. */
static void trim_spaces (char *s)
{
- size_t l;
-
- for (l = strlen (s) - 1; (l > 0) && isspace ((int) s[l]); l--)
+ for (size_t l = strlen (s) - 1; (l > 0) && isspace ((int) s[l]); l--)
s[l] = '\0';
}
diff --git a/src/md.c b/src/md.c
index 3725f9a9b78fc2c10fcd676b529c9a9e2df3144d..44cad2edbeef32102cf7324fb73d5974c1159796 100644 (file)
--- a/src/md.c
+++ b/src/md.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
#include <linux/major.h>
#include <linux/raid/md_u.h>
+#ifdef HAVE_SYS_SYSMACROS_H
+#include <sys/sysmacros.h>
+#endif
+
#define PROC_DISKSTATS "/proc/diskstats"
#define DEV_DIR "/dev"
diff --git a/src/memcachec.c b/src/memcachec.c
index d7e6c286f69e0b3bb4229949dba9c8209f0941de..1b6ab673d772f0ebaf1386ed31fd778960eba192 100644 (file)
--- a/src/memcachec.c
+++ b/src/memcachec.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
web_match_t *match;
int status;
- int i;
if (ci->values_num != 0)
{
}
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
web_page_t *page;
int status;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
/* Process all children */
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
int success;
int errors;
int status;
- int i;
success = 0;
errors = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int cmc_read_page (web_page_t *wp) /* {{{ */
{
- web_match_t *wm;
memcached_return rc;
size_t string_length;
uint32_t flags;
return (-1);
}
- for (wm = wp->matches; wm != NULL; wm = wm->next)
+ for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next)
{
cu_match_value_t *mv;
static int cmc_read (void) /* {{{ */
{
- web_page_t *wp;
-
- for (wp = pages_g; wp != NULL; wp = wp->next)
+ for (web_page_t *wp = pages_g; wp != NULL; wp = wp->next)
cmc_read_page (wp);
return (0);
diff --git a/src/memcached.c b/src/memcached.c
index faff5793459e8ea1c56a79422ce26485e0925b2c..42882ae5082b34a1e99dbb387982a24684dac16a 100644 (file)
--- a/src/memcached.c
+++ b/src/memcached.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
const char *host;
const char *port;
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list, *ai_ptr;
+ struct addrinfo *ai_list;
int status;
int fd = -1;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
- ai_hints.ai_protocol = 0;
-
host = (st->host != NULL) ? st->host : MEMCACHED_DEF_HOST;
port = (st->port != NULL) ? st->port : MEMCACHED_DEF_PORT;
- ai_list = NULL;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM
+ };
+
status = getaddrinfo (host, port, &ai_hints, &ai_list);
if (status != 0)
{
return (-1);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
/* create our socket descriptor */
fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype, ai_ptr->ai_protocol);
@@ -242,21 +240,24 @@ static int memcached_query_daemon (char *buffer, size_t buffer_size, memcached_t
static void memcached_init_vl (value_list_t *vl, memcached_t const *st)
{
+ char const *host = st->host;
+
+ /* Set vl->host to hostname_g, if:
+ * - Legacy mode is used.
+ * - "Socket" option is given (doc: "Host option is ignored").
+ * - "Host" option is not provided.
+ * - "Host" option is set to "localhost" or "127.0.0.1". */
+ if ((strcmp (st->name, "__legacy__") == 0)
+ || (st->socket != NULL)
+ || (st->host == NULL)
+ || (strcmp ("127.0.0.1", st->host) == 0)
+ || (strcmp ("localhost", st->host) == 0))
+ host = hostname_g;
+
sstrncpy (vl->plugin, "memcached", sizeof (vl->plugin));
- if (strcmp (st->name, "__legacy__") == 0) /* legacy mode */
- {
- sstrncpy (vl->host, hostname_g, sizeof (vl->host));
- }
- else
- {
- if (st->socket != NULL)
- sstrncpy (vl->host, hostname_g, sizeof (vl->host));
- else
- sstrncpy (vl->host,
- (st->host != NULL) ? st->host : MEMCACHED_DEF_HOST,
- sizeof (vl->host));
+ sstrncpy (vl->host, host, sizeof (vl->host));
+ if (strcmp (st->name, "__legacy__") != 0)
sstrncpy (vl->plugin_instance, st->name, sizeof (vl->plugin_instance));
- }
}
static void submit_derive (const char *type, const char *type_inst,
static int config_add_instance(oconfig_item_t *ci)
{
memcached_t *st;
- int i;
int status = 0;
/* Disable automatic generation of default instance in the init callback. */
}
assert (st->name != NULL);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
int status = 0;
_Bool have_instance_block = 0;
- int i;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/memory.c b/src/memory.c
index 744af1a8e7999b51706395889e451f6a740b39b0..16b8e09fbac720d6c32f7a919bf2f46cc793713e 100644 (file)
--- a/src/memory.c
+++ b/src/memory.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int memory_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("ValuesAbsolute", child->key) == 0)
};
double sysctl_vals[8];
- int i;
-
- for (i = 0; sysctl_keys[i] != NULL; i++)
+ for (int i = 0; sysctl_keys[i] != NULL; i++)
{
int value;
size_t value_len = sizeof (value);
} /* for (sysctl_keys) */
/* multiply all all page counts with the pagesize */
- for (i = 1; sysctl_keys[i] != NULL; i++)
+ for (int i = 1; sysctl_keys[i] != NULL; i++)
if (!isnan (sysctl_vals[i]))
sysctl_vals[i] *= sysctl_vals[0];
diff --git a/src/mic.c b/src/mic.c
index 570da51bcfd56c20296effdd64e570e3ff9eb6b9..3e31889fe83f560d89a09ce20df0d26c55d95dc6 100644 (file)
--- a/src/mic.c
+++ b/src/mic.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "utils_ignorelist.h"
static int mic_read_temps(int mic)
{
size_t num_therms = STATIC_ARRAY_SIZE(therm_ids);
- size_t j;
- for (j = 0; j < num_therms; j++) {
+ for (size_t j = 0; j < num_therms; j++) {
U32 status;
U32 temp_buffer;
U32 buffer_size = (U32)sizeof(temp_buffer);
}
if (show_cpu_cores) {
- int j;
- for (j = 0; j < core_util.core; j++) {
+ for (int j = 0; j < core_util.core; j++) {
mic_submit_cpu(mic, "user", j, core_jiffs[j].user);
mic_submit_cpu(mic, "sys", j, core_jiffs[j].sys);
mic_submit_cpu(mic, "nice", j, core_jiffs[j].nice);
static int mic_read (void)
{
- int i;
U32 ret;
int error;
error=0;
- for (i=0;i<num_mics;i++) {
+ for (int i=0;i<num_mics;i++) {
ret = MicInitAdapter(&mic_handle,&mics[i]);
if (ret != MIC_ACCESS_API_SUCCESS) {
ERROR("mic plugin: Problem initializing MicAdapter: %s",
diff --git a/src/modbus.c b/src/modbus.c
index 809194b4c51538d39a3f25180d8be5df77ebc843..db7d033d3f1c0be05cb0f5d08623a369390f0d8e 100644 (file)
--- a/src/modbus.c
+++ b/src/modbus.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static mb_data_t *data_get_by_name (mb_data_t *src, /* {{{ */
const char *name)
{
- mb_data_t *ptr;
-
if (name == NULL)
return (NULL);
- for (ptr = src; ptr != NULL; ptr = ptr->next)
+ for (mb_data_t *ptr = src; ptr != NULL; ptr = ptr->next)
if (strcasecmp (ptr->name, name) == 0)
return (ptr);
static int mb_read_slave (mb_host_t *host, mb_slave_t *slave) /* {{{ */
{
- mb_data_t *data;
int success;
int status;
return (EINVAL);
success = 0;
- for (data = slave->collect; data != NULL; data = data->next)
+ for (mb_data_t *data = slave->collect; data != NULL; data = data->next)
{
status = mb_read_data (host, slave, data);
if (status == 0)
static int mb_read (user_data_t *user_data) /* {{{ */
{
mb_host_t *host;
- size_t i;
int success;
int status;
host = user_data->data;
success = 0;
- for (i = 0; i < host->slaves_num; i++)
+ for (size_t i = 0; i < host->slaves_num; i++)
{
status = mb_read_slave (host, host->slaves + i);
if (status == 0)
static void slaves_free_all (mb_slave_t *slaves, size_t slaves_num) /* {{{ */
{
- size_t i;
-
if (slaves == NULL)
return;
- for (i = 0; i < slaves_num; i++)
+ for (size_t i = 0; i < slaves_num; i++)
data_free_all (slaves[i].collect);
sfree (slaves);
} /* }}} void slaves_free_all */
{
mb_data_t data = { 0 };
int status;
- int i;
data.name = NULL;
data.register_type = REG_TYPE_UINT16;
if (status != 0)
return (status);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
const char *address)
{
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
- struct addrinfo ai_hints = { 0 };
int status;
if ((host == NULL) || (address == NULL))
return (EINVAL);
-#if AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- /* XXX: libmodbus can only handle IPv4 addresses. */
- ai_hints.ai_family = AF_INET;
- ai_hints.ai_addr = NULL;
- ai_hints.ai_canonname = NULL;
- ai_hints.ai_next = NULL;
+ struct addrinfo ai_hints = {
+ /* XXX: libmodbus can only handle IPv4 addresses. */
+ .ai_family = AF_INET,
+ .ai_flags = AI_ADDRCONFIG
+ };
- ai_list = NULL;
status = getaddrinfo (address, /* service = */ NULL,
&ai_hints, &ai_list);
if (status != 0)
return (status);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
status = getnameinfo (ai_ptr->ai_addr, ai_ptr->ai_addrlen,
host->node, sizeof (host->node),
{
mb_slave_t *slave;
int status;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
if (status != 0)
return (status);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
mb_host_t *host;
int status;
- int i;
host = calloc (1, sizeof (*host));
if (host == NULL)
return (EINVAL);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
status = 0;
static int mb_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
if (ci == NULL)
return (EINVAL);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/mqtt.c b/src/mqtt.c
index b318f2116c3030d0e193a92001d9b58925f07e21..a7a0b86d3c4c00c6386fcb27dcea476e564acc0f 100644 (file)
--- a/src/mqtt.c
+++ b/src/mqtt.c
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_complain.h"
static char *strip_prefix (char *topic)
{
- size_t num;
- size_t i;
+ size_t num = 0;
- num = 0;
- for (i = 0; topic[i] != 0; i++)
+ for (size_t i = 0; topic[i] != 0; i++)
if (topic[i] == '/')
num++;
char cb_name[1024];
user_data_t user_data = { 0 };
int status;
- int i;
conf = calloc (1, sizeof (*conf));
if (conf == NULL)
C_COMPLAIN_INIT (&conf->complaint_cantpublish);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Host", child->key) == 0)
mqtt_client_conf_t **tmp;
mqtt_client_conf_t *conf;
int status;
- int i;
conf = calloc (1, sizeof (*conf));
if (conf == NULL)
C_COMPLAIN_INIT (&conf->complaint_cantpublish);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Host", child->key) == 0)
*/
static int mqtt_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int mqtt_init (void)
{
- size_t i;
-
mosquitto_lib_init ();
- for (i = 0; i < subscribers_num; i++)
+ for (size_t i = 0; i < subscribers_num; i++)
{
int status;
diff --git a/src/multimeter.c b/src/multimeter.c
index 00e9964b85f82718d104c7d4bce8688c702ba6b2..02fe1ad312f4be22a58982bb91f5ce033e29dd3f 100644 (file)
--- a/src/multimeter.c
+++ b/src/multimeter.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int multimeter_init (void)
{
- int i;
char device[] = "/dev/ttyS ";
- for (i = 0; i < 10; i++)
+ for (int i = 0; i < 10; i++)
{
device[strlen(device)-1] = i + '0';
diff --git a/src/mysql.c b/src/mysql.c
index 419a154389b768c0e88d67b892f77ef592f3b8e7..ff6c0a7af38a614e4703a732deb2b7f0437a4fe8 100644 (file)
--- a/src/mysql.c
+++ b/src/mysql.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
char *user;
char *pass;
char *database;
+
+ /* mysql_ssl_set params */
+ char *key;
+ char *cert;
+ char *ca;
+ char *capath;
+ char *cipher;
+
char *socket;
int port;
int timeout;
_Bool master_stats;
_Bool slave_stats;
_Bool innodb_stats;
+ _Bool wsrep_stats;
_Bool slave_notif;
_Bool slave_io_running;
sfree (db->socket);
sfree (db->instance);
sfree (db->database);
+ sfree (db->key);
+ sfree (db->cert);
+ sfree (db->ca);
+ sfree (db->capath);
+ sfree (db->cipher);
sfree (db);
} /* }}} void mysql_database_free */
{
mysql_database_t *db;
int status = 0;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
db->user = NULL;
db->pass = NULL;
db->database = NULL;
+ db->key = NULL;
+ db->cert = NULL;
+ db->ca = NULL;
+ db->capath = NULL;
+ db->cipher = NULL;
+
db->socket = NULL;
db->con = NULL;
db->timeout = 0;
assert (db->instance != NULL);
/* Fill the `mysql_database_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
status = cf_util_get_string (child, &db->socket);
else if (strcasecmp ("Database", child->key) == 0)
status = cf_util_get_string (child, &db->database);
+ else if (strcasecmp ("SSLKey", child->key) == 0)
+ status = cf_util_get_string (child, &db->key);
+ else if (strcasecmp ("SSLCert", child->key) == 0)
+ status = cf_util_get_string (child, &db->cert);
+ else if (strcasecmp ("SSLCA", child->key) == 0)
+ status = cf_util_get_string (child, &db->ca);
+ else if (strcasecmp ("SSLCAPath", child->key) == 0)
+ status = cf_util_get_string (child, &db->capath);
+ else if (strcasecmp ("SSLCipher", child->key) == 0)
+ status = cf_util_get_string (child, &db->cipher);
else if (strcasecmp ("ConnectTimeout", child->key) == 0)
status = cf_util_get_int (child, &db->timeout);
else if (strcasecmp ("MasterStats", child->key) == 0)
status = cf_util_get_boolean (child, &db->slave_notif);
else if (strcasecmp ("InnodbStats", child->key) == 0)
status = cf_util_get_boolean (child, &db->innodb_stats);
+ else if (strcasecmp ("WsrepStats", child->key) == 0)
+ status = cf_util_get_boolean (child, &db->wsrep_stats);
else
{
WARNING ("mysql plugin: Option `%s' not allowed here.", child->key);
static int mysql_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
if (ci == NULL)
return (EINVAL);
/* Fill the `mysql_database_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static MYSQL *getconnection (mysql_database_t *db)
{
+ const char *cipher;
+
if (db->is_connected)
{
int status;
/* Configure TCP connect timeout (default: 0) */
db->con->options.connect_timeout = db->timeout;
+ mysql_ssl_set (db->con, db->key, db->cert, db->ca, db->capath, db->cipher);
+
if (mysql_real_connect (db->con, db->host, db->user, db->pass,
db->database, db->port, db->socket, 0) == NULL)
{
return (NULL);
}
+ cipher = mysql_get_ssl_cipher (db->con);
+
INFO ("mysql plugin: Successfully connected to database %s "
- "at server %s (server version: %s, protocol version: %d)",
+ "at server %s with cipher %s "
+ "(server version: %s, protocol version: %d) ",
(db->database != NULL) ? db->database : "<none>",
mysql_get_host_info (db->con),
+ (cipher != NULL) ? cipher : "<none>",
mysql_get_server_info (db->con),
mysql_get_proto_info (db->con));
{ "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_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 },
return (0);
}
+static int mysql_read_wsrep_stats (mysql_database_t *db, MYSQL *con)
+{
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+
+ const char *query;
+ struct {
+ const char *key;
+ const char *type;
+ int ds_type;
+ } metrics[] = {
+
+ { "wsrep_apply_oooe", "operations", DS_TYPE_DERIVE },
+ { "wsrep_apply_oool", "operations", DS_TYPE_DERIVE },
+ { "wsrep_causal_reads", "operations", DS_TYPE_DERIVE },
+ { "wsrep_commit_oooe", "operations", DS_TYPE_DERIVE },
+ { "wsrep_commit_oool", "operations", DS_TYPE_DERIVE },
+ { "wsrep_flow_control_recv", "operations", DS_TYPE_DERIVE },
+ { "wsrep_flow_control_sent", "operations", DS_TYPE_DERIVE },
+ { "wsrep_flow_control_paused", "operations", DS_TYPE_DERIVE },
+ { "wsrep_local_bf_aborts", "operations", DS_TYPE_DERIVE },
+ { "wsrep_local_cert_failures", "operations", DS_TYPE_DERIVE },
+ { "wsrep_local_commits", "operations", DS_TYPE_DERIVE },
+ { "wsrep_local_replays", "operations", DS_TYPE_DERIVE },
+ { "wsrep_received", "operations", DS_TYPE_DERIVE },
+ { "wsrep_replicated", "operations", DS_TYPE_DERIVE },
+
+ { "wsrep_received_bytes", "total_bytes", DS_TYPE_DERIVE },
+ { "wsrep_replicated_bytes", "total_bytes", DS_TYPE_DERIVE },
+
+ { "wsrep_apply_window", "gauge", DS_TYPE_GAUGE },
+ { "wsrep_commit_window", "gauge", DS_TYPE_GAUGE },
+
+ { "wsrep_cluster_size", "gauge", DS_TYPE_GAUGE },
+ { "wsrep_cert_deps_distance", "gauge", DS_TYPE_GAUGE },
+
+ { "wsrep_local_recv_queue", "queue_length", DS_TYPE_GAUGE },
+ { "wsrep_local_send_queue", "queue_length", DS_TYPE_GAUGE },
+
+ { NULL, NULL, 0}
+
+ };
+
+ query = "SHOW GLOBAL STATUS LIKE 'wsrep_%'";
+
+ res = exec_query (con, query);
+ if (res == NULL)
+ return (-1);
+
+ row = mysql_fetch_row (res);
+ if (row == NULL)
+ {
+ ERROR ("mysql plugin: Failed to get wsrep statistics: "
+ "`%s' did not return any rows.", query);
+ mysql_free_result (res);
+ return (-1);
+ }
+
+ while ((row = mysql_fetch_row (res)))
+ {
+ 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_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);
+} /* mysql_read_wsrep_stats */
+
static int mysql_read (user_data_t *ud)
{
mysql_database_t *db;
counter_submit ("mysql_bpool_counters", "read_requests", val, db);
else if (strcmp (key, "Innodb_buffer_pool_reads") == 0)
counter_submit ("mysql_bpool_counters", "reads", val, db);
+ else if (strcmp (key, "Innodb_buffer_pool_wait_free") == 0)
+ counter_submit ("mysql_bpool_counters", "wait_free", val, db);
else if (strcmp (key, "Innodb_buffer_pool_write_requests") == 0)
counter_submit ("mysql_bpool_counters", "write_requests", val, db);
else if (strcmp (key, "Innodb_buffer_pool_bytes_data") == 0)
counter_submit ("mysql_innodb_dblwr", "writes", val, db);
else if (strcmp (key, "Innodb_dblwr_pages_written") == 0)
counter_submit ("mysql_innodb_dblwr", "written", val, db);
+ else if (strcmp (key, "Innodb_dblwr_page_size") == 0)
+ gauge_submit ("mysql_innodb_dblwr", "page_size", val, db);
/* log */
else if (strcmp (key, "Innodb_log_waits") == 0)
counter_submit ("mysql_sort", "scan", val, db);
}
- else if (strncmp (key, "Slow_queries", strlen ("Slow_queries")) == 0)
+ else if (strncmp (key, "Slow_queries", strlen ("Slow_queries")) == 0)
{
counter_submit ("mysql_slow_queries", NULL , val, db);
}
if ((db->slave_stats) || (db->slave_notif))
mysql_read_slave_stats (db, con);
+ if (db->wsrep_stats)
+ mysql_read_wsrep_stats (db, con);
+
return (0);
} /* int mysql_read */
diff --git a/src/netapp.c b/src/netapp.c
index 45395ae04b0daf7c7fc9656a5c09b94388711bf9..26577dadba5abfde0ec6ca06d95c3c9d836c3c5a 100644 (file)
--- a/src/netapp.c
+++ b/src/netapp.c
**/
#include "collectd.h"
+
#include "common.h"
#include "utils_ignorelist.h"
const char *plugin_inst;
na_elem_t *instances;
- na_elem_t *counter;
na_elem_iter_t counter_iter;
perf_data.timestamp = cna_child_get_cdtime (data);
/* Iterate over all counters */
counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
- for (counter = na_iterator_next (&counter_iter);
+ for (na_elem_t *counter = na_iterator_next (&counter_iter);
counter != NULL;
counter = na_iterator_next (&counter_iter))
{
{
cdtime_t timestamp;
na_elem_t *instances;
- na_elem_t *instance;
na_elem_iter_t instance_iter;
disk_t *worst_disk = NULL;
/* Iterate over all children */
instance_iter = na_child_iterator (instances);
- for (instance = na_iterator_next (&instance_iter);
+ for (na_elem_t *instance = na_iterator_next (&instance_iter);
instance != NULL;
instance = na_iterator_next(&instance_iter))
{
disk_t new_data = { 0 };
na_elem_iter_t counter_iterator;
- na_elem_t *counter;
new_data.timestamp = timestamp;
new_data.disk_busy_percent = NAN;
/* Look for the "disk_busy" and "base_for_disk_busy" counters */
counter_iterator = na_child_iterator(na_elem_child(instance, "counters"));
- for (counter = na_iterator_next(&counter_iterator);
+ for (na_elem_t *counter = na_iterator_next(&counter_iterator);
counter != NULL;
counter = na_iterator_next(&counter_iterator))
{
cdtime_t timestamp;
na_elem_t *elem_instances;
na_elem_iter_t iter_instances;
- na_elem_t *elem_instance;
timestamp = cna_child_get_cdtime (data);
}
iter_instances = na_child_iterator (elem_instances);
- for (elem_instance = na_iterator_next(&iter_instances);
+ for (na_elem_t *elem_instance = na_iterator_next(&iter_instances);
elem_instance != NULL;
elem_instance = na_iterator_next(&iter_instances))
{
na_elem_t *elem_counters;
na_elem_iter_t iter_counters;
- na_elem_t *elem_counter;
perf_data.timestamp = timestamp;
continue;
iter_counters = na_child_iterator (elem_counters);
- for (elem_counter = na_iterator_next(&iter_counters);
+ for (na_elem_t *elem_counter = na_iterator_next(&iter_counters);
elem_counter != NULL;
elem_counter = na_iterator_next(&iter_counters))
{
static int cna_submit_volume_usage_data (const char *hostname, /* {{{ */
cfg_volume_usage_t *cfg_volume, int interval)
{
- data_volume_usage_t *v;
-
- for (v = cfg_volume->volumes; v != NULL; v = v->next)
+ for (data_volume_usage_t *v = cfg_volume->volumes; v != NULL; v = v->next)
{
char plugin_instance[DATA_MAX_NAME_LEN];
data_volume_usage_t *v)
{
uint64_t snap_used = 0, value;
- na_elem_t *data, *elem_snap, *elem_snapshots;
+ na_elem_t *data, *elem_snapshots;
na_elem_iter_t iter_snap;
data = na_server_invoke_elem(host->srv, v->snap_query);
}
iter_snap = na_child_iterator (elem_snapshots);
- for (elem_snap = na_iterator_next (&iter_snap);
+ for (na_elem_t *elem_snap = na_iterator_next (&iter_snap);
elem_snap != NULL;
elem_snap = na_iterator_next (&iter_snap))
{
static int cna_handle_volume_usage_data (const host_config_t *host, /* {{{ */
cfg_volume_usage_t *cfg_volume, na_elem_t *data)
{
- na_elem_t *elem_volume;
na_elem_t *elem_volumes;
na_elem_iter_t iter_volume;
}
iter_volume = na_child_iterator (elem_volumes);
- for (elem_volume = na_iterator_next (&iter_volume);
+ for (na_elem_t *elem_volume = na_iterator_next (&iter_volume);
elem_volume != NULL;
elem_volume = na_iterator_next (&iter_volume))
{
static int cna_handle_quota_data (const host_config_t *host, /* {{{ */
cfg_quota_t *cfg_quota, na_elem_t *data)
{
- na_elem_t *elem_quota;
na_elem_t *elem_quotas;
na_elem_iter_t iter_quota;
}
iter_quota = na_child_iterator (elem_quotas);
- for (elem_quota = na_iterator_next (&iter_quota);
+ for (na_elem_t *elem_quota = na_iterator_next (&iter_quota);
elem_quota != NULL;
elem_quota = na_iterator_next (&iter_quota))
{
static int cna_handle_snapvault_data (const char *hostname, /* {{{ */
cfg_snapvault_t *cfg_snapvault, na_elem_t *data, cdtime_t interval)
{
- na_elem_t *status;
na_elem_iter_t status_iter;
status = na_elem_child (data, "status-list");
}
status_iter = na_child_iterator (status);
- for (status = na_iterator_next (&status_iter);
+ for (na_elem_t *status = na_iterator_next (&status_iter);
status != NULL;
status = na_iterator_next (&status_iter))
{
const char *tag;
uint32_t records_count;
- uint32_t i;
records_count = na_child_get_uint32 (data, "records", UINT32_MAX);
if (records_count == UINT32_MAX)
DEBUG ("netapp plugin: Iterating %u SV records (tag = %s)", records_count, tag);
- for (i = 0; i < records_count; ++i) {
+ for (uint32_t i = 0; i < records_count; ++i) {
na_elem_t *elem;
elem = na_server_invoke (host->srv,
cfg_system_t *cfg_system, na_elem_t *data, int interval)
{
na_elem_t *instances;
- na_elem_t *counter;
na_elem_iter_t counter_iter;
derive_t disk_read = 0, disk_written = 0;
}
counter_iter = na_child_iterator (na_elem_child (instances, "counters"));
- for (counter = na_iterator_next (&counter_iter);
+ for (na_elem_t *counter = na_iterator_next (&counter_iter);
counter != NULL;
counter = na_iterator_next (&counter_iter))
{
const oconfig_item_t *ci)
{
cfg_volume_perf_t *cfg_volume_perf;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
}
cfg_volume_perf = host->cfg_volume_perf;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
/* if (!item || !item->key || !*item->key) continue; */
@@ -2517,7 +2505,6 @@ static void cna_config_volume_usage_default (cfg_volume_usage_t *cvu, /* {{{ */
static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
{
cfg_quota_t *cfg_quota;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
@@ -2533,7 +2520,7 @@ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
}
cfg_quota = host->cfg_quota;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp (item->key, "Interval") == 0)
@@ -2549,7 +2536,6 @@ static int cna_config_quota (host_config_t *host, oconfig_item_t *ci) /* {{{ */
/* Corresponds to a <Disks /> block */
static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
cfg_disk_t *cfg_disk;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
@@ -2569,7 +2555,7 @@ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
}
cfg_disk = host->cfg_disk;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
/* if (!item || !item->key || !*item->key) continue; */
@@ -2594,7 +2580,6 @@ static int cna_config_disk(host_config_t *host, oconfig_item_t *ci) { /* {{{ */
static int cna_config_wafl(host_config_t *host, oconfig_item_t *ci) /* {{{ */
{
cfg_wafl_t *cfg_wafl;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
}
cfg_wafl = host->cfg_wafl;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0)
const oconfig_item_t *ci)
{
cfg_volume_usage_t *cfg_volume_usage;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
}
cfg_volume_usage = host->cfg_volume_usage;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
/* if (!item || !item->key || !*item->key) continue; */
const oconfig_item_t *ci)
{
cfg_snapvault_t *cfg_snapvault;
- int i;
if ((host == NULL) || (ci == NULL))
return EINVAL;
cfg_snapvault = host->cfg_snapvault;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp (item->key, "Interval") == 0)
oconfig_item_t *ci)
{
cfg_system_t *cfg_system;
- int i;
if ((host == NULL) || (ci == NULL))
return (EINVAL);
}
cfg_system = host->cfg_system;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp(item->key, "Interval") == 0) {
oconfig_item_t *item;
_Bool is_vfiler = 0;
int status;
- int i;
if (! strcasecmp (ci->key, "VFiler"))
is_vfiler = 1;
if (status != 0)
return (1);
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
item = ci->children + i;
status = 0;
} /* }}} int cna_read */
static int cna_config (oconfig_item_t *ci) { /* {{{ */
- int i;
oconfig_item_t *item;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
item = ci->children + i;
if (strcasecmp(item->key, "Host") == 0)
diff --git a/src/netlink.c b/src/netlink.c
index 5c3a9f007beb656aeefcc2a81152243671243d1e..cfca46f7494084de4939288f72a95632c2fcdd44 100644 (file)
--- a/src/netlink.c
+++ b/src/netlink.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
static int check_ignorelist (const char *dev,
const char *type, const char *type_instance)
{
- ir_ignorelist_t *i;
-
assert ((dev != NULL) && (type != NULL));
if (ir_ignorelist_head == NULL)
return (ir_ignorelist_invert ? 0 : 1);
- for (i = ir_ignorelist_head; i != NULL; i = i->next)
+ for (ir_ignorelist_t *i = ir_ignorelist_head; i != NULL; i = i->next)
{
/* i->device == NULL => match all devices */
if ((i->device != NULL)
int ret;
unsigned int seq, portid;
- size_t ifindex;
-
static const int type_id[] = { RTM_GETQDISC, RTM_GETTCLASS, RTM_GETTFILTER };
static const char *type_name[] = { "qdisc", "class", "filter" };
/* `link_filter_cb' will update `iflist' which is used here to iterate
* over all interfaces. */
- for (ifindex = 1; ifindex < iflist_len; ifindex++)
+ for (size_t ifindex = 1; ifindex < iflist_len; ifindex++)
{
struct tcmsg *tm;
- size_t type_index;
if (iflist[ifindex] == NULL)
continue;
- for (type_index = 0; type_index < STATIC_ARRAY_SIZE (type_id); type_index++)
+ for (size_t type_index = 0; type_index < STATIC_ARRAY_SIZE (type_id); type_index++)
{
if (check_ignorelist (iflist[ifindex], type_name[type_index], NULL))
{
diff --git a/src/network.c b/src/network.c
index 5a8a88efe388317cd48288ad97e63412b8b6acef..1458a0ae88f66c5665bce965bec01ca0674cd5cf 100644 (file)
--- a/src/network.c
+++ b/src/network.c
#define _BSD_SOURCE /* For struct ip_mreq */
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
static _Bool check_notify_received (const notification_t *n) /* {{{ */
{
- notification_meta_t *ptr;
-
- for (ptr = n->meta; ptr != NULL; ptr = ptr->next)
+ for (notification_meta_t *ptr = n->meta; ptr != NULL; ptr = ptr->next)
if ((strcmp ("network:received", ptr->name) == 0)
&& (ptr->type == NM_TYPE_BOOLEAN))
return ((_Bool) ptr->nm_value.nm_boolean);
} /* }}} int network_dispatch_notification */
#if HAVE_LIBGCRYPT
-static void network_init_gcrypt (void) /* {{{ */
+static int network_init_gcrypt (void) /* {{{ */
{
gcry_error_t err;
* Because you can't know in a library whether another library has
* already initialized the library */
if (gcry_control (GCRYCTL_ANY_INITIALIZATION_P))
- return;
+ return (0);
/* http://www.gnupg.org/documentation/manuals/gcrypt/Multi_002dThreading.html
* To ensure thread-safety, it's important to set GCRYCTL_SET_THREAD_CBS
if (err)
{
ERROR ("network plugin: gcry_control (GCRYCTL_SET_THREAD_CBS) failed: %s", gcry_strerror (err));
- abort ();
+ return (-1);
}
# endif
if (err)
{
ERROR ("network plugin: gcry_control (GCRYCTL_INIT_SECMEM) failed: %s", gcry_strerror (err));
- abort ();
+ return (-1);
}
gcry_control (GCRYCTL_INITIALIZATION_FINISHED);
-} /* }}} void network_init_gcrypt */
+ return (0);
+} /* }}} int network_init_gcrypt */
static gcry_cipher_hd_t network_get_aes256_cypher (sockent_t *se, /* {{{ */
const void *iv, size_t iv_size, const char *username)
value_t *pkg_values;
size_t offset;
- int i;
num_values = vl->values_len;
packet_len = sizeof (part_header_t) + sizeof (uint16_t)
pkg_num_values = htons ((uint16_t) vl->values_len);
- for (i = 0; i < num_values; i++)
+ for (int i = 0; i < num_values; i++)
{
pkg_values_types[i] = (uint8_t) ds->ds[i].type;
switch (ds->ds[i].type)
uint16_t tmp16;
size_t exp_size;
- size_t i;
uint16_t pkg_length;
uint16_t pkg_type;
memcpy (pkg_values, buffer, pkg_numval * sizeof (*pkg_values));
buffer += pkg_numval * sizeof (*pkg_values);
- for (i = 0; i < pkg_numval; i++)
+ for (size_t i = 0; i < pkg_numval; i++)
{
switch (pkg_types[i])
{
if (memcmp (pss.hash, hash, sizeof (pss.hash)) != 0)
{
WARNING ("network plugin: Verifying HMAC-SHA-256 signature failed: "
- "Hash mismatch.");
+ "Hash mismatch. Username: %s", pss.username);
}
else
{
pea.username);
if (cypher == NULL)
{
+ ERROR ("network plugin: Failed to get cypher. Username: %s", pea.username);
sfree (pea.username);
return (-1);
}
if (err != 0)
{
sfree (pea.username);
- ERROR ("network plugin: gcry_cipher_decrypt returned: %s",
- gcry_strerror (err));
+ ERROR ("network plugin: gcry_cipher_decrypt returned: %s. Username: %s",
+ gcry_strerror (err), pea.username);
return (-1);
}
buffer + buffer_offset, payload_len);
if (memcmp (hash, pea.hash, sizeof (hash)) != 0)
{
+ ERROR ("network plugin: Checksum mismatch. Username: %s", pea.username);
sfree (pea.username);
- ERROR ("network plugin: Decryption failed: Checksum mismatch.");
return (-1);
}
#if HAVE_LIBGCRYPT
int packet_was_signed = (flags & PP_SIGNED);
- int packet_was_encrypted = (flags & PP_ENCRYPTED);
+ int packet_was_encrypted = (flags & PP_ENCRYPTED);
int printed_ignore_warning = 0;
#endif /* HAVE_LIBGCRYPT */
static void free_sockent_server (struct sockent_server *ses) /* {{{ */
{
- size_t i;
-
- for (i = 0; i < ses->fd_num; i++)
+ for (size_t i = 0; i < ses->fd_num; i++)
{
if (ses->fd[i] >= 0)
{
{
if (se->data.client.security_level > SECURITY_LEVEL_NONE)
{
- network_init_gcrypt ();
+ if (network_init_gcrypt () < 0)
+ {
+ ERROR ("network plugin: Cannot configure client socket with "
+ "security: Failed to initialize crypto library.");
+ return (-1);
+ }
if ((se->data.client.username == NULL)
|| (se->data.client.password == NULL))
{
if (se->data.server.security_level > SECURITY_LEVEL_NONE)
{
- network_init_gcrypt ();
+ if (network_init_gcrypt () < 0)
+ {
+ ERROR ("network plugin: Cannot configure server socket with "
+ "security: Failed to initialize crypto library.");
+ return (-1);
+ }
if (se->data.server.auth_file == NULL)
{
static c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
struct sockent_client *client;
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list = NULL, *ai_ptr;
+ struct addrinfo *ai_list;
int status;
_Bool reconnect = 0;
cdtime_t now;
if (client->fd >= 0 && !reconnect) /* already connected and not stale*/
return (0);
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
- ai_hints.ai_protocol = IPPROTO_UDP;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_protocol = IPPROTO_UDP,
+ .ai_socktype = SOCK_DGRAM
+ };
status = getaddrinfo (se->node,
(se->service != NULL) ? se->service : NET_DEFAULT_PORT,
se->node);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
if (client->fd >= 0) /* when we reconnect */
sockent_client_disconnect(se);
/* Open the file descriptors for a initialized sockent structure. */
static int sockent_server_listen (sockent_t *se) /* {{{ */
{
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list, *ai_ptr;
+ struct addrinfo *ai_list;
int status;
const char *node;
DEBUG ("network plugin: sockent_server_listen: node = %s; service = %s;",
node, service);
-#ifdef AI_PASSIVE
- ai_hints.ai_flags |= AI_PASSIVE;
-#endif
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
- ai_hints.ai_protocol = IPPROTO_UDP;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG | AI_PASSIVE,
+ .ai_protocol = IPPROTO_UDP,
+ .ai_socktype = SOCK_DGRAM
+ };
status = getaddrinfo (node, service, &ai_hints, &ai_list);
if (status != 0)
return (-1);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
int *tmp;
if (se->type == SOCKENT_TYPE_SERVER)
{
struct pollfd *tmp;
- size_t i;
tmp = realloc (listen_sockets_pollfd,
sizeof (*tmp) * (listen_sockets_num
listen_sockets_pollfd = tmp;
tmp = listen_sockets_pollfd + listen_sockets_num;
- for (i = 0; i < se->data.server.fd_num; i++)
+ for (size_t i = 0; i < se->data.server.fd_num; i++)
{
memset (tmp + i, 0, sizeof (*tmp));
tmp[i].fd = se->data.server.fd[i];
char buffer[network_config_packet_size];
int buffer_len;
- size_t i;
int status = 0;
receive_list_entry_t *private_list_head;
break;
}
- for (i = 0; (i < listen_sockets_num) && (status > 0); i++)
+ for (size_t i = 0; (i < listen_sockets_num) && (status > 0); i++)
{
receive_list_entry_t *ent;
static void network_send_buffer (char *buffer, size_t buffer_len) /* {{{ */
{
- sockent_t *se;
-
DEBUG ("network plugin: network_send_buffer: buffer_len = %zu", buffer_len);
- for (se = sending_sockets; se != NULL; se = se->next)
+ for (sockent_t *se = sending_sockets; se != NULL; se = se->next)
{
#if HAVE_LIBGCRYPT
if (se->data.client.security_level == SECURITY_LEVEL_ENCRYPT)
{
int status;
+ /* listen_loop is set to non-zero in the shutdown callback, which is
+ * guaranteed to be called *after* all the write threads have been shut
+ * down. */
+ assert (listen_loop == 0);
+
if (!check_send_okay (vl))
{
#if COLLECT_DEBUG
{
sockent_t *se;
int status;
- int i;
if ((ci->values_num < 1) || (ci->values_num > 2)
|| (ci->values[0].type != OCONFIG_TYPE_STRING)
if (ci->values_num >= 2)
se->service = strdup (ci->values[1].value.string);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
{
sockent_t *se;
int status;
- int i;
if ((ci->values_num < 1) || (ci->values_num > 2)
|| (ci->values[0].type != OCONFIG_TYPE_STRING)
if (ci->values_num >= 2)
se->service = strdup (ci->values[1].value.string);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int network_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
/* The options need to be applied first */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("TimeToLive", child->key) == 0)
network_config_set_ttl (child);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int network_shutdown (void)
{
- sockent_t *se;
-
listen_loop++;
/* Kill the listening thread */
sfree (send_buffer);
- for (se = sending_sockets; se != NULL; se = se->next)
+ for (sockent_t *se = sending_sockets; se != NULL; se = se->next)
sockent_client_disconnect (se);
sockent_destroy (sending_sockets);
have_init = 1;
#if HAVE_LIBGCRYPT
- network_init_gcrypt ();
+ if (network_init_gcrypt () < 0)
+ {
+ ERROR ("network plugin: Failed to initialize crypto library.");
+ return (-1);
+ }
#endif
if (network_config_stats)
diff --git a/src/nfs.c b/src/nfs.c
index 0948bc79a6534f23a39c2d305b3b4869d0cd5204..c128c8173fea1a494333da877765ab8f9bf208fb 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#elif HAVE_LIBKSTAT
static int nfs_init (void)
{
- kstat_t *ksp_chain = NULL;
-
nfs2_ksp_client = NULL;
nfs2_ksp_server = NULL;
nfs3_ksp_client = NULL;
if (kc == NULL)
return (-1);
- for (ksp_chain = kc->kc_chain; ksp_chain != NULL;
+ for (kstat_t *ksp_chain = kc->kc_chain; ksp_chain != NULL;
ksp_chain = ksp_chain->ks_next)
{
if (strncmp (ksp_chain->ks_module, "nfs", 3) != 0)
value_t *values, size_t values_num)
{
value_list_t vl = VALUE_LIST_INIT;
- size_t i;
vl.values_len = 1;
sstrncpy (vl.host, hostname_g, sizeof (vl.host));
sizeof (vl.plugin_instance));
sstrncpy (vl.type, "nfs_procedure", sizeof (vl.type));
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
vl.values = values + i;
sstrncpy (vl.type_instance, type_instances[i],
{
char plugin_instance[DATA_MAX_NAME_LEN];
value_t values[fields_num];
- size_t i;
ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s",
nfs_version, instance);
- for (i = 0; i < fields_num; i++)
+ for (size_t i = 0; i < fields_num; i++)
(void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE);
nfs_procedures_submit (plugin_instance, proc_names, values,
{
char plugin_instance[DATA_MAX_NAME_LEN];
value_t values[proc_names_num];
- size_t i;
if (ksp == NULL)
return (EINVAL);
nfs_version, inst);
kstat_read(kc, ksp, NULL);
- for (i = 0; i < proc_names_num; i++)
+ for (size_t i = 0; i < proc_names_num; i++)
{
/* The name passed to kstat_data_lookup() doesn't have the
* "const" modifier, so we need to copy the name here. */
diff --git a/src/nginx.c b/src/nginx.c
index 7587c1f9b5b8429f4fb7c5e1b7db0ce04a378f35..e346cee30a9d8696af19a34058fb4b2ff4ff5dd1 100644 (file)
--- a/src/nginx.c
+++ b/src/nginx.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int nginx_read (void)
{
- int i;
-
char *ptr;
char *lines[16];
int lines_num = 0;
* 16630948 16630948 31070465
* Reading: 6 Writing: 179 Waiting: 106
*/
- for (i = 0; i < lines_num; i++)
+ for (int i = 0; i < lines_num; i++)
{
fields_num = strsplit (lines[i], fields,
(sizeof (fields) / sizeof (fields[0])));
diff --git a/src/notify_desktop.c b/src/notify_desktop.c
index c2d97520ed99c9bcbb8839900ea1858ba39731bf..ef7b95b873b4efa9a6d3d35a6bd462390ae1bfa8 100644 (file)
--- a/src/notify_desktop.c
+++ b/src/notify_desktop.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int c_notify_config (oconfig_item_t *ci)
{
- int i = 0;
-
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "OkayTimeout"))
diff --git a/src/notify_email.c b/src/notify_email.c
index 0120a4039466e240c753ed3e7e2472995dec3335..cefeb22f4717d6b53695b123099ca570491d47f8 100644 (file)
--- a/src/notify_email.c
+++ b/src/notify_email.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int authinteract (auth_client_request_t request, char **result,
int fields, void __attribute__((unused)) *arg)
{
- int i;
- for (i = 0; i < fields; i++)
+ for (int i = 0; i < fields; i++)
{
if (request[i].flags & AUTH_USER)
result[i] = smtp_user;
diff --git a/src/notify_nagios.c b/src/notify_nagios.c
index c16922232b4deb49250ff03b36f0c760251d7a7e..57a034da886be318f53a5a20208a41152653da47 100644 (file)
--- a/src/notify_nagios.c
+++ b/src/notify_nagios.c
*/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
static int nagios_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/ntpd.c b/src/ntpd.c
index f7b57ba30ce30ecc3c7826f879d2d4bb99629028..a0093655e4066493cae5f0c3f5533b5ececb705f 100644 (file)
--- a/src/ntpd.c
+++ b/src/ntpd.c
#define _BSD_SOURCE /* For NI_MAXHOST */
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
const char *host;
const char *port;
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
int status;
if (sock_descr >= 0)
if (strlen (port) == 0)
port = NTPD_DEFAULT_PORT;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = PF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
- ai_hints.ai_protocol = IPPROTO_UDP;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_protocol = IPPROTO_UDP,
+ .ai_socktype = SOCK_DGRAM
+ };
if ((status = getaddrinfo (host, port, &ai_hints, &ai_list)) != 0)
{
return (-1);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
/* create our socket descriptor */
if ((sock_descr = socket (ai_ptr->ai_family,
struct resp_pkt res;
int status;
int done;
- int i;
char *items;
size_t items_num;
items_num += pkt_item_num;
*res_data = items;
- for (i = 0; i < pkt_item_num; i++)
+ for (int i = 0; i < pkt_item_num; i++)
{
/* dst: There are already `*res_items' items with
* res_item_size bytes each in in `*res_data'. Set
gauge_t offset_error;
int status;
- int i;
/* On Linux, if the STA_NANO bit is set in ik->status, then ik->offset
* is is nanoseconds, otherwise it's microseconds. */
return (-1);
}
- for (i = 0; i < ps_num; i++)
+ for (int i = 0; i < ps_num; i++)
{
struct info_peer_summary *ptr;
double offset;
diff --git a/src/numa.c b/src/numa.c
index 4bcc2468826fe5c0313b95e732fb6552f23264f1..8f5bf4803821c9fe40be370f4c5c5ee0d4cd4520 100644 (file)
--- a/src/numa.c
+++ b/src/numa.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/nut.c b/src/nut.c
index a033e2f668503520eb8860fc8bf54f2354d803d3..b5c6b41b6522142aba73716ed36b5a05e4886608 100644 (file)
--- a/src/nut.c
+++ b/src/nut.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int nut_read (void)
{
- nut_ups_t *ups;
int success = 0;
pthread_mutex_lock (&read_lock);
if (success != 0)
return (0);
- for (ups = upslist_head; ups != NULL; ups = ups->next)
+ for (nut_ups_t *ups = upslist_head; ups != NULL; ups = ups->next)
if (nut_read_one (ups) == 0)
success++;
diff --git a/src/olsrd.c b/src/olsrd.c
index 2b7e767e7702151762880f744823e0e9c4ea3c81..899ad3e8f2ef4e565cb782c4290f8cfbf08f39cf 100644 (file)
--- a/src/olsrd.c
+++ b/src/olsrd.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
@@ -149,20 +150,18 @@ static size_t strtabsplit (char *string, char **fields, size_t size) /* {{{ */
static FILE *olsrd_connect (void) /* {{{ */
{
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list, *ai_ptr;
+ struct addrinfo *ai_list;
int ai_return;
FILE *fh;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = PF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
- ai_hints.ai_protocol = IPPROTO_TCP;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_protocol = IPPROTO_TCP,
+ .ai_socktype = SOCK_STREAM
+ };
- ai_list = NULL;
ai_return = getaddrinfo (olsrd_get_node (), olsrd_get_service (),
&ai_hints, &ai_list);
if (ai_return != 0)
}
fh = NULL;
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
int fd;
int status;
diff --git a/src/onewire.c b/src/onewire.c
index 42bd1eb8213c5e0700584bea21c381711900a1e6..235eff80a8d4663b5e479627db39f3183f99aa21 100644 (file)
--- a/src/onewire.c
+++ b/src/onewire.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
int success = 0;
- size_t i;
if (sensor_list != NULL)
{
sstrncpy (vl.plugin, "onewire", sizeof (vl.plugin));
sstrncpy (vl.plugin_instance, name, sizeof (vl.plugin_instance));
- for (i = 0; i < family_info->features_num; i++)
+ for (size_t i = 0; i < family_info->features_num; i++)
{
char *buffer;
size_t buffer_size;
diff --git a/src/openldap.c b/src/openldap.c
index 3dac057eb4bd9bb64768ae36cff670191c1b1b43..282e2dc7d1f128d6097695c8230945c52ebbeab5 100644 (file)
--- a/src/openldap.c
+++ b/src/openldap.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int cldap_read_host (user_data_t *ud) /* {{{ */
{
cldap_t *st;
- LDAPMessage *e, *result;
+ LDAPMessage *result;
char *dn;
int rc;
int status;
return (-1);
}
- for (e = ldap_first_entry (st->ld, result); e != NULL;
+ for (LDAPMessage *e = ldap_first_entry (st->ld, result); e != NULL;
e = ldap_next_entry (st->ld, e))
{
if ((dn = ldap_get_dn (st->ld, e)) != NULL)
static int cldap_config_add (oconfig_item_t *ci) /* {{{ */
{
cldap_t *st;
- int i;
int status;
st = calloc (1, sizeof (*st));
st->verifyhost = 1;
st->version = LDAP_VERSION3;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int cldap_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
int status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int cldap_shutdown (void) /* {{{ */
{
- size_t i;
-
- for (i = 0; i < databases_num; i++)
+ for (size_t i = 0; i < databases_num; i++)
if (databases[i]->ld != NULL)
ldap_unbind_ext_s (databases[i]->ld, NULL, NULL);
sfree (databases);
diff --git a/src/openvpn.c b/src/openvpn.c
index 85760e996d27b8cd6a6cce3abb531631ad908ab1..00ae736ad4b01c70555f509c0b3580afb8fa8329 100644 (file)
--- a/src/openvpn.c
+++ b/src/openvpn.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int openvpn_read (void)
{
FILE *fh;
- int i, read;
+ int read;
read = 0;
/* call the right read function for every status entry in the list */
- for (i = 0; i < vpn_num; i++)
+ for (int i = 0; i < vpn_num; i++)
{
int vpn_read = 0;
if (strcasecmp ("StatusFile", key) == 0)
{
char *status_file, *status_name, *filename;
- int status_version, i;
+ int status_version;
vpn_status_t *temp;
/* try to detect the status file format */
}
/* scan the list looking for a clone */
- for (i = 0; i < vpn_num; i++)
+ for (int i = 0; i < vpn_num; i++)
{
if (strcasecmp (vpn_list[i]->name, status_name) == 0)
{
/* shutdown callback */
static int openvpn_shutdown (void)
{
- int i;
-
- for (i = 0; i < vpn_num; i++)
+ for (int i = 0; i < vpn_num; i++)
{
sfree (vpn_list[i]->file);
sfree (vpn_list[i]);
diff --git a/src/oracle.c b/src/oracle.c
index cb9b3dbf9230aede137294f91160ddea73db2af4..1554830099e89558733e314bbee3fc73ac0e2437 100644 (file)
--- a/src/oracle.c
+++ b/src/oracle.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
char buffer[2048];
sb4 error_code;
int status;
- unsigned int record_number;
if (db_name == NULL)
db_name = "(none)";
/* An operation may cause / return multiple errors. Loop until we have
* handled all errors available (with a fail-save limit of 16). */
- for (record_number = 1; record_number <= 16; record_number++)
+ for (unsigned int record_number = 1; record_number <= 16; record_number++)
{
memset (buffer, 0, sizeof (buffer));
error_code = -1;
static void o_database_free (o_database_t *db) /* {{{ */
{
- size_t i;
-
if (db == NULL)
return;
sfree (db->queries);
if (db->q_prep_areas != NULL)
- for (i = 0; i < db->queries_num; ++i)
+ for (size_t i = 0; i < db->queries_num; ++i)
udb_query_delete_preparation_area (db->q_prep_areas[i]);
free (db->q_prep_areas);
{
o_database_t *db;
int status;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING))
}
/* Fill the `o_database_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
break;
}
- for (i = 0; i < db->queries_num; ++i)
+ for (int i = 0; i < db->queries_num; ++i)
{
db->q_prep_areas[i]
= udb_query_allocate_preparation_area (db->queries[i]);
static int o_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Query", child->key) == 0)
OCIDefine **oci_defines;
int status;
- size_t i;
oci_statement = udb_query_get_user_data (q);
ALLOC_OR_FAIL (column_names, column_num * sizeof (char *));
ALLOC_OR_FAIL (column_names[0], column_num * DATA_MAX_NAME_LEN
* sizeof (char));
- for (i = 1; i < column_num; i++)
+ for (size_t i = 1; i < column_num; i++)
column_names[i] = column_names[i - 1] + DATA_MAX_NAME_LEN;
ALLOC_OR_FAIL (column_values, column_num * sizeof (char *));
ALLOC_OR_FAIL (column_values[0], column_num * DATA_MAX_NAME_LEN
* sizeof (char));
- for (i = 1; i < column_num; i++)
+ for (size_t i = 1; i < column_num; i++)
column_values[i] = column_values[i - 1] + DATA_MAX_NAME_LEN;
ALLOC_OR_FAIL (oci_defines, column_num * sizeof (OCIDefine *));
/* ``Define'' the returned data, i. e. bind the columns to the buffers
* allocated above. */
- for (i = 0; i < column_num; i++) /* {{{ */
+ for (size_t i = 0; i < column_num; i++) /* {{{ */
{
char *column_name;
ub4 column_name_length;
static int o_read_database (o_database_t *db) /* {{{ */
{
- size_t i;
int status;
if (db->oci_service_context != NULL)
DEBUG ("oracle plugin: o_read_database: db->connect_id = %s; db->oci_service_context = %p;",
db->connect_id, db->oci_service_context);
- for (i = 0; i < db->queries_num; i++)
+ for (size_t i = 0; i < db->queries_num; i++)
o_read_database_query (db, db->queries[i], db->q_prep_areas[i]);
return (0);
diff --git a/src/perl.c b/src/perl.c
index fe9f97b5f6dc8f2cbff2430dd57fa5b8d9dba7a2..48374b69b8df5fc041fc4c25732bcd4c691cfff8 100644 (file)
--- a/src/perl.c
+++ b/src/perl.c
#define DONT_POISON_SPRINTF_YET 1
#include "collectd.h"
+
#undef DONT_POISON_SPRINTF_YET
#include "configfile.h"
static size_t av2value (pTHX_ char *name, AV *array, value_t *value, size_t array_len)
{
const data_set_t *ds;
- size_t i;
if ((NULL == name) || (NULL == array) || (NULL == value) || (array_len == 0))
return 0;
@@ -328,7 +328,7 @@ static size_t av2value (pTHX_ char *name, AV *array, value_t *value, size_t arra
name, array_len, ds->ds_num);
}
- for (i = 0; i < ds->ds_num; ++i) {
+ for (size_t i = 0; i < ds->ds_num; ++i) {
SV **tmp = av_fetch (array, i, 0);
if (NULL != tmp) {
static int av2data_set (pTHX_ AV *array, char *name, data_set_t *ds)
{
- int len, i;
+ int len;
if ((NULL == array) || (NULL == name) || (NULL == ds))
return -1;
ds->ds = smalloc ((len + 1) * sizeof (*ds->ds));
ds->ds_num = len + 1;
- for (i = 0; i <= len; ++i) {
+ for (int i = 0; i <= len; ++i) {
SV **elem = av_fetch (array, i, 0);
if (NULL == elem) {
notification_meta_t **m = meta;
int len = av_len (array);
- int i;
- for (i = 0; i <= len; ++i) {
+ for (int i = 0; i <= len; ++i) {
SV **tmp = av_fetch (array, i, 0);
HV *hash;
static int data_set2av (pTHX_ data_set_t *ds, AV *array)
{
- size_t i;
-
if ((NULL == ds) || (NULL == array))
return -1;
av_extend (array, ds->ds_num);
- for (i = 0; i < ds->ds_num; ++i) {
+ for (size_t i = 0; i < ds->ds_num; ++i) {
HV *source = newHV ();
if (NULL == hv_store (source, "name", 4,
static int notification_meta2av (pTHX_ notification_meta_t *meta, AV *array)
{
int meta_num = 0;
- int i;
while (meta) {
++meta_num;
av_extend (array, meta_num);
- for (i = 0; NULL != meta; meta = meta->next, ++i) {
+ for (int i = 0; NULL != meta; meta = meta->next, ++i) {
HV *m = newHV ();
SV *value;
static int oconfig_item2hv (pTHX_ oconfig_item_t *ci, HV *hash)
{
- int i;
-
AV *values;
AV *children;
return -1;
}
- for (i = 0; i < ci->values_num; ++i) {
+ for (int i = 0; i < ci->values_num; ++i) {
SV *value;
switch (ci->values[i].type) {
return -1;
}
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
HV *child = newHV ();
if (0 != oconfig_item2hv (aTHX_ ci->children + i, child)) {
SV *tmp = NULL;
char *file = __FILE__;
- int i = 0;
-
dXSUB_SYS;
/* enable usage of Perl modules using shared libraries */
newXS ("DynaLoader::boot_DynaLoader", boot_DynaLoader, file);
/* register API */
- for (i = 0; NULL != api[i].f; ++i)
+ for (int i = 0; NULL != api[i].f; ++i)
newXS (api[i].name, api[i].f, file);
stash = gv_stashpv ("Collectd", 1);
/* export "constants" */
- for (i = 0; '\0' != constants[i].name[0]; ++i)
+ for (int i = 0; '\0' != constants[i].name[0]; ++i)
newCONSTSUB (stash, constants[i].name, newSViv (constants[i].value));
/* export global variables
* accessing any such variable (this is basically the same as using
* tie() in Perl) */
/* global strings */
- for (i = 0; '\0' != g_strings[i].name[0]; ++i) {
+ for (int i = 0; '\0' != g_strings[i].name[0]; ++i) {
tmp = get_sv (g_strings[i].name, 1);
sv_magicext (tmp, NULL, PERL_MAGIC_ext, &g_pv_vtbl,
g_strings[i].var, 0);
log_info ("Initializing Perl interpreter...");
#if COLLECT_DEBUG
{
- int i = 0;
-
- for (i = 0; i < argc; ++i)
+ for (int i = 0; i < argc; ++i)
log_debug ("argv[%i] = \"%s\"", i, argv[i]);
}
#endif /* COLLECT_DEBUG */
static int perl_config (oconfig_item_t *ci)
{
int status = 0;
- int i = 0;
dTHXa (NULL);
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
int current_status = 0;
diff --git a/src/pf.c b/src/pf.c
index c9aeb5ff22f3be3b48c295e16f242f530a112858..d7a5a15cff11b4cd3d2baf07297161fcc56867f3 100644 (file)
--- a/src/pf.c
+++ b/src/pf.c
*/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
struct pf_status state;
int fd;
int status;
- int i;
fd = open (pf_device, O_RDONLY);
if (fd < 0)
return (-1);
}
- for (i = 0; i < PFRES_MAX; i++)
+ for (int i = 0; i < PFRES_MAX; i++)
pf_submit ("pf_counters", pf_reasons[i], state.counters[i],
/* is gauge = */ 0);
- for (i = 0; i < LCNT_MAX; i++)
+ for (int i = 0; i < LCNT_MAX; i++)
pf_submit ("pf_limits", pf_lcounters[i], state.lcounters[i],
/* is gauge = */ 0);
- for (i = 0; i < FCNT_MAX; i++)
+ for (int i = 0; i < FCNT_MAX; i++)
pf_submit ("pf_state", pf_fcounters[i], state.fcounters[i],
/* is gauge = */ 0);
- for (i = 0; i < SCNT_MAX; i++)
+ for (int i = 0; i < SCNT_MAX; i++)
pf_submit ("pf_source", pf_scounters[i], state.scounters[i],
/* is gauge = */ 0);
diff --git a/src/pinba.c b/src/pinba.c
index 833fa1b8cdd4cc997363af376652748fe2dc49d1..b9eed68ebb16341a3b3a5149e5cb3cf0da10945a 100644 (file)
--- a/src/pinba.c
+++ b/src/pinba.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static void service_process_request (Pinba__Request *request) /* {{{ */
{
- unsigned int i;
-
pthread_mutex_lock (&stat_nodes_lock);
- for (i = 0; i < stat_nodes_num; i++)
+ for (unsigned int i = 0; i < stat_nodes_num; i++)
{
if ((stat_nodes[i].host != NULL)
&& (strcmp (request->hostname, stat_nodes[i].host) != 0))
{
pinba_socket_t *s;
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
- struct addrinfo ai_hints = { 0 };
int status;
- ai_hints.ai_flags = AI_PASSIVE;
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
- ai_hints.ai_addr = NULL;
- ai_hints.ai_canonname = NULL;
- ai_hints.ai_next = NULL;
-
if (node == NULL)
node = PINBA_DEFAULT_NODE;
if (service == NULL)
service = PINBA_DEFAULT_SERVICE;
- ai_list = NULL;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_PASSIVE,
+ .ai_socktype = SOCK_DGRAM
+ };
+
status = getaddrinfo (node, service,
&ai_hints, &ai_list);
if (status != 0)
return (NULL);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
status = pb_add_socket (s, ai_ptr);
if (status != 0)
static void pinba_socket_free (pinba_socket_t *socket) /* {{{ */
{
- nfds_t i;
-
if (!socket)
return;
- for (i = 0; i < socket->fd_num; i++)
+ for (nfds_t i = 0; i < socket->fd_num; i++)
{
if (socket->fd[i].fd < 0)
continue;
while (!collector_thread_do_shutdown)
{
int status;
- nfds_t i;
if (s->fd_num < 1)
break;
return (-1);
}
- for (i = 0; i < s->fd_num; i++)
+ for (nfds_t i = 0; i < s->fd_num; i++)
{
if (s->fd[i].revents & (POLLERR | POLLHUP | POLLNVAL))
{
char *server = NULL;
char *script = NULL;
int status;
- int i;
status = cf_util_get_string (ci, &name);
if (status != 0)
return (status);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
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);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/pinba.proto b/src/pinba.proto
index 5fd5439a11a0d501a5a127041c36710325a1d72e..22e61c6a4f06dd185bcc6ac792cd773e09b4fa04 100644 (file)
--- a/src/pinba.proto
+++ b/src/pinba.proto
+syntax = "proto2";
+
package Pinba;
option optimize_for = SPEED;
diff --git a/src/ping.c b/src/ping.c
index e16ba07706b24a0eddee4c4a13a0d51d30bb6ef4..52db2c718f593db6d9b9e512266856df5eb7c047 100644 (file)
--- a/src/ping.c
+++ b/src/ping.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
# include <netdb.h> /* NI_MAXHOST */
#endif
+#ifdef HAVE_SYS_CAPABILITY_H
+# include <sys/capability.h>
+#endif
+
#include <oping.h>
#ifndef NI_MAXHOST
static int ping_dispatch_all (pingobj_t *pingobj) /* {{{ */
{
- pingobj_iter_t *iter;
hostlist_t *hl;
int status;
- for (iter = ping_iterator_get (pingobj);
+ for (pingobj_iter_t *iter = ping_iterator_get (pingobj);
iter != NULL;
iter = ping_iterator_next (iter))
{ /* {{{ */
struct timespec ts_wait;
struct timespec ts_int;
- hostlist_t *hl;
int count;
c_complain_t complaint = C_COMPLAIN_INIT_STATIC;
/* Add all the hosts to the ping object. */
count = 0;
- for (hl = hostlist_head; hl != NULL; hl = hl->next)
+ for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next)
{
int tmp_status;
tmp_status = ping_host_add (pingobj, hl->host);
if (ping_thread_loop != 0)
{
pthread_mutex_unlock (&ping_lock);
- return (-1);
+ return (0);
}
ping_thread_loop = 1;
"Will use a timeout of %gs.", ping_timeout);
}
- if (start_thread () != 0)
- return (-1);
+#if defined(HAVE_SYS_CAPABILITY_H) && defined(CAP_NET_RAW)
+ if (check_capability (CAP_NET_RAW) != 0)
+ {
+ if (getuid () == 0)
+ WARNING ("ping plugin: Running collectd as root, but the CAP_NET_RAW "
+ "capability is missing. The plugin's read function will probably "
+ "fail. Is your init system dropping capabilities?");
+ else
+ WARNING ("ping plugin: collectd doesn't have the CAP_NET_RAW capability. "
+ "If you don't want to run collectd as root, try running \"setcap "
+ "cap_net_raw=ep\" on the collectd binary.");
+ }
+#endif
- return (0);
+ return (start_thread ());
} /* }}} int ping_init */
static int config_set_string (const char *name, /* {{{ */
/* Max IP packet size - (IPv6 + ICMP) = 65535 - (40 + 8) = 65487 */
if (size <= 65487)
{
- size_t i;
-
sfree (ping_data);
ping_data = malloc (size + 1);
if (ping_data == NULL)
* Optimally we would follow the ping(1) behaviour, but we
* cannot use byte 00 or start data payload at exactly same
* location, due to oping library limitations. */
- for (i = 0; i < size; i++) /* {{{ */
+ for (size_t i = 0; i < size; i++) /* {{{ */
{
/* This restricts data pattern to be only composed of easily
* printable characters, and not NUL character. */
static int ping_read (void) /* {{{ */
{
- hostlist_t *hl;
-
if (ping_thread_error != 0)
{
ERROR ("ping plugin: The ping thread had a problem. Restarting it.");
stop_thread ();
- for (hl = hostlist_head; hl != NULL; hl = hl->next)
+ for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next)
{
hl->pkg_sent = 0;
hl->pkg_recv = 0;
return (-1);
} /* if (ping_thread_error != 0) */
- for (hl = hostlist_head; hl != NULL; hl = hl->next) /* {{{ */
+ for (hostlist_t *hl = hostlist_head; hl != NULL; hl = hl->next) /* {{{ */
{
uint32_t pkg_sent;
uint32_t pkg_recv;
diff --git a/src/postgresql.c b/src/postgresql.c
index 65766a9f107a2ab3ec67e5ee9571bd88f1ed4df4..7e69877c43e132ab776205574a97f2503a043099 100644 (file)
--- a/src/postgresql.c
+++ b/src/postgresql.c
*/
#include "collectd.h"
+
#include "common.h"
#include "configfile.h"
static void c_psql_database_delete (void *data)
{
- size_t i;
-
c_psql_database_t *db = data;
--db->ref_cnt;
db->conn = NULL;
if (db->q_prep_areas)
- for (i = 0; i < db->queries_num; ++i)
+ for (size_t i = 0; i < db->queries_num; ++i)
udb_query_delete_preparation_area (db->q_prep_areas[i]);
free (db->q_prep_areas);
{
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));
assert (db->max_params_num >= data->params_num);
- for (i = 0; i < data->params_num; ++i) {
+ for (int i = 0; i < data->params_num; ++i) {
switch (data->params[i]) {
case C_PSQL_PARAM_HOST:
params[i] = C_PSQL_IS_UNIX_DOMAIN_SOCKET (db->host)
int rows_num;
int status;
- int row, col;
/* The user data may hold parameter information, but may be NULL. */
data = udb_query_get_user_data (q);
BAIL_OUT (-1);
}
- for (col = 0; col < column_num; ++col) {
+ for (int col = 0; col < column_num; ++col) {
/* Pointers returned by `PQfname' are freed by `PQclear' via
* `BAIL_OUT'. */
column_names[col] = PQfname (res, col);
BAIL_OUT (-1);
}
- for (row = 0; row < rows_num; ++row) {
+ for (int row = 0; row < rows_num; ++row) {
+ int col;
for (col = 0; col < column_num; ++col) {
/* Pointers returned by `PQgetvalue' are freed by `PQclear' via
* `BAIL_OUT'. */
c_psql_database_t *db;
int success = 0;
- size_t i;
if ((ud == NULL) || (ud->data == NULL)) {
log_err ("c_psql_read: Invalid user data.");
return -1;
}
- for (i = 0; i < db->queries_num; ++i)
+ for (size_t i = 0; i < db->queries_num; ++i)
{
udb_query_preparation_area_t *prep_area;
udb_query_t *q;
{
char *str_ptr;
size_t str_len;
- size_t i;
str_ptr = string;
str_len = string_len;
- for (i = 0; i < ds->ds_num; ++i) {
+ for (size_t i = 0; i < ds->ds_num; ++i) {
int status = ssnprintf (str_ptr, str_len, ",'%s'", ds->ds[i].name);
if (status < 1)
{
char *str_ptr;
size_t str_len;
- size_t i;
str_ptr = string;
str_len = string_len;
- for (i = 0; i < ds->ds_num; ++i) {
+ for (size_t i = 0; i < ds->ds_num; ++i) {
int status;
if (store_rates)
@@ -745,12 +740,11 @@ static char *values_to_sqlarray (const data_set_t *ds, const value_list_t *vl,
size_t str_len;
gauge_t *rates = NULL;
- size_t i;
str_ptr = string;
str_len = string_len;
- for (i = 0; i < vl->values_len; ++i) {
+ for (size_t i = 0; i < vl->values_len; ++i) {
int status = 0;
if ((ds->ds[i].type != DS_TYPE_GAUGE)
const char *params[9];
int success = 0;
- size_t i;
if ((ud == NULL) || (ud->data == NULL)) {
log_err ("c_psql_write: Invalid user data.");
&& (db->next_commit == 0))
c_psql_begin (db);
- for (i = 0; i < db->writers_num; ++i) {
+ for (size_t i = 0; i < db->writers_num; ++i) {
c_psql_writer_t *writer;
PGresult *res;
{
c_psql_database_t **dbs = databases;
size_t dbs_num = databases_num;
- size_t i;
if ((ud != NULL) && (ud->data != NULL)) {
dbs = (void *)&ud->data;
dbs_num = 1;
}
- for (i = 0; i < dbs_num; ++i) {
+ for (size_t i = 0; i < dbs_num; ++i) {
c_psql_database_t *db = dbs[i];
/* don't commit if the timeout is larger than the regular commit
static int c_psql_shutdown (void)
{
- size_t i = 0;
-
_Bool had_flush = 0;
plugin_unregister_read_group ("postgresql");
- for (i = 0; i < databases_num; ++i) {
+ for (size_t i = 0; i < databases_num; ++i) {
c_psql_database_t *db = databases[i];
if (db->writers_num > 0) {
c_psql_writer_t *tmp;
int status = 0;
- int i;
if ((ci->values_num != 1)
|| (ci->values[0].type != OCONFIG_TYPE_STRING)) {
writer->statement = NULL;
writer->store_rates = 1;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (strcasecmp ("Statement", c->key) == 0)
static _Bool have_flush = 0;
- int i;
-
if ((1 != ci->values_num)
|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
log_err ("<Database> expects a single string argument.");
if (db == NULL)
return -1;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Host"))
/* If no `Query' options were given, add the default queries.. */
if ((db->queries_num == 0) && (db->writers_num == 0)){
- for (i = 0; i < def_queries_num; i++)
+ for (int i = 0; i < def_queries_num; i++)
udb_query_pick_from_list_by_name (def_queries[i],
queries, queries_num,
&db->queries, &db->queries_num);
}
}
- for (i = 0; (size_t)i < db->queries_num; ++i) {
+ for (int i = 0; (size_t)i < db->queries_num; ++i) {
c_psql_user_data_t *data;
data = udb_query_get_user_data (db->queries[i]);
if ((data != NULL) && (data->params_num > db->max_params_num))
{
static int have_def_config = 0;
- int i;
-
if (0 == have_def_config) {
oconfig_item_t *c;
"any queries - please check your installation.");
}
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Query"))
diff --git a/src/powerdns.c b/src/powerdns.c
index 55f13fef09fbac6f0a30297bcb4d90f72da9c9c2..e215a8c3e1bb462b7e6fe169e037e1e0d6161ecb 100644 (file)
--- a/src/powerdns.c
+++ b/src/powerdns.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
saveptr = NULL;
while ((key = strtok_r (dummy, ",", &saveptr)) != NULL)
{
- int i;
-
dummy = NULL;
value = strchr (key, '=');
continue;
/* Check if this item was requested. */
+ int i;
for (i = 0; i < fields_num; i++)
if (strcasecmp (key, fields[i]) == 0)
break;
static int powerdns_config_add_collect (list_item_t *li, /* {{{ */
oconfig_item_t *ci)
{
- int i;
char **temp;
if (ci->values_num < 1)
return (-1);
}
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
WARNING ("powerdns plugin: Only string arguments are allowed to "
}
li->fields = temp;
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
li->fields[li->fields_num] = strdup (ci->values[i].value.string);
if (li->fields[li->fields_num] == NULL)
list_item_t *item;
int status;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
}
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
static int powerdns_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
DEBUG ("powerdns plugin: powerdns_config (ci = %p);", (void *) ci);
if (list == NULL)
}
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
static int powerdns_read (void)
{
- llentry_t *e;
-
- for (e = llist_head (list); e != NULL; e = e->next)
+ for (llentry_t *e = llist_head (list); e != NULL; e = e->next)
{
list_item_t *item = e->value;
item->func (item);
static int powerdns_shutdown (void)
{
- llentry_t *e;
-
if (list == NULL)
return (0);
- for (e = llist_head (list); e != NULL; e = e->next)
+ for (llentry_t *e = llist_head (list); e != NULL; e = e->next)
{
list_item_t *item = (list_item_t *) e->value;
e->value = NULL;
diff --git a/src/processes.c b/src/processes.c
index f029a6c2bff53ef621cbb053c058b3a4bedd157f..d34fe40f3f4db5f45860e15bf20f522695503dad 100644 (file)
--- a/src/processes.c
+++ b/src/processes.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
/* add process entry to 'instances' of process 'name' (or refresh it) */
static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t *entry)
{
- procstat_t *ps;
procstat_entry_t *pse;
if (entry->id == 0)
return;
- for (ps = list_head_g; ps != NULL; ps = ps->next)
+ for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next)
{
_Bool want_init;
@@ -482,11 +482,10 @@ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t
/* remove old entries from instances of processes in list_head_g */
static void ps_list_reset (void)
{
- procstat_t *ps;
procstat_entry_t *pse;
procstat_entry_t *pse_prev;
- for (ps = list_head_g; ps != NULL; ps = ps->next)
+ for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next)
{
ps->num_proc = 0;
ps->num_lwp = 0;
/* put all pre-defined 'Process' names from config to list_head_g tree */
static int ps_config (oconfig_item_t *ci)
{
- int i;
-
#if KERNEL_LINUX
const size_t max_procname_len = 15;
#elif KERNEL_SOLARIS || KERNEL_FREEBSD
const size_t max_procname_len = MAXCOMLEN -1;
#endif
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (strcasecmp (c->key, "Process") == 0)
static int read_fork_rate (void)
{
extern kstat_ctl_t *kc;
- kstat_t *ksp_chain = NULL;
derive_t result = 0;
if (kc == NULL)
return (-1);
- for (ksp_chain = kc->kc_chain;
+ for (kstat_t *ksp_chain = kc->kc_chain;
ksp_chain != NULL;
ksp_chain = ksp_chain->ks_next)
{
#if HAVE_THREAD_INFO
kern_return_t status;
- int pset;
processor_set_t port_pset_priv;
- int task;
task_array_t task_list;
mach_msg_type_number_t task_list_len;
int task_pid;
char task_name[MAXCOMLEN + 1];
- int thread;
thread_act_array_t thread_list;
mach_msg_type_number_t thread_list_len;
thread_basic_info_data_t thread_data;
* Tasks are assigned to sets of processors, so that's where you go to
* get a list.
*/
- for (pset = 0; pset < pset_list_len; pset++)
+ for (int pset = 0; pset < pset_list_len; pset++)
{
if ((status = host_processor_set_priv (port_host_self,
pset_list[pset],
continue;
}
- for (task = 0; task < task_list_len; task++)
+ for (int task = 0; task < task_list_len; task++)
{
ps = NULL;
if (mach_get_task_name (task_list[task],
continue; /* with next task_list */
}
- for (thread = 0; thread < thread_list_len; thread++)
+ for (int thread = 0; thread < thread_list_len; thread++)
{
thread_data_len = THREAD_BASIC_INFO_COUNT;
status = thread_info (thread_list[thread],
procstat_entry_t pse;
char state;
- procstat_t *ps_ptr;
-
running = sleeping = zombies = stopped = paging = blocked = 0;
ps_list_reset ();
ps_submit_state ("paging", paging);
ps_submit_state ("blocked", blocked);
- for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
+ for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
ps_submit_proc_list (ps_ptr);
read_fork_rate();
struct kinfo_proc *procs; /* array of processes */
struct kinfo_proc *proc_ptr = NULL;
int count; /* returns number of processes */
- int i;
- procstat_t *ps_ptr;
procstat_entry_t pse;
ps_list_reset ();
}
/* Iterate through the processes in kinfo_proc */
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
/* Create only one process list entry per _process_, i.e.
* filter out threads (duplicate PID entries). */
ps_submit_state ("idle", idle);
ps_submit_state ("wait", wait);
- for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
+ for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
ps_submit_proc_list (ps_ptr);
/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_FREEBSD */
struct kinfo_proc *procs; /* array of processes */
struct kinfo_proc *proc_ptr = NULL;
int count; /* returns number of processes */
- int i;
- procstat_t *ps_ptr;
procstat_entry_t pse;
ps_list_reset ();
}
/* Iterate through the processes in kinfo_proc */
- for (i = 0; i < count; i++)
+ for (int i = 0; i < count; i++)
{
/* Create only one process list entry per _process_, i.e.
* filter out threads (duplicate PID entries). */
ps_submit_state ("idle", idle);
ps_submit_state ("dead", dead);
- for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
+ for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
ps_submit_proc_list (ps_ptr);
/* #endif HAVE_LIBKVM_GETPROCS && HAVE_STRUCT_KINFO_PROC_OPENBSD */
pid_t pindex = 0;
int nprocs;
- procstat_t *ps;
procstat_entry_t pse;
ps_list_reset ();
/* fdsinfo = */ NULL, sizeof(struct fdsinfo64),
&pindex, MAXPROCENTRY)) > 0)
{
- int i;
-
- for (i = 0; i < nprocs; i++)
+ for (int i = 0; i < nprocs; i++)
{
tid64_t thindex;
int nthreads;
ps_submit_state ("paging", paging);
ps_submit_state ("blocked", blocked);
- for (ps = list_head_g; ps != NULL; ps = ps->next)
+ for (procstat_t *ps = list_head_g; ps != NULL; ps = ps->next)
ps_submit_proc_list (ps);
/* #endif HAVE_PROCINFO_H */
DIR *proc;
int status;
- procstat_t *ps_ptr;
char state;
char cmdline[PRARGSZ];
ps_submit_state ("system", system);
ps_submit_state ("orphan", orphan);
- for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
+ for (procstat_t *ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
ps_submit_proc_list (ps_ptr);
read_fork_rate();
diff --git a/src/protocols.c b/src/protocols.c
index 4d2b2eadf0e69bc17991af0956f18250850b7ee5..208da8b20f41b9c89e6342c4d7bac71bc81dcfb5 100644 (file)
--- a/src/protocols.c
+++ b/src/protocols.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
diff --git a/src/pyconfig.c b/src/pyconfig.c
index 32b31cc548db947de28f7022666dcb20268c230e..83748b4fa45f9cee15e4dffd7f7b2ded66d0f729 100644 (file)
--- a/src/pyconfig.c
+++ b/src/pyconfig.c
#include <structmember.h>
#include "collectd.h"
+
#include "common.h"
#include "cpython.h"
diff --git a/src/python.c b/src/python.c
index 3a282918c6eafe6ae32b3de7109fff388edf1075..24046de4568723b979889d3f558d6cfe1325c959 100644 (file)
--- a/src/python.c
+++ b/src/python.c
#include <signal.h>
#include "collectd.h"
+
#include "common.h"
#include "cpython.h"
@@ -218,7 +219,9 @@ static char reg_shutdown_doc[] = "register_shutdown(callback[, data][, name]) ->
" data if it was supplied.";
-static int do_interactive = 0;
+static pthread_t main_thread;
+static PyOS_sighandler_t python_sigint_handler;
+static _Bool do_interactive = 0;
/* This is our global thread state. Python saves some stuff in thread-local
* storage. So if we allow the interpreter to run in the background
@@ -270,7 +273,7 @@ static void cpy_build_name(char *buf, size_t size, PyObject *callback, const cha
}
void cpy_log_exception(const char *context) {
- int l = 0, i;
+ int l = 0;
const char *typename = NULL, *message = NULL;
PyObject *type, *value, *traceback, *tn, *m, *list;
if (list)
l = PyObject_Length(list);
- for (i = 0; i < l; ++i) {
+ for (int i = 0; i < l; ++i) {
PyObject *line;
char const *msg;
char *cpy;
}
static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_list, user_data_t *data) {
- size_t i;
cpy_callback_t *c = data->data;
PyObject *ret, *list, *temp, *dict = NULL;
Values *v;
@@ -363,7 +365,7 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li
cpy_log_exception("write callback");
CPY_RETURN_FROM_THREADS 0;
}
- for (i = 0; i < value_list->values_len; ++i) {
+ for (size_t i = 0; i < value_list->values_len; ++i) {
if (ds->ds[i].type == DS_TYPE_COUNTER) {
PyList_SetItem(list, i, PyLong_FromUnsignedLongLong(value_list->values[i].counter));
} else if (ds->ds[i].type == DS_TYPE_GAUGE) {
@@ -392,7 +394,7 @@ static int cpy_write_callback(const data_set_t *ds, const value_list_t *value_li
meta_data_t *meta = value_list->meta;
num = meta_data_toc(meta, &table);
- for (i = 0; i < num; ++i) {
+ for (size_t i = 0; i < num; ++i) {
int type;
char *string;
int64_t si;
}
static PyObject *cpy_get_dataset(PyObject *self, PyObject *args) {
- size_t i;
char *name;
const data_set_t *ds;
PyObject *list, *tuple;
return NULL;
}
list = PyList_New(ds->ds_num); /* New reference. */
- for (i = 0; i < ds->ds_num; ++i) {
+ for (size_t i = 0; i < ds->ds_num; ++i) {
tuple = PyTuple_New(4);
PyTuple_SET_ITEM(tuple, 0, cpy_string_to_unicode_or_bytes(ds->ds[i].name));
PyTuple_SET_ITEM(tuple, 1, cpy_string_to_unicode_or_bytes(DS_TYPE_TO_STRING(ds->ds[i].type)));
};
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);
- for (c = cpy_shutdown_callbacks; c; c = c->next) {
+ for (cpy_callback_t *c = cpy_shutdown_callbacks; c; c = c->next) {
ret = PyObject_CallFunctionObjArgs(c->callback, c->data, (void *) 0); /* New reference. */
if (ret == NULL)
cpy_log_exception("shutdown callback");
return 0;
}
-static void cpy_int_handler(int sig) {
- return;
-}
-
static void *cpy_interactive(void *data) {
- sigset_t sigset;
- struct sigaction old;
+ PyOS_sighandler_t cur_sig;
/* Signal handler in a plugin? Bad stuff, but the best way to
* handle it I guess. In an interactive session people will
* 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.
- * 3. Unblock SIGINT in the interactive thread.
+ * 1. Restore Python's own signal handler
+ * 2. Tell Python we just forked so it will accept this thread
+ * as the main one. No version of Python will ever handle
+ * interrupts anywhere but in the main thread.
+ * 3. After the interactive loop is done, restore collectd's
+ * SIGINT handler.
+ * 4. Raise SIGINT for a clean shutdown. The signal is sent to
+ * the main thread to ensure it wakes up the main interval
+ * sleep so that collectd shuts down immediately not in 10
+ * seconds.
*
* This will make sure that SIGINT won't kill collectd but
- * still interrupt syscalls like sleep and pause.
- * It does not raise a KeyboardInterrupt exception because so
- * far nobody managed to figure out how to do that. */
- struct sigaction 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);
+ * still interrupt syscalls like sleep and pause. */
+
PyEval_AcquireThread(state);
if (PyImport_ImportModule("readline") == NULL) {
/* This interactive session will suck. */
cpy_log_exception("interactive session init");
- }
+ }
+ cur_sig = PyOS_setsig(SIGINT, python_sigint_handler);
+ /* We totally forked just now. Everyone saw that, right? */
+ PyOS_AfterFork();
PyRun_InteractiveLoop(stdin, "<stdin>");
+ PyOS_setsig(SIGINT, cur_sig);
PyErr_Print();
PyEval_ReleaseThread(state);
NOTICE("python: Interactive interpreter exited, stopping collectd ...");
- /* Restore the original collectd SIGINT handler and raise SIGINT.
- * The main thread still has SIGINT blocked and there's nothing we
- * can do about that so this thread will handle it. But that's not
- * important, except that it won't interrupt the main loop and so
- * it might take a few seconds before collectd really shuts down. */
- sigaction (SIGINT, &old, NULL);
- raise(SIGINT);
- pause();
+ pthread_kill(main_thread, SIGINT);
return NULL;
}
static int cpy_init(void) {
- cpy_callback_t *c;
PyObject *ret;
static pthread_t thread;
- sigset_t sigset;
if (!Py_IsInitialized()) {
WARNING("python: Plugin loaded but not configured.");
}
PyEval_InitThreads();
/* Now it's finally OK to use python threads. */
- for (c = cpy_init_callbacks; c; c = c->next) {
+ for (cpy_callback_t *c = cpy_init_callbacks; c; c = c->next) {
ret = PyObject_CallFunctionObjArgs(c->callback, c->data, (void *) 0); /* New reference. */
if (ret == NULL)
cpy_log_exception("init callback");
else
Py_DECREF(ret);
}
- sigemptyset(&sigset);
- sigaddset(&sigset, SIGINT);
- pthread_sigmask(SIG_BLOCK, &sigset, NULL);
state = PyEval_SaveThread();
+ main_thread = pthread_self();
if (do_interactive) {
if (plugin_thread_create(&thread, NULL, cpy_interactive, NULL)) {
ERROR("python: Error creating thread for interactive interpreter.");
}
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) {
+ for (int i = 0; i < ci->values_num; ++i) {
if (ci->values[i].type == OCONFIG_TYPE_STRING) {
PyTuple_SET_ITEM(values, i, cpy_string_to_unicode_or_bytes(ci->values[i].value.string));
} else if (ci->values[i].type == OCONFIG_TYPE_NUMBER) {
@@ -1020,7 +1005,7 @@ static PyObject *cpy_oconfig_to_pyconfig(oconfig_item_t *ci, PyObject *parent) {
if (item == NULL)
return NULL;
children = PyTuple_New(ci->children_num); /* New reference. */
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
PyTuple_SET_ITEM(children, i, cpy_oconfig_to_pyconfig(ci->children + i, item));
}
tmp = ((Config *) item)->children;
#endif
static int cpy_init_python(void) {
+ PyOS_sighandler_t cur_sig;
PyObject *sys;
PyObject *module;
char *argv = "";
#endif
+ /* Chances are the current signal handler is already SIG_DFL, but let's make sure. */
+ cur_sig = PyOS_setsig(SIGINT, SIG_DFL);
Py_Initialize();
+ python_sigint_handler = PyOS_setsig(SIGINT, cur_sig);
PyType_Ready(&ConfigType);
PyType_Ready(&PluginDataType);
}
static int cpy_config(oconfig_item_t *ci) {
- int i;
PyObject *tb;
+ int status = 0;
/* Ok in theory we shouldn't do initialization at this point
* but we have to. In order to give python scripts a chance
if (!Py_IsInitialized() && cpy_init_python()) return 1;
- for (i = 0; i < ci->children_num; ++i) {
+ for (int 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)
+ if (cf_util_get_boolean(item, &do_interactive) != 0) {
+ status = 1;
continue;
- do_interactive = item->values[0].value.boolean;
+ }
} else if (strcasecmp(item->key, "Encoding") == 0) {
- if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_STRING)
+ char *encoding = NULL;
+ if (cf_util_get_string(item, &encoding) != 0) {
+ status = 1;
continue;
+ }
#ifdef IS_PY3K
- NOTICE("python: \"Encoding\" was used in the config file but Python3 was used, which does not support changing encodings. Ignoring this.");
+ ERROR("python: \"Encoding\" was used in the config file but Python3 was used, which does not support changing encodings");
+ status = 1;
+ sfree(encoding);
+ continue;
#else
/* Why is this even necessary? And undocumented? */
- if (PyUnicode_SetDefaultEncoding(item->values[0].value.string))
+ if (PyUnicode_SetDefaultEncoding(encoding)) {
cpy_log_exception("setting default encoding");
+ status = 1;
+ }
#endif
+ sfree(encoding);
} else if (strcasecmp(item->key, "LogTraces") == 0) {
- if (item->values_num != 1 || item->values[0].type != OCONFIG_TYPE_BOOLEAN)
+ _Bool log_traces;
+ if (cf_util_get_boolean(item, &log_traces) != 0) {
+ status = 1;
continue;
- if (!item->values[0].value.boolean) {
+ }
+ if (!log_traces) {
Py_XDECREF(cpy_format_exception);
cpy_format_exception = NULL;
continue;
tb = PyImport_ImportModule("traceback"); /* New reference. */
if (tb == NULL) {
cpy_log_exception("python initialization");
+ status = 1;
continue;
}
cpy_format_exception = PyObject_GetAttrString(tb, "format_exception"); /* New reference. */
Py_DECREF(tb);
- if (cpy_format_exception == NULL)
+ if (cpy_format_exception == NULL) {
cpy_log_exception("python initialization");
+ status = 1;
+ }
} 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) {
+ status = 1;
continue;
+ }
dir_object = cpy_string_to_unicode_or_bytes(dir); /* New reference. */
if (dir_object == NULL) {
ERROR("python plugin: Unable to convert \"%s\" to "
"a python object.", dir);
free(dir);
cpy_log_exception("python initialization");
+ status = 1;
continue;
}
if (PyList_Insert(sys_path, 0, dir_object) != 0) {
ERROR("python plugin: Unable to prepend \"%s\" to "
"python module path.", dir);
cpy_log_exception("python initialization");
+ status = 1;
}
Py_DECREF(dir_object);
free(dir);
char *module_name = NULL;
PyObject *module;
- if (cf_util_get_string(item, &module_name) != 0)
+ if (cf_util_get_string(item, &module_name) != 0) {
+ status = 1;
continue;
+ }
module = PyImport_ImportModule(module_name); /* New reference. */
if (module == NULL) {
ERROR("python plugin: Error importing module \"%s\".", module_name);
cpy_log_exception("importing module");
+ status = 1;
}
free(module_name);
Py_XDECREF(module);
cpy_callback_t *c;
PyObject *ret;
- if (cf_util_get_string(item, &name) != 0)
+ if (cf_util_get_string(item, &name) != 0) {
+ status = 1;
continue;
+ }
for (c = cpy_config_callbacks; c; c = c->next) {
if (strcasecmp(c->name + 7, name) == 0)
break;
else
ret = PyObject_CallFunction(c->callback, "NO",
cpy_oconfig_to_pyconfig(item, NULL), c->data); /* New reference. */
- if (ret == NULL)
+ if (ret == NULL) {
cpy_log_exception("loading module");
- else
+ status = 1;
+ } else
Py_DECREF(ret);
} else {
- WARNING("python plugin: Ignoring unknown config key \"%s\".", item->key);
+ ERROR("python plugin: Unknown config key \"%s\".", item->key);
+ status = 1;
}
}
- return 0;
+ return (status);
}
void module_register(void) {
diff --git a/src/pyvalues.c b/src/pyvalues.c
index 0ba04360687a5906d32e1a51276137dce655b78d..a7cb792357fcef570fe4f6d04902d26b4f17204e 100644 (file)
--- a/src/pyvalues.c
+++ b/src/pyvalues.c
#include <structmember.h>
#include "collectd.h"
+
#include "common.h"
#include "cpython.h"
}
static meta_data_t *cpy_build_meta(PyObject *meta) {
- int i, s;
+ int s;
meta_data_t *m = NULL;
PyObject *l;
}
m = meta_data_create();
- for (i = 0; i < s; ++i) {
+ for (int i = 0; i < s; ++i) {
const char *string, *keystring;
PyObject *key, *value, *item, *tmp;
static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
int ret;
const data_set_t *ds;
- size_t size, i;
+ size_t size;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values, *meta = self->meta;
@@ -548,22 +549,25 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
return NULL;
}
value = calloc(size, sizeof(*value));
- for (i = 0; i < size; ++i) {
+ for (size_t i = 0; i < size; ++i) {
PyObject *item, *num;
item = PySequence_Fast_GET_ITEM(values, (int) i); /* Borrowed reference. */
- if (ds->ds->type == DS_TYPE_COUNTER) {
+ switch (ds->ds[i].type) {
+ case DS_TYPE_COUNTER:
num = PyNumber_Long(item); /* New reference. */
if (num != NULL) {
value[i].counter = PyLong_AsUnsignedLongLong(num);
Py_XDECREF(num);
}
- } else if (ds->ds->type == DS_TYPE_GAUGE) {
+ break;
+ case DS_TYPE_GAUGE:
num = PyNumber_Float(item); /* New reference. */
if (num != NULL) {
value[i].gauge = PyFloat_AsDouble(num);
Py_XDECREF(num);
}
- } else if (ds->ds->type == DS_TYPE_DERIVE) {
+ break;
+ case DS_TYPE_DERIVE:
/* This might overflow without raising an exception.
* Not much we can do about it */
num = PyNumber_Long(item); /* New reference. */
@@ -571,7 +575,8 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
value[i].derive = PyLong_AsLongLong(num);
Py_XDECREF(num);
}
- } else if (ds->ds->type == DS_TYPE_ABSOLUTE) {
+ break;
+ case DS_TYPE_ABSOLUTE:
/* This might overflow without raising an exception.
* Not much we can do about it */
num = PyNumber_Long(item); /* New reference. */
@@ -579,9 +584,10 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
value[i].absolute = PyLong_AsUnsignedLongLong(num);
Py_XDECREF(num);
}
- } else {
+ break;
+ default:
free(value);
- PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, value_list.type);
+ PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds[i].type, value_list.type);
return NULL;
}
if (PyErr_Occurred() != NULL) {
@@ -613,7 +619,7 @@ static PyObject *Values_dispatch(Values *self, PyObject *args, PyObject *kwds) {
static PyObject *Values_write(Values *self, PyObject *args, PyObject *kwds) {
int ret;
const data_set_t *ds;
- size_t size, i;
+ size_t size;
value_t *value;
value_list_t value_list = VALUE_LIST_INIT;
PyObject *values = self->values, *meta = self->meta;
return NULL;
}
value = calloc(size, sizeof(*value));
- for (i = 0; i < size; ++i) {
+ for (size_t i = 0; i < size; ++i) {
PyObject *item, *num;
item = PySequence_Fast_GET_ITEM(values, i); /* Borrowed reference. */
- if (ds->ds->type == DS_TYPE_COUNTER) {
+ switch (ds->ds[i].type) {
+ case DS_TYPE_COUNTER:
num = PyNumber_Long(item); /* New reference. */
if (num != NULL) {
value[i].counter = PyLong_AsUnsignedLongLong(num);
Py_XDECREF(num);
}
- } else if (ds->ds->type == DS_TYPE_GAUGE) {
+ break;
+ case DS_TYPE_GAUGE:
num = PyNumber_Float(item); /* New reference. */
if (num != NULL) {
value[i].gauge = PyFloat_AsDouble(num);
Py_XDECREF(num);
}
- } else if (ds->ds->type == DS_TYPE_DERIVE) {
+ break;
+ case DS_TYPE_DERIVE:
/* This might overflow without raising an exception.
* Not much we can do about it */
num = PyNumber_Long(item); /* New reference. */
value[i].derive = PyLong_AsLongLong(num);
Py_XDECREF(num);
}
- } else if (ds->ds->type == DS_TYPE_ABSOLUTE) {
+ break;
+ case DS_TYPE_ABSOLUTE:
/* This might overflow without raising an exception.
* Not much we can do about it */
num = PyNumber_Long(item); /* New reference. */
value[i].absolute = PyLong_AsUnsignedLongLong(num);
Py_XDECREF(num);
}
- } else {
+ break;
+ default:
free(value);
- PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds->type, value_list.type);
+ PyErr_Format(PyExc_RuntimeError, "unknown data type %d for %s", ds->ds[i].type, value_list.type);
return NULL;
}
if (PyErr_Occurred() != NULL) {
diff --git a/src/redis.c b/src/redis.c
index 47d0d707f5c8ca52b972c42e2e1bf416cd89e2e0..7395ba0685f61faef3c193775333e3039b83e5a5 100644 (file)
--- a/src/redis.c
+++ b/src/redis.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
redis_query_t *rq;
int status;
- int i;
rq = calloc(1, sizeof(*rq));
if (rq == NULL) {
(void)sstrncpy(rq->instance, rq->query, sizeof(rq->instance));
replace_special(rq->instance, sizeof(rq->instance));
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *option = ci->children + i;
if (strcasecmp("Type", option->key) == 0) {
static int redis_config_node (oconfig_item_t *ci) /* {{{ */
{
redis_query_t *rq;
- int i;
int status;
int timeout;
if (status != 0)
return (status);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
static int redis_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
@@ -379,10 +376,7 @@ static int redis_handle_query (redisContext *rh, redis_node_t *rn, redis_query_t
static int redis_read (void) /* {{{ */
{
- redis_node_t *rn;
- redis_query_t *rq;
-
- for (rn = nodes_head; rn != NULL; rn = rn->next)
+ for (redis_node_t *rn = nodes_head; rn != NULL; rn = rn->next)
{
redisContext *rh;
redisReply *rr;
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)
+ for (redis_query_t *rq = rn->queries; rq != NULL; rq = rq->next)
redis_handle_query(rh, rn, rq);
redis_fail:
diff --git a/src/routeros.c b/src/routeros.c
index 7ee302487f9dd841c9a35aeac86fef54eb9a597b..a270f484981dbde8a9e1ac2681a8205c445049ba 100644 (file)
--- a/src/routeros.c
+++ b/src/routeros.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
char read_name[128];
user_data_t user_data;
int status;
- int i;
router_data = calloc (1, sizeof (*router_data));
if (router_data == NULL)
router_data->password = NULL;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int cr_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/rrdcached.c b/src/rrdcached.c
index 3a6c98516a55772d3c51c543a2dcd1cb4aa10078..0425419445d738a6e80992c77c51b229112ca173 100644 (file)
--- a/src/rrdcached.c
+++ b/src/rrdcached.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "utils_rrdcreate.h"
{
int offset;
int status;
- size_t i;
time_t t;
assert (0 == strcmp (ds->type, vl->type));
return (-1);
offset = status;
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_COUNTER)
&& (ds->ds[i].type != DS_TYPE_GAUGE)
static int rc_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t const *child = ci->children + i;
const char *key = child->key;
{
int status;
rrdc_stats_t *head;
- rrdc_stats_t *ptr;
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
return (-1);
}
- for (ptr = head; ptr != NULL; ptr = ptr->next)
+ for (rrdc_stats_t *ptr = head; ptr != NULL; ptr = ptr->next)
{
if (ptr->type == RRDC_STATS_TYPE_GAUGE)
values[0].gauge = (gauge_t) ptr->value.gauge;
diff --git a/src/rrdtool.c b/src/rrdtool.c
index 348f28762c364d03b527cb9b04bfc71b54c69533..094dd42a7a6b8217a5fec858ec0683a535342be1 100644 (file)
--- a/src/rrdtool.c
+++ b/src/rrdtool.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "utils_avltree.h"
int offset;
int status;
time_t tt;
- size_t i;
memset (buffer, '\0', buffer_len);
return (-1);
offset = status;
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if ((ds->ds[i].type != DS_TYPE_COUNTER)
&& (ds->ds[i].type != DS_TYPE_GAUGE)
char **values;
int values_num;
int status;
- int i;
values = NULL;
values_num = 0;
pthread_mutex_unlock (&queue_lock);
/* We now need the cache lock so the entry isn't updated while
- * we make a copy of it's values */
+ * we make a copy of its values */
pthread_mutex_lock (&cache_lock);
status = c_avl_get (cache, queue_entry->filename,
values_num, (values_num == 1) ? "" : "s",
queue_entry->filename);
- for (i = 0; i < values_num; i++)
+ for (int i = 0; i < values_num; i++)
{
sfree (values[i]);
}
char *key;
c_avl_iterator_t *iter;
- int i;
DEBUG ("rrdtool plugin: Flushing cache, timeout = %.3f",
CDTIME_T_TO_DOUBLE (timeout));
} /* while (c_avl_iterator_next) */
c_avl_iterator_destroy (iter);
- for (i = 0; i < keys_num; i++)
+ for (int i = 0; i < keys_num; i++)
{
if (c_avl_remove (cache, keys[i], (void *) &key, (void *) &rc) != 0)
{
while (c_avl_pick (cache, &key, &value) == 0)
{
rrd_cache_t *rc;
- int i;
sfree (key);
key = NULL;
if (rc->values_num > 0)
non_empty++;
- for (i = 0; i < rc->values_num; i++)
+ for (int i = 0; i < rc->values_num; i++)
sfree (rc->values[i]);
sfree (rc->values);
sfree (rc);
diff --git a/src/sensors.c b/src/sensors.c
index 63a1c8ee01ae6f56bd10c081194b3f53b9680651..de2a4f7b9ede16efc6cf917fe0fd9f24ace63210 100644 (file)
--- a/src/sensors.c
+++ b/src/sensors.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int sensors_feature_name_to_type (const char *name)
{
- int i;
-
/* Yes, this is slow, but it's only ever done during initialization, so
* it's a one time cost.. */
- for (i = 0; i < known_features_num; i++)
+ for (int i = 0; i < known_features_num; i++)
if (strcasecmp (known_features[i].label, name) == 0)
return (known_features[i].type);
static void sensors_free_features (void)
{
- featurelist_t *thisft;
featurelist_t *nextft;
if (first_feature == NULL)
sensors_cleanup ();
- for (thisft = first_feature; thisft != NULL; thisft = nextft)
+ for (featurelist_t *thisft = first_feature; thisft != NULL; thisft = nextft)
{
nextft = thisft->next;
sfree (thisft);
static int sensors_read (void)
{
- featurelist_t *fl;
-
if (sensors_load_conf () != 0)
return (-1);
#if SENSORS_API_VERSION < 0x400
- for (fl = first_feature; fl != NULL; fl = fl->next)
+ for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next)
{
double value;
int status;
/* #endif SENSORS_API_VERSION < 0x400 */
#elif (SENSORS_API_VERSION >= 0x400) && (SENSORS_API_VERSION < 0x500)
- for (fl = first_feature; fl != NULL; fl = fl->next)
+ for (featurelist_t *fl = first_feature; fl != NULL; fl = fl->next)
{
double value;
int status;
diff --git a/src/serial.c b/src/serial.c
index 0878d3c93b1dac2b4d4bc331e4d13e56a358ede9..cf7ad2a1ed9961d4c5ae254bf02b3371a87561e2 100644 (file)
--- a/src/serial.c
+++ b/src/serial.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
char *fields[16];
int numfields;
- int i;
numfields = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
if (numfields < 6)
continue;
fields[0][len - 1] = 0;
- for (i = 1; i < numfields; i++)
+ for (int i = 1; i < numfields; i++)
{
len = strlen (fields[i]);
if (len < 4)
diff --git a/src/sigrok.c b/src/sigrok.c
index d8c65c08d39f6b3d8d25bd9794c3d2e57f506029..400645538d7d842f5d47f422f1347a2be5d7112d 100644 (file)
--- a/src/sigrok.c
+++ b/src/sigrok.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int sigrok_config_device(oconfig_item_t *ci)
{
struct config_device *cfdev;
- int i;
if (!(cfdev = calloc(1, sizeof(*cfdev)))) {
ERROR("sigrok plugin: calloc failed.");
}
cfdev->min_dispatch_interval = DEFAULT_MIN_DISPATCH_INTERVAL;
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *item = ci->children + i;
if (!strcasecmp(item->key, "driver"))
cf_util_get_string(item, &cfdev->driver);
static int sigrok_config(oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
oconfig_item_t *item = ci->children + i;
if (strcasecmp("LogLevel", item->key) == 0) {
int status;
{
const struct sr_datafeed_analog *analog;
struct config_device *cfdev;
- GSList *l;
value_t value;
value_list_t vl = VALUE_LIST_INIT;
/* Find this device's configuration. */
cfdev = NULL;
- for (l = config_devices; l; l = l->next) {
+ for (GSList *l = config_devices; l; l = l->next) {
cfdev = l->data;
if (cfdev->sdi == sdi) {
/* Found it. */
diff --git a/src/smart.c b/src/smart.c
index 33b9751c2c72cff88fcce6500c4c6794d9c31afe..752cb74cbe603baf47be59d482c0475983f063a6 100644 (file)
--- a/src/smart.c
+++ b/src/smart.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_ignorelist.h"
diff --git a/src/snmp.c b/src/snmp.c
index 084925586d1f7eb37936e5ad1db5cddf7865462c..e0e19732be3a687ac7e3fd301996d7b9d54b84fc 100644 (file)
--- a/src/snmp.c
+++ b/src/snmp.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_complain.h"
{
char oid_str[MAX_OID_LEN][16];
char *oid_str_ptr[MAX_OID_LEN];
- size_t i;
- for (i = 0; i < o->oid_len; i++)
+ for (size_t i = 0; i < o->oid_len; i++)
{
ssnprintf (oid_str[i], sizeof (oid_str[i]), "%lu", (unsigned long) o->oid[i]);
oid_str_ptr[i] = oid_str[i];
static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *ci)
{
- int i;
-
if (ci->values_num < 1)
{
WARNING ("snmp plugin: `Values' needs at least one argument.");
return (-1);
}
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
WARNING ("snmp plugin: `Values' needs only string argument.");
@@ -313,7 +311,7 @@ static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *
return (-1);
dd->values_len = (size_t) ci->values_num;
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
dd->values[i].oid_len = MAX_OID_LEN;
@@ -334,12 +332,10 @@ static int csnmp_config_add_data_values (data_definition_t *dd, oconfig_item_t *
static int csnmp_config_add_data_blacklist(data_definition_t *dd, oconfig_item_t *ci)
{
- int i;
-
if (ci->values_num < 1)
return (0);
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
@@ -351,7 +347,7 @@ static int csnmp_config_add_data_blacklist(data_definition_t *dd, oconfig_item_t
dd->ignores_len = 0;
dd->ignores = NULL;
- for (i = 0; i < ci->values_num; ++i)
+ for (int i = 0; i < ci->values_num; ++i)
{
if (strarray_add(&(dd->ignores), &(dd->ignores_len), ci->values[i].value.string) != 0)
{
{
data_definition_t *dd;
int status = 0;
- int i;
dd = calloc (1, sizeof (*dd));
if (dd == NULL)
dd->scale = 1.0;
dd->shift = 0.0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
data_definition_t *data;
data_definition_t **data_list;
int data_list_len;
- int i;
if (ci->values_num < 1)
{
return (-1);
}
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
WARNING ("snmp plugin: All arguments to `Collect' must be strings.");
return (-1);
host->data_list = data_list;
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
for (data = data_head; data != NULL; data = data->next)
if (strcasecmp (ci->values[i].value.string, data->name) == 0)
{
host_definition_t *hd;
int status = 0;
- int i;
/* Registration stuff. */
char cb_name[DATA_MAX_NAME_LEN];
hd->sess_handle = NULL;
hd->interval = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
status = 0;
static int csnmp_config (oconfig_item_t *ci)
{
- int i;
-
call_snmp_init_once ();
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("Data", child->key) == 0)
{
char *buffer_ptr;
size_t buffer_free;
- size_t i;
dst[0] = 0;
buffer_ptr = dst;
buffer_free = dst_size;
- for (i = 0; i < vb->val_len; i++)
+ for (size_t i = 0; i < vb->val_len; i++)
{
int status;
{
char *src;
size_t num_chars;
- size_t i;
if (vb->type == ASN_OCTET_STR)
src = (char *) vb->val.string;
if (num_chars > vb->val_len)
num_chars = vb->val_len;
- for (i = 0; i < num_chars; i++)
+ for (size_t i = 0; i < num_chars; i++)
{
/* Check for control characters. */
if ((unsigned char)src[i] < 32)
struct variable_list *vb;
oid_t vb_name;
int status;
- uint32_t i;
uint32_t is_matched;
/* Set vb on the last variable */
csnmp_strvbcopy (il->instance, vb, sizeof (il->instance));
is_matched = 0;
- for (i = 0; i < dd->ignores_len; i++)
+ for (uint32_t i = 0; i < dd->ignores_len; i++)
{
status = fnmatch(dd->ignores[i], il->instance, 0);
if (status == 0)
@@ -1372,8 +1360,12 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat
for (i = 0; i < data->values_len; i++)
vl.values[i] = value_table_ptr[i]->value;
- /* If we get here `vl.type_instance' and all `vl.values' have been set */
- plugin_dispatch_values (&vl);
+ /* If we get here `vl.type_instance' and all `vl.values' have been set
+ * vl.type_instance can be empty, i.e. a blank port description on a
+ * switch if you're using IF-MIB::ifDescr as Instance.
+ */
+ if (vl.type_instance[0] != '\0')
+ plugin_dispatch_values (&vl);
if (instance_list != NULL)
instance_list_ptr = instance_list_ptr->next;
diff --git a/src/statsd.c b/src/statsd.c
index 1eb8cb94c59df032f1615909a1341ec63cab432c..040181aab456b2697fcf702124a0da71eab5c331 100644 (file)
--- a/src/statsd.c
+++ b/src/statsd.c
*/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
struct pollfd *fds = NULL;
size_t fds_num = 0;
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai_list = NULL;
- struct addrinfo *ai_ptr;
+ struct addrinfo *ai_list;
int status;
char const *node = (conf_node != NULL) ? conf_node : STATSD_DEFAULT_NODE;
char const *service = (conf_service != NULL)
? conf_service : STATSD_DEFAULT_SERVICE;
- ai_hints.ai_flags = AI_PASSIVE;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_DGRAM;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_PASSIVE | AI_ADDRCONFIG,
+ .ai_socktype = SOCK_DGRAM
+ };
status = getaddrinfo (node, service, &ai_hints, &ai_list);
if (status != 0)
return (status);
}
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
int fd;
struct pollfd *tmp;
struct pollfd *fds = NULL;
size_t fds_num = 0;
int status;
- size_t i;
status = statsd_network_init (&fds, &fds_num);
if (status != 0)
break;
}
- for (i = 0; i < fds_num; i++)
+ for (size_t i = 0; i < fds_num; i++)
{
if ((fds[i].revents & (POLLIN | POLLPRI)) == 0)
continue;
} /* while (!network_thread_shutdown) */
/* Clean up */
- for (i = 0; i < fds_num; i++)
+ for (size_t i = 0; i < fds_num; i++)
close (fds[i].fd);
sfree (fds);
static int statsd_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
@@ -781,7 +776,6 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri
values[0].gauge = (gauge_t) metric->value;
else if (metric->type == STATSD_TIMER)
{
- size_t i;
_Bool have_events = (metric->updates_num > 0);
/* Make sure all timer metrics share the *same* timestamp. */
@@ -821,7 +815,7 @@ static int statsd_metric_submit_unsafe (char const *name, statsd_metric_t *metri
plugin_dispatch_values (&vl);
}
- for (i = 0; i < conf_timer_percentile_num; i++)
+ for (size_t i = 0; i < conf_timer_percentile_num; i++)
{
ssnprintf (vl.type_instance, sizeof (vl.type_instance),
"%s-percentile-%.0f", name, conf_timer_percentile[i]);
char **to_be_deleted = NULL;
size_t to_be_deleted_num = 0;
- size_t i;
pthread_mutex_lock (&metrics_lock);
}
c_avl_iterator_destroy (iter);
- for (i = 0; i < to_be_deleted_num; i++)
+ for (size_t i = 0; i < to_be_deleted_num; i++)
{
int status;
diff --git a/src/swap.c b/src/swap.c
index 645dc586023523ae7af55722da4f20e3ca416442..9c63e9bbb56ca82a7e4ce25de7219d79aa8040d2 100644 (file)
--- a/src/swap.c
+++ b/src/swap.c
#endif
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static int swap_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
if (strcasecmp ("ReportBytes", child->key) == 0)
char *s_paths;
int swap_num;
int status;
- int i;
gauge_t avail = 0;
gauge_t total = 0;
sfree (s);
return (-1);
}
- for (i = 0; i < swap_num; i++)
+ for (int i = 0; i < swap_num; i++)
s->swt_ent[i].ste_path = s_paths + (i * PATH_MAX);
s->swt_n = swap_num;
/* less elements returned than requested */
swap_num = status;
- for (i = 0; i < swap_num; i++)
+ for (int i = 0; i < swap_num; i++)
{
char path[PATH_MAX];
gauge_t this_total;
struct swapent *swap_entries;
int swap_num;
int status;
- int i;
gauge_t used = 0;
gauge_t total = 0;
/* TODO: Report per-device stats. The path name is available from
* swap_entries[i].se_path */
- for (i = 0; i < swap_num; i++)
+ for (int i = 0; i < swap_num; i++)
{
if ((swap_entries[i].se_flags & SWF_ENABLE) == 0)
continue;
{
ERROR ("swap plugin: Total swap space (%g) is less than used swap space (%g).",
total, used);
+ sfree (swap_entries);
return (-1);
}
diff --git a/src/syslog.c b/src/syslog.c
index 849f7d1b1331a04daec6de6d6888c6234044912d..73e5e1f39fa440376fe2aa353b019b0690925a6f 100644 (file)
--- a/src/syslog.c
+++ b/src/syslog.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/table.c b/src/table.c
index 38d5f03a0161fc6e905da089fb6ce9002ee5f739..ba65f41c3263e3b29d67bfe257a9da0d64bb8377 100644 (file)
--- a/src/table.c
+++ b/src/table.c
*/
#include "collectd.h"
+
#include "common.h"
#include "configfile.h"
static void tbl_clear (tbl_t *tbl)
{
- size_t i;
-
sfree (tbl->file);
sfree (tbl->sep);
sfree (tbl->instance);
- for (i = 0; i < tbl->results_num; ++i)
+ for (size_t i = 0; i < tbl->results_num; ++i)
tbl_result_clear (tbl->results + i);
sfree (tbl->results);
tbl->results_num = 0;
{
size_t *tmp;
size_t num;
- size_t i;
if (1 > ci->values_num) {
log_err ("\"%s\" expects at least one argument.", name);
}
num = (size_t) ci->values_num;
- for (i = 0; i < num; ++i) {
+ for (size_t i = 0; i < num; ++i) {
if (OCONFIG_TYPE_NUMBER != ci->values[i].type) {
log_err ("\"%s\" expects numerical arguments only.", name);
return 1;
}
*var = tmp;
- for (i = 0; i < num; ++i) {
+ for (size_t i = 0; i < num; ++i) {
(*var)[*len] = (size_t) ci->values[i].value.number;
(*len)++;
}
tbl_result_t *res;
int status = 0;
- int i;
if (0 != ci->values_num) {
log_err ("<Result> does not expect any arguments.");
res = tbl->results + tbl->results_num - 1;
tbl_result_setup (res);
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Type"))
tbl_t *tbl;
int status = 0;
- size_t i;
if ((1 != ci->values_num)
|| (OCONFIG_TYPE_STRING != ci->values[0].type)) {
tbl = tables + tables_num - 1;
tbl_setup (tbl, ci->values[0].value.string);
- for (i = 0; i < ((size_t) ci->children_num); ++i) {
+ for (size_t i = 0; i < ((size_t) ci->children_num); ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Separator"))
return status;
}
- for (i = 0; i < tbl->results_num; ++i) {
+ for (size_t i = 0; i < tbl->results_num; ++i) {
tbl_result_t *res = tbl->results + i;
- size_t j;
- for (j = 0; j < res->instances_num; ++j)
+ for (size_t j = 0; j < res->instances_num; ++j)
if (res->instances[j] > tbl->max_colnum)
tbl->max_colnum = res->instances[j];
- for (j = 0; j < res->values_num; ++j)
+ for (size_t j = 0; j < res->values_num; ++j)
if (res->values[j] > tbl->max_colnum)
tbl->max_colnum = res->values[j];
}
static int tbl_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; ++i) {
+ for (int i = 0; i < ci->children_num; ++i) {
oconfig_item_t *c = ci->children + i;
if (0 == strcasecmp (c->key, "Table"))
static int tbl_prepare (tbl_t *tbl)
{
- size_t i;
-
- for (i = 0; i < tbl->results_num; ++i) {
+ for (size_t i = 0; i < tbl->results_num; ++i) {
tbl_result_t *res = tbl->results + i;
res->ds = plugin_get_ds (res->type);
static int tbl_finish (tbl_t *tbl)
{
- size_t i;
-
- for (i = 0; i < tbl->results_num; ++i)
+ for (size_t i = 0; i < tbl->results_num; ++i)
tbl->results[i].ds = NULL;
return 0;
} /* tbl_finish */
value_list_t vl = VALUE_LIST_INIT;
value_t values[res->values_num];
- size_t i;
-
assert (NULL != res->ds);
assert (res->values_num == res->ds->ds_num);
- for (i = 0; i < res->values_num; ++i) {
+ for (size_t i = 0; i < res->values_num; ++i) {
char *value;
assert (res->values[i] < fields_num);
char *instances[res->instances_num];
char instances_str[DATA_MAX_NAME_LEN];
- for (i = 0; i < res->instances_num; ++i) {
+ for (size_t i = 0; i < res->instances_num; ++i) {
assert (res->instances[i] < fields_num);
instances[i] = fields[res->instances[i]];
}
char *fields[tbl->max_colnum + 1];
char *ptr, *saveptr;
- size_t i;
+ size_t i = 0;
- i = 0;
ptr = line;
saveptr = NULL;
while (NULL != (fields[i] = strtok_r (ptr, tbl->sep, &saveptr))) {
static int tbl_read (void)
{
int status = -1;
- size_t i;
if (0 == tables_num)
return 0;
- for (i = 0; i < tables_num; ++i) {
+ for (size_t i = 0; i < tables_num; ++i) {
tbl_t *tbl = tables + i;
if (0 != tbl_prepare (tbl)) {
static int tbl_shutdown (void)
{
- size_t i;
-
- for (i = 0; i < tables_num; ++i)
+ for (size_t i = 0; i < tables_num; ++i)
tbl_clear (&tables[i]);
sfree (tables);
return 0;
diff --git a/src/tail.c b/src/tail.c
index b9e9206890ff965f52521ab77ae722c64e9cfedc..b8922ecb388039098ebde1209cb69ed3ec464c13 100644 (file)
--- a/src/tail.c
+++ b/src/tail.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_tail_match.h"
{
ctail_config_match_t cm = { 0 };
int status;
- int i;
if (ci->values_num != 0)
{
}
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
cdtime_t interval = 0;
char *plugin_instance = NULL;
int num_matches = 0;
- int i;
if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING))
{
return (-1);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
int status = 0;
static int ctail_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
char str[255];
user_data_t ud = { 0 };
- size_t i;
if (tail_match_list_num == 0)
{
return (-1);
}
- for (i = 0; i < tail_match_list_num; i++)
+ for (size_t i = 0; i < tail_match_list_num; i++)
{
ud.data = (void *)tail_match_list[i];
ssnprintf(str, sizeof(str), "tail-%zu", i);
static int ctail_shutdown (void)
{
- size_t i;
-
- for (i = 0; i < tail_match_list_num; i++)
+ for (size_t i = 0; i < tail_match_list_num; i++)
{
tail_match_destroy (tail_match_list[i]);
tail_match_list[i] = NULL;
diff --git a/src/tail_csv.c b/src/tail_csv.c
index 70710216f320c99f5e971e05e3ac05d62ebd921e..79ea46654659ced9fab69bd8ae97e6111dc9c842 100644 (file)
--- a/src/tail_csv.c
+++ b/src/tail_csv.c
**/
#include "collectd.h"
+
#include "plugin.h" /* plugin_register_*, plugin_dispatch_values */
#include "common.h" /* auxiliary functions */
#include "utils_tail.h"
static int tcsv_config_add_metric(oconfig_item_t *ci){
metric_definition_t *md;
int status;
- int i;
md = calloc(1, sizeof(*md));
if (md == NULL)
return (-1);
}
- for (i = 0; i < ci->children_num; ++i){
+ for (int i = 0; i < ci->children_num; ++i){
oconfig_item_t *option = ci->children + i;
if (strcasecmp("Type", option->key) == 0)
@@ -376,7 +376,6 @@ static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_i
metric_definition_t *metric;
metric_definition_t **metric_list;
size_t metric_list_size;
- int i;
if (ci->values_num < 1) {
WARNING("tail_csv plugin: The `Collect' config option needs at least one argument.");
@@ -389,7 +388,7 @@ static int tcsv_config_add_instance_collect(instance_definition_t *id, oconfig_i
return (-1);
id->metric_list = metric_list;
- for (i = 0; i < ci->values_num; i++) {
+ for (int i = 0; i < ci->values_num; i++) {
char *metric_name;
if (ci->values[i].type != OCONFIG_TYPE_STRING) {
{
instance_definition_t* id;
int status = 0;
- int i;
/* Registration variables */
char cb_name[DATA_MAX_NAME_LEN];
/* Use default interval. */
id->interval = plugin_get_interval();
- for (i = 0; i < ci->children_num; ++i){
+ for (int i = 0; i < ci->children_num; ++i){
oconfig_item_t *option = ci->children + i;
status = 0;
/* Parse blocks */
static int tcsv_config(oconfig_item_t *ci){
- int i;
- for (i = 0; i < ci->children_num; ++i){
+ for (int i = 0; i < ci->children_num; ++i){
oconfig_item_t *child = ci->children + i;
if (strcasecmp("Metric", child->key) == 0)
tcsv_config_add_metric(child);
diff --git a/src/tape.c b/src/tape.c
index a8e7dc45faab08bdf18ffd42fbebd242f3f3477f..52da2bc69db465a6e99bf97e529f43c56a0cd5c8 100644 (file)
--- a/src/tape.c
+++ b/src/tape.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
# error "kstat_io_t does not have the required members"
#endif
static kstat_io_t kio;
- int i;
if (kc == NULL)
return (-1);
if (numtape <= 0)
return (-1);
- for (i = 0; i < numtape; i++)
+ for (int i = 0; i < numtape; i++)
{
if (kstat_read (kc, ksp[i], &kio) == -1)
continue;
index 63e4f3154f15b97356a012560c2242cb06bb7db5..21c071ed422f36d625f44366ace457add857f46e 100644 (file)
**/
#include "collectd.h"
+
#include "common.h"
#include "filter_chain.h"
#include "utils_cache.h"
{
tn_data_t *data;
int status;
- int i;
data = calloc (1, sizeof (*data));
if (data == NULL)
data->severity = 0;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
gauge_t *rates;
int rates_failed;
- size_t i;
-
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
return (-EINVAL);
rates_failed = 0;
rates = NULL;
- for (i = 0; i < ds->ds_num; i++)
+
+ for (size_t i = 0; i < ds->ds_num; i++)
{
char template[DATA_MAX_NAME_LEN];
char value_str[DATA_MAX_NAME_LEN];
diff --git a/src/target_replace.c b/src/target_replace.c
index 8d774c570f849d7beed5e378a7d936c5d6f2a070..40a6fec992687466720d11abea95778fb5984aa2 100644 (file)
--- a/src/target_replace.c
+++ b/src/target_replace.c
**/
#include "collectd.h"
+
#include "common.h"
#include "filter_chain.h"
#include "utils_subst.h"
static int tr_action_invoke (tr_action_t *act_head, /* {{{ */
char *buffer_in, size_t buffer_in_size, int may_be_empty)
{
- tr_action_t *act;
int status;
char buffer[DATA_MAX_NAME_LEN];
regmatch_t matches[8] = { [0] = { 0 } };
DEBUG ("target_replace plugin: tr_action_invoke: <- buffer = %s;", buffer);
- for (act = act_head; act != NULL; act = act->next)
+ for (tr_action_t *act = act_head; act != NULL; act = act->next)
{
char temp[DATA_MAX_NAME_LEN];
char *subst_status;
{
tr_data_t *data;
int status;
- int i;
data = calloc (1, sizeof (*data));
if (data == NULL)
data->type_instance = NULL;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/target_scale.c b/src/target_scale.c
index 579d01a03c3908b0e5b8e85e5316ce1815a6f8c2..22af4e319d60af7db98e0a86790b3438dfe640b3 100644 (file)
--- a/src/target_scale.c
+++ b/src/target_scale.c
**/
#include "collectd.h"
+
#include "common.h"
#include "filter_chain.h"
{
size_t new_data_sources_num;
char **temp;
- int i;
/* Check number of arbuments. */
if (ci->values_num < 1)
}
/* Check type of arguments */
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
if (ci->values[i].type == OCONFIG_TYPE_STRING)
continue;
data->data_sources = temp;
/* Copy the strings, allocating memory as needed. */
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
size_t j;
if ((data != NULL) && (data->data_sources != NULL))
{
- size_t i;
- for (i = 0; i < data->data_sources_num; i++)
+ for (size_t i = 0; i < data->data_sources_num; i++)
sfree (data->data_sources[i]);
sfree (data->data_sources);
}
{
ts_data_t *data;
int status;
- int i;
data = calloc (1, sizeof (*data));
if (data == NULL)
data->offset = NAN;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
notification_meta_t __attribute__((unused)) **meta, void **user_data)
{
ts_data_t *data;
- size_t i;
if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
return (-EINVAL);
return (-EINVAL);
}
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
/* If we've got a list of data sources, is it in the list? */
if (data->data_sources) {
diff --git a/src/target_set.c b/src/target_set.c
index 2060dcde6b050e1616acc83481ce48ea5a957098..fee5ffdcbaac2e09e719cd9d9460f5f3cc21de7f 100644 (file)
--- a/src/target_set.c
+++ b/src/target_set.c
**/
#include "collectd.h"
+
#include "common.h"
#include "filter_chain.h"
{
ts_data_t *data;
int status;
- int i;
data = calloc (1, sizeof (*data));
if (data == NULL)
data->meta = NULL;
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/target_v5upgrade.c b/src/target_v5upgrade.c
index 6d661711b3cfab1632825519ade9f75f2f62a34e..f7baa3aee468ce5e1a5cac6f29ea7f2a8ee8ecc9 100644 (file)
--- a/src/target_v5upgrade.c
+++ b/src/target_v5upgrade.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "filter_chain.h"
diff --git a/src/tcpconns.c b/src/tcpconns.c
index da916950e301c5a705fdfe5c18c80b48b336d4a3..e74e4bc8856d6360472a44d52a7dae93a3586ca2 100644 (file)
--- a/src/tcpconns.c
+++ b/src/tcpconns.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- int i;
conn_prepare_vl (&vl, values);
ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
"%"PRIu16"-local", pe->port);
- for (i = 1; i <= TCP_STATE_MAX; i++)
+ for (int i = 1; i <= TCP_STATE_MAX; i++)
{
vl.values[0].gauge = pe->count_local[i];
ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance),
"%"PRIu16"-remote", pe->port);
- for (i = 1; i <= TCP_STATE_MAX; i++)
+ for (int i = 1; i <= TCP_STATE_MAX; i++)
{
vl.values[0].gauge = pe->count_remote[i];
{
value_t values[1];
value_list_t vl = VALUE_LIST_INIT;
- int i;
conn_prepare_vl (&vl, values);
sstrncpy (vl.plugin_instance, "all", sizeof (vl.plugin_instance));
- for (i = 1; i <= TCP_STATE_MAX; i++)
+ for (int i = 1; i <= TCP_STATE_MAX; i++)
{
vl.values[0].gauge = count_total[i];
static void conn_submit_all (void)
{
- port_entry_t *pe;
-
if (port_collect_total)
conn_submit_port_total ();
- for (pe = port_list_head; pe != NULL; pe = pe->next)
+ for (port_entry_t *pe = port_list_head; pe != NULL; pe = pe->next)
conn_submit_port_entry (pe);
} /* void conn_submit_all */
static int conn_read (void)
{
int size;
- int i;
int nconn;
void *data;
struct netinfo_header *header;
nconn = header->size;
conn = (struct netinfo_conn *)(data + sizeof(struct netinfo_header));
- for (i=0; i < nconn; conn++, i++)
+ for (int i = 0; i < nconn; conn++, i++)
{
conn_handle_ports (conn->srcport, conn->dstport, conn->tcp_state);
}
diff --git a/src/teamspeak2.c b/src/teamspeak2.c
index cf093c5feec35debf969b27d4c1fac8b432b20ba..a1cde320dd2cb3e9a83f9910da40beb31eefbb43 100644 (file)
--- a/src/teamspeak2.c
+++ b/src/teamspeak2.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
* Returns connected file objects or establishes the connection
* if it's not already present
*/
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_head;
- struct addrinfo *ai_ptr;
int sd = -1;
int status;
}
/* Get all addrs for this hostname */
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM
+ };
status = getaddrinfo ((config_host != NULL) ? config_host : DEFAULT_HOST,
(config_port != NULL) ? config_port : DEFAULT_PORT,
}
/* Try all given hosts until we can connect to one */
- for (ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_head; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
/* Create socket */
sd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
* Poll function which collects global and vserver information
* and submits it to collectd
*/
- vserver_list_t *vserver;
int success = 0;
int status;
}
/* Handle vservers */
- for (vserver = server_list; vserver != NULL; vserver = vserver->next)
+ for (vserver_list_t *vserver = server_list; vserver != NULL; vserver = vserver->next)
{
status = tss2_read_vserver (vserver);
if (status == 0)
diff --git a/src/ted.c b/src/ted.c
index 282212b114f0c1832a4401663825aebf0678715c..96c94e5d3f64d0bbb854dd83df7640ec49424f22 100644 (file)
--- a/src/ted.c
+++ b/src/ted.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
while (end_flag == 0)
{
ssize_t receive_buffer_length;
- ssize_t i;
/* check for timeout or input error*/
status = select (fd + 1, &input, NULL, NULL, &timeout);
* the beginning of the package has been found. */
escape_flag = 0;
- for (i = 0; i < receive_buffer_length; i++)
+ for (ssize_t i = 0; i < receive_buffer_length; i++)
{
/* Check if previous byte was the escape byte. */
if (escape_flag == 1)
double power;
double voltage;
int status;
- int i;
status = ted_open_device ();
if (status != 0)
power = NAN;
voltage = NAN;
- for (i = 0; i <= conf_retries; i++)
+ for (int i = 0; i <= conf_retries; i++)
{
status = ted_read_value (&power, &voltage);
if (status == 0)
diff --git a/src/thermal.c b/src/thermal.c
index 54311a647cc786aa40c27e85b4b1a514e0dbad11..c6db8c046036f52552e487ea8f11d780c323ffa5 100644 (file)
--- a/src/thermal.c
+++ b/src/thermal.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
diff --git a/src/threshold.c b/src/threshold.c
index f12b405773609c89cbe37ea4e8061d93d714a706..1d9bcf95ba8fcfe52a2ce0de5a1d1a5c5ce07034 100644 (file)
--- a/src/threshold.c
+++ b/src/threshold.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_avltree.h"
static int ut_config_type (const threshold_t *th_orig, oconfig_item_t *ci)
{
- int i;
threshold_t th;
int status = 0;
th.hysteresis = 0;
th.flags = UT_FLAG_INTERESTING; /* interesting by default */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
static int ut_config_plugin (const threshold_t *th_orig, oconfig_item_t *ci)
{
- int i;
threshold_t th;
int status = 0;
memcpy (&th, th_orig, sizeof (th));
sstrncpy (th.plugin, ci->values[0].value.string, sizeof (th.plugin));
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
static int ut_config_host (const threshold_t *th_orig, oconfig_item_t *ci)
{
- int i;
threshold_t th;
int status = 0;
memcpy (&th, th_orig, sizeof (th));
sstrncpy (th.host, ci->values[0].value.string, sizeof (th.host));
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
{
gauge_t value;
gauge_t sum;
- size_t i;
sum = 0.0;
- for (i = 0; i < vl->values_len; i++)
+ for (size_t i = 0; i < vl->values_len; i++)
{
if (isnan (values[i]))
continue;
{ /* {{{ */
int ret = -1;
int ds_index = -1;
- size_t i;
gauge_t values_copy[ds->ds_num];
memcpy (values_copy, values, sizeof (values_copy));
}
/* Prepare `sum' and `num'. */
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
if (!isnan (values[i]))
{
num++;
if ((num == 0) /* All data sources are undefined. */
|| (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */
{
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
values_copy[i] = NAN;
}
else /* We can actually calculate the percentage. */
{
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
values_copy[i] = 100.0 * values[i] / sum;
}
} /* if (UT_FLAG_PERCENTAGE) */
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
int status;
static int ut_config (oconfig_item_t *ci)
{ /* {{{ */
- int i;
int status = 0;
int old_size = c_avl_size (threshold_tree);
.flags = UT_FLAG_INTERESTING /* interesting by default */
};
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *option = ci->children + i;
diff --git a/src/tokyotyrant.c b/src/tokyotyrant.c
index befbd50a91c52d1464e03934076ec7145c40b209..7c6d9129e709ee9b71a30a3a57848fc9fca56b06 100644 (file)
--- a/src/tokyotyrant.c
+++ b/src/tokyotyrant.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "utils_cache.h"
diff --git a/src/turbostat.c b/src/turbostat.c
index bd5d86cdd626b7f216a7c82252d01227facdba44..2d8a08e646319b961f8ffb24f1a8654bb470c23f 100644 (file)
--- a/src/turbostat.c
+++ b/src/turbostat.c
#define _GNU_SOURCE
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_time.h"
@@ -651,11 +652,10 @@ for_all_cpus(int (func)(struct thread_data *, struct core_data *, struct pkg_dat
struct thread_data *thread_base, struct core_data *core_base, struct pkg_data *pkg_base)
{
int retval;
- unsigned int pkg_no, core_no, thread_no;
- for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
- for (core_no = 0; core_no < topology.num_cores; ++core_no) {
- for (thread_no = 0; thread_no < topology.num_threads; ++thread_no) {
+ for (unsigned int pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
+ for (unsigned int core_no = 0; core_no < topology.num_cores; ++core_no) {
+ for (unsigned int thread_no = 0; thread_no < topology.num_threads; ++thread_no) {
struct thread_data *t;
struct core_data *c;
struct pkg_data *p;
@@ -691,11 +691,10 @@ for_all_cpus_delta(const struct thread_data *thread_new_base, const struct core_
const struct thread_data *thread_old_base, const struct core_data *core_old_base, const struct pkg_data *pkg_old_base)
{
int retval;
- unsigned int pkg_no, core_no, thread_no;
- for (pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
- for (core_no = 0; core_no < topology.num_cores; ++core_no) {
- for (thread_no = 0; thread_no < topology.num_threads; ++thread_no) {
+ for (unsigned int pkg_no = 0; pkg_no < topology.num_packages; ++pkg_no) {
+ for (unsigned int core_no = 0; core_no < topology.num_cores; ++core_no) {
+ for (unsigned int thread_no = 0; thread_no < topology.num_threads; ++thread_no) {
struct thread_data *t_delta;
const struct thread_data *t_old, *t_new;
struct core_data *c_delta;
static int __attribute__((warn_unused_result))
topology_probe(void)
{
- unsigned int i;
int ret;
unsigned int max_package_id, max_core_id, max_threads;
max_package_id = max_core_id = max_threads = 0;
* For online cpus
* find max_core_id, max_package_id
*/
- for (i = 0; i <= topology.max_cpu_id; ++i) {
+ for (unsigned int i = 0; i <= topology.max_cpu_id; ++i) {
unsigned int num_threads;
struct cpu_topology *cpu = &topology.cpus[i];
static int
allocate_counters(struct thread_data **threads, struct core_data **cores, struct pkg_data **packages)
{
- unsigned int i;
unsigned int total_threads, total_cores;
if ((topology.num_threads == 0)
@@ -1271,7 +1268,7 @@ allocate_counters(struct thread_data **threads, struct core_data **cores, struct
return -1;
}
- for (i = 0; i < total_threads; ++i)
+ for (unsigned int i = 0; i < total_threads; ++i)
(*threads)[i].cpu_id = topology.max_cpu_id + 1;
total_cores = topology.num_cores * topology.num_packages;
static void
initialize_counters(void)
{
- unsigned int cpu_id;
-
- for (cpu_id = 0; cpu_id <= topology.max_cpu_id; ++cpu_id) {
+ for (unsigned int cpu_id = 0; cpu_id <= topology.max_cpu_id; ++cpu_id) {
if (cpu_is_not_present(cpu_id))
continue;
init_counter(EVEN_COUNTERS, cpu_id);
static int
check_permissions(void)
{
-#ifdef HAVE_SYS_CAPABILITY_H
- struct __user_cap_header_struct cap_header_data;
- cap_user_header_t cap_header = &cap_header_data;
- struct __user_cap_data_struct cap_data_data;
- cap_user_data_t cap_data = &cap_data_data;
- int ret = 0;
-#endif /* HAVE_SYS_CAPABILITY_H */
if (getuid() == 0) {
/* We have everything we need */
return 0;
-#ifndef HAVE_SYS_CAPABILITY_H
+#if !defined(HAVE_SYS_CAPABILITY_H) && !defined(CAP_SYS_RAWIO)
} else {
ERROR("turbostat plugin: Initialization failed: this plugin "
"requires collectd to run as root");
return -1;
}
-#else /* HAVE_SYS_CAPABILITY_H */
+#else /* HAVE_SYS_CAPABILITY_H && CAP_SYS_RAWIO */
}
- /* check for CAP_SYS_RAWIO */
- cap_header->pid = getpid();
- cap_header->version = _LINUX_CAPABILITY_VERSION;
- if (capget(cap_header, cap_data) < 0) {
- ERROR("turbostat plugin: capget failed");
- return -1;
- }
+ int ret = 0;
- if ((cap_data->effective & (1 << CAP_SYS_RAWIO)) == 0) {
+ if (check_capability(CAP_SYS_RAWIO) != 0) {
WARNING("turbostat plugin: Collectd doesn't have the "
"CAP_SYS_RAWIO capability. If you don't want to run "
"collectd as root, try running \"setcap "
"collectd a special capability (CAP_SYS_RAWIO) and read "
"access to /dev/cpu/*/msr (see previous warnings)");
return ret;
-#endif /* HAVE_SYS_CAPABILITY_H */
+#endif /* HAVE_SYS_CAPABILITY_H && CAP_SYS_RAWIO */
}
static int
diff --git a/src/types.db b/src/types.db
index 8c6a99560a4f51cb8a3972463f5975b0439deb17..cc79af07f26d50cdcf92a304242a032f357ea522 100644 (file)
--- a/src/types.db
+++ b/src/types.db
df used:GAUGE:0:1125899906842623, free:GAUGE:0:1125899906842623
df_complex value:GAUGE:0:U
df_inodes value:GAUGE:0:U
+dilution_of_precision 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
route_etx value:GAUGE:0:U
route_metric value:GAUGE:0:U
routes value:GAUGE:0:U
+satellites 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
diff --git a/src/unixsock.c b/src/unixsock.c
index 5454fd8c273eb948b9d119e4d4dab73414c0636f..1faeff9c5cd00fc9ed10bb1afdbd0719587e0329 100644 (file)
--- a/src/unixsock.c
+++ b/src/unixsock.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
diff --git a/src/uptime.c b/src/uptime.c
index 4116b810fc176c2a73ec7aa6bf807cc8971ab8d9..cbe2f8c5dcaf2ebcaf4ff4fc059bbffa684d805e 100644 (file)
--- a/src/uptime.c
+++ b/src/uptime.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/users.c b/src/users.c
index a4ee4ef7d1df2c2afc619b9ade1b0598a8a60ae9..30e0dbe67020817ed0d4b2630eb0341f99cdd5be 100644 (file)
--- a/src/users.c
+++ b/src/users.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/utils_cmd_flush.c b/src/utils_cmd_flush.c
index 410616640bd00ae5e1d2ebe9aa502e3af111e6ea..1876150f38a0f6155fca7de383b86a49247f3c1d 100644 (file)
--- a/src/utils_cmd_flush.c
+++ b/src/utils_cmd_flush.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_parse_option.h"
char **identifiers = NULL;
size_t identifiers_num = 0;
- size_t i;
-
#define PRINT_TO_SOCK(fh, ...) \
do { \
if (fprintf (fh, __VA_ARGS__) < 0) { \
}
} /* while (*buffer != 0) */
- for (i = 0; (i == 0) || (i < plugins_num); i++)
+ for (size_t i = 0; (i == 0) || (i < plugins_num); i++)
{
char *plugin = NULL;
- size_t j;
if (plugins_num != 0)
plugin = plugins[i];
- for (j = 0; (j == 0) || (j < identifiers_num); j++)
+ for (size_t j = 0; (j == 0) || (j < identifiers_num); j++)
{
char *identifier = NULL;
int status;
index 7e4a9db19f4961392ed5bfb19f0680860c10e0b3..b2a0a23bfd892e7b77b6e24c4c1ad3934d69a6bc 100644 (file)
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/utils_cmd_getval.c b/src/utils_cmd_getval.c
index 4d679f000e1650a51224767eea4e2ee5ab3702ac..cd88760a3746f01e4dee0a25f121987553e48ae8 100644 (file)
--- a/src/utils_cmd_getval.c
+++ b/src/utils_cmd_getval.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
const data_set_t *ds;
int status;
- size_t i;
if ((fh == NULL) || (buffer == NULL))
return (-1);
print_to_socket (fh, "%zu Value%s found\n", values_num,
(values_num == 1) ? "" : "s");
- for (i = 0; i < values_num; i++)
+ for (size_t i = 0; i < values_num; i++)
{
print_to_socket (fh, "%s=", ds->ds[i].name);
if (isnan (values[i]))
index b698388d3304e9686ae70f5c0202a1422a0fd36e..afbd01d0ceed106dd2b4852d06ca5b7a76e3dcea 100644 (file)
--- a/src/utils_cmd_listval.c
+++ b/src/utils_cmd_listval.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_parse_option.h"
#define free_everything_and_return(status) do { \
- size_t j; \
- for (j = 0; j < number; j++) { \
+ for (size_t j = 0; j < number; j++) { \
sfree(names[j]); \
names[j] = NULL; \
} \
char **names = NULL;
cdtime_t *times = NULL;
size_t number = 0;
- size_t i;
int status;
DEBUG ("utils_cmd_listval: handle_listval (fh = %p, buffer = %s);",
print_to_socket (fh, "%i Value%s found\n",
(int) number, (number == 1) ? "" : "s");
- for (i = 0; i < number; i++)
+ for (size_t i = 0; i < number; i++)
print_to_socket (fh, "%.3f %s\n", CDTIME_T_TO_DOUBLE (times[i]),
names[i]);
index 956ed745cffdd102a824bc8bc363e8bc102d74e7..669ef837b94fa6ff5ae0678f249ddebbe25088b5 100644 (file)
--- a/src/utils_cmd_putnotif.c
+++ b/src/utils_cmd_putnotif.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/utils_cmd_putval.c b/src/utils_cmd_putval.c
index 4c40e557a2a27b22af35fd0f53469c0ba7d83ebb..bf3e2b6f2b9880cf50f6d602bf721ed42c51afb7 100644 (file)
--- a/src/utils_cmd_putval.c
+++ b/src/utils_cmd_putval.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/utils_crc32.c b/src/utils_crc32.c
index f9eaf880c03737863741ce3e12bcd3c8f94ab658..79d77a23901a23695c8ae8703e3630bb9f2be502 100644 (file)
--- a/src/utils_crc32.c
+++ b/src/utils_crc32.c
uint32_t
crc32_buffer(const unsigned char *s, size_t len)
{
- size_t i;
uint32_t ret;
ret = 0;
- for (i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
ret = crc32_tab[(ret ^ s[i]) & 0xff] ^ (ret >> 8);
return ret;
}
diff --git a/src/utils_curl_stats.c b/src/utils_curl_stats.c
index 258c5cfaa458132dd2958cb165215075a7597b07..0509ff43beaf58e8c646689b2992fddff628ece0 100644 (file)
--- a/src/utils_curl_stats.c
+++ b/src/utils_curl_stats.c
**/
#include "collectd.h"
+
#include "common.h"
#include "utils_curl_stats.h"
curl_stats_t *curl_stats_from_config (oconfig_item_t *ci)
{
curl_stats_t *s;
- int i;
if (ci == NULL)
return NULL;
if (s == NULL)
return NULL;
- for (i = 0; i < ci->children_num; ++i)
+ for (int i = 0; i < ci->children_num; ++i)
{
oconfig_item_t *c = ci->children + i;
size_t field;
const char *hostname, const char *plugin, const char *plugin_instance)
{
value_list_t vl = VALUE_LIST_INIT;
- size_t field;
if (s == NULL)
return 0;
if (plugin_instance != NULL)
sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance));
- for (field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field)
+ for (size_t field = 0; field < STATIC_ARRAY_SIZE (field_specs); ++field)
{
int status;
diff --git a/src/utils_db_query.c b/src/utils_db_query.c
index f683fb5d2bd571d409192bbc70e41ab295d871ee..e734358f80e5ff05cd0f3827122a2afd6726b1e9 100644 (file)
--- a/src/utils_db_query.c
+++ b/src/utils_db_query.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
{
char **array;
size_t array_len;
- int i;
if (ci->values_num < 1)
{
return (-1);
}
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
if (ci->values[i].type != OCONFIG_TYPE_STRING)
{
}
*ret_array = array;
- for (i = 0; i < ci->values_num; i++)
+ for (int i = 0; i < ci->values_num; i++)
{
array[array_len] = strdup (ci->values[i].value.string);
if (array[array_len] == NULL)
udb_query_t const *q, udb_query_preparation_area_t *q_area)
{
value_list_t vl = VALUE_LIST_INIT;
- size_t i;
- int status;
assert (r != NULL);
assert (r_area->ds != NULL);
}
vl.values_len = r_area->ds->ds_num;
- for (i = 0; i < r->values_num; i++)
+ for (size_t i = 0; i < r->values_num; i++)
{
char *value_str = r_area->values_buffer[i];
{
if (r->instance_prefix == NULL)
{
- strjoin (vl.type_instance, sizeof (vl.type_instance),
+ int status = strjoin (vl.type_instance, sizeof (vl.type_instance),
r_area->instances_buffer, r->instances_num, "-");
+ if (status < 0)
+ {
+ ERROR ("udb_result_submit: creating type_instance failed with status %d.",
+ status);
+ return (status);
+ }
}
else
{
char tmp[DATA_MAX_NAME_LEN];
- strjoin (tmp, sizeof (tmp), r_area->instances_buffer,
+ int status = strjoin (tmp, sizeof (tmp), r_area->instances_buffer,
r->instances_num, "-");
+ if (status < 0)
+ {
+ ERROR ("udb_result_submit: creating type_instance failed with status %d.",
+ status);
+ return (status);
+ }
tmp[sizeof (tmp) - 1] = 0;
snprintf (vl.type_instance, sizeof (vl.type_instance), "%s-%s",
return (-ENOMEM);
}
- for (i = 0; i < r->metadata_num; i++)
+ for (size_t i = 0; i < r->metadata_num; i++)
{
- status = meta_data_add_string (vl.meta, r->metadata[i],
+ int status = meta_data_add_string (vl.meta, r->metadata[i],
r_area->metadata_buffer[i]);
if (status != 0)
{
udb_result_preparation_area_t *r_area,
udb_query_t const *q, char **column_values)
{
- size_t i;
-
assert (r && q_area && r_area);
- for (i = 0; i < r->instances_num; i++)
+ for (size_t i = 0; i < r->instances_num; i++)
r_area->instances_buffer[i] = column_values[r_area->instances_pos[i]];
- for (i = 0; i < r->values_num; i++)
+ for (size_t i = 0; i < r->values_num; i++)
r_area->values_buffer[i] = column_values[r_area->values_pos[i]];
- for (i = 0; i < r->metadata_num; i++)
+ for (size_t i = 0; i < r->metadata_num; i++)
r_area->metadata_buffer[i] = column_values[r_area->metadata_pos[i]];
if (q->plugin_instance_from)
udb_result_preparation_area_t *prep_area,
char **column_names, size_t column_num)
{
- size_t i;
-
if ((r == NULL) || (prep_area == NULL))
return (-EINVAL);
/* }}} */
/* Determine the position of the plugin instance column {{{ */
- for (i = 0; i < r->instances_num; i++)
+ for (size_t i = 0; i < r->instances_num; i++)
{
size_t j;
/* Determine the position of the value columns {{{ */
- for (i = 0; i < r->values_num; i++)
+ for (size_t i = 0; i < r->values_num; i++)
{
size_t j;
} /* }}} for (i = 0; i < r->values_num; i++) */
/* Determine the position of the metadata columns {{{ */
- for (i = 0; i < r->metadata_num; i++)
+ for (size_t i = 0; i < r->metadata_num; i++)
{
size_t j;
static void udb_result_free (udb_result_t *r) /* {{{ */
{
- size_t i;
-
if (r == NULL)
return;
sfree (r->type);
sfree (r->instance_prefix);
- for (i = 0; i < r->instances_num; i++)
+ for (size_t i = 0; i < r->instances_num; i++)
sfree (r->instances[i]);
sfree (r->instances);
- for (i = 0; i < r->values_num; i++)
+ for (size_t i = 0; i < r->values_num; i++)
sfree (r->values[i]);
sfree (r->values);
- for (i = 0; i < r->metadata_num; i++)
+ for (size_t i = 0; i < r->metadata_num; i++)
sfree (r->metadata[i]);
sfree (r->metadata);
{
udb_result_t *r;
int status;
- int i;
if (ci->values_num != 0)
{
/* Fill the `udb_result_t' structure.. */
status = 0;
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
udb_query_t *q;
int status;
- int i;
if ((ret_query_list == NULL) || (ret_query_list_len == NULL))
return (-EINVAL);
}
/* Fill the `udb_query_t' structure.. */
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
void udb_query_free (udb_query_t **query_list, size_t query_list_len) /* {{{ */
{
- size_t i;
-
if (query_list == NULL)
return;
- for (i = 0; i < query_list_len; i++)
+ for (size_t i = 0; i < query_list_len; i++)
udb_query_free_one (query_list[i]);
sfree (query_list);
udb_query_t **src_list, size_t src_list_len,
udb_query_t ***dst_list, size_t *dst_list_len)
{
- size_t i;
int num_added;
if ((name == NULL) || (src_list == NULL) || (dst_list == NULL)
}
num_added = 0;
- for (i = 0; i < src_list_len; i++)
+ for (size_t i = 0; i < src_list_len; i++)
{
udb_query_t **tmp_list;
size_t tmp_list_len;
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG /* {{{ */
do
{
- size_t i;
-
- for (i = 0; i < prep_area->column_num; i++)
+ for (size_t i = 0; i < prep_area->column_num; i++)
{
DEBUG ("db query utils: udb_query_handle_result (%s, %s): "
"column[%zu] = %s;",
#if defined(COLLECT_DEBUG) && COLLECT_DEBUG
do
{
- size_t i;
-
- for (i = 0; i < column_num; i++)
+ for (size_t i = 0; i < column_num; i++)
{
DEBUG ("db query utils: udb_query_prepare_result: "
"query = %s; column[%zu] = %s;",
diff --git a/src/utils_dns.c b/src/utils_dns.c
index a1e4222f3cb2180fd1c692b86de0aaafccb82f17..f38a7bd1995d212f458d57136a52ac2edfa73d5d 100644 (file)
--- a/src/utils_dns.c
+++ b/src/utils_dns.c
#define _BSD_SOURCE
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
static inline int ignore_list_match (const struct in6_addr *addr)
{
- ip_list_t *ptr;
-
- for (ptr = IgnoreList; ptr != NULL; ptr = ptr->next)
+ for (ip_list_t *ptr = IgnoreList; ptr != NULL; ptr = ptr->next)
if (cmp_in6_addr (addr, &ptr->addr) == 0)
return (1);
return (0);
void ignore_list_add_name (const char *name)
{
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
struct in6_addr addr;
int status;
if (status != 0)
return;
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
if (ai_ptr->ai_family == AF_INET)
{
case ns_t_srv: return ("SRV");
case ns_t_atma: return ("ATMA");
case ns_t_naptr: return ("NAPTR");
+ case ns_t_opt: return ("OPT");
+# if __NAMESER >= 19991006
case ns_t_kx: return ("KX");
case ns_t_cert: return ("CERT");
case ns_t_a6: return ("A6");
case ns_t_dname: return ("DNAME");
case ns_t_sink: return ("SINK");
- case ns_t_opt: return ("OPT");
-# if __NAMESER >= 19991006
case ns_t_tsig: return ("TSIG");
# endif
+# if __NAMESER >= 20090302
+ case ns_t_apl: return ("APL");
+ case ns_t_ds: return ("DS");
+ case ns_t_sshfp: return ("SSHFP");
+ case ns_t_ipseckey: return ("IPSECKEY");
+ case ns_t_rrsig: return ("RRSIG");
+ case ns_t_nsec: return ("NSEC");
+ case ns_t_dnskey: return ("DNSKEY");
+ case ns_t_dhcid: return ("DHCID");
+ case ns_t_nsec3: return ("NSEC3");
+ case ns_t_nsec3param: return ("NSEC3PARAM");
+ case ns_t_hip: return ("HIP");
+ case ns_t_spf: return ("SPF");
case ns_t_ixfr: return ("IXFR");
+# endif
case ns_t_axfr: return ("AXFR");
case ns_t_mailb: return ("MAILB");
case ns_t_maila: return ("MAILA");
case ns_t_any: return ("ANY");
+# if __NAMESER >= 19991006
case ns_t_zxfr: return ("ZXFR");
-/* #endif __NAMESER >= 19991006 */
+# endif
+# if __NAMESER >= 20090302
+ case ns_t_dlv: return ("DLV");
+# endif
+/* #endif __NAMESER >= 19991001 */
#elif (defined (__BIND)) && (__BIND >= 19950621)
case T_A: return ("A"); /* 1 ... */
case T_NS: return ("NS");
diff --git a/src/utils_fbhash.c b/src/utils_fbhash.c
index d980f58605c1750d3451d7647b3f50fdbd5f03ee..893bfbd49bded329e7b320cadd28c3da8c42bd5f 100644 (file)
--- a/src/utils_fbhash.c
+++ b/src/utils_fbhash.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "utils_fbhash.h"
index eb5b4b327119210c4f2c6424ae99c47b3ec1dc5a..e523420415a78521210f3fc3f932aa6e76cfaaf4 100644 (file)
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
static void gr_copy_escape_part (char *dst, const char *src, size_t dst_len,
char escape_char)
{
- size_t i;
-
memset (dst, 0, dst_len);
if (src == NULL)
return;
- for (i = 0; i < dst_len; i++)
+ for (size_t i = 0; i < dst_len; i++)
{
if (src[i] == 0)
{
static void escape_graphite_string (char *buffer, char escape_char)
{
- char *head;
-
assert (strchr(GRAPHITE_FORBIDDEN, escape_char) == NULL);
- for (head = buffer + strcspn(buffer, GRAPHITE_FORBIDDEN);
+ for (char *head = buffer + strcspn(buffer, GRAPHITE_FORBIDDEN);
*head != '\0';
head += strcspn(head, GRAPHITE_FORBIDDEN))
*head = escape_char;
unsigned int flags)
{
int status = 0;
- size_t i;
int buffer_pos = 0;
gauge_t *rates = NULL;
if (flags & GRAPHITE_STORE_RATES)
rates = uc_get_rate (ds, vl);
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
char const *ds_name = NULL;
char key[10*DATA_MAX_NAME_LEN];
index 398defbeabab0b31c8de7916df1ba2b9e86eca8c..60576dacb913d363947e40f1111d7cd701c33e13 100644 (file)
#define UTILS_FORMAT_GRAPHITE_H 1
#include "collectd.h"
+
#include "plugin.h"
#define GRAPHITE_STORE_RATES 0x01
index 800b4219109b6070b64157620bb97fb6c5a17a70..5b5fcdf0536170b5cae56c3230f90e7e95995dc9 100644 (file)
--- a/src/utils_format_json.c
+++ b/src/utils_format_json.c
/**
* collectd - src/utils_format_json.c
- * Copyright (C) 2009 Florian octo Forster
+ * Copyright (C) 2009-2015 Florian octo Forster
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
**/
#include "collectd.h"
+
+#include "utils_format_json.h"
+
#include "plugin.h"
#include "common.h"
-
#include "utils_cache.h"
-#include "utils_format_json.h"
+
+#if HAVE_LIBYAJL
+# include <yajl/yajl_common.h>
+# include <yajl/yajl_gen.h>
+# if HAVE_YAJL_YAJL_VERSION_H
+# include <yajl/yajl_version.h>
+# endif
+# if defined(YAJL_MAJOR) && (YAJL_MAJOR > 1)
+# define HAVE_YAJL_V2 1
+# endif
+#endif
static int json_escape_string (char *buffer, size_t buffer_size, /* {{{ */
const char *string)
{
- size_t src_pos;
size_t dst_pos;
if ((buffer == NULL) || (string == NULL))
/* Escape special characters */
BUFFER_ADD ('"');
- for (src_pos = 0; string[src_pos] != 0; src_pos++)
+ for (size_t src_pos = 0; string[src_pos] != 0; src_pos++)
{
if ((string[src_pos] == '"')
|| (string[src_pos] == '\\'))
const data_set_t *ds, const value_list_t *vl, int store_rates)
{
size_t offset = 0;
- size_t i;
gauge_t *rates = NULL;
memset (buffer, 0, buffer_size);
} while (0)
BUFFER_ADD ("[");
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if (i > 0)
BUFFER_ADD (",");
const data_set_t *ds)
{
size_t offset = 0;
- size_t i;
memset (buffer, 0, buffer_size);
} while (0)
BUFFER_ADD ("[");
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if (i > 0)
BUFFER_ADD (",");
const data_set_t *ds)
{
size_t offset = 0;
- size_t i;
memset (buffer, 0, buffer_size);
} while (0)
BUFFER_ADD ("[");
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
if (i > 0)
BUFFER_ADD (",");
{
size_t offset = 0;
int status;
- size_t i;
buffer[0] = 0;
offset += ((size_t) status); \
} while (0)
- for (i = 0; i < keys_num; ++i)
+ for (size_t i = 0; i < keys_num; ++i)
{
int type;
char *key = keys[i];
char **keys = NULL;
size_t keys_num;
int status;
- size_t i;
if ((buffer == NULL) || (buffer_size == 0) || (meta == NULL))
return (EINVAL);
status = meta_data_keys_to_json (buffer, buffer_size, meta, keys, keys_num);
- for (i = 0; i < keys_num; ++i)
+ for (size_t i = 0; i < keys_num; ++i)
sfree (keys[i]);
sfree (keys);
store_rates, (*ret_buffer_free) - 2));
} /* }}} int format_json_value_list */
+#if HAVE_LIBYAJL
+static int json_add_string (yajl_gen g, char const *str) /* {{{ */
+{
+ if (str == NULL)
+ return (int) yajl_gen_null (g);
+
+ return (int) yajl_gen_string (g, (unsigned char const *) str, (unsigned int) strlen (str));
+} /* }}} int json_add_string */
+
+#define JSON_ADD(g, str) do { \
+ yajl_gen_status status = json_add_string (g, str); \
+ if (status != yajl_gen_status_ok) { return -1; } \
+} while (0)
+
+#define JSON_ADDF(g, format, ...) do { \
+ char *str = ssnprintf_alloc (format, __VA_ARGS__); \
+ yajl_gen_status status = json_add_string (g, str); \
+ free (str); \
+ if (status != yajl_gen_status_ok) { return -1; } \
+} while (0)
+
+static int format_json_meta (yajl_gen g, notification_meta_t *meta) /* {{{ */
+{
+ if (meta == NULL)
+ return 0;
+
+ JSON_ADD (g, meta->name);
+ switch (meta->type)
+ {
+ case NM_TYPE_STRING:
+ JSON_ADD (g, meta->nm_value.nm_string);
+ break;
+ case NM_TYPE_SIGNED_INT:
+ JSON_ADDF (g, "%"PRIi64, meta->nm_value.nm_signed_int);
+ break;
+ case NM_TYPE_UNSIGNED_INT:
+ JSON_ADDF (g, "%"PRIu64, meta->nm_value.nm_unsigned_int);
+ break;
+ case NM_TYPE_DOUBLE:
+ JSON_ADDF (g, JSON_GAUGE_FORMAT, meta->nm_value.nm_double);
+ break;
+ case NM_TYPE_BOOLEAN:
+ JSON_ADD (g, meta->nm_value.nm_boolean ? "true" : "false");
+ break;
+ default:
+ ERROR ("format_json_meta: unknown meta data type %d (name \"%s\")", meta->type, meta->name);
+ yajl_gen_null (g);
+ }
+
+ return format_json_meta (g, meta->next);
+} /* }}} int format_json_meta */
+
+static int format_time (yajl_gen g, cdtime_t t) /* {{{ */
+{
+ char buffer[RFC3339NANO_SIZE] = "";
+
+ if (rfc3339nano (buffer, sizeof (buffer), t) != 0)
+ return -1;
+
+ JSON_ADD (g, buffer);
+ return 0;
+} /* }}} int format_time */
+
+static int format_alert (yajl_gen g, notification_t const *n) /* {{{ */
+{
+ yajl_gen_array_open (g);
+ yajl_gen_map_open (g); /* BEGIN alert */
+
+ /*
+ * labels
+ */
+ JSON_ADD (g, "labels");
+ yajl_gen_map_open (g); /* BEGIN labels */
+
+ JSON_ADD (g, "alertname");
+ if (strncmp (n->plugin, n->type, strlen (n->plugin)) == 0)
+ JSON_ADDF (g, "collectd_%s", n->type);
+ else
+ JSON_ADDF (g, "collectd_%s_%s", n->plugin, n->type);
+
+ JSON_ADD (g, "instance");
+ JSON_ADD (g, n->host);
+
+ /* mangling of plugin instance and type instance into labels is copied from
+ * the Prometheus collectd exporter. */
+ if (strlen (n->plugin_instance) > 0)
+ {
+ JSON_ADD (g, n->plugin);
+ JSON_ADD (g, n->plugin_instance);
+ }
+ if (strlen (n->type_instance) > 0)
+ {
+ if (strlen (n->plugin_instance) > 0)
+ JSON_ADD (g, "type");
+ else
+ JSON_ADD (g, n->plugin);
+ JSON_ADD (g, n->type_instance);
+ }
+
+ JSON_ADD (g, "severity");
+ JSON_ADD (g, (n->severity == NOTIF_FAILURE) ? "FAILURE"
+ : (n->severity == NOTIF_WARNING) ? "WARNING"
+ : (n->severity == NOTIF_OKAY) ? "OKAY"
+ : "UNKNOWN");
+
+ JSON_ADD (g, "service");
+ JSON_ADD (g, "collectd");
+
+ yajl_gen_map_close (g); /* END labels */
+
+ /*
+ * annotations
+ */
+ JSON_ADD (g, "annotations");
+ yajl_gen_map_open (g); /* BEGIN annotations */
+
+ JSON_ADD (g, "summary");
+ JSON_ADD (g, n->message);
+
+ if (format_json_meta (g, n->meta) != 0)
+ return -1;
+
+ yajl_gen_map_close (g); /* END annotations */
+
+ JSON_ADD (g, "startsAt");
+ format_time (g, n->time);
+
+ yajl_gen_map_close (g); /* END alert */
+ yajl_gen_array_close (g);
+
+ return 0;
+} /* }}} format_alert */
+
+/*
+ * Format (prometheus/alertmanager v1):
+ *
+ * [{
+ * "labels": {
+ * "alertname": "collectd_cpu",
+ * "instance": "host.example.com",
+ * "severity": "FAILURE",
+ * "service": "collectd",
+ * "cpu": "0",
+ * "type": "wait"
+ * },
+ * "annotations": {
+ * "summary": "...",
+ * // meta
+ * },
+ * "startsAt": <rfc3339 time>,
+ * "endsAt": <rfc3339 time>, // not used
+ * }]
+ */
+int format_json_notification (char *buffer, size_t buffer_size, /* {{{ */
+ notification_t const *n)
+{
+ yajl_gen g;
+ unsigned char const *out;
+#if HAVE_YAJL_V2
+ size_t unused_out_len;
+#else
+ unsigned int unused_out_len;
+#endif
+
+ if ((buffer == NULL) || (n == NULL))
+ return EINVAL;
+
+#if HAVE_YAJL_V2
+ g = yajl_gen_alloc (NULL);
+ if (g == NULL)
+ return -1;
+# if COLLECT_DEBUG
+ yajl_gen_config (g, yajl_gen_beautify, 1);
+ yajl_gen_config (g, yajl_gen_validate_utf8, 1);
+# endif
+
+#else /* !HAVE_YAJL_V2 */
+ yajl_gen_config conf = { 0 };
+# if COLLECT_DEBUG
+ conf.beautify = 1;
+ conf.indentString = " ";
+# endif
+ g = yajl_gen_alloc (&conf, NULL);
+ if (g == NULL)
+ return -1;
+#endif
+
+ if (format_alert (g, n) != 0)
+ {
+ yajl_gen_clear (g);
+ yajl_gen_free (g);
+ return -1;
+ }
+
+ /* copy to output buffer */
+ yajl_gen_get_buf (g, &out, &unused_out_len);
+ sstrncpy (buffer, (void *) out, buffer_size);
+
+ yajl_gen_clear (g);
+ yajl_gen_free (g);
+ return 0;
+} /* }}} format_json_notification */
+#else
+int format_json_notification (char *buffer, size_t buffer_size, /* {{{ */
+ notification_t const *n)
+{
+ ERROR ("format_json_notification: Not available (requires libyajl).");
+ return ENOTSUP;
+} /* }}} int format_json_notification */
+#endif
+
/* vim: set sw=2 sts=2 et fdm=marker : */
index f1fbb6e72766d7895446f322644ecedb4c70e617..a3eda30413b87b7a364640ef44623d2e3c2f4a72 100644 (file)
--- a/src/utils_format_json.h
+++ b/src/utils_format_json.h
#define UTILS_FORMAT_JSON_H 1
#include "collectd.h"
+
#include "plugin.h"
#ifndef JSON_GAUGE_FORMAT
const data_set_t *ds, const value_list_t *vl, int store_rates);
int format_json_finalize (char *buffer,
size_t *ret_buffer_fill, size_t *ret_buffer_free);
+int format_json_notification (char *buffer, size_t buffer_size,
+ notification_t const *n);
#endif /* UTILS_FORMAT_JSON_H */
diff --git a/src/utils_format_json_test.c b/src/utils_format_json_test.c
--- /dev/null
@@ -0,0 +1,170 @@
+/**
+ * collectd - src/utils_format_json_test.c
+ * Copyright (C) 2015 Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Florian octo Forster <octo at collectd.org>
+ */
+
+#include "collectd.h"
+
+#include "testing.h"
+#include "utils_format_json.h"
+#include "common.h" /* for STATIC_ARRAY_SIZE */
+
+#include <yajl/yajl_common.h>
+#include <yajl/yajl_parse.h>
+#if HAVE_YAJL_YAJL_VERSION_H
+# include <yajl/yajl_version.h>
+#endif
+#if YAJL_MAJOR > 1
+# define HAVE_YAJL_V2 1
+#endif
+
+typedef struct
+{
+ char const *key;
+ char const *value;
+} label_t;
+
+typedef struct
+{
+ label_t *expected_labels;
+ size_t expected_labels_num;
+
+ label_t *current_label;
+} test_case_t;
+
+#if HAVE_YAJL_V2
+static int test_map_key (void *ctx, unsigned char const *key, size_t key_len)
+#else
+static int test_map_key (void *ctx, unsigned char const *key, unsigned int key_len)
+#endif
+{
+ test_case_t *c = ctx;
+ size_t i;
+
+ c->current_label = NULL;
+ for (i = 0; i < c->expected_labels_num; i++)
+ {
+ label_t *l = c->expected_labels + i;
+ if ((strlen (l->key) == key_len)
+ && (strncmp (l->key, (char const *) key, key_len) == 0))
+ {
+ c->current_label = l;
+ break;
+ }
+ }
+
+ return 1; /* continue */
+}
+
+static int expect_label (char const *name, char const *got, char const *want)
+{
+ _Bool ok = (strcmp (got, want) == 0);
+ char msg[1024];
+
+ if (ok)
+ snprintf (msg, sizeof (msg), "label[\"%s\"] = \"%s\"", name, got);
+ else
+ snprintf (msg, sizeof (msg), "label[\"%s\"] = \"%s\", want \"%s\"", name, got, want);
+
+ OK1 (ok, msg);
+ return 0;
+}
+
+#if HAVE_YAJL_V2
+static int test_string (void *ctx, unsigned char const *value, size_t value_len)
+#else
+static int test_string (void *ctx, unsigned char const *value, unsigned int value_len)
+#endif
+{
+ test_case_t *c = ctx;
+
+ if (c->current_label != NULL)
+ {
+ label_t *l = c->current_label;
+ char *got;
+ int status;
+
+ got = malloc (value_len + 1);
+ memmove (got, value, value_len);
+ got[value_len] = 0;
+
+ status = expect_label (l->key, got, l->value);
+
+ free (got);
+
+ if (status != 0)
+ return 0; /* abort */
+ }
+
+ return 1; /* continue */
+}
+
+static int expect_json_labels (char *json, label_t *labels, size_t labels_num)
+{
+ yajl_callbacks funcs = {
+ .yajl_string = test_string,
+ .yajl_map_key = test_map_key,
+ };
+
+ test_case_t c = { labels, labels_num, NULL };
+
+ yajl_handle hndl;
+#if HAVE_YAJL_V2
+ CHECK_NOT_NULL (hndl = yajl_alloc (&funcs, /* alloc = */ NULL, &c));
+#else
+ CHECK_NOT_NULL (hndl = yajl_alloc (&funcs, /* config = */ NULL, /* alloc = */ NULL, &c));
+#endif
+ OK (yajl_parse (hndl, (unsigned char *) json, strlen (json)) == yajl_status_ok);
+
+ yajl_free (hndl);
+ return 0;
+}
+
+DEF_TEST(notification)
+{
+ label_t labels[] = {
+ {"summary", "this is a message"},
+ {"alertname", "collectd_unit_test"},
+ {"instance", "example.com"},
+ {"service", "collectd"},
+ {"unit", "case"},
+ };
+
+ /* 1448284606.125 ^= 1555083754651779072 */
+ notification_t n = { NOTIF_WARNING, 1555083754651779072ULL, "this is a message",
+ "example.com", "unit", "", "test", "case", NULL };
+
+ char got[1024];
+ CHECK_ZERO (format_json_notification (got, sizeof (got), &n));
+ // printf ("got = \"%s\";\n", got);
+
+ return expect_json_labels (got, labels, STATIC_ARRAY_SIZE (labels));
+}
+
+int main (void)
+{
+ RUN_TEST(notification);
+
+ END_TEST;
+}
index 6258c492a50cf9e7cd9aaa468ac057502d0f3850..41055c7b336ded0e9580f2982ba607e9be64e673 100644 (file)
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
static int kairosdb_escape_string (char *buffer, size_t buffer_size, /* {{{ */
const char *string)
{
- size_t src_pos;
size_t dst_pos;
if ((buffer == NULL) || (string == NULL))
/* Escape special characters */
/* authorize -_. and alpha num but also escapes " */
BUFFER_ADD ('"');
- for (src_pos = 0; string[src_pos] != 0; src_pos++)
+ for (size_t src_pos = 0; string[src_pos] != 0; src_pos++)
{
if (isalnum(string[src_pos]) ||
0x2d == string[src_pos] ||
char temp[512];
size_t offset = 0;
int status;
- size_t i;
memset (buffer, 0, buffer_size);
BUFFER_ADD (",\"%s\": %s", (key), temp); \
} while (0)
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
/* All value lists have a leading comma. The first one will be replaced with
* a square bracket in `format_kairosdb_finalize'. */
index 23cc862e8bc98980bc118cc684d6ad68f2cb0d49..764b0b1ed8cf2fe1cd32394f898cd76752ebec68 100644 (file)
#define UTILS_FORMAT_KAIROSDB_H 1
#include "collectd.h"
+
#include "plugin.h"
#ifndef JSON_GAUGE_FORMAT
diff --git a/src/utils_latency.c b/src/utils_latency.c
index 41af00cb14188b5e51f8a9d0e3d3e559e16a2967..c67752a376b67d1475ef0bc1c45e61aa7064ee58 100644 (file)
--- a/src/utils_latency.c
+++ b/src/utils_latency.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "utils_latency.h"
#include "common.h"
if (lc->num > 0) // if the histogram has data then iterate else skip
{
double width_change_ratio = ((double) old_bin_width) / ((double) new_bin_width);
- size_t i;
- for (i = 0; i < HISTOGRAM_NUM_BINS; i++)
+ for (size_t i = 0; i < HISTOGRAM_NUM_BINS; i++)
{
size_t new_bin = (size_t) (((double) i) * width_change_ratio);
if (i == new_bin)
if (lc == NULL)
return (NULL);
- latency_counter_reset (lc);
lc->bin_width = HISTOGRAM_DEFAULT_BIN_WIDTH;
+ latency_counter_reset (lc);
return (lc);
} /* }}} latency_counter_t *latency_counter_create */
return;
cdtime_t bin_width = lc->bin_width;
+ cdtime_t max_bin = (lc->max - 1) / lc->bin_width;
+
+/*
+ If max latency is REDUCE_THRESHOLD times less than histogram's range,
+ then cut it in half. REDUCE_THRESHOLD must be >= 2.
+ Value of 4 is selected to reduce frequent changes of bin width.
+*/
+#define REDUCE_THRESHOLD 4
+ if ((lc->num > 0) && (lc->bin_width >= HISTOGRAM_DEFAULT_BIN_WIDTH * 2)
+ && (max_bin < HISTOGRAM_NUM_BINS / REDUCE_THRESHOLD))
+ {
+ /* new bin width will be the previous power of 2 */
+ bin_width = bin_width / 2;
+
+ DEBUG("utils_latency: latency_counter_reset: max_latency = %.3f; "
+ "max_bin = %"PRIu64"; old_bin_width = %.3f; new_bin_width = %.3f;",
+ CDTIME_T_TO_DOUBLE (lc->max),
+ max_bin,
+ CDTIME_T_TO_DOUBLE (lc->bin_width),
+ CDTIME_T_TO_DOUBLE (bin_width));
+ }
+
memset (lc, 0, sizeof (*lc));
/* preserve bin width */
diff --git a/src/utils_latency.h b/src/utils_latency.h
index 2cfa71b6d8eb838e0cd643dcac860f71a7f4b3e3..cb56b082524c87c33f34cf7836b01851bd8176f6 100644 (file)
--- a/src/utils_latency.h
+++ b/src/utils_latency.h
**/
#include "collectd.h"
+
#include "utils_time.h"
struct latency_counter_s;
index f275813d59c121fbd44a5be35e6203893c6bb079..9c3b0add5f9047f98accee8ef8545618b7e0e944 100644 (file)
--- a/src/utils_latency_test.c
+++ b/src/utils_latency_test.c
#include "common.h" /* for STATIC_ARRAY_SIZE */
#include "collectd.h"
+
#include "testing.h"
#include "utils_time.h"
#include "utils_latency.h"
{ 99, 0.3, 99, 103, 20.6},
/* { -1, 0.3, 99, 103, 20.6}, see issue #1139 */
};
- size_t i;
latency_counter_t *l;
CHECK_NOT_NULL (l = latency_counter_create ());
- for (i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
+ for (size_t i = 0; i < STATIC_ARRAY_SIZE (cases); i++) {
printf ("# case %zu: DOUBLE_TO_CDTIME_T(%g) = %"PRIu64"\n",
i, cases[i].val, DOUBLE_TO_CDTIME_T (cases[i].val));
latency_counter_add (l, DOUBLE_TO_CDTIME_T (cases[i].val));
DEF_TEST(percentile)
{
- size_t i;
latency_counter_t *l;
CHECK_NOT_NULL (l = latency_counter_create ());
- for (i = 0; i < 100; i++) {
+ for (size_t i = 0; i < 100; i++) {
latency_counter_add (l, TIME_T_TO_CDTIME_T (((time_t) i) + 1));
}
diff --git a/src/utils_mount.c b/src/utils_mount.c
index a36882c475ac2143395d628c7afdb31b3c249782..b8dabb1703ae109d4d3eef20738ea41d8b19eb79 100644 (file)
--- a/src/utils_mount.c
+++ b/src/utils_mount.c
#endif
#include "collectd.h"
+
#include "utils_mount.h"
#include "common.h" /* sstrncpy() et alii */
FILE *procpt;
char uuid[16], *label = NULL;
char device[110];
- int firstPass;
int handleOnFirst;
if(uuidCache) {
return;
}
- for(firstPass = 1; firstPass >= 0; firstPass--) {
+ for(int firstPass = 1; firstPass >= 0; firstPass--) {
fseek(procpt, 0, SEEK_SET);
while(fgets(line, sizeof(line), procpt)) {
if(sscanf(line, " %d %d %d %[^\n ]",
get_spec_by_uuid(const char *s)
{
char uuid[16];
- int i;
if(strlen(s) != 36
|| s[8] != '-' || s[13] != '-' || s[18] != '-' || s[23] != '-') {
goto bad_uuid;
}
- for(i=0; i<16; i++) {
+ for(int i=0; i<16; i++) {
if(*s == '-') {
s++;
}
static cu_mount_t *cu_mount_listmntent (void)
{
cu_mount_t *last = *list;
- struct tabmntent *p;
struct mntent *mnt;
struct tabmntent *mntlist;
#endif /* COLLECT_DEBUG */
}
- for(p = mntlist; p; p = p->next) {
+ for(struct tabmntent *p = mntlist; p; p = p->next) {
char *loop = NULL, *device = NULL;
mnt = p->ment;
STRUCT_STATFS *buf;
int num;
- int i;
cu_mount_t *first = NULL;
cu_mount_t *last = NULL;
return (NULL);
}
- for (i = 0; i < num; i++)
+ for (int i = 0; i < num; i++)
{
if ((new = calloc (1, sizeof (*new))) == NULL)
break;
void cu_mount_freelist (cu_mount_t *list)
{
- cu_mount_t *this;
cu_mount_t *next;
- for (this = list; this != NULL; this = next)
+ for (cu_mount_t *this = list; this != NULL; this = next)
{
next = this->next;
diff --git a/src/utils_mount_test.c b/src/utils_mount_test.c
index dc6f79f9b8f3e2f5ae28296aee5cad414f5788a6..c084debe46381d54e6ffb95cff612e392930ced6 100644 (file)
--- a/src/utils_mount_test.c
+++ b/src/utils_mount_test.c
*/
#include "collectd.h"
+
#include "common.h"
#include "testing.h"
#include "utils_mount.h"
index f3ec71ae1c28fd23d99badabb34ef070f0bb5843..3652a666c2a73ef99a9c5563d712937cf88ffec0 100644 (file)
--- a/src/utils_parse_option.c
+++ b/src/utils_parse_option.c
**/
#include "collectd.h"
+
#include "utils_parse_option.h"
int parse_string (char **ret_buffer, char **ret_string)
diff --git a/src/utils_rrdcreate.c b/src/utils_rrdcreate.c
index 6da5167d4344a780e33e28e4654adc062dd470f5..884de8f9a77308e521a08ce2da4898492882bb47 100644 (file)
--- a/src/utils_rrdcreate.c
+++ b/src/utils_rrdcreate.c
**/
#include "collectd.h"
+
#include "common.h"
#include "utils_rrdcreate.h"
*/
static void rra_free (int rra_num, char **rra_def) /* {{{ */
{
- int i;
-
- for (i = 0; i < rra_num; i++)
+ for (int i = 0; i < rra_num; i++)
{
sfree (rra_def[i]);
}
sfree (args->filename);
if (args->argv != NULL)
{
- int i;
- for (i = 0; i < args->argc; i++)
+ for (int i = 0; i < args->argc; i++)
sfree (args->argv[i]);
sfree (args->argv);
}
int cdp_num;
int cdp_len;
- int i, j;
/* The stepsize we use here: If it is user-set, use it. If not, use the
* interval of the value-list. */
rra_num = 0;
cdp_len = 0;
- for (i = 0; i < rts_num; i++)
+ for (int i = 0; i < rts_num; i++)
{
int span = rts[i];
cdp_num = (int) ceil (((double) span)
/ ((double) (cdp_len * ss)));
- for (j = 0; j < rra_types_num; j++)
+ for (int j = 0; j < rra_types_num; j++)
{
char buffer[128];
int status;
static void ds_free (int ds_num, char **ds_def) /* {{{ */
{
- int i;
-
- for (i = 0; i < ds_num; i++)
+ for (int i = 0; i < ds_num; i++)
if (ds_def[i] != NULL)
free (ds_def[i]);
free (ds_def);
diff --git a/src/utils_vl_lookup.c b/src/utils_vl_lookup.c
index 6081c90ef29d24801ce2f36c8062e61be9d2824c..2ca9ddf8e551bd43691dd9b3f4b5d0f3c54188b9 100644 (file)
--- a/src/utils_vl_lookup.c
+++ b/src/utils_vl_lookup.c
#include "collectd.h"
+
#include <pthread.h>
#include <regex.h>
index 668a8d0ca4975c3fc669ade6834ad0f5cf97445c..44660638c4234b79a85e77566f338b7383f33bcd 100644 (file)
**/
#include "collectd.h"
+
#include "testing.h"
#include "utils_vl_lookup.h"
diff --git a/src/uuid.c b/src/uuid.c
index 3836e5215f5ab93df9181915e6fbbafed26c11bb..89766268740aa7f7a40ab81bbdb21c40e8ed35e4 100644 (file)
--- a/src/uuid.c
+++ b/src/uuid.c
/**
* collectd - src/uuid.c
* Copyright (C) 2007 Red Hat Inc.
+ * Copyright (C) 2015 Ruben Kerkhof
*
* 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
**/
#include "collectd.h"
+
#include "common.h"
#include "configfile.h"
#include "plugin.h"
+#if HAVE_SYS_SYSCTL_H
+#include <sys/sysctl.h>
+#endif
+
#if HAVE_LIBHAL_H
#include <libhal.h>
#endif
{
int len;
- if (!uuid) return 0;
+ if (!uuid)
+ return (0);
len = strlen (uuid);
if (len < UUID_PRINTABLE_COMPACT_LENGTH)
- return 0;
+ return (0);
while (*uuid) {
- if (!isxdigit ((int)*uuid) && *uuid != '-') return 0;
+ if (!isxdigit ((int)*uuid) && *uuid != '-')
+ return (0);
uuid++;
}
- return 1;
+ return (1);
}
static char *
if (!looks_like_a_uuid (fields[1]))
continue;
- return strdup (fields[1]);
+ return (strdup (fields[1]));
}
- return NULL;
+ return (NULL);
}
static char *
uuid_get_from_dmidecode(void)
{
- FILE *dmidecode = popen("dmidecode 2>/dev/null", "r");
+ FILE *dmidecode = popen("dmidecode -t system 2>/dev/null", "r");
char *uuid;
- if (!dmidecode) {
- return NULL;
- }
+ if (!dmidecode)
+ return (NULL);
uuid = uuid_parse_dmidecode(dmidecode);
pclose(dmidecode);
- return uuid;
+ return (uuid);
+}
+
+#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__)
+static char *
+uuid_get_from_sysctlbyname(const char *name)
+{
+ char uuid[UUID_PRINTABLE_NORMAL_LENGTH + 1];
+ size_t len = sizeof (uuid);
+ if (sysctlbyname(name, &uuid, &len, NULL, 0) == -1)
+ return NULL;
+ return (strdup (uuid));
+}
+#elif defined(__OpenBSD__)
+static char *
+uuid_get_from_sysctl(void)
+{
+ char uuid[UUID_PRINTABLE_NORMAL_LENGTH + 1];
+ size_t len = sizeof (uuid);
+ int mib[2];
+
+ mib[0] = CTL_HW;
+ mib[1] = HW_UUID;
+
+ if (sysctl(mib, 2, uuid, &len, NULL, 0) == -1)
+ return NULL;
+ return (strdup (uuid));
}
+#endif
#if HAVE_LIBHAL_H
dbus_error_init(&error);
- if (!(con = dbus_bus_get(DBUS_BUS_SYSTEM, &error)) ) {
+ if (!(con = dbus_bus_get(DBUS_BUS_SYSTEM, &error)))
goto bailout_nobus;
- }
ctx = libhal_ctx_new();
libhal_ctx_set_dbus_connection(ctx, con);
- if (!libhal_ctx_init(ctx, &error)) {
+ if (!libhal_ctx_init(ctx, &error))
goto bailout;
- }
if (!libhal_device_property_exists(ctx,
UUID_PATH,
UUID_PROPERTY,
- &error)) {
+ &error))
goto bailout;
- }
char *uuid = libhal_device_get_property_string(ctx,
UUID_PATH,
UUID_PROPERTY,
&error);
- if (looks_like_a_uuid (uuid)) {
- return uuid;
- }
+ if (looks_like_a_uuid (uuid))
+ return (uuid);
bailout:
{
DBusError ctxerror;
dbus_error_init(&ctxerror);
- if (!(libhal_ctx_shutdown(ctx, &ctxerror))) {
+ if (!(libhal_ctx_shutdown(ctx, &ctxerror)))
dbus_error_free(&ctxerror);
- }
}
libhal_ctx_free(ctx);
- //dbus_connection_unref(con);
bailout_nobus:
- if (dbus_error_is_set(&error)) {
- /*printf("Error %s\n", error.name);*/
+ if (dbus_error_is_set(&error))
dbus_error_free(&error);
- }
- return NULL;
+ return (NULL);
}
#endif
file = fopen (path, "r");
if (file == NULL)
- return NULL;
+ return (NULL);
if (!fgets(uuid, sizeof(uuid), file)) {
fclose(file);
- return NULL;
+ return (NULL);
}
fclose(file);
strstripnewline (uuid);
- return strdup (uuid);
+ return (strdup (uuid));
}
static char *
char *uuid;
/* Check /etc/uuid / UUIDFile before any other method. */
- if ((uuid = uuid_get_from_file(uuidfile ? uuidfile : "/etc/uuid")) != NULL){
- return uuid;
- }
+ if ((uuid = uuid_get_from_file(uuidfile ? uuidfile : "/etc/uuid")) != NULL)
+ return (uuid);
+
+#if defined(__APPLE__)
+ if ((uuid = uuid_get_from_sysctlbyname("kern.uuid")) != NULL)
+ return (uuid);
+#elif defined(__FreeBSD__)
+ if ((uuid = uuid_get_from_sysctlbyname("kern.hostuuid")) != NULL)
+ return (uuid);
+#elif defined(__NetBSD__)
+ if ((uuid = uuid_get_from_sysctlbyname("machdep.dmi.system-uuid")) != NULL)
+ return (uuid);
+#elif defined(__OpenBSD__)
+ if ((uuid = uuid_get_from_sysctl()) != NULL)
+ return (uuid);
+#elif defined(__linux__)
+ if ((uuid = uuid_get_from_file("/sys/class/dmi/id/product_uuid")) != NULL)
+ return (uuid);
+#endif
#if HAVE_LIBHAL_H
- if ((uuid = uuid_get_from_hal()) != NULL) {
- return uuid;
- }
+ if ((uuid = uuid_get_from_hal()) != NULL)
+ return (uuid);
#endif
- if ((uuid = uuid_get_from_dmidecode()) != NULL) {
- return uuid;
- }
+ if ((uuid = uuid_get_from_dmidecode()) != NULL)
+ return (uuid);
- if ((uuid = uuid_get_from_file("/sys/hypervisor/uuid")) != NULL) {
- return uuid;
- }
+#if defined(__linux__)
+ if ((uuid = uuid_get_from_file("/sys/hypervisor/uuid")) != NULL)
+ return (uuid);
+#endif
- return NULL;
+ return (NULL);
}
static int
if (strcasecmp (key, "UUIDFile") == 0) {
char *tmp = strdup (value);
if (tmp == NULL)
- return -1;
+ return (-1);
sfree (uuidfile);
uuidfile = tmp;
- } else {
- return 1;
+ return (0);
}
- return 0;
+ return (1);
}
static int
if (uuid) {
sstrncpy (hostname_g, uuid, DATA_MAX_NAME_LEN);
sfree (uuid);
- return 0;
+ return (0);
}
WARNING ("uuid: could not read UUID using any known method");
- return 0;
+ return (0);
}
void module_register (void)
diff --git a/src/varnish.c b/src/varnish.c
index 771d4a41c47545b2c1e4ef9d3da5b13d5e6693ed..bc6d294a976ec3e0c8cd7de7cc3a432b0851f363 100644 (file)
--- a/src/varnish.c
+++ b/src/varnish.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
user_config_t *conf;
user_data_t ud;
char callback_name[DATA_MAX_NAME_LEN];
- int i;
conf = calloc (1, sizeof (*conf));
if (conf == NULL)
return (EINVAL);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int varnish_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/virt.c b/src/virt.c
index 16bb77b101505cdd592977736248be540148cf1d..7df51c1309a39817d3d4ff55eaf202dc03ee3b6e 100644 (file)
--- a/src/virt.c
+++ b/src/virt.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static void
init_value_list (value_list_t *vl, virDomainPtr dom)
{
- int i, n;
+ int n;
const char *name;
char uuid[VIR_UUID_STRING_BUFLEN];
vl->host[0] = '\0';
/* Construct the hostname field according to HostnameFormat. */
- for (i = 0; i < HF_MAX_FIELDS; ++i) {
+ for (int i = 0; i < HF_MAX_FIELDS; ++i) {
if (hostname_format[i] == hf_none)
continue;
vl->host[sizeof (vl->host) - 1] = '\0';
/* Construct the plugin instance field according to PluginInstanceFormat. */
- for (i = 0; i < PLGINST_MAX_FIELDS; ++i) {
+ for (int i = 0; i < PLGINST_MAX_FIELDS; ++i) {
if (plugin_instance_format[i] == plginst_none)
continue;
if (strcasecmp (key, "HostnameFormat") == 0) {
char *value_copy;
char *fields[HF_MAX_FIELDS];
- int i, n;
+ int n;
value_copy = strdup (value);
if (value_copy == NULL) {
return -1;
}
- for (i = 0; i < n; ++i) {
+ for (int i = 0; i < n; ++i) {
if (strcasecmp (fields[i], "hostname") == 0)
hostname_format[i] = hf_hostname;
else if (strcasecmp (fields[i], "name") == 0)
}
sfree (value_copy);
- for (i = n; i < HF_MAX_FIELDS; ++i)
+ for (int i = n; i < HF_MAX_FIELDS; ++i)
hostname_format[i] = hf_none;
return 0;
if (strcasecmp (key, "PluginInstanceFormat") == 0) {
char *value_copy;
char *fields[PLGINST_MAX_FIELDS];
- int i, n;
+ int n;
value_copy = strdup (value);
if (value_copy == NULL) {
return -1;
}
- for (i = 0; i < n; ++i) {
+ for (int i = 0; i < n; ++i) {
if (strcasecmp (fields[i], "none") == 0) {
plugin_instance_format[i] = plginst_none;
break;
}
sfree (value_copy);
- for (i = n; i < PLGINST_MAX_FIELDS; ++i)
+ for (int i = n; i < PLGINST_MAX_FIELDS; ++i)
plugin_instance_format[i] = plginst_none;
return 0;
lv_read (void)
{
time_t t;
- int i;
if (conn == NULL) {
/* `conn_string == NULL' is acceptable. */
}
#if 0
- for (i = 0; i < nr_domains; ++i)
+ for (int i = 0; i < nr_domains; ++i)
fprintf (stderr, "domain %s\n", virDomainGetName (domains[i]));
- for (i = 0; i < nr_block_devices; ++i)
+ for (int i = 0; i < nr_block_devices; ++i)
fprintf (stderr, "block device %d %s:%s\n",
i, virDomainGetName (block_devices[i].dom),
block_devices[i].path);
- for (i = 0; i < nr_interface_devices; ++i)
+ for (int i = 0; i < nr_interface_devices; ++i)
fprintf (stderr, "interface device %d %s:%s\n",
i, virDomainGetName (interface_devices[i].dom),
interface_devices[i].path);
#endif
/* Get CPU usage, memory, VCPU usage for each domain. */
- for (i = 0; i < nr_domains; ++i) {
+ for (int i = 0; i < nr_domains; ++i) {
virDomainInfo info;
virVcpuInfoPtr vinfo = NULL;
virDomainMemoryStatPtr minfo = NULL;
int status;
- int j;
status = virDomainGetInfo (domains[i], &info);
if (status != 0)
continue;
}
- for (j = 0; j < info.nrVirtCpu; ++j)
+ for (int j = 0; j < info.nrVirtCpu; ++j)
vcpu_submit (vinfo[j].cpuTime,
domains[i], vinfo[j].number, "virt_vcpu");
continue;
}
- for (j = 0; j < status; j++) {
+ for (int j = 0; j < status; j++) {
memory_stats_submit ((gauge_t) minfo[j].val * 1024, domains[i], minfo[j].tag);
}
/* Get block device stats for each domain. */
- for (i = 0; i < nr_block_devices; ++i) {
+ for (int i = 0; i < nr_block_devices; ++i) {
struct _virDomainBlockStats stats;
if (virDomainBlockStats (block_devices[i].dom, block_devices[i].path,
} /* for (nr_block_devices) */
/* Get interface stats for each domain. */
- for (i = 0; i < nr_interface_devices; ++i) {
+ for (int i = 0; i < nr_interface_devices; ++i) {
struct _virDomainInterfaceStats stats;
char *display_name = NULL;
}
if (n > 0) {
- int i;
int *domids;
/* Get list of domains. */
free_domains ();
/* Fetch each domain and add it to the list, unless ignore. */
- for (i = 0; i < n; ++i) {
+ for (int i = 0; i < n; ++i) {
virDomainPtr dom = NULL;
const char *name;
char *xml = NULL;
xmlDocPtr xml_doc = NULL;
xmlXPathContextPtr xpath_ctx = NULL;
xmlXPathObjectPtr xpath_obj = NULL;
- int j;
dom = virDomainLookupByID (conn, domids[i]);
if (dom == NULL) {
xpath_obj->nodesetval == NULL)
goto cont;
- for (j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
+ for (int j = 0; j < xpath_obj->nodesetval->nodeNr; ++j) {
xmlNodePtr node;
char *path = NULL;
xmlNodeSetPtr xml_interfaces = xpath_obj->nodesetval;
- for (j = 0; j < xml_interfaces->nodeNr; ++j) {
+ for (int j = 0; j < xml_interfaces->nodeNr; ++j) {
char *path = NULL;
char *address = NULL;
xmlNodePtr xml_interface;
xml_interface = xml_interfaces->nodeTab[j];
if (!xml_interface) continue;
- xmlNodePtr child = NULL;
- for (child = xml_interface->children; child; child = child->next) {
+ for (xmlNodePtr child = xml_interface->children; child; child = child->next) {
if (child->type != XML_ELEMENT_NODE) continue;
if (xmlStrEqual(child->name, (const xmlChar *) "target")) {
static void
free_domains (void)
{
- int i;
-
if (domains) {
- for (i = 0; i < nr_domains; ++i)
+ for (int i = 0; i < nr_domains; ++i)
virDomainFree (domains[i]);
sfree (domains);
}
static void
free_block_devices (void)
{
- int i;
-
if (block_devices) {
- for (i = 0; i < nr_block_devices; ++i)
+ for (int i = 0; i < nr_block_devices; ++i)
sfree (block_devices[i].path);
sfree (block_devices);
}
static void
free_interface_devices (void)
{
- int i;
-
if (interface_devices) {
- for (i = 0; i < nr_interface_devices; ++i) {
+ for (int i = 0; i < nr_interface_devices; ++i) {
sfree (interface_devices[i].path);
sfree (interface_devices[i].address);
sfree (interface_devices[i].number);
diff --git a/src/vmem.c b/src/vmem.c
index f50170685c2fd1bb296f4d9a5d3d886cd30a9b1a..46ffa13b1108582b3de120decc22180cf569c2d3 100644 (file)
--- a/src/vmem.c
+++ b/src/vmem.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/vserver.c b/src/vserver.c
index 1d957eb3164d191183f77caff4677247eef72b27..a730593654bb79c3c0d6b58d69aef812ef2cb838 100644 (file)
--- a/src/vserver.c
+++ b/src/vserver.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/wireless.c b/src/wireless.c
index 8445af22248ea192ac0a2b6e529f60ae10856cd6..b998462598fd764c1214ebf5c7d07a7fae81a44d 100644 (file)
--- a/src/wireless.c
+++ b/src/wireless.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/write_graphite.c b/src/write_graphite.c
index 25c7a637759daa0a78ec66f5f080ffd99ef22893..77003f1cd635634d4521008d9b12e7509de1c3bb 100644 (file)
--- a/src/write_graphite.c
+++ b/src/write_graphite.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int wg_callback_init (struct wg_callback *cb)
{
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
cdtime_t now;
int status;
return (EAGAIN);
cb->last_connect_time = now;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG
+ };
if (0 == strcasecmp ("tcp", cb->protocol))
ai_hints.ai_socktype = SOCK_STREAM;
else
ai_hints.ai_socktype = SOCK_DGRAM;
- ai_list = NULL;
-
status = getaddrinfo (cb->node, cb->service, &ai_hints, &ai_list);
if (status != 0)
{
}
assert (ai_list != NULL);
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
cb->sock_fd = socket (ai_ptr->ai_family, ai_ptr->ai_socktype,
ai_ptr->ai_protocol);
continue;
}
+ set_sock_opts (cb->sock_fd);
+
status = connect (cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0)
{
struct wg_callback *cb;
user_data_t user_data = { 0 };
char callback_name[DATA_MAX_NAME_LEN];
- int i;
int status = 0;
cb = calloc (1, sizeof (*cb));
pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
C_COMPLAIN_INIT (&cb->init_complaint);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int wg_config (oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/write_http.c b/src/write_http.c
index 3c2f72489fe1d05a3c6b1fd5b923cb24fbb40e1f..d8d8c34e60f9fd0e1f2dcdb709ea63d65e61766d 100644 (file)
--- a/src/write_http.c
+++ b/src/write_http.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "utils_format_json.h"
#define WH_FORMAT_JSON 1
#define WH_FORMAT_KAIROSDB 2
int format;
+ _Bool send_metrics;
+ _Bool send_notifications;
CURL *curl;
struct curl_slist *headers;
static void wh_reset_buffer (wh_callback_t *cb) /* {{{ */
{
+ if ((cb == NULL) || (cb->send_buffer == NULL))
+ return;
+
memset (cb->send_buffer, 0, cb->send_buffer_size);
cb->send_buffer_free = cb->send_buffer_size;
cb->send_buffer_fill = 0;
}
} /* }}} wh_reset_buffer */
-static int wh_send_buffer (wh_callback_t *cb) /* {{{ */
+/* must hold cb->send_lock when calling */
+static int wh_post_nolock (wh_callback_t *cb, char const *data) /* {{{ */
{
int status = 0;
- curl_easy_setopt (cb->curl, CURLOPT_POSTFIELDS, cb->send_buffer);
+ curl_easy_setopt (cb->curl, CURLOPT_POSTFIELDS, data);
status = curl_easy_perform (cb->curl);
wh_log_http_error (cb);
status, cb->curl_errbuf);
}
return (status);
-} /* }}} wh_send_buffer */
+} /* }}} wh_post_nolock */
static int wh_callback_init (wh_callback_t *cb) /* {{{ */
{
return (0);
}
- status = wh_send_buffer (cb);
+ status = wh_post_nolock (cb, cb->send_buffer);
wh_reset_buffer (cb);
}
else if (cb->format == WH_FORMAT_JSON || cb->format == WH_FORMAT_KAIROSDB)
return (status);
}
- status = wh_send_buffer (cb);
+ status = wh_post_nolock (cb, cb->send_buffer);
wh_reset_buffer (cb);
}
else
pthread_mutex_lock (&cb->send_lock);
- if (cb->curl == NULL)
+ if (wh_callback_init (cb) != 0)
{
- status = wh_callback_init (cb);
- if (status != 0)
- {
- ERROR ("write_http plugin: wh_callback_init failed.");
- pthread_mutex_unlock (&cb->send_lock);
- return (-1);
- }
+ ERROR ("write_http plugin: wh_callback_init failed.");
+ pthread_mutex_unlock (&cb->send_lock);
+ return (-1);
}
status = wh_flush_nolock (timeout, cb);
cb = data;
- wh_flush_nolock (/* timeout = */ 0, cb);
+ if (cb->send_buffer != NULL)
+ wh_flush_nolock (/* timeout = */ 0, cb);
if (cb->curl != NULL)
{
@@ -393,16 +397,11 @@ static int wh_write_command (const data_set_t *ds, const value_list_t *vl, /* {{
}
pthread_mutex_lock (&cb->send_lock);
-
- if (cb->curl == NULL)
+ if (wh_callback_init (cb) != 0)
{
- status = wh_callback_init (cb);
- if (status != 0)
- {
- ERROR ("write_http plugin: wh_callback_init failed.");
- pthread_mutex_unlock (&cb->send_lock);
- return (-1);
- }
+ ERROR ("write_http plugin: wh_callback_init failed.");
+ pthread_mutex_unlock (&cb->send_lock);
+ return (-1);
}
if (command_len >= cb->send_buffer_free)
@@ -441,16 +440,11 @@ static int wh_write_json (const data_set_t *ds, const value_list_t *vl, /* {{{ *
int status;
pthread_mutex_lock (&cb->send_lock);
-
- if (cb->curl == NULL)
+ if (wh_callback_init (cb) != 0)
{
- status = wh_callback_init (cb);
- if (status != 0)
- {
- ERROR ("write_http plugin: wh_callback_init failed.");
- pthread_mutex_unlock (&cb->send_lock);
- return (-1);
- }
+ ERROR ("write_http plugin: wh_callback_init failed.");
+ pthread_mutex_unlock (&cb->send_lock);
+ return (-1);
}
status = format_json_value_list (cb->send_buffer,
return (-EINVAL);
cb = user_data->data;
+ assert (cb->send_metrics);
switch(cb->format) {
case WH_FORMAT_JSON:
return (status);
} /* }}} int wh_write */
+static int wh_notify (notification_t const *n, user_data_t *ud) /* {{{ */
+{
+ wh_callback_t *cb;
+ char alert[4096];
+ int status;
+
+ if ((ud == NULL) || (ud->data == NULL))
+ return (EINVAL);
+
+ cb = ud->data;
+ assert (cb->send_notifications);
+
+ status = format_json_notification (alert, sizeof (alert), n);
+ if (status != 0)
+ {
+ ERROR ("write_http plugin: formatting notification failed");
+ return status;
+ }
+
+ pthread_mutex_lock (&cb->send_lock);
+ if (wh_callback_init (cb) != 0)
+ {
+ ERROR ("write_http plugin: wh_callback_init failed.");
+ pthread_mutex_unlock (&cb->send_lock);
+ return (-1);
+ }
+
+ status = wh_post_nolock (cb, alert);
+ pthread_mutex_unlock (&cb->send_lock);
+
+ return (status);
+} /* }}} int wh_notify */
+
static int config_set_format (wh_callback_t *cb, /* {{{ */
oconfig_item_t *ci)
{
user_data_t user_data = { 0 };
char callback_name[DATA_MAX_NAME_LEN];
int status = 0;
- int i;
cb = calloc (1, sizeof (*cb));
if (cb == NULL)
cb->timeout = 0;
cb->log_http_error = 0;
cb->headers = NULL;
-
+ cb->send_metrics = 1;
+ cb->send_notifications = 0;
pthread_mutex_init (&cb->send_lock, /* attr = */ NULL);
if (strcasecmp ("URL", ci->key) == 0)
cf_util_get_string (ci, &cb->location);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
}
else if (strcasecmp ("Format", child->key) == 0)
status = config_set_format (cb, child);
+ else if (strcasecmp ("Metrics", child->key) == 0)
+ cf_util_get_boolean (child, &cb->send_metrics);
+ else if (strcasecmp ("Notifications", child->key) == 0)
+ cf_util_get_boolean (child, &cb->send_notifications);
else if (strcasecmp ("StoreRates", child->key) == 0)
status = cf_util_get_boolean (child, &cb->store_rates);
else if (strcasecmp ("BufferSize", child->key) == 0)
return (-1);
}
+ if (!cb->send_metrics && !cb->send_notifications)
+ {
+ ERROR ("write_http plugin: Neither metrics nor notifications "
+ "are enabled for \"%s\".", cb->name);
+ wh_callback_free (cb);
+ return (-1);
+ }
+
if (cb->low_speed_limit > 0)
cb->low_speed_time = CDTIME_T_TO_TIME_T(plugin_get_interval());
plugin_register_flush (callback_name, wh_flush, &user_data);
user_data.free_func = wh_callback_free;
- plugin_register_write (callback_name, wh_write, &user_data);
+
+ if (cb->send_metrics)
+ {
+ plugin_register_write (callback_name, wh_write, &user_data);
+ user_data.free_func = NULL;
+
+ plugin_register_flush (callback_name, wh_flush, &user_data);
+ }
+
+ if (cb->send_notifications)
+ {
+ plugin_register_notification (callback_name, wh_notify, &user_data);
+ user_data.free_func = NULL;
+ }
return (0);
} /* }}} int wh_config_node */
static int wh_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/write_kafka.c b/src/write_kafka.c
index 6b5bc398dcb8cbf3e2c75353e96faf1f926db230..6364c6c32eaec57f9629d11c9653d91d0c6458c7 100644 (file)
--- a/src/write_kafka.c
+++ b/src/write_kafka.c
*/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{ */
{
int status;
- int i;
struct kafka_topic_context *tctx;
char *key = NULL;
char *val;
@@ -292,7 +292,7 @@ static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{
goto errout;
}
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
/*
* The code here could be simplified but makes room
* for easy adding of new options later on.
@@ -411,7 +411,6 @@ static void kafka_config_topic(rd_kafka_conf_t *conf, oconfig_item_t *ci) /* {{{
static int kafka_config(oconfig_item_t *ci) /* {{{ */
{
- int i;
oconfig_item_t *child;
rd_kafka_conf_t *conf;
rd_kafka_conf_res_t ret;
WARNING("cannot allocate kafka configuration.");
return -1;
}
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
child = &ci->children[i];
if (strcasecmp("Topic", child->key) == 0) {
diff --git a/src/write_log.c b/src/write_log.c
index 25ff55e2c509638481b96fd8c7035d23c3d73658..3c599784bb835b20ad45a3772ef36acc3d41d8ae 100644 (file)
--- a/src/write_log.c
+++ b/src/write_log.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
diff --git a/src/write_mongodb.c b/src/write_mongodb.c
index fb80ba28eeb7370b0c4689a07448da37522e6cc0..8fb13c3486bef46f5caa6abb7c3634f6385d0e43 100644 (file)
--- a/src/write_mongodb.c
+++ b/src/write_mongodb.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
{
bson *ret;
gauge_t *rates;
- int i;
ret = bson_alloc (); /* matched by bson_dealloc() */
if (ret == NULL)
bson_append_string (ret, "type_instance", vl->type_instance);
bson_append_start_array (ret, "values"); /* {{{ */
- for (i = 0; i < ds->ds_num; i++)
+ for (int i = 0; i < ds->ds_num; i++)
{
char key[16];
bson_append_finish_array (ret); /* }}} values */
bson_append_start_array (ret, "dstypes"); /* {{{ */
- for (i = 0; i < ds->ds_num; i++)
+ for (int i = 0; i < ds->ds_num; i++)
{
char key[16];
bson_append_finish_array (ret); /* }}} dstypes */
bson_append_start_array (ret, "dsnames"); /* {{{ */
- for (i = 0; i < ds->ds_num; i++)
+ for (int i = 0; i < ds->ds_num; i++)
{
char key[16];
{
wm_node_t *node;
int status;
- int i;
node = calloc (1, sizeof (*node));
if (node == NULL)
return (status);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int wm_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/write_redis.c b/src/write_redis.c
index 4ec75d59b269ad6b4a671c596b6ad3123ce42fb5..135a458785ba55da955ea5c3c206a1467c3f4269 100644 (file)
--- a/src/write_redis.c
+++ b/src/write_redis.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
wr_node_t *node;
int timeout;
int status;
- int i;
node = calloc (1, sizeof (*node));
if (node == NULL)
return (status);
}
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int wr_config (oconfig_item_t *ci) /* {{{ */
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/write_riemann.c b/src/write_riemann.c
index 261327a37b750796c603e990650cb45e70e5d89a..f143723431e0dafd8b88259a5e7d074be3e0c359 100644 (file)
--- a/src/write_riemann.c
+++ b/src/write_riemann.c
}
}
+ set_sock_opts(riemann_client_get_fd(host->client));
+
c_release(LOG_INFO, &host->init_complaint,
"write_riemann plugin: Successfully connected to %s:%d", node,
port);
riemann_event_t *event;
char service_buffer[6 * DATA_MAX_NAME_LEN];
char const *severity;
- notification_meta_t *meta;
- size_t i;
switch (n->severity) {
case NOTIF_OKAY:
riemann_event_string_attribute_add(event, "type_instance",
n->type_instance);
- for (i = 0; i < riemann_attrs_num; i += 2)
+ for (size_t i = 0; i < riemann_attrs_num; i += 2)
riemann_event_string_attribute_add(event, riemann_attrs[i],
riemann_attrs[i + 1]);
- for (i = 0; i < riemann_tags_num; i++)
+ for (size_t i = 0; i < riemann_tags_num; i++)
riemann_event_tag_add(event, riemann_tags[i]);
if (n->message[0] != 0)
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) {
+ for (notification_meta_t *meta = n->meta; meta != NULL; meta = meta->next) {
if (strcasecmp("CurrentValue", meta->name) == 0 &&
meta->type == NM_TYPE_DOUBLE) {
riemann_event_set(event, RIEMANN_EVENT_FIELD_METRIC_D,
index a4249ecf7468c451b8bcb0911b38b921c47180d4..f2ba9dc8c9609c2b26961cda2698ab391e90e1b1 100644 (file)
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "utils_avltree.h"
int *statuses)
{ /* {{{ */
int ret = -1;
- size_t i;
int status;
gauge_t values_copy[ds->ds_num];
}
/* Prepare `sum' and `num'. */
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
if (!isnan (values[i]))
{
num++;
if ((num == 0) /* All data sources are undefined. */
|| (sum == 0.0)) /* Sum is zero, cannot calculate percentage. */
{
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
values_copy[i] = NAN;
}
else /* We can actually calculate the percentage. */
{
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
values_copy[i] = 100.0 * values[i] / sum;
}
} /* if (UT_FLAG_PERCENTAGE) */
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
status = ut_check_one_data_source (ds, vl, th, values_copy, i);
if (status != -1) {
diff --git a/src/write_sensu.c b/src/write_sensu.c
index d37792b4f5e589ef5d764e3b571c4d87e4215692..6cb499437983f3c8c42e24a601d4c58c4a331c2a 100644 (file)
--- a/src/write_sensu.c
+++ b/src/write_sensu.c
#define _GNU_SOURCE
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
#include "configfile.h"
#define SENSU_HOST "localhost"
#define SENSU_PORT "3030"
+#ifdef HAVE_ASPRINTF
+#define my_asprintf asprintf
+#define my_vasprintf vasprintf
+#else
+/*
+ * asprintf() is available from Solaris 10 update 11.
+ * For older versions, use asprintf() portable implementation from
+ * https://github.com/littlstar/asprintf.c/blob/master/
+ * copyright (c) 2014 joseph werle <joseph.werle@gmail.com> under MIT license.
+ */
+
+static int my_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;
+}
+
+static int my_asprintf(char **str, const char *fmt, ...) {
+ int size = 0;
+ va_list args;
+ // init variadic argumens
+ va_start(args, fmt);
+ // format and get size
+ size = my_vasprintf(str, fmt, args);
+ // toss args
+ va_end(args);
+ return size;
+}
+
+#endif
+
struct str_list {
int nb_strs;
char **strs;
static void free_str_list(struct str_list *strs) /* {{{ */
{
- int i;
- for (i=0; i<strs->nb_strs; i++)
+ for (int i=0; i<strs->nb_strs; i++)
free(strs->strs[i]);
free(strs->strs);
}
static int sensu_connect(struct sensu_host *host) /* {{{ */
{
int e;
- struct addrinfo *ai, hints;
char const *node;
char const *service;
// Resolve the target if we haven't done already
if (!(host->flags & F_READY)) {
- memset(&hints, 0, sizeof(hints));
memset(&service, 0, sizeof(service));
host->res = NULL;
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
-#ifdef AI_ADDRCONFIG
- hints.ai_flags |= AI_ADDRCONFIG;
-#endif
node = (host->node != NULL) ? host->node : SENSU_HOST;
service = (host->service != NULL) ? host->service : SENSU_PORT;
- if ((e = getaddrinfo(node, service, &hints, &(host->res))) != 0) {
+ struct addrinfo ai_hints = {
+ .ai_family = AF_INET,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM
+ };
+
+ if ((e = getaddrinfo(node, service, &ai_hints, &(host->res))) != 0) {
ERROR("write_sensu plugin: Unable to resolve host \"%s\": %s",
node, gai_strerror(e));
return -1;
struct linger so_linger;
host->s = -1;
- for (ai = host->res; ai != NULL; ai = ai->ai_next) {
+ for (struct addrinfo *ai = host->res; ai != NULL; ai = ai->ai_next) {
// create the socket
if ((host->s = socket(ai->ai_family,
ai->ai_socktype,
if (setsockopt(host->s, SOL_SOCKET, SO_LINGER, &so_linger, sizeof so_linger) != 0)
WARNING("write_sensu plugin: failed to set socket close() lingering");
+ set_sock_opts(host->s);
+
// connect the socket
if (connect(host->s, ai->ai_addr, ai->ai_addrlen) != 0) {
close(host->s);
@@ -178,7 +228,6 @@ static char *build_json_str_list(const char *tag, struct str_list const *list) /
int res;
char *ret_str = NULL;
char *temp_str;
- int i;
if (list->nb_strs == 0) {
ret_str = malloc(sizeof(char));
if (ret_str == NULL) {
@@ -188,14 +237,14 @@ static char *build_json_str_list(const char *tag, struct str_list const *list) /
ret_str[0] = '\0';
}
- res = asprintf(&temp_str, "\"%s\": [\"%s\"", tag, list->strs[0]);
+ res = my_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++) {
- res = asprintf(&ret_str, "%s, \"%s\"", temp_str, list->strs[i]);
+ for (int i=1; i<list->nb_strs; i++) {
+ res = my_asprintf(&ret_str, "%s, \"%s\"", temp_str, list->strs[i]);
free(temp_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
@@ -203,7 +252,7 @@ static char *build_json_str_list(const char *tag, struct str_list const *list) /
}
temp_str = ret_str;
}
- res = asprintf(&ret_str, "%s]", temp_str);
+ res = my_asprintf(&ret_str, "%s]", temp_str);
free(temp_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
static void in_place_replace_sensu_name_reserved(char *orig_name) /* {{{ */
{
- int i;
int len=strlen(orig_name);
- for (i=0; i<len; i++) {
+ for (int i=0; i<len; i++) {
// some plugins like ipmi generate special characters in metric name
switch(orig_name[i]) {
case '(': orig_name[i] = '_'; break;
{
char name_buffer[5 * DATA_MAX_NAME_LEN];
char service_buffer[6 * DATA_MAX_NAME_LEN];
- size_t i;
char *ret_str;
char *temp_str;
char *value_str;
}
}
else {
- res = asprintf(&ret_str, "%s, %s", part1, handlers_str);
+ res = my_asprintf(&ret_str, "%s, %s", part1, handlers_str);
free(handlers_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
}
// incorporate the plugin name information
- res = asprintf(&temp_str, "%s, \"collectd_plugin\": \"%s\"", ret_str, vl->plugin);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin\": \"%s\"", ret_str, vl->plugin);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
ret_str = temp_str;
// incorporate the plugin type
- res = asprintf(&temp_str, "%s, \"collectd_plugin_type\": \"%s\"", ret_str, vl->type);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin_type\": \"%s\"", ret_str, vl->type);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// incorporate the plugin instance if any
if (vl->plugin_instance[0] != 0) {
- res = asprintf(&temp_str, "%s, \"collectd_plugin_instance\": \"%s\"", ret_str, vl->plugin_instance);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin_instance\": \"%s\"", ret_str, vl->plugin_instance);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// incorporate the plugin type instance if any
if (vl->type_instance[0] != 0) {
- res = asprintf(&temp_str, "%s, \"collectd_plugin_type_instance\": \"%s\"", ret_str, vl->type_instance);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin_type_instance\": \"%s\"", ret_str, vl->type_instance);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
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));
- res = asprintf(&temp_str, "%s, \"collectd_data_source_type\": \"%s\"", ret_str, ds_type);
+ res = my_asprintf(&temp_str, "%s, \"collectd_data_source_type\": \"%s\"", ret_str, ds_type);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
}
ret_str = temp_str;
} else {
- res = asprintf(&temp_str, "%s, \"collectd_data_source_type\": \"%s\"", ret_str, DS_TYPE_TO_STRING(ds->ds[index].type));
+ res = my_asprintf(&temp_str, "%s, \"collectd_data_source_type\": \"%s\"", ret_str, DS_TYPE_TO_STRING(ds->ds[index].type));
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
}
// incorporate the data source name
- res = asprintf(&temp_str, "%s, \"collectd_data_source_name\": \"%s\"", ret_str, ds->ds[index].name);
+ res = my_asprintf(&temp_str, "%s, \"collectd_data_source_name\": \"%s\"", ret_str, ds->ds[index].name);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
{
char ds_index[DATA_MAX_NAME_LEN];
ssnprintf (ds_index, sizeof (ds_index), "%zu", index);
- res = asprintf(&temp_str, "%s, \"collectd_data_source_index\": %s", ret_str, ds_index);
+ res = my_asprintf(&temp_str, "%s, \"collectd_data_source_index\": %s", ret_str, ds_index);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
}
// add key value attributes from config if any
- for (i = 0; i < sensu_attrs_num; i += 2) {
- res = asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, sensu_attrs[i], sensu_attrs[i+1]);
+ for (size_t i = 0; i < sensu_attrs_num; i += 2) {
+ res = my_asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, sensu_attrs[i], sensu_attrs[i+1]);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// incorporate sensu tags from config if any
if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) {
- res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags);
+ res = my_asprintf(&temp_str, "%s, %s", ret_str, sensu_tags);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// calculate the value and set to a string
if (ds->ds[index].type == DS_TYPE_GAUGE) {
- res = asprintf(&value_str, GAUGE_FORMAT, vl->values[index].gauge);
+ res = my_asprintf(&value_str, GAUGE_FORMAT, vl->values[index].gauge);
if (res == -1) {
free(ret_str);
ERROR("write_sensu plugin: Unable to alloc memory");
return NULL;
}
} else if (rates != NULL) {
- res = asprintf(&value_str, GAUGE_FORMAT, rates[index]);
+ res = my_asprintf(&value_str, GAUGE_FORMAT, rates[index]);
if (res == -1) {
free(ret_str);
ERROR("write_sensu plugin: Unable to alloc memory");
}
} else {
if (ds->ds[index].type == DS_TYPE_DERIVE) {
- res = asprintf(&value_str, "%"PRIi64, vl->values[index].derive);
+ res = my_asprintf(&value_str, "%"PRIi64, vl->values[index].derive);
if (res == -1) {
free(ret_str);
ERROR("write_sensu plugin: Unable to alloc memory");
}
}
else if (ds->ds[index].type == DS_TYPE_ABSOLUTE) {
- res = asprintf(&value_str, "%"PRIu64, vl->values[index].absolute);
+ res = my_asprintf(&value_str, "%"PRIu64, vl->values[index].absolute);
if (res == -1) {
free(ret_str);
ERROR("write_sensu plugin: Unable to alloc memory");
}
}
else {
- res = asprintf(&value_str, "%llu", vl->values[index].counter);
+ res = my_asprintf(&value_str, "%llu", vl->values[index].counter);
if (res == -1) {
free(ret_str);
ERROR("write_sensu plugin: Unable to alloc memory");
in_place_replace_sensu_name_reserved(service_buffer);
// finalize the buffer by setting the output and closing curly bracket
- res = asprintf(&temp_str, "%s, \"output\": \"%s %s %ld\"}\n", ret_str, service_buffer, value_str, CDTIME_T_TO_TIME_T(vl->time));
+ res = my_asprintf(&temp_str, "%s, \"output\": \"%s %s %lld\"}\n",ret_str, service_buffer, value_str, (long long)CDTIME_T_TO_TIME_T(vl->time));
free(ret_str);
free(value_str);
if (res == -1) {
{
char service_buffer[6 * DATA_MAX_NAME_LEN];
char const *severity;
- notification_meta_t *meta;
char *ret_str;
char *temp_str;
int status;
severity = "UNKNOWN";
status = 3;
}
- res = asprintf(&temp_str, "{\"status\": %d", status);
+ res = my_asprintf(&temp_str, "{\"status\": %d", status);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
return NULL;
ret_str = temp_str;
// incorporate the timestamp
- res = asprintf(&temp_str, "%s, \"timestamp\": %ld", ret_str, CDTIME_T_TO_TIME_T(n->time));
+ res = my_asprintf(&temp_str, "%s, \"timestamp\": %lld", ret_str, (long long)CDTIME_T_TO_TIME_T(n->time));
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
}
// incorporate the handlers
if (strlen(handlers_str) != 0) {
- res = asprintf(&temp_str, "%s, %s", ret_str, handlers_str);
+ res = my_asprintf(&temp_str, "%s, %s", ret_str, handlers_str);
free(ret_str);
free(handlers_str);
if (res == -1) {
// incorporate the plugin name information if any
if (n->plugin[0] != 0) {
- res = asprintf(&temp_str, "%s, \"collectd_plugin\": \"%s\"", ret_str, n->plugin);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin\": \"%s\"", ret_str, n->plugin);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// incorporate the plugin type if any
if (n->type[0] != 0) {
- res = asprintf(&temp_str, "%s, \"collectd_plugin_type\": \"%s\"", ret_str, n->type);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin_type\": \"%s\"", ret_str, n->type);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// incorporate the plugin instance if any
if (n->plugin_instance[0] != 0) {
- res = asprintf(&temp_str, "%s, \"collectd_plugin_instance\": \"%s\"", ret_str, n->plugin_instance);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin_instance\": \"%s\"", ret_str, n->plugin_instance);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// incorporate the plugin type instance if any
if (n->type_instance[0] != 0) {
- res = asprintf(&temp_str, "%s, \"collectd_plugin_type_instance\": \"%s\"", ret_str, n->type_instance);
+ res = my_asprintf(&temp_str, "%s, \"collectd_plugin_type_instance\": \"%s\"", ret_str, n->type_instance);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// add key value attributes from config if any
for (i = 0; i < sensu_attrs_num; i += 2) {
- res = asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, sensu_attrs[i], sensu_attrs[i+1]);
+ res = my_asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, sensu_attrs[i], sensu_attrs[i+1]);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
// incorporate sensu tags from config if any
if ((sensu_tags != NULL) && (strlen(sensu_tags) != 0)) {
- res = asprintf(&temp_str, "%s, %s", ret_str, sensu_tags);
+ res = my_asprintf(&temp_str, "%s, %s", ret_str, sensu_tags);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
n->type, n->type_instance, host->separator);
// replace sensu event name chars that are considered illegal
in_place_replace_sensu_name_reserved(service_buffer);
- res = asprintf(&temp_str, "%s, \"name\": \"%s\"", ret_str, &service_buffer[1]);
+ res = my_asprintf(&temp_str, "%s, \"name\": \"%s\"", ret_str, &service_buffer[1]);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
free(ret_str);
return NULL;
}
- res = asprintf(&temp_str, "%s, \"output\": \"%s - %s\"", ret_str, severity, msg);
+ res = my_asprintf(&temp_str, "%s, \"output\": \"%s - %s\"", ret_str, severity, msg);
free(ret_str);
free(msg);
if (res == -1) {
}
// Pull in values from threshold and add extra attributes
- for (meta = n->meta; meta != NULL; meta = meta->next) {
+ for (notification_meta_t *meta = n->meta; meta != NULL; meta = meta->next) {
if (strcasecmp("CurrentValue", meta->name) == 0 && meta->type == NM_TYPE_DOUBLE) {
- res = asprintf(&temp_str, "%s, \"current_value\": \"%.8f\"", ret_str, meta->nm_value.nm_double);
+ res = my_asprintf(&temp_str, "%s, \"current_value\": \"%.8f\"", ret_str, meta->nm_value.nm_double);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
ret_str = temp_str;
}
if (meta->type == NM_TYPE_STRING) {
- res = asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, meta->name, meta->nm_value.nm_string);
+ res = my_asprintf(&temp_str, "%s, \"%s\": \"%s\"", ret_str, meta->name, meta->nm_value.nm_string);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
}
// close the curly bracket
- res = asprintf(&temp_str, "%s}\n", ret_str);
+ res = my_asprintf(&temp_str, "%s}\n", ret_str);
free(ret_str);
if (res == -1) {
ERROR("write_sensu plugin: Unable to alloc memory");
int statuses[vl->values_len];
struct sensu_host *host = ud->data;
gauge_t *rates = NULL;
- size_t i;
char *msg;
pthread_mutex_lock(&host->lock);
return -1;
}
}
- for (i = 0; i < vl->values_len; i++) {
+ for (size_t i = 0; i < vl->values_len; i++) {
msg = sensu_value_to_json(host, ds, vl, (int) i, rates, statuses[i]);
if (msg == NULL) {
sfree(rates);
{
struct sensu_host *host = NULL;
int status = 0;
- int i;
oconfig_item_t *child;
char callback_name[DATA_MAX_NAME_LEN];
user_data_t ud;
return -1;
}
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
child = &ci->children[i];
status = 0;
static int sensu_config(oconfig_item_t *ci) /* {{{ */
{
- int i;
oconfig_item_t *child;
int status;
struct str_list sensu_tags_arr;
sensu_tags_arr.nb_strs = 0;
sensu_tags_arr.strs = NULL;
- for (i = 0; i < ci->children_num; i++) {
+ for (int i = 0; i < ci->children_num; i++) {
child = &ci->children[i];
if (strcasecmp("Node", child->key) == 0) {
diff --git a/src/write_tsdb.c b/src/write_tsdb.c
index a044b6819a64a24ef51cfed8c3235422ef60dcf6..bf49ba5f2b10ea553509dbda92346d4eded8fc51 100644 (file)
--- a/src/write_tsdb.c
+++ b/src/write_tsdb.c
*/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
#include "configfile.h"
static int wt_callback_init(struct wt_callback *cb)
{
- struct addrinfo ai_hints = { 0 };
struct addrinfo *ai_list;
- struct addrinfo *ai_ptr;
int status;
const char *node = cb->node ? cb->node : WT_DEFAULT_NODE;
if (cb->sock_fd > 0)
return 0;
-#ifdef AI_ADDRCONFIG
- ai_hints.ai_flags |= AI_ADDRCONFIG;
-#endif
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
-
- ai_list = NULL;
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM
+ };
status = getaddrinfo(node, service, &ai_hints, &ai_list);
if (status != 0)
}
assert (ai_list != NULL);
- for (ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
+ for (struct addrinfo *ai_ptr = ai_list; ai_ptr != NULL; ai_ptr = ai_ptr->ai_next)
{
cb->sock_fd = socket(ai_ptr->ai_family, ai_ptr->ai_socktype,
ai_ptr->ai_protocol);
if (cb->sock_fd < 0)
continue;
+ set_sock_opts(cb->sock_fd);
+
status = connect(cb->sock_fd, ai_ptr->ai_addr, ai_ptr->ai_addrlen);
if (status != 0)
{
char values[512];
int status;
- size_t i;
if (0 != strcmp(ds->type, vl->type))
{
return -1;
}
- for (i = 0; i < ds->ds_num; i++)
+ for (size_t i = 0; i < ds->ds_num; i++)
{
const char *ds_name = NULL;
struct wt_callback *cb;
user_data_t user_data = { 0 };
char callback_name[DATA_MAX_NAME_LEN];
- int i;
cb = calloc(1, sizeof(*cb));
if (cb == NULL)
pthread_mutex_init (&cb->send_lock, NULL);
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
static int wt_config(oconfig_item_t *ci)
{
- int i;
-
- for (i = 0; i < ci->children_num; i++)
+ for (int i = 0; i < ci->children_num; i++)
{
oconfig_item_t *child = ci->children + i;
diff --git a/src/xencpu.c b/src/xencpu.c
index 2b87235025d09f357e3078ae739b5eef34e3dcf4..f1cd938810ac80b1640004ff98916e349a4b8229 100644 (file)
--- a/src/xencpu.c
+++ b/src/xencpu.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
{
ERROR ("xencpu: xc_interface_open() failed");
return (-1);
- };
+ }
xc_physinfo_t *physinfo;
xc_interface_close(xc_handle);
free(physinfo);
return (-1);
- };
+ }
num_cpus = physinfo->nr_cpus;
free(physinfo);
return (-1);
}
- int cpu, status;
- for (cpu = 0; cpu < nr_cpus; cpu++) {
+ int status;
+ for (int cpu = 0; cpu < nr_cpus; cpu++) {
gauge_t rate = NAN;
value_t value = {.derive = cpu_info[cpu].idletime};
diff --git a/src/xmms.c b/src/xmms.c
index 29f2acd0f630977b42d3dff37b59965e8b60be21..353599502fe5f53f3193fbc59ccac2a38ef8f24a 100644 (file)
--- a/src/xmms.c
+++ b/src/xmms.c
**/
#include "collectd.h"
+
#include "plugin.h"
#include "common.h"
diff --git a/src/zfs_arc.c b/src/zfs_arc.c
index 37a918b54bec75daa872ac1d40e1566af888d218..8261282a825e1fc5ea13dea2bfacf222a35b4037 100644 (file)
--- a/src/zfs_arc.c
+++ b/src/zfs_arc.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
static void free_zfs_values (kstat_t *ksp)
{
- llentry_t *e;
-
if (ksp == NULL)
return;
- for (e = llist_head (ksp); e != NULL; e = e->next)
+ for (llentry_t *e = llist_head (ksp); e != NULL; e = e->next)
{
sfree (e->key);
sfree (e->value);
za_read_derive (ksp, "deleted", "cache_operation", "deleted");
#if defined(KERNEL_FREEBSD)
za_read_derive (ksp, "allocated","cache_operation", "allocated");
-#if __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 */
diff --git a/src/zone.c b/src/zone.c
index 87c65172292c6630a775a369be158bc9bf53e6f3..3751bfde9e95ee4522587261f74b8954e708128c 100644 (file)
--- a/src/zone.c
+++ b/src/zone.c
#endif
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
diff --git a/src/zookeeper.c b/src/zookeeper.c
index a236c8ae66404bd5173c0be7e2537246e34511f4..84174853d24c62bd8ba22aaa17bc28e5f68aaa3d 100644 (file)
--- a/src/zookeeper.c
+++ b/src/zookeeper.c
**/
#include "collectd.h"
+
#include "common.h"
#include "plugin.h"
{
int sk = -1;
int status;
- struct addrinfo ai_hints = { 0 };
- struct addrinfo *ai;
struct addrinfo *ai_list;
const char *host;
const char *port;
- ai_hints.ai_family = AF_UNSPEC;
- ai_hints.ai_socktype = SOCK_STREAM;
-
host = (zk_host != NULL) ? zk_host : ZOOKEEPER_DEF_HOST;
port = (zk_port != NULL) ? zk_port : ZOOKEEPER_DEF_PORT;
+
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_socktype = SOCK_STREAM
+ };
+
status = getaddrinfo (host, port, &ai_hints, &ai_list);
if (status != 0)
{
return (-1);
}
- for (ai = ai_list; ai != NULL; ai = ai->ai_next)
+ for (struct addrinfo *ai = ai_list; ai != NULL; ai = ai->ai_next)
{
sk = socket (ai->ai_family, SOCK_STREAM, 0);
if (sk < 0)