summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 32edd54)
raw | patch | inline | side by side (parent: 32edd54)
author | octo <octo> | |
Mon, 12 Dec 2005 07:58:44 +0000 (07:58 +0000) | ||
committer | octo <octo> | |
Mon, 12 Dec 2005 07:58:44 +0000 (07:58 +0000) |
src/collectd.c | patch | blob | history | |
src/collectd.h | patch | blob | history | |
src/processes.c | [new file with mode: 0644] | patch | blob |
diff --git a/src/collectd.c b/src/collectd.c
index dabc346e8e8c5e79bfc7b388ad67675a5b0fec31..ddfb9f207a391734e60d32831fe9bab85a1b4262 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
int main (int argc, char **argv)
{
struct sigaction sigIntAction, sigChldAction;
+#if COLLECT_DAEMON
pid_t pid;
+#endif
char *plugindir = NULL;
char *basedir = DATADIR;
/*
* fork off child
*/
-#if DEBUG == 0
+#if COLLECT_DAEMON
if (daemonize)
{
if ((pid = fork ()) == -1)
return (1);
}
} /* if (daemonize) */
-#endif
+#endif /* COLLECT_DAEMON */
/*
* run the actual loops
diff --git a/src/collectd.h b/src/collectd.h
index 57b709c515ba377606d02958e2a1c91b717c8160..1614483a28bcd350002879a33322ffad7ea039b5 100644 (file)
--- a/src/collectd.h
+++ b/src/collectd.h
#define COLLECTD_H
#if HAVE_CONFIG_H
-# include "config.h"
+# include <config.h>
#endif
#include <stdio.h>
#if HAVE_UNISTD_H
# include <unistd.h>
#endif
-#include <sys/wait.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <syslog.h>
-#include <limits.h>
-#include <time.h>
+#if HAVE_SYS_WAIT_H
+# include <sys/wait.h>
+#endif
+#ifndef WEXITSTATUS
+# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
+#endif
+#ifndef WIFEXITED
+# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif
+#if HAVE_SIGNAL_H
+# include <signal.h>
+#endif
+#if HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#if HAVE_ERRNO_H
+# include <errno.h>
+#endif
+#if HAVE_SYSLOG_H
+# include <syslog.h>
+#endif
+#if HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if HAVE_SYS_NDIR_H
+# include <sys/ndir.h>
+# endif
+# if HAVE_SYS_DIR_H
+# include <sys/dir.h>
+# endif
+# if HAVE_NDIR_H
+# include <ndir.h>
+# endif
+#endif
+
+#if HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+#if HAVE_CTYPE_H
+# include <ctype.h>
+#endif
#ifndef HAVE_RRD_H
#undef HAVE_LIBRRD
#include <statgrab.h>
#endif
-#ifndef DEBUG
-#define DEBUG 0
-#endif
-
#ifndef LOCALSTATEDIR
#define LOCALSTATEDIR "/opt/collectd/var"
#endif
#define MODE_CLIENT 0x02
#define MODE_LOCAL 0x03
+extern time_t curtime;
+extern int operating_mode;
+
#endif /* COLLECTD_H */
diff --git a/src/processes.c b/src/processes.c
--- /dev/null
+++ b/src/processes.c
@@ -0,0 +1,129 @@
+#include "processes.h"
+
+/*
+ * Originally written by Lyonel Vincent
+ */
+
+#if COLLECT_PROCESSES
+#define MODULE_NAME "processes"
+
+#include "common.h"
+#include "plugin.h"
+
+static char *ps_file = "processes.rrd";
+
+static char *ds_def[] =
+{
+ "DS:running:GAUGE:25:0:65535",
+ "DS:sleeping:GAUGE:25:0:65535",
+ "DS:zombies:GAUGE:25:0:65535",
+ "DS:stopped:GAUGE:25:0:65535",
+ "DS:paging:GAUGE:25:0:65535",
+ "DS:blocked:GAUGE:25:0:65535",
+ NULL
+};
+static int ds_num = 6;
+
+extern time_t curtime;
+
+void ps_init (void)
+{
+}
+
+void ps_write (char *host, char *inst, char *val)
+{
+ rrd_update_file (host, ps_file, val, ds_def, ds_num);
+}
+
+#define BUFSIZE 256
+void ps_submit (unsigned int running,
+ unsigned int sleeping,
+ unsigned int zombies,
+ unsigned int stopped,
+ unsigned int paging,
+ unsigned int blocked)
+{
+ char buf[BUFSIZE];
+
+ if (snprintf (buf, BUFSIZE, "%u:%u:%u:%u:%u:%u:%u",
+ (unsigned int) curtime,
+ running, sleeping, zombies, stopped, paging,
+ blocked) >= BUFSIZE)
+ return;
+
+ plugin_submit (MODULE_NAME, "-", buf);
+}
+
+void ps_read (void)
+{
+#ifdef KERNEL_LINUX
+ unsigned int running, sleeping, zombies, stopped, paging, blocked;
+
+ char buf[BUFSIZE];
+ char filename[20]; /* need 17 bytes */
+ char *fields[256];
+
+ struct dirent *ent;
+ DIR *proc;
+ FILE *fh;
+
+ running = sleeping = zombies = stopped = paging = blocked = 0;
+
+ if ((proc = opendir ("/proc")) == NULL)
+ {
+ syslog (LOG_ERR, "Cannot open `/proc': %s", strerror (errno));
+ return;
+ }
+
+ int strsplit (char *string, char **fields, size_t size);
+
+ while ((ent = readdir (proc)) != NULL)
+ {
+ if (!isdigit (ent->d_name[0]))
+ continue;
+
+ if (snprintf (filename, 20, "/proc/%s/stat", ent->d_name) >= 20)
+ continue;
+
+ if ((fh = fopen (filename, "r")) == NULL)
+ {
+ syslog (LOG_ERR, "Cannot open `%s': %s", filename, strerror (errno));
+ continue;
+ }
+
+ if (fgets (buf, BUFSIZE, fh) == NULL)
+ {
+ fclose (fh);
+ continue;
+ }
+
+ fclose (fh);
+
+ if (strsplit (buf, fields, 256) < 3)
+ continue;
+
+ switch (fields[2][0])
+ {
+ case 'R': running++; break;
+ case 'S': sleeping++; break;
+ case 'D': blocked++; break;
+ case 'Z': zombies++; break;
+ case 'T': stopped++; break;
+ case 'W': paging++; break;
+ }
+ }
+
+ closedir(proc);
+
+ ps_submit (running, sleeping, zombies, stopped, paging, blocked);
+#endif /* defined(KERNEL_LINUX) */
+}
+#undef BUFSIZE
+
+void module_register (void)
+{
+ plugin_register (MODULE_NAME, ps_init, ps_read, ps_write);
+}
+
+#undef MODULE_NAME
+#endif /* COLLECT_PROCESSES */