X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdisk.c;h=bafc82e042274d9f7da4eadca94d48ad6543dc90;hb=e88be91ffc1d4ea252f19d5c126390285bd0917e;hp=b60fefa03bd1186aede7264bbc2d6e640ecd38e0;hpb=6164fe4456716e6dc36aaa2ab617b104a7ac5ff3;p=collectd.git diff --git a/src/disk.c b/src/disk.c index b60fefa0..bafc82e0 100644 --- a/src/disk.c +++ b/src/disk.c @@ -293,44 +293,46 @@ static void disk_submit (const char *plugin_instance, plugin_dispatch_values (&vl); } /* void disk_submit */ -#if KERNEL_LINUX -static void submit_in_progress (char const *disk_name, gauge_t in_progress) +#if KERNEL_FREEBSD || KERNEL_LINUX +static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time) { - value_t v; + value_t values[2]; value_list_t vl = VALUE_LIST_INIT; - if (ignorelist_match (ignorelist, disk_name) != 0) + if (ignorelist_match (ignorelist, plugin_instance) != 0) return; - v.gauge = in_progress; + values[0].derive = io_time; + values[1].derive = weighted_time; - vl.values = &v; - vl.values_len = 1; + vl.values = values; + vl.values_len = 2; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); - sstrncpy (vl.plugin_instance, disk_name, sizeof (vl.plugin_instance)); - sstrncpy (vl.type, "pending_operations", sizeof (vl.type)); + sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "disk_io_time", sizeof (vl.type)); plugin_dispatch_values (&vl); -} +} /* void submit_io_time */ +#endif /* KERNEL_FREEBSD || KERNEL_LINUX */ -static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time) +#if KERNEL_LINUX +static void submit_in_progress (char const *disk_name, gauge_t in_progress) { - value_t values[2]; + value_t v; value_list_t vl = VALUE_LIST_INIT; - if (ignorelist_match (ignorelist, plugin_instance) != 0) + if (ignorelist_match (ignorelist, disk_name) != 0) return; - values[0].derive = io_time; - values[1].derive = weighted_time; + v.gauge = in_progress; - vl.values = values; - vl.values_len = 2; + vl.values = &v; + vl.values_len = 1; sstrncpy (vl.host, hostname_g, sizeof (vl.host)); sstrncpy (vl.plugin, "disk", sizeof (vl.plugin)); - sstrncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); - sstrncpy (vl.type, "disk_io_time", sizeof (vl.type)); + sstrncpy (vl.plugin_instance, disk_name, sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "pending_operations", sizeof (vl.type)); plugin_dispatch_values (&vl); } @@ -389,7 +391,7 @@ static signed long long dict_get_value (CFDictionaryRef dict, const char *key) DEBUG ("CFStringCreateWithCString (%s) failed.", key); return (-1LL); } - + /* get => we don't need to release (== free) the object */ val_obj = (CFNumberRef) CFDictionaryGetValue (dict, key_obj); @@ -536,7 +538,7 @@ static int disk_read (void) struct gident *geom_id; const char *disk_name; - long double read_time, write_time; + long double read_time, write_time, busy_time, total_duration; for (retry = 0, dirty = 1; retry < 5 && dirty == 1; retry++) { if (snap != NULL) @@ -631,13 +633,23 @@ static int disk_read (void) disk_submit (disk_name, "disk_time", (derive_t)(read_time*1000), (derive_t)(write_time*1000)); } + if (devstat_compute_statistics(snap_iter, NULL, 1.0, + DSM_TOTAL_BUSY_TIME, &busy_time, + DSM_TOTAL_DURATION, &total_duration, + DSM_NONE) != 0) { + WARNING("%s", devstat_errbuf); + } + else + { + submit_io_time(disk_name, busy_time, total_duration); + } } geom_stats_snapshot_free(snap); #elif KERNEL_LINUX FILE *fh; char buffer[1024]; - + char *fields[32]; int numfields; int fieldshift = 0; @@ -936,10 +948,10 @@ static int disk_read (void) #endif int counter; char name[DATA_MAX_NAME_LEN]; - + if ((ds = sg_get_disk_io_stats(&disks)) == NULL) return (0); - + for (counter=0; counter < disks; counter++) { strncpy(name, ds->disk_name, sizeof(name)); name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */ @@ -959,7 +971,7 @@ static int disk_read (void) int rnumdisk; int i; - if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0) + if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0) { char errbuf[1024]; WARNING ("disk plugin: perfstat_disk: %s", @@ -968,14 +980,14 @@ static int disk_read (void) } if (numdisk != pnumdisk || stat_disk==NULL) { - if (stat_disk!=NULL) + if (stat_disk!=NULL) free(stat_disk); stat_disk = (perfstat_disk_t *)calloc(numdisk, sizeof(perfstat_disk_t)); - } + } pnumdisk = numdisk; firstpath.name[0]='\0'; - if ((rnumdisk = perfstat_disk(&firstpath, stat_disk, sizeof(perfstat_disk_t), numdisk)) < 0) + if ((rnumdisk = perfstat_disk(&firstpath, stat_disk, sizeof(perfstat_disk_t), numdisk)) < 0) { char errbuf[1024]; WARNING ("disk plugin: perfstat_disk : %s", @@ -983,7 +995,7 @@ static int disk_read (void) return (-1); } - for (i = 0; i < rnumdisk; i++) + for (i = 0; i < rnumdisk; i++) { read_sectors = stat_disk[i].rblks*stat_disk[i].bsize; write_sectors = stat_disk[i].wblks*stat_disk[i].bsize;