config-step/src/collectd.h:
[collectd.git] / src / memory.c
index f792445..13ee950 100644 (file)
  *   Florian octo Forster <octo at verplant.org>
  **/
 
-#include "memory.h"
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
 
-#if COLLECT_MEMORY
-#define MODULE_NAME "memory"
+#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT)
+# define MEMORY_HAVE_READ 1
+#else
+# define MEMORY_HAVE_READ 0
+#endif
 
-#include "plugin.h"
-#include "common.h"
+#define MODULE_NAME "memory"
 
 static char *memory_file = "memory.rrd";
 
 /* 9223372036854775807 == LLONG_MAX */
 static char *ds_def[] =
 {
-       "DS:used:GAUGE:25:0:9223372036854775807",
-       "DS:free:GAUGE:25:0:9223372036854775807",
-       "DS:buffers:GAUGE:25:0:9223372036854775807",
-       "DS:cached:GAUGE:25:0:9223372036854775807",
+       "DS:used:GAUGE:"COLLECTD_HEARTBEAT":0:9223372036854775807",
+       "DS:free:GAUGE:"COLLECTD_HEARTBEAT":0:9223372036854775807",
+       "DS:buffers:GAUGE:"COLLECTD_HEARTBEAT":0:9223372036854775807",
+       "DS:cached:GAUGE:"COLLECTD_HEARTBEAT":0:9223372036854775807",
        NULL
 };
 static int ds_num = 4;
@@ -46,7 +50,7 @@ static int pagesize;
 static kstat_t *ksp;
 #endif /* HAVE_LIBKSTAT */
 
-void memory_init (void)
+static void memory_init (void)
 {
 #ifdef HAVE_LIBKSTAT
        /* getpagesize(3C) tells me this does not fail.. */
@@ -58,13 +62,14 @@ void memory_init (void)
        return;
 }
 
-void memory_write (char *host, char *inst, char *val)
+static void memory_write (char *host, char *inst, char *val)
 {
        rrd_update_file (host, memory_file, val, ds_def, ds_num);
 }
 
+#if MEMORY_HAVE_READ
 #define BUFSIZE 512
-void memory_submit (long long mem_used, long long mem_buffered,
+static void memory_submit (long long mem_used, long long mem_buffered,
                long long mem_cached, long long mem_free)
 {
        char buf[BUFSIZE];
@@ -78,7 +83,7 @@ void memory_submit (long long mem_used, long long mem_buffered,
 }
 #undef BUFSIZE
 
-void memory_read (void)
+static void memory_read (void)
 {
 #ifdef KERNEL_LINUX
        FILE *fh;
@@ -163,6 +168,9 @@ void memory_read (void)
                memory_submit (ios->used, 0LL, ios->cache, ios->free);
 #endif /* HAVE_LIBSTATGRAB */
 }
+#else
+# define memory_read NULL
+#endif /* MEMORY_HAVE_READ */
 
 void module_register (void)
 {
@@ -170,4 +178,3 @@ void module_register (void)
 }
 
 #undef MODULE_NAME
-#endif /* COLLECT_MEMORY */