]> arthur.barton.de Git - netdata.git/blob - src/proc_diskstats.c
disk now get the mount point at the menu (only when they are not partitions) #295
[netdata.git] / src / proc_diskstats.c
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10
11 #include "common.h"
12 #include "log.h"
13 #include "appconfig.h"
14 #include "procfile.h"
15 #include "rrd.h"
16 #include "plugin_proc.h"
17
18 #include "proc_self_mountinfo.h"
19
20 #define RRD_TYPE_DISK "disk"
21
22 struct disk {
23         unsigned long major;
24         unsigned long minor;
25         int partition_id;       // -1 = this is not a partition
26         char *family;
27         struct disk *next;
28 } *disk_root = NULL;
29
30 struct disk *get_disk(unsigned long major, unsigned long minor) {
31         static char path_find_block_device_partition[FILENAME_MAX + 1] = "";
32         static struct mountinfo *mountinfo_root = NULL;
33         struct disk *d;
34
35         // search for it in our RAM list.
36         // this is sequential, but since we just walk through
37         // and the number of disks / partitions in a system
38         // should not be that many, it should be acceptable
39         for(d = disk_root; d ; d = d->next)
40                 if(unlikely(d->major == major && d->minor == minor))
41                         break;
42
43         // if we found it, return it
44         if(likely(d))
45                 return d;
46
47         if(unlikely(!path_find_block_device_partition[0])) {
48                 char filename[FILENAME_MAX + 1];
49                 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/dev/block/%lu:%lu/partition");
50                 snprintf(path_find_block_device_partition, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get block device partition", filename));
51         }
52
53         // not found
54         // create a new disk structure
55         d = (struct disk *)malloc(sizeof(struct disk));
56         if(!d) fatal("Cannot allocate memory for struct disk in proc_diskstats.");
57
58         d->major = major;
59         d->minor = minor;
60         d->partition_id = -1;
61         d->next = NULL;
62
63         // append it to the list
64         if(!disk_root)
65                 disk_root = d;
66         else {
67                 struct disk *last;
68                 for(last = disk_root; last->next ;last = last->next);
69                 last->next = d;
70         }
71
72         // find if it is a partition
73         // by reading /sys/dev/block/MAJOR:MINOR/partition
74         char buffer[FILENAME_MAX + 1];
75         snprintf(buffer, FILENAME_MAX, path_find_block_device_partition, major, minor);
76
77         int fd = open(buffer, O_RDONLY, 0666);
78         if(likely(fd != -1)) {
79                 // we opened it
80                 int bytes = read(fd, buffer, FILENAME_MAX);
81                 close(fd);
82
83                 if(bytes > 0)
84                         d->partition_id = strtoul(buffer, NULL, 10);
85         }
86         // if the /partition file does not exist, it is a disk, not a partition
87
88         // ------------------------------------------------------------------------
89         // check if we can find its mount point
90
91         // mountinfo_find() can be called with NULL mountinfo_root
92         struct mountinfo *mi = mountinfo_find(mountinfo_root, d->major, d->minor);
93         if(unlikely(!mi)) {
94                 // mountinfo_free() can be called with NULL mountinfo_root
95                 mountinfo_free(mountinfo_root);
96
97                 // re-read mountinfo in case something changed
98                 mountinfo_root = mountinfo_read();
99
100                 // search again for this disk
101                 mi = mountinfo_find(mountinfo_root, d->major, d->minor);
102         }
103
104         if(mi)
105                 d->family = strdup(mi->mount_point);
106                 // no need to check for NULL
107         else
108                 d->family = NULL;
109
110         return d;
111 }
112
113 int do_proc_diskstats(int update_every, unsigned long long dt) {
114         static procfile *ff = NULL;
115         static char path_to_get_hw_sector_size[FILENAME_MAX + 1] = "";
116         static int enable_new_disks = -1;
117         static int do_io = -1, do_ops = -1, do_mops = -1, do_iotime = -1, do_qops = -1, do_util = -1, do_backlog = -1;
118
119         if(enable_new_disks == -1)      enable_new_disks = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "enable new disks detected at runtime", CONFIG_ONDEMAND_ONDEMAND);
120
121         if(do_io == -1)         do_io           = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "bandwidth for all disks", CONFIG_ONDEMAND_ONDEMAND);
122         if(do_ops == -1)        do_ops          = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "operations for all disks", CONFIG_ONDEMAND_ONDEMAND);
123         if(do_mops == -1)       do_mops         = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "merged operations for all disks", CONFIG_ONDEMAND_ONDEMAND);
124         if(do_iotime == -1)     do_iotime       = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "i/o time for all disks", CONFIG_ONDEMAND_ONDEMAND);
125         if(do_qops == -1)       do_qops         = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "queued operations for all disks", CONFIG_ONDEMAND_ONDEMAND);
126         if(do_util == -1)       do_util         = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "utilization percentage for all disks", CONFIG_ONDEMAND_ONDEMAND);
127         if(do_backlog == -1)do_backlog  = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "backlog for all disks", CONFIG_ONDEMAND_ONDEMAND);
128
129         if(!ff) {
130                 char filename[FILENAME_MAX + 1];
131                 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/diskstats");
132                 ff = procfile_open(config_get("plugin:proc:/proc/diskstats", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
133         }
134         if(!ff) return 1;
135
136         if(!path_to_get_hw_sector_size[0]) {
137                 char filename[FILENAME_MAX + 1];
138                 snprintf(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/block/%s/queue/hw_sector_size");
139                 snprintf(path_to_get_hw_sector_size, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get h/w sector size", filename));
140         }
141
142         ff = procfile_readall(ff);
143         if(!ff) return 0; // we return 0, so that we will retry to open it next time
144
145         uint32_t lines = procfile_lines(ff), l;
146         uint32_t words;
147
148         for(l = 0; l < lines ;l++) {
149                 char *disk;
150                 unsigned long long      major = 0, minor = 0,
151                                                         reads = 0,  mreads = 0,  readsectors = 0,  readms = 0,
152                                                         writes = 0, mwrites = 0, writesectors = 0, writems = 0,
153                                                         queued_ios = 0, busy_ms = 0, backlog_ms = 0;
154
155                 unsigned long long      last_reads = 0,  last_readsectors = 0,  last_readms = 0,
156                                                         last_writes = 0, last_writesectors = 0, last_writems = 0,
157                                                         last_busy_ms = 0;
158
159                 words = procfile_linewords(ff, l);
160                 if(words < 14) continue;
161
162                 major                   = strtoull(procfile_lineword(ff, l, 0), NULL, 10);
163                 minor                   = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
164                 disk                    = procfile_lineword(ff, l, 2);
165
166                 // # of reads completed # of writes completed
167                 // This is the total number of reads or writes completed successfully.
168                 reads                   = strtoull(procfile_lineword(ff, l, 3), NULL, 10);      // rd_ios
169                 writes                  = strtoull(procfile_lineword(ff, l, 7), NULL, 10);      // wr_ios
170
171                 // # of reads merged # of writes merged
172                 // Reads and writes which are adjacent to each other may be merged for
173             // efficiency.  Thus two 4K reads may become one 8K read before it is
174             // ultimately handed to the disk, and so it will be counted (and queued)
175                 mreads                  = strtoull(procfile_lineword(ff, l, 4), NULL, 10);      // rd_merges_or_rd_sec
176                 mwrites                 = strtoull(procfile_lineword(ff, l, 8), NULL, 10);      // wr_merges
177
178                 // # of sectors read # of sectors written
179                 // This is the total number of sectors read or written successfully.
180                 readsectors     = strtoull(procfile_lineword(ff, l, 5), NULL, 10);      // rd_sec_or_wr_ios
181                 writesectors    = strtoull(procfile_lineword(ff, l, 9), NULL, 10);      // wr_sec
182
183                 // # of milliseconds spent reading # of milliseconds spent writing
184                 // This is the total number of milliseconds spent by all reads or writes (as
185                 // measured from __make_request() to end_that_request_last()).
186                 readms                  = strtoull(procfile_lineword(ff, l, 6), NULL, 10);      // rd_ticks_or_wr_sec
187                 writems                 = strtoull(procfile_lineword(ff, l, 10), NULL, 10);     // wr_ticks
188
189                 // # of I/Os currently in progress
190                 // The only field that should go to zero. Incremented as requests are
191                 // given to appropriate struct request_queue and decremented as they finish.
192                 queued_ios              = strtoull(procfile_lineword(ff, l, 11), NULL, 10);     // ios_pgr
193
194                 // # of milliseconds spent doing I/Os
195                 // This field increases so long as field queued_ios is nonzero.
196                 busy_ms                 = strtoull(procfile_lineword(ff, l, 12), NULL, 10);     // tot_ticks
197
198                 // weighted # of milliseconds spent doing I/Os
199                 // This field is incremented at each I/O start, I/O completion, I/O
200                 // merge, or read of these stats by the number of I/Os in progress
201                 // (field queued_ios) times the number of milliseconds spent doing I/O since the
202                 // last update of this field.  This can provide an easy measure of both
203                 // I/O completion time and the backlog that may be accumulating.
204                 backlog_ms              = strtoull(procfile_lineword(ff, l, 13), NULL, 10);     // rq_ticks
205
206                 int def_enabled = 0;
207
208                 // remove slashes from disk names
209                 char *s;
210                 for(s = disk; *s ;s++) if(*s == '/') *s = '_';
211
212                 struct disk *d = get_disk(major, minor);
213                 if(d->partition_id == -1)
214                         def_enabled = enable_new_disks;
215                 else
216                         def_enabled = 0;
217
218                 char *family = d->family;
219                 if(!family) family = disk;
220
221 /*
222                 switch(major) {
223                         case 9: // MDs
224                         case 43: // network block
225                         case 144: // nfs
226                         case 145: // nfs
227                         case 146: // nfs
228                         case 199: // veritas
229                         case 201: // veritas
230                         case 251: // dm
231                         case 253: // virtio
232                                 def_enabled = enable_new_disks;
233                                 break;
234
235                         case 48: // RAID
236                         case 49: // RAID
237                         case 50: // RAID
238                         case 51: // RAID
239                         case 52: // RAID
240                         case 53: // RAID
241                         case 54: // RAID
242                         case 55: // RAID
243                         case 112: // RAID
244                         case 136: // RAID
245                         case 137: // RAID
246                         case 138: // RAID
247                         case 139: // RAID
248                         case 140: // RAID
249                         case 141: // RAID
250                         case 142: // RAID
251                         case 143: // RAID
252                         case 179: // MMC
253                         case 180: // USB
254                                 if(minor % 8) def_enabled = 0; // partitions
255                                 else def_enabled = enable_new_disks;
256                                 break;
257
258                         case 8: // scsi disks
259                         case 65: // scsi disks
260                         case 66: // scsi disks
261                         case 67: // scsi disks
262                         case 68: // scsi disks
263                         case 69: // scsi disks
264                         case 70: // scsi disks
265                         case 71: // scsi disks
266                         case 72: // scsi disks
267                         case 73: // scsi disks
268                         case 74: // scsi disks
269                         case 75: // scsi disks
270                         case 76: // scsi disks
271                         case 77: // scsi disks
272                         case 78: // scsi disks
273                         case 79: // scsi disks
274                         case 80: // i2o
275                         case 81: // i2o
276                         case 82: // i2o
277                         case 83: // i2o
278                         case 84: // i2o
279                         case 85: // i2o
280                         case 86: // i2o
281                         case 87: // i2o
282                         case 101: // hyperdisk
283                         case 102: // compressed
284                         case 104: // scsi
285                         case 105: // scsi
286                         case 106: // scsi
287                         case 107: // scsi
288                         case 108: // scsi
289                         case 109: // scsi
290                         case 110: // scsi
291                         case 111: // scsi
292                         case 114: // bios raid
293                         case 116: // ram board
294                         case 128: // scsi
295                         case 129: // scsi
296                         case 130: // scsi
297                         case 131: // scsi
298                         case 132: // scsi
299                         case 133: // scsi
300                         case 134: // scsi
301                         case 135: // scsi
302                         case 153: // raid
303                         case 202: // xen
304                         case 254: // virtio3
305                         case 256: // flash
306                         case 257: // flash
307                         case 259: // nvme0n1 issue #119
308                                 if(minor % 16) def_enabled = 0; // partitions
309                                 else def_enabled = enable_new_disks;
310                                 break;
311
312                         case 160: // raid
313                         case 161: // raid
314                                 if(minor % 32) def_enabled = 0; // partitions
315                                 else def_enabled = enable_new_disks;
316                                 break;
317
318                         case 3: // ide
319                         case 13: // 8bit ide
320                         case 22: // ide
321                         case 33: // ide
322                         case 34: // ide
323                         case 56: // ide
324                         case 57: // ide
325                         case 88: // ide
326                         case 89: // ide
327                         case 90: // ide
328                         case 91: // ide
329                                 if(minor % 64) def_enabled = 0; // partitions
330                                 else def_enabled = enable_new_disks;
331                                 break;
332
333                         case 252: // zram
334                                 def_enabled = 0;
335                                 break;
336
337                         default:
338                                 def_enabled = 0;
339                                 break;
340                 }
341 */
342
343                 int ddo_io = do_io, ddo_ops = do_ops, ddo_mops = do_mops, ddo_iotime = do_iotime, ddo_qops = do_qops, ddo_util = do_util, ddo_backlog = do_backlog;
344
345                 // check which charts are enabled for this disk
346                 {
347                         char var_name[4096 + 1];
348                         snprintf(var_name, 4096, "plugin:proc:/proc/diskstats:%s", disk);
349                         def_enabled = config_get_boolean_ondemand(var_name, "enabled", def_enabled);
350                         if(def_enabled == CONFIG_ONDEMAND_NO) continue;
351                         if(def_enabled == CONFIG_ONDEMAND_ONDEMAND && !reads && !writes) continue;
352
353
354                         ddo_io          = config_get_boolean_ondemand(var_name, "bandwidth", ddo_io);
355                         ddo_ops         = config_get_boolean_ondemand(var_name, "operations", ddo_ops);
356                         ddo_mops        = config_get_boolean_ondemand(var_name, "merged operations", ddo_mops);
357                         ddo_iotime      = config_get_boolean_ondemand(var_name, "i/o time", ddo_iotime);
358                         ddo_qops        = config_get_boolean_ondemand(var_name, "queued operations", ddo_qops);
359                         ddo_util        = config_get_boolean_ondemand(var_name, "utilization percentage", ddo_util);
360                         ddo_backlog = config_get_boolean_ondemand(var_name, "backlog", ddo_backlog);
361
362                         // by default, do not add charts that do not have values
363                         if(ddo_io == CONFIG_ONDEMAND_ONDEMAND && !reads && !writes) ddo_io = 0;
364                         if(ddo_mops == CONFIG_ONDEMAND_ONDEMAND && mreads == 0 && mwrites == 0) ddo_mops = 0;
365                         if(ddo_iotime == CONFIG_ONDEMAND_ONDEMAND && readms == 0 && writems == 0) ddo_iotime = 0;
366                         if(ddo_util == CONFIG_ONDEMAND_ONDEMAND && busy_ms == 0) ddo_util = 0;
367                         if(ddo_backlog == CONFIG_ONDEMAND_ONDEMAND && backlog_ms == 0) ddo_backlog = 0;
368                         if(ddo_qops == CONFIG_ONDEMAND_ONDEMAND && backlog_ms == 0) ddo_qops = 0;
369
370                         // for absolute values, we need to switch the setting to 'yes'
371                         // to allow it refresh from now on
372                         if(ddo_qops == CONFIG_ONDEMAND_ONDEMAND) config_set(var_name, "queued operations", "yes");
373                 }
374
375                 RRDSET *st;
376
377                 // --------------------------------------------------------------------
378
379                 int sector_size = 512;
380                 if(ddo_io) {
381                         st = rrdset_find_bytype(RRD_TYPE_DISK, disk);
382                         if(!st) {
383                                 char tf[FILENAME_MAX + 1], *t;
384                                 char ssfilename[FILENAME_MAX + 1];
385
386                                 strncpy(tf, disk, FILENAME_MAX);
387                                 tf[FILENAME_MAX] = '\0';
388
389                                 // replace all / with !
390                                 while((t = strchr(tf, '/'))) *t = '!';
391
392                                 snprintf(ssfilename, FILENAME_MAX, path_to_get_hw_sector_size, tf);
393                                 FILE *fpss = fopen(ssfilename, "r");
394                                 if(fpss) {
395                                         char ssbuffer[1025];
396                                         char *tmp = fgets(ssbuffer, 1024, fpss);
397
398                                         if(tmp) {
399                                                 sector_size = atoi(tmp);
400                                                 if(sector_size <= 0) {
401                                                         error("Invalid sector size %d for device %s in %s. Assuming 512.", sector_size, disk, ssfilename);
402                                                         sector_size = 512;
403                                                 }
404                                         }
405                                         else error("Cannot read data for sector size for device %s from %s. Assuming 512.", disk, ssfilename);
406
407                                         fclose(fpss);
408                                 }
409                                 else error("Cannot read sector size for device %s from %s. Assuming 512.", disk, ssfilename);
410
411                                 st = rrdset_create(RRD_TYPE_DISK, disk, NULL, family, "disk.io", "Disk I/O Bandwidth", "kilobytes/s", 2000, update_every, RRDSET_TYPE_AREA);
412
413                                 rrddim_add(st, "reads", NULL, sector_size, 1024, RRDDIM_INCREMENTAL);
414                                 rrddim_add(st, "writes", NULL, sector_size * -1, 1024, RRDDIM_INCREMENTAL);
415                         }
416                         else rrdset_next_usec(st, dt);
417
418                         last_readsectors  = rrddim_set(st, "reads", readsectors);
419                         last_writesectors = rrddim_set(st, "writes", writesectors);
420                         rrdset_done(st);
421                 }
422
423                 // --------------------------------------------------------------------
424
425                 if(ddo_ops) {
426                         st = rrdset_find_bytype("disk_ops", disk);
427                         if(!st) {
428                                 st = rrdset_create("disk_ops", disk, NULL, family, "disk.ops", "Disk Completed I/O Operations", "operations/s", 2001, update_every, RRDSET_TYPE_LINE);
429                                 st->isdetail = 1;
430
431                                 rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_INCREMENTAL);
432                                 rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_INCREMENTAL);
433                         }
434                         else rrdset_next_usec(st, dt);
435
436                         last_reads  = rrddim_set(st, "reads", reads);
437                         last_writes = rrddim_set(st, "writes", writes);
438                         rrdset_done(st);
439                 }
440
441                 // --------------------------------------------------------------------
442
443                 if(ddo_qops) {
444                         st = rrdset_find_bytype("disk_qops", disk);
445                         if(!st) {
446                                 st = rrdset_create("disk_qops", disk, NULL, family, "disk.qops", "Disk Current I/O Operations", "operations", 2002, update_every, RRDSET_TYPE_LINE);
447                                 st->isdetail = 1;
448
449                                 rrddim_add(st, "operations", NULL, 1, 1, RRDDIM_ABSOLUTE);
450                         }
451                         else rrdset_next_usec(st, dt);
452
453                         rrddim_set(st, "operations", queued_ios);
454                         rrdset_done(st);
455                 }
456
457                 // --------------------------------------------------------------------
458
459                 if(ddo_backlog) {
460                         st = rrdset_find_bytype("disk_backlog", disk);
461                         if(!st) {
462                                 st = rrdset_create("disk_backlog", disk, NULL, family, "disk.backlog", "Disk Backlog", "backlog (ms)", 2003, update_every, RRDSET_TYPE_AREA);
463                                 st->isdetail = 1;
464
465                                 rrddim_add(st, "backlog", NULL, 1, 10, RRDDIM_INCREMENTAL);
466                         }
467                         else rrdset_next_usec(st, dt);
468
469                         rrddim_set(st, "backlog", backlog_ms);
470                         rrdset_done(st);
471                 }
472
473                 // --------------------------------------------------------------------
474
475                 if(ddo_util) {
476                         st = rrdset_find_bytype("disk_util", disk);
477                         if(!st) {
478                                 st = rrdset_create("disk_util", disk, NULL, family, "disk.util", "Disk Utilization Time", "% of time working", 2004, update_every, RRDSET_TYPE_AREA);
479                                 st->isdetail = 1;
480
481                                 rrddim_add(st, "utilization", NULL, 1, 10, RRDDIM_INCREMENTAL);
482                         }
483                         else rrdset_next_usec(st, dt);
484
485                         last_busy_ms = rrddim_set(st, "utilization", busy_ms);
486                         rrdset_done(st);
487                 }
488
489                 // --------------------------------------------------------------------
490
491                 if(ddo_mops) {
492                         st = rrdset_find_bytype("disk_mops", disk);
493                         if(!st) {
494                                 st = rrdset_create("disk_mops", disk, NULL, family, "disk.mops", "Disk Merged Operations", "merged operations/s", 2021, update_every, RRDSET_TYPE_LINE);
495                                 st->isdetail = 1;
496
497                                 rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_INCREMENTAL);
498                                 rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_INCREMENTAL);
499                         }
500                         else rrdset_next_usec(st, dt);
501
502                         rrddim_set(st, "reads", mreads);
503                         rrddim_set(st, "writes", mwrites);
504                         rrdset_done(st);
505                 }
506
507                 // --------------------------------------------------------------------
508
509                 if(ddo_iotime) {
510                         st = rrdset_find_bytype("disk_iotime", disk);
511                         if(!st) {
512                                 st = rrdset_create("disk_iotime", disk, NULL, family, "disk.iotime", "Disk Total I/O Time", "milliseconds/s", 2022, update_every, RRDSET_TYPE_LINE);
513                                 st->isdetail = 1;
514
515                                 rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_INCREMENTAL);
516                                 rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_INCREMENTAL);
517                         }
518                         else rrdset_next_usec(st, dt);
519
520                         last_readms  = rrddim_set(st, "reads", readms);
521                         last_writems = rrddim_set(st, "writes", writems);
522                         rrdset_done(st);
523                 }
524
525                 // --------------------------------------------------------------------
526                 // calculate differential charts
527                 // only if this is not the first time we run
528
529                 if(dt) {
530                         if(ddo_iotime && ddo_ops) {
531                                 st = rrdset_find_bytype("disk_await", disk);
532                                 if(!st) {
533                                         st = rrdset_create("disk_await", disk, NULL, family, "disk.await", "Average Completed I/O Operation Time", "ms per operation", 2005, update_every, RRDSET_TYPE_LINE);
534                                         st->isdetail = 1;
535
536                                         rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_ABSOLUTE);
537                                         rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_ABSOLUTE);
538                                 }
539                                 else rrdset_next_usec(st, dt);
540
541                                 rrddim_set(st, "reads", (reads - last_reads) ? (readms - last_readms) / (reads - last_reads) : 0);
542                                 rrddim_set(st, "writes", (writes - last_writes) ? (writems - last_writems) / (writes - last_writes) : 0);
543                                 rrdset_done(st);
544                         }
545
546                         if(ddo_io && ddo_ops) {
547                                 st = rrdset_find_bytype("disk_avgsz", disk);
548                                 if(!st) {
549                                         st = rrdset_create("disk_avgsz", disk, NULL, family, "disk.avgsz", "Average Completed I/O Operation Bandwidth", "kilobytes per operation", 2006, update_every, RRDSET_TYPE_AREA);
550                                         st->isdetail = 1;
551
552                                         rrddim_add(st, "reads", NULL, sector_size, 1024, RRDDIM_ABSOLUTE);
553                                         rrddim_add(st, "writes", NULL, -sector_size, 1024, RRDDIM_ABSOLUTE);
554                                 }
555                                 else rrdset_next_usec(st, dt);
556
557                                 rrddim_set(st, "reads", (reads - last_reads) ? (readsectors - last_readsectors) / (reads - last_reads) : 0);
558                                 rrddim_set(st, "writes", (writes - last_writes) ? (writesectors - last_writesectors) / (writes - last_writes) : 0);
559                                 rrdset_done(st);
560                         }
561
562                         if(ddo_util && ddo_ops) {
563                                 st = rrdset_find_bytype("disk_svctm", disk);
564                                 if(!st) {
565                                         st = rrdset_create("disk_svctm", disk, NULL, family, "disk.svctm", "Average Service Time", "ms per operation", 2007, update_every, RRDSET_TYPE_LINE);
566                                         st->isdetail = 1;
567
568                                         rrddim_add(st, "svctm", NULL, 1, 1, RRDDIM_ABSOLUTE);
569                                 }
570                                 else rrdset_next_usec(st, dt);
571
572                                 rrddim_set(st, "svctm", ((reads - last_reads) + (writes - last_writes)) ? (busy_ms - last_busy_ms) / ((reads - last_reads) + (writes - last_writes)) : 0);
573                                 rrdset_done(st);
574                         }
575                 }
576         }
577
578         return 0;
579 }