Changed the DS of the apache-plugin to contain upper limits. Since logrotate restarts...
[collectd.git] / src / disk.c
index dc0232d..992c2d2 100644 (file)
  *   Florian octo Forster <octo at verplant.org>
  **/
 
-#include "disk.h"
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
 
-#if COLLECT_DISK
 #define MODULE_NAME "disk"
 
-#include "plugin.h"
-#include "common.h"
+#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";
+
+/* 104857600 == 100 MB */
+static char *disk_ds_def[] =
+{
+       "DS:rcount:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       "DS:rmerged:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       "DS:rbytes:COUNTER:"COLLECTD_HEARTBEAT":0:104857600",
+       "DS:rtime:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       "DS:wcount:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       "DS:wmerged:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       "DS:wbytes:COUNTER:"COLLECTD_HEARTBEAT":0:104857600",
+       "DS:wtime:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       NULL
+};
+static int disk_ds_num = 8;
+
+static char *part_ds_def[] =
+{
+       "DS:rcount:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       "DS:rbytes:COUNTER:"COLLECTD_HEARTBEAT":0:104857600",
+       "DS:wcount:COUNTER:"COLLECTD_HEARTBEAT":0:U",
+       "DS:wbytes:COUNTER:"COLLECTD_HEARTBEAT":0:104857600",
+       NULL
+};
+static int part_ds_num = 4;
 
 #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;
 
@@ -43,7 +78,7 @@ typedef struct diskstats
 } diskstats_t;
 
 static diskstats_t *disklist;
-/* KERNEL_LINUX */
+/* #endif defined(KERNEL_LINUX) */
 
 #elif defined(HAVE_LIBKSTAT)
 #define MAX_NUMDISK 256
@@ -52,35 +87,7 @@ static kstat_t *ksp[MAX_NUMDISK];
 static int numdisk = 0;
 #endif /* HAVE_LIBKSTAT */
 
-static char *disk_filename_template = "disk-%s.rrd";
-static char *part_filename_template = "partition-%s.rrd";
-
-/* 104857600 == 100 MB */
-static char *disk_ds_def[] =
-{
-       "DS:rcount:COUNTER:25:0:U",
-       "DS:rmerged:COUNTER:25:0:U",
-       "DS:rbytes:COUNTER:25:0:104857600",
-       "DS:rtime:COUNTER:25:0:U",
-       "DS:wcount:COUNTER:25:0:U",
-       "DS:wmerged:COUNTER:25:0:U",
-       "DS:wbytes:COUNTER:25:0:104857600",
-       "DS:wtime:COUNTER:25:0:U",
-       NULL
-};
-static int disk_ds_num = 8;
-
-static char *part_ds_def[] =
-{
-       "DS:rcount:COUNTER:25:0:U",
-       "DS:rbytes:COUNTER:25:0:104857600",
-       "DS:wcount:COUNTER:25:0:U",
-       "DS:wbytes:COUNTER:25:0:104857600",
-       NULL
-};
-static int part_ds_num = 4;
-
-void disk_init (void)
+static void disk_init (void)
 {
 #ifdef HAVE_LIBKSTAT
        kstat_t *ksp_chain;
@@ -106,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;
@@ -120,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;
@@ -134,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,
@@ -157,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,
@@ -175,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;
@@ -295,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;
@@ -331,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)
 {
@@ -340,4 +355,3 @@ void module_register (void)
 }
 
 #undef MODULE_NAME
-#endif /* COLLECT_DISK */