Fixed wrong define. Good think this is fixed in `trunk'
[collectd.git] / src / disk.c
index a6a583d..ea49717 100644 (file)
  *   Florian octo Forster <octo at verplant.org>
  **/
 
-#include "disk.h"
-
-#if COLLECT_DISK
-#define MODULE_NAME "disk"
-
-#include "plugin.h"
+#include "collectd.h"
 #include "common.h"
+#include "plugin.h"
 
-#ifdef KERNEL_LINUX
-typedef struct diskstats
-{
-       char *name;
-
-       unsigned int read_sectors;
-       unsigned int write_sectors;
-
-       unsigned long long read_bytes;
-       unsigned long long write_bytes;
-
-       struct diskstats *next;
-} diskstats_t;
-
-static diskstats_t *disklist;
-/* KERNEL_LINUX */
+#define MODULE_NAME "disk"
 
-#elif defined(HAVE_LIBKSTAT)
-#define MAX_NUMDISK 256
-extern kstat_ctl_t *kc;
-static kstat_t *ksp[MAX_NUMDISK];
-static int numdisk = 0;
-#endif /* HAVE_LIBKSTAT */
+#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT)
+# define DISK_HAVE_READ 1
+#else
+# define DISK_HAVE_READ 0
+#endif
 
 static char *disk_filename_template = "disk-%s.rrd";
 static char *part_filename_template = "partition-%s.rrd";
@@ -80,9 +60,34 @@ static char *part_ds_def[] =
 };
 static int part_ds_num = 4;
 
-extern time_t curtime;
+#ifdef KERNEL_LINUX
+typedef struct diskstats
+{
+       char *name;
+
+       /* This overflows in roughly 1361 year */
+       unsigned int poll_count;
+
+       unsigned int read_sectors;
+       unsigned int write_sectors;
 
-void disk_init (void)
+       unsigned long long read_bytes;
+       unsigned long long write_bytes;
+
+       struct diskstats *next;
+} diskstats_t;
+
+static diskstats_t *disklist;
+/* #endif defined(KERNEL_LINUX) */
+
+#elif defined(HAVE_LIBKSTAT)
+#define MAX_NUMDISK 256
+extern kstat_ctl_t *kc;
+static kstat_t *ksp[MAX_NUMDISK];
+static int numdisk = 0;
+#endif /* HAVE_LIBKSTAT */
+
+static void disk_init (void)
 {
 #ifdef HAVE_LIBKSTAT
        kstat_t *ksp_chain;
@@ -108,7 +113,7 @@ void disk_init (void)
        return;
 }
 
-void disk_write (char *host, char *inst, char *val)
+static void disk_write (char *host, char *inst, char *val)
 {
        char file[512];
        int status;
@@ -122,7 +127,7 @@ void disk_write (char *host, char *inst, char *val)
        rrd_update_file (host, file, val, disk_ds_def, disk_ds_num);
 }
 
-void partition_write (char *host, char *inst, char *val)
+static void partition_write (char *host, char *inst, char *val)
 {
        char file[512];
        int status;
@@ -136,8 +141,9 @@ void partition_write (char *host, char *inst, char *val)
        rrd_update_file (host, file, val, part_ds_def, part_ds_num);
 }
 
+#if DISK_HAVE_READ
 #define BUFSIZE 512
-void disk_submit (char *disk_name,
+static void disk_submit (char *disk_name,
                unsigned long long read_count,
                unsigned long long read_merged,
                unsigned long long read_bytes,
@@ -159,7 +165,7 @@ void disk_submit (char *disk_name,
        plugin_submit (MODULE_NAME, disk_name, buf);
 }
 
-void partition_submit (char *part_name,
+static void partition_submit (char *part_name,
                unsigned long long read_count,
                unsigned long long read_bytes,
                unsigned long long write_count,
@@ -177,7 +183,7 @@ void partition_submit (char *part_name,
 }
 #undef BUFSIZE
 
-void disk_read (void)
+static void disk_read (void)
 {
 #ifdef KERNEL_LINUX
        FILE *fh;
@@ -297,6 +303,10 @@ void disk_read (void)
                read_bytes  = ds->read_bytes;
                write_bytes = ds->write_bytes;
 
+               /* Don't write to the RRDs if we've just started.. */
+               ds->poll_count++;
+               if (ds->poll_count <= 6)
+                       continue;
 
                if ((read_count == 0) && (write_count == 0))
                        continue;
@@ -333,7 +343,10 @@ void disk_read (void)
                                        kio.writes,kio.nwritten);
        }
 #endif /* defined(HAVE_LIBKSTAT) */
-}
+} /* static void disk_read (void) */
+#else
+# define disk_read NULL
+#endif /* DISK_HAVE_READ */
 
 void module_register (void)
 {
@@ -342,4 +355,3 @@ void module_register (void)
 }
 
 #undef MODULE_NAME
-#endif /* COLLECT_DISK */