summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 82d65d8)
raw | patch | inline | side by side (parent: 82d65d8)
author | octo <octo> | |
Tue, 6 Dec 2005 12:24:51 +0000 (12:24 +0000) | ||
committer | octo <octo> | |
Tue, 6 Dec 2005 12:24:51 +0000 (12:24 +0000) |
configure.in | patch | blob | history | |
src/config.h.in | patch | blob | history | |
src/load.c | [new file with mode: 0644] | patch | blob |
src/load.h | [new file with mode: 0644] | patch | blob |
diff --git a/configure.in b/configure.in
index aeda992cd3232190ac195f3619a5b91dcfcf14ba..f297bdad70deaea92304cf0338499eb40e77c6b8 100644 (file)
--- a/configure.in
+++ b/configure.in
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
diff --git a/src/config.h.in b/src/config.h.in
index 975f16e1c99966f38d030f1cf05ed53791ca4cf0..1c63a1fb29bf4152794df6382c458cba4b4f2720 100644 (file)
--- a/src/config.h.in
+++ b/src/config.h.in
/* Define to 1 if you have the `gethostbyname' function. */
#undef HAVE_GETHOSTBYNAME
+/* Define to 1 if you have the `getloadavg' function. */
+#undef HAVE_GETLOADAVG
+
/* Define to 1 if you have the `gettimeofday' function. */
#undef HAVE_GETTIMEOFDAY
/* Define to 1 if you have the <syslog.h> header file. */
#undef HAVE_SYSLOG_H
+/* Define to 1 if you have the <sys/loadavg.h> header file. */
+#undef HAVE_SYS_LOADAVG_H
+
/* Define to 1 if you have the <sys/resource.h> header file. */
#undef HAVE_SYS_RESOURCE_H
diff --git a/src/load.c b/src/load.c
--- /dev/null
+++ b/src/load.c
@@ -0,0 +1,124 @@
+#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 */
diff --git a/src/load.h b/src/load.h
--- /dev/null
+++ b/src/load.h
@@ -0,0 +1,15 @@
+#ifndef LOAD_H
+#define LOAD_H
+
+#include "collectd.h"
+#include "common.h"
+
+#ifndef COLLECT_LOAD
+#if defined(HAVE_GETLOADAVG) || defined(KERNEL_LINUX) || defined(HAVE_LIBSTATGRAB)
+#define COLLECT_LOAD 1
+#else
+#define COLLECT_LOAD 0
+#endif
+#endif /* !defined(COLLECT_LOAD) */
+
+#endif /* LOAD_H */