* 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;
} diskstats_t;
static diskstats_t *disklist;
-/* KERNEL_LINUX */
+/* #endif defined(KERNEL_LINUX) */
#elif defined(HAVE_LIBKSTAT)
#define MAX_NUMDISK 256
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;
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;
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;
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,
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,
}
#undef BUFSIZE
-void disk_read (void)
+static void disk_read (void)
{
#ifdef KERNEL_LINUX
FILE *fh;
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;
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)
{
}
#undef MODULE_NAME
-#endif /* COLLECT_DISK */