AC_PREFIX_DEFAULT("/opt/collectd")
-dnl Checks for programs.
+#
+# Checks for programs.
+#
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL
AC_PROG_LIBTOOL
#AC_PROG_RANLIB
-dnl Checks for header files.
+#
+# Checks for header files.
+#
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h unistd.h)
AC_CHECK_HEADERS(sys/types.h)
AC_CHECK_HEADERS(sys/resource.h)
AC_CHECK_HEADERS(errno.h)
+AC_CHECK_HEADERS(syslog.h)
+AC_CHECK_HEADERS(dlfcn.h)
+
+# For load module
+AC_CHECK_HEADERS(sys/loadavg.h)
+
+# For ping module
AC_CHECK_HEADERS(arpa/inet.h)
AC_CHECK_HEADERS(netinet/in.h)
AC_CHECK_HEADERS(netdb.h)
-AC_CHECK_HEADERS(syslog.h)
-AC_CHECK_HEADERS(dlfcn.h)
+
+# For users module
AC_CHECK_HEADERS(utmp.h)
AC_CHECK_HEADERS(utmpx.h)
dnl Checking for libraries
AC_CHECK_LIB(m, ext)
-dnl Checks for typedefs, structures, and compiler characteristics.
+#
+# Checks for typedefs, structures, and compiler characteristics.
+#
AC_C_CONST
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
-dnl Checks for library functions.
+#
+# Checks for library functions.
+#
AC_PROG_GCC_TRADITIONAL
AC_CHECK_FUNCS(gettimeofday select socket strdup strstr strtol)
AC_CHECK_FUNCS(socket, , AC_CHECK_LIB(socket, socket))
AC_CHECK_FUNCS(gethostbyname, , AC_CHECK_LIB(nsl, gethostbyname))
AC_CHECK_FUNCS(strchr memcpy strstr strcmp strncmp strncpy strlen)
AC_CHECK_FUNCS(strncasecmp strcasecmp strncmp)
+
+# For load module
+AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"])
+
+# For users module
AC_CHECK_FUNCS(getutent getutxent)
AC_MSG_CHECKING([for kernel type ($host_os)])
AC_ARG_ENABLE(load, AC_HELP_STRING([--disable-load], [Disable system load statistics]),, [enable_load="yes"])
if test "x$enable_load" != "xno"
then
- if test "x$ac_system" = "xLinux" -o "x$with_kstat" = "xyes" -o "x$with_libstatgrab" = "xyes"
+ if test "x$have_getloadavg" = "xyes" -o "x$ac_system" = "xLinux" -o "x$with_libstatgrab" = "xyes"
then
enable_load="yes"
else
--- /dev/null
+#include "load.h"
+
+#if COLLECT_LOAD
+#define MODULE_NAME "load"
+
+#include "plugin.h"
+#include "common.h"
+
+#ifdef HAVE_SYS_LOADAVG_H
+#include <sys/loadavg.h>
+#endif
+
+#ifdef HAVE_GETLOADAVG
+#if !defined(LOADAVG_1MIN) || !defined(LOADAVG_5MIN) || !defined(LOADAVG_15MIN)
+#define LOADAVG_1MIN 0
+#define LOADAVG_5MIN 1
+#define LOADAVG_15MIN 2
+#endif
+#endif /* defined(HAVE_GETLOADAVG) */
+
+static char *load_file = "load.rrd";
+
+static char *ds_def[] =
+{
+ "DS:shortterm:GAUGE:25:0:100",
+ "DS:midterm:GAUGE:25:0:100",
+ "DS:longterm:GAUGE:25:0:100",
+ NULL
+};
+static int ds_num = 3;
+
+extern time_t curtime;
+
+void load_init (void)
+{
+ return;
+}
+
+void load_write (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, load_file, val, ds_def, ds_num);
+}
+
+#define BUFSIZE 256
+void load_submit (double snum, double mnum, double lnum)
+{
+ char buf[BUFSIZE];
+
+ if (snprintf (buf, BUFSIZE, "%u:%.2f:%.2f:%.2f", (unsigned int) curtime,
+ snum, mnum, lnum) >= BUFSIZE)
+ return;
+
+ plugin_submit (MODULE_NAME, "-", buf);
+}
+#undef BUFSIZE
+
+void load_read (void)
+{
+#if defined(HAVE_GETLOADAVG)
+ double load[3];
+
+ if (getloadavg (load, 3) == 3)
+ load_submit (load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]);
+ else
+ syslog (LOG_WARNING, "load: getloadavg failed: %s", strerror (errno));
+/* #endif HAVE_GETLOADAVG */
+
+#elif defined(KERNEL_LINUX)
+ double snum, mnum, lnum;
+ FILE *loadavg;
+ char buffer[16];
+
+ char *fields[8];
+ int numfields;
+
+ if ((loadavg = fopen ("/proc/loadavg", "r")) == NULL)
+ {
+ syslog (LOG_WARNING, "load: fopen: %s", strerror (errno));
+ return;
+ }
+
+ if (fgets (buffer, 16, loadavg) == NULL)
+ {
+ syslog (LOG_WARNING, "load: fgets: %s", strerror (errno));
+ return;
+ }
+
+ if (fclose (loadavg))
+ syslog (LOG_WARNING, "load: fclose: %s", strerror (errno));
+
+ numfields = strsplit (buffer, fields, 8);
+
+ if (numfields < 3)
+ return;
+
+ snum = atof (fields[0]);
+ mnum = atof (fields[1]);
+ lnum = atof (fields[2]);
+
+ load_submit (snum, mnum, lnum);
+/* #endif KERNEL_LINUX */
+
+#elif defined(HAVE_LIBSTATGRAB)
+ double snum, mnum, lnum;
+ sg_load_stats *ls;
+
+ if ((ls = sg_get_load_stats ()) == NULL)
+ return;
+
+ snum = ls->min1;
+ mnum = ls->min5;
+ lnum = ls->min15;
+
+ load_submit (snum, mnum, lnum);
+#endif /* HAVE_LIBSTATGRAB */
+}
+
+void module_register (void)
+{
+ plugin_register (MODULE_NAME, load_init, load_read, load_write);
+}
+
+#undef MODULE_NAME
+#endif /* COLLECT_LOAD */