Code

Fixed documentation in `configfile.h': s/Module/Plugin/
[collectd.git] / src / cpu.c
index 67db5bcc4d7b2f8d8ab5a10d8e885ff771879051..62e814578cb688d50bb5a857a34899f65bc520c2 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
  **/
 
 #include "collectd.h"
-#include "plugin.h"
 #include "common.h"
+#include "plugin.h"
+
+#define MODULE_NAME "cpu"
 
 #ifdef HAVE_LIBKSTAT
 # include <sys/sysinfo.h>
 # endif
 #endif /* HAVE_SYSCTLBYNAME */
 
+#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) || defined(HAVE_SYSCTLBYNAME)
+# define CPU_HAVE_READ 1
+#else
+# define CPU_HAVE_READ 0
+#endif
+
 #ifdef HAVE_LIBKSTAT
 /* colleague tells me that Sun doesn't sell systems with more than 100 or so CPUs.. */
 # define MAX_NUMCPU 256
@@ -59,8 +67,6 @@ static int numcpu;
 static int numcpu;
 #endif /* HAVE_SYSCTLBYNAME */
 
-#define MODULE_NAME "cpu"
-
 static char *cpu_filename = "cpu-%s.rrd";
 
 static char *ds_def[] =
@@ -74,7 +80,7 @@ static char *ds_def[] =
 };
 static int ds_num = 5;
 
-void cpu_init (void)
+static void cpu_init (void)
 {
 #ifdef HAVE_LIBKSTAT
        kstat_t *ksp_chain;
@@ -110,7 +116,7 @@ void cpu_init (void)
        return;
 }
 
-void cpu_write (char *host, char *inst, char *val)
+static void cpu_write (char *host, char *inst, char *val)
 {
        char file[512];
        int status;
@@ -124,6 +130,7 @@ void cpu_write (char *host, char *inst, char *val)
        rrd_update_file (host, file, val, ds_def, ds_num);
 }
 
+#if CPU_HAVE_READ
 #define BUFSIZE 512
 static void cpu_submit (int cpu_num, unsigned long long user,
                unsigned long long nice, unsigned long long syst,
@@ -222,7 +229,7 @@ static void cpu_read (void)
        }
 /* #endif defined(HAVE_LIBKSTAT) */
 
-#elif defined (HAVE_SYSCTLBYNAME)
+#elif defined(HAVE_SYSCTLBYNAME)
        long cpuinfo[CPUSTATES];
        size_t cpuinfo_size;
 
@@ -242,6 +249,9 @@ static void cpu_read (void)
 
        return;
 }
+#else
+# define cpu_read NULL
+#endif /* CPU_HAVE_READ */
 
 void module_register (void)
 {