summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c9b431c)
raw | patch | inline | side by side (parent: c9b431c)
author | octo <octo> | |
Sun, 18 Dec 2005 11:59:35 +0000 (11:59 +0000) | ||
committer | octo <octo> | |
Sun, 18 Dec 2005 11:59:35 +0000 (11:59 +0000) |
configure.in | patch | blob | history | |
src/Makefile.am | patch | blob | history | |
src/df.c | [new file with mode: 0644] | patch | blob |
src/disk.c | patch | blob | history |
diff --git a/configure.in b/configure.in
index dffe2f672fda45f8fe83e6e56c8b032502410e7b..976f9329c527d38d8fd7c25c00d53ea993bc23c7 100644 (file)
--- a/configure.in
+++ b/configure.in
AC_CHECK_HEADERS(sys/mnttab.h)
AC_CHECK_HEADERS(sys/mount.h)
AC_CHECK_HEADERS(sys/statfs.h)
+AC_CHECK_HEADERS(sys/statvfs.h)
AC_CHECK_HEADERS(sys/vfs.h)
AC_CHECK_HEADERS(sys/vfstab.h)
# For cpu module
AC_CHECK_FUNCS(sysctlbyname, [have_sysctlbyname="yes"], [have_sysctlbyname="no"])
+# For df module
+AC_CHECK_FUNCS(statfs statvfs)
+
# For load module
AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"])
AC_COLLECTD([cpu], [disable], [module], [cpu usage statistics])
AC_COLLECTD([cpufreq], [disable], [module], [system cpu frequency statistics])
AC_COLLECTD([disk], [disable], [module], [disk/partition statistics])
+AC_COLLECTD([df], [disable], [module], [df statistics])
AC_COLLECTD([quota], [enable], [module], [quota statistics (experimental)])
AC_COLLECTD([hddtemp], [disable], [module], [hdd temperature statistics])
AC_COLLECTD([load], [disable], [module], [system load statistics])
Modules:
cpu . . . . . . . . $enable_cpu
cpufreq . . . . . . $enable_cpufreq
+ df . . . . . . . . $enable_df
disk . . . . . . . $enable_disk
hddtemp . . . . . . $enable_hddtemp
load . . . . . . . $enable_load
diff --git a/src/Makefile.am b/src/Makefile.am
index 1f309101ed323b99152956be41bd2a07076d462b..6710595080a207e1fe19f5a1f2fdbc99cad983e9 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
collectd_DEPENDENCIES += cpufreq.la
endif
+if BUILD_MODULE_DF
+pkglib_LTLIBRARIES += df.la
+df_la_SOURCES = df.c
+df_la_LDFLAGS = -module -avoid-version
+df_la_CFLAGS = -Wall -Werror
+collectd_LDADD += "-dlopen" df.la
+collectd_DEPENDENCIES += df.la
+endif
+
if BUILD_MODULE_DISK
pkglib_LTLIBRARIES += disk.la
disk_la_SOURCES = disk.c disk.h
diff --git a/src/df.c b/src/df.c
--- /dev/null
+++ b/src/df.c
@@ -0,0 +1,140 @@
+/**
+ * collectd - src/df.c
+ * Copyright (C) 2005 Florian octo Forster
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors:
+ * Florian octo Forster <octo at verplant.org>
+ **/
+
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
+#include "utils_mount.h"
+
+#define MODULE_NAME "df"
+
+#if HAVE_STATFS || HAVE_STATVFS
+# define DF_HAVE_READ 1
+#else
+# define DF_HAVE_READ 0
+#endif
+
+#if HAVE_STATFS
+#define STATANYFS statfs
+#define BLOCKSIZE(s) (s).f_bsize
+
+#elif HAVE_STATVFS
+#define STATANYFS statvfs
+#define BLOCKSIZE(s) ((s).f_frsize ? (s).f_frsize : (s).f_bsize)
+#endif
+
+static char *filename_template = "df-%s.rrd";
+
+/* 104857600 == 100 MB */
+static char *ds_def[] =
+{
+ "DS:used:GAUGE:25:0:U",
+ "DS:free:GAUGE:25:0:U",
+ NULL
+};
+static int ds_num = 2;
+
+#define BUFSIZE 512
+
+static void df_init (void)
+{
+ return;
+}
+
+static void df_write (char *host, char *inst, char *val)
+{
+ char file[BUFSIZE];
+ int status;
+
+ status = snprintf (file, BUFSIZE, filename_template, inst);
+ if (status < 1)
+ return;
+ else if (status >= BUFSIZE)
+ return;
+
+ rrd_update_file (host, file, val, ds_def, ds_num);
+}
+
+#if DF_HAVE_READ
+static void df_submit (char *df_name,
+ unsigned long long df_used,
+ unsigned long long df_free)
+{
+ char buf[BUFSIZE];
+
+ if (snprintf (buf, BUFSIZE, "%u:%llu:%llu", (unsigned int) curtime,
+ df_used, df_free) >= BUFSIZE)
+ return;
+
+ plugin_submit (MODULE_NAME, df_name, buf);
+}
+
+static void df_read (void)
+{
+ struct STATANYFS statbuf;
+ cu_mount_t *mnt_list;
+ cu_mount_t *mnt_ptr;
+
+ unsigned long long blocksize;
+ unsigned long long df_free;
+ unsigned long long df_used;
+
+ mnt_list = NULL;
+ if (cu_mount_getlist (&mnt_list) == NULL)
+ {
+ syslog (LOG_WARNING, "cu_mount_getlist returned `NULL'");
+ return;
+ }
+
+ for (mnt_ptr = mnt_list; mnt_ptr != NULL; mnt_ptr = mnt_ptr->next)
+ {
+
+ if (STATANYFS (mnt_ptr->dir, &statbuf) < 0)
+ {
+ syslog (LOG_ERR, "statv?fs failed: %s", strerror (errno));
+ continue;
+ }
+
+ if (!statbuf.f_blocks)
+ continue;
+
+ blocksize = BLOCKSIZE(statbuf);
+ df_free = statbuf.f_bfree * blocksize;
+ df_used = (statbuf.f_blocks - statbuf.f_bfree) * blocksize;
+
+ syslog (LOG_INFO, "blocksize = %llu, free = %llu, used = %llu, dir = %s", blocksize, df_free, df_used, mnt_ptr->dir);
+ df_submit ("blahfoo", df_used, df_free);
+ }
+
+ cu_mount_freelist (mnt_list);
+} /* static void df_read (void) */
+#else
+# define df_read NULL
+#endif /* DF_HAVE_READ */
+
+void module_register (void)
+{
+ plugin_register (MODULE_NAME, df_init, df_read, df_write);
+}
+
+#undef BUFSIZE
+#undef MODULE_NAME
diff --git a/src/disk.c b/src/disk.c
index e3638f22017d1b768b09127e6e513dd7ce2ce882..4e53df0d75c8c7a435db9a8a8e6c98ac55196bf7 100644 (file)
--- a/src/disk.c
+++ b/src/disk.c
rrd_update_file (host, file, val, part_ds_def, part_ds_num);
}
+#if DISK_HAVE_READ
#define BUFSIZE 512
static void disk_submit (char *disk_name,
unsigned long long read_count,
plugin_submit (MODULE_NAME, disk_name, buf);
}
-#if DISK_HAVE_READ
static void partition_submit (char *part_name,
unsigned long long read_count,
unsigned long long read_bytes,