]> granicus.if.org Git - sysstat/blobdiff - rd_stats.c
sar/sadc: Add stable identifier support for disks statistics
[sysstat] / rd_stats.c
index deee09ebae1d3914f6156d1b0d3ca246a611b094..2569fae28e8c91f9d8fd71e820e4bed36c4ffdc8 100644 (file)
@@ -791,8 +791,9 @@ __nr_t read_diskstats_disk(struct stats_disk *st_disk, __nr_t nr_alloc,
        char line[1024];
        char dev_name[MAX_NAME_LEN];
        struct stats_disk *st_disk_i;
-       unsigned int major, minor, rd_ticks, wr_ticks, dc_ticks, tot_ticks, rq_ticks;
+       unsigned int major, minor, rd_ticks, wr_ticks, dc_ticks, tot_ticks, rq_ticks, part_nr;
        unsigned long rd_ios, wr_ios, dc_ios, rd_sec, wr_sec, dc_sec;
+       unsigned long long wwn[2];
        __nr_t dsk_read = 0;
 
        if ((fp = fopen(DISKSTATS, "r")) == NULL)
@@ -839,6 +840,15 @@ __nr_t read_diskstats_disk(struct stats_disk *st_disk, __nr_t nr_alloc,
                                st_disk_i->dc_ticks  = dc_ticks;
                                st_disk_i->tot_ticks = tot_ticks;
                                st_disk_i->rq_ticks  = rq_ticks;
+
+                               if (get_wwnid_from_pretty(dev_name, wwn, &part_nr) < 0) {
+                                       st_disk_i->wwn[0] = 0ULL;
+                               }
+                               else {
+                                       st_disk_i->wwn[0] = wwn[0];
+                                       st_disk_i->wwn[1] = wwn[1];
+                                       st_disk_i->part_nr = part_nr;
+                               }
                        }
                }
        }
@@ -1545,6 +1555,7 @@ __nr_t read_net_eicmp(struct stats_net_eicmp *st_net_eicmp)
 {
        FILE *fp;
        char line[1024];
+       static char format[256] = "";
        int sw = FALSE;
 
        if ((fp = fopen(NET_SNMP, "r")) == NULL)
@@ -1554,8 +1565,7 @@ __nr_t read_net_eicmp(struct stats_net_eicmp *st_net_eicmp)
 
                if (!strncmp(line, "Icmp:", 5)) {
                        if (sw) {
-                               sscanf(line + 5, "%*u %lu %lu %lu %lu %lu %lu %*u %*u "
-                                      "%*u %*u %*u %*u %*u %lu %lu %lu %lu %lu %lu",
+                               sscanf(line + 5, format,
                                       &st_net_eicmp->InErrors,
                                       &st_net_eicmp->InDestUnreachs,
                                       &st_net_eicmp->InTimeExcds,
@@ -1572,6 +1582,25 @@ __nr_t read_net_eicmp(struct stats_net_eicmp *st_net_eicmp)
                                break;
                        }
                        else {
+                               if (!strlen(format)) {
+                                       if (strstr(line, "InCsumErrors")) {
+                                               /*
+                                                * New format: InCsumErrors field exists at position #3.
+                                                * Capture: 2,4,5,6,7,8,16,17,18,19,20,21
+                                                */
+                                               strcpy(format, "%*u %lu %*u %lu %lu %lu %lu %lu %*u %*u "
+                                                              "%*u %*u %*u %*u %*u %lu %lu %lu %lu %lu %lu");
+                                       }
+                                       else {
+                                               /*
+                                                * Old format: InCsumErrors field doesn't exist.
+                                                * Capture: 2,3,4,5,6,7,15,16,17,18,19,20
+                                                */
+                                               strcpy(format, "%*u %lu %lu %lu %lu %lu %lu %*u %*u "
+                                                              "%*u %*u %*u %*u %*u %lu %lu %lu %lu %lu %lu");
+
+                                       }
+                               }
                                sw = TRUE;
                        }
                }
@@ -2577,14 +2606,14 @@ __nr_t read_fchost(struct stats_fchost *st_fc, __nr_t nr_alloc)
        unsigned long rx_frames, tx_frames, rx_words, tx_words;
 
        /* Each host, if present, will have its own hostX entry within SYSFS_FCHOST */
-       if ((dir = opendir(SYSFS_FCHOST)) == NULL)
+       if ((dir = __opendir(SYSFS_FCHOST)) == NULL)
                return 0; /* No FC hosts */
 
        /*
         * Read each of the counters via sysfs, where they are
         * returned as hex values (e.g. 0x72400).
         */
-       while ((drd = readdir(dir)) != NULL) {
+       while ((drd = __readdir(dir)) != NULL) {
                rx_frames = tx_frames = rx_words = tx_words = 0;
 
                if (!strncmp(drd->d_name, "host", 4)) {
@@ -2640,7 +2669,7 @@ __nr_t read_fchost(struct stats_fchost *st_fc, __nr_t nr_alloc)
                }
        }
 
-       closedir(dir);
+       __closedir(dir);
        return fch_read;
 }