Code

* disk plugin: call ignorelist_match() once per device, not for each sent metric
authorPavel Rochnyack <pavel2000@ngs.ru>
Thu, 25 Feb 2016 15:10:55 +0000 (22:10 +0700)
committerPavel Rochnyack <pavel2000@ngs.ru>
Sun, 24 Apr 2016 12:08:33 +0000 (18:08 +0600)
src/disk.c

index 0aac2db3b208b29cf69b65ccf6afab2778ade643..0d6248866efa0671be1ceb01a64fb3edb808d9dd 100644 (file)
@@ -279,10 +279,6 @@ static void disk_submit (const char *plugin_instance,
        value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
 
-       /* Both `ignorelist' and `plugin_instance' may be NULL. */
-       if (ignorelist_match (ignorelist, plugin_instance) != 0)
-         return;
-
        values[0].derive = read;
        values[1].derive = write;
 
@@ -303,9 +299,6 @@ static void submit_io_time (char const *plugin_instance, derive_t io_time, deriv
        value_t values[2];
        value_list_t vl = VALUE_LIST_INIT;
 
-       if (ignorelist_match (ignorelist, plugin_instance) != 0)
-         return;
-
        values[0].derive = io_time;
        values[1].derive = weighted_time;
 
@@ -326,9 +319,6 @@ static void submit_in_progress (char const *disk_name, gauge_t in_progress)
        value_t v;
        value_list_t vl = VALUE_LIST_INIT;
 
-       if (ignorelist_match (ignorelist, disk_name) != 0)
-         return;
-
        v.gauge = in_progress;
 
        vl.values = &v;
@@ -510,6 +500,15 @@ static int disk_read (void)
                else
                        ssnprintf (disk_name, sizeof (disk_name), "%i-%i", disk_major, disk_minor);
 
+               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
+
+               /* check the name against ignore list */
+               if (ignorelist_match (ignorelist, disk_name) != 0) {
+                       CFRelease (props_dict);
+                       IOObjectRelease (disk);
+                       continue;
+               }
+
                /* extract the stats */
                read_ops  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsReadsKey);
                read_byt  = dict_get_value (stats_dict, kIOBlockStorageDriverStatisticsBytesReadKey);
@@ -521,7 +520,6 @@ static int disk_read (void)
                IOObjectRelease (disk);
 
                /* and submit */
-               DEBUG ("disk plugin: disk_name = \"%s\"", disk_name);
                if ((read_byt != -1LL) || (write_byt != -1LL))
                        disk_submit (disk_name, "disk_octets", read_byt, write_byt);
                if ((read_ops != -1LL) || (write_ops != -1LL))
@@ -619,6 +617,9 @@ static int disk_read (void)
 
                disk_name = ((struct gprovider *)geom_id->lg_ptr)->lg_name;
 
+               if (ignorelist_match (ignorelist, disk_name) != 0)
+                       continue;
+
                if ((snap_iter->bytes[DEVSTAT_READ] != 0) || (snap_iter->bytes[DEVSTAT_WRITE] != 0)) {
                        disk_submit(disk_name, "disk_octets",
                                        (derive_t)snap_iter->bytes[DEVSTAT_READ],
@@ -871,6 +872,9 @@ static int disk_read (void)
                        output_name = alt_name;
 #endif
 
+               if (ignorelist_match (ignorelist, output_name) != 0)
+                       continue;
+
                if ((ds->read_bytes != 0) || (ds->write_bytes != 0))
                        disk_submit (output_name, "disk_octets",
                                        ds->read_bytes, ds->write_bytes);
@@ -938,6 +942,9 @@ static int disk_read (void)
 
                if (strncmp (ksp[i]->ks_class, "disk", 4) == 0)
                {
+                       if (ignorelist_match (ignorelist, ksp[i]->ks_name) != 0)
+                               continue;
+
                        disk_submit (ksp[i]->ks_name, "disk_octets",
                                        kio.KIO_ROCTETS, kio.KIO_WOCTETS);
                        disk_submit (ksp[i]->ks_name, "disk_ops",
@@ -948,6 +955,9 @@ static int disk_read (void)
                }
                else if (strncmp (ksp[i]->ks_class, "partition", 9) == 0)
                {
+                       if (ignorelist_match (ignorelist, ksp[i]->ks_name) != 0)
+                               continue;
+
                        disk_submit (ksp[i]->ks_name, "disk_octets",
                                        kio.KIO_ROCTETS, kio.KIO_WOCTETS);
                        disk_submit (ksp[i]->ks_name, "disk_ops",
@@ -972,6 +982,12 @@ static int disk_read (void)
        for (counter=0; counter < disks; counter++) {
                strncpy(name, ds->disk_name, sizeof(name));
                name[sizeof(name)-1] = '\0'; /* strncpy doesn't terminate longer strings */
+
+               if (ignorelist_match (ignorelist, name) != 0) {
+                       ds++;
+                       continue;
+               }
+
                disk_submit (name, "disk_octets", ds->read_bytes, ds->write_bytes);
                ds++;
        }
@@ -1014,6 +1030,9 @@ static int disk_read (void)
 
        for (i = 0; i < rnumdisk; i++)
        {
+               if (ignorelist_match (ignorelist, stat_disk[i].name) != 0)
+                       continue;
+
                read_sectors = stat_disk[i].rblks*stat_disk[i].bsize;
                write_sectors = stat_disk[i].wblks*stat_disk[i].bsize;
                disk_submit (stat_disk[i].name, "disk_octets", read_sectors, write_sectors);