amqp, write_graphite and write_kafka plugins: Implement the "[Graphite]PreserveSepara...
[collectd.git] / src / disk.c
index 9965bca..a07288d 100644 (file)
@@ -22,6 +22,7 @@
  **/
 
 #include "collectd.h"
+
 #include "common.h"
 #include "plugin.h"
 #include "utils_ignorelist.h"
@@ -127,7 +128,7 @@ static int numdisk = 0;
 /* #endif HAVE_LIBKSTAT */
 
 #elif defined(HAVE_LIBSTATGRAB)
-/* #endif HAVE_LIBKSTATGRAB */
+/* #endif HAVE_LIBSTATGRAB */
 
 #elif HAVE_PERFSTAT
 static perfstat_disk_t * stat_disk;
@@ -296,15 +297,14 @@ static void disk_submit (const char *plugin_instance,
                const char *type,
                derive_t read, derive_t write)
 {
-       value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
-
-       values[0].derive = read;
-       values[1].derive = write;
+       value_t values[] = {
+               { .derive = read },
+               { .derive = write },
+       };
 
        vl.values = values;
-       vl.values_len = 2;
-       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       vl.values_len = STATIC_ARRAY_SIZE (values);
        sstrncpy (vl.plugin, "disk", sizeof (vl.plugin));
        sstrncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));
@@ -316,15 +316,14 @@ static void disk_submit (const char *plugin_instance,
 #if KERNEL_FREEBSD || KERNEL_LINUX
 static void submit_io_time (char const *plugin_instance, derive_t io_time, derive_t weighted_time)
 {
-       value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
-
-       values[0].derive = io_time;
-       values[1].derive = weighted_time;
+       value_t values[] = {
+               { .derive = io_time },
+               { .derive = weighted_time },
+       };
 
        vl.values = values;
-       vl.values_len = 2;
-       sstrncpy (vl.host, hostname_g, sizeof (vl.host));
+       vl.values_len = STATIC_ARRAY_SIZE (values);
        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));
@@ -336,14 +335,10 @@ static void submit_io_time (char const *plugin_instance, derive_t io_time, deriv
 #if KERNEL_LINUX
 static void submit_in_progress (char const *disk_name, gauge_t in_progress)
 {
-       value_t v;
        value_list_t vl = VALUE_LIST_INIT;
 
-       v.gauge = in_progress;
-
-       vl.values = &v;
+       vl.values = &(value_t) { .gauge = in_progress };
        vl.values_len = 1;
-       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));
@@ -351,7 +346,6 @@ static void submit_in_progress (char const *disk_name, gauge_t in_progress)
        plugin_dispatch_values (&vl);
 }
 
-
 static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops)
 {
        double interval = CDTIME_T_TO_DOUBLE (plugin_get_interval ());
@@ -953,12 +947,11 @@ static int disk_read (void)
 #  error "kstat_io_t does not have the required members"
 # endif
        static kstat_io_t kio;
-       int i;
 
        if (kc == NULL)
                return (-1);
 
-       for (i = 0; i < numdisk; i++)
+       for (int i = 0; i < numdisk; i++)
        {
                if (kstat_read (kc, ksp[i], &kio) == -1)
                        continue;
@@ -996,13 +989,12 @@ static int disk_read (void)
 # else
        int disks;
 #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++) {
+       for (int counter = 0; counter < disks; counter++) {
                strncpy(name, ds->disk_name, sizeof(name));
                name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
 
@@ -1025,7 +1017,6 @@ static int disk_read (void)
        derive_t write_ops;
        perfstat_id_t firstpath;
        int rnumdisk;
-       int i;
 
        if ((numdisk = perfstat_disk(NULL, NULL, sizeof(perfstat_disk_t), 0)) < 0)
        {
@@ -1051,7 +1042,7 @@ static int disk_read (void)
                return (-1);
        }
 
-       for (i = 0; i < rnumdisk; i++)
+       for (int i = 0; i < rnumdisk; i++)
        {
                if (ignorelist_match (ignorelist, stat_disk[i].name) != 0)
                        continue;