3 #define RRD_TYPE_DISK "disk"
5 #define DISK_TYPE_PHYSICAL 1
6 #define DISK_TYPE_PARTITION 2
7 #define DISK_TYPE_CONTAINER 3
9 static int check_for_new_mountpoints_every = 15;
12 char *disk; // the name of the disk (sda, sdb, etc)
20 // disk options caching
33 static struct mountinfo *disk_mountinfo_root = NULL;
35 static inline void mountinfo_reload(int force) {
36 static time_t last_loaded = 0;
37 time_t now = now_realtime_sec();
39 if(force || now - last_loaded >= check_for_new_mountpoints_every) {
40 // mountinfo_free() can be called with NULL disk_mountinfo_root
41 mountinfo_free(disk_mountinfo_root);
43 // re-read mountinfo in case something changed
44 disk_mountinfo_root = mountinfo_read(0);
50 static struct disk *get_disk(unsigned long major, unsigned long minor, char *disk) {
51 static char path_to_get_hw_sector_size[FILENAME_MAX + 1] = "";
52 static char path_to_get_hw_sector_size_partitions[FILENAME_MAX + 1] = "";
53 static char path_find_block_device[FILENAME_MAX + 1] = "";
56 // search for it in our RAM list.
57 // this is sequential, but since we just walk through
58 // and the number of disks / partitions in a system
59 // should not be that many, it should be acceptable
60 for(d = disk_root; d ; d = d->next)
61 if(unlikely(d->major == major && d->minor == minor))
64 // if we found it, return it
69 // create a new disk structure
70 d = (struct disk *)mallocz(sizeof(struct disk));
72 d->disk = strdupz(disk);
75 d->type = DISK_TYPE_PHYSICAL; // Default type. Changed later if not correct.
77 d->sector_size = 512; // the default, will be changed below
80 // append it to the list
81 if(unlikely(!disk_root))
85 for(last = disk_root; last->next ;last = last->next);
89 // ------------------------------------------------------------------------
90 // find the type of the device
92 char buffer[FILENAME_MAX + 1];
94 // get the default path for finding info about the block device
95 if(unlikely(!path_find_block_device[0])) {
96 snprintfz(buffer, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/dev/block/%lu:%lu/%s");
97 snprintfz(path_find_block_device, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get block device infos", buffer));
100 // find if it is a partition
101 // by checking if /sys/dev/block/MAJOR:MINOR/partition is readable.
102 snprintfz(buffer, FILENAME_MAX, path_find_block_device, major, minor, "partition");
103 if(likely(access(buffer, R_OK) == 0)) {
104 d->type = DISK_TYPE_PARTITION;
107 // find if it is a container
108 // by checking if /sys/dev/block/MAJOR:MINOR/slaves has entries
109 snprintfz(buffer, FILENAME_MAX, path_find_block_device, major, minor, "slaves/");
110 DIR *dirp = opendir(buffer);
111 if(likely(dirp != NULL)) {
113 while( (dp = readdir(dirp)) ) {
114 // . and .. are also files in empty folders.
115 if(unlikely(strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)) {
119 d->type = DISK_TYPE_CONTAINER;
121 // Stop the loop after we found one file.
124 if(unlikely(closedir(dirp) == -1))
125 error("Unable to close dir %s", buffer);
129 // ------------------------------------------------------------------------
130 // check if we can find its mount point
132 // mountinfo_find() can be called with NULL disk_mountinfo_root
133 struct mountinfo *mi = mountinfo_find(disk_mountinfo_root, d->major, d->minor);
135 d->mount_point = strdupz(mi->mount_point);
137 d->mount_point = NULL;
139 // ------------------------------------------------------------------------
140 // find the disk sector size
142 if(unlikely(!path_to_get_hw_sector_size[0])) {
143 snprintfz(buffer, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/block/%s/queue/hw_sector_size");
144 snprintfz(path_to_get_hw_sector_size, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get h/w sector size", buffer));
146 if(unlikely(!path_to_get_hw_sector_size_partitions[0])) {
147 snprintfz(buffer, FILENAME_MAX, "%s%s", global_host_prefix, "/sys/dev/block/%lu:%lu/subsystem/%s/../queue/hw_sector_size");
148 snprintfz(path_to_get_hw_sector_size_partitions, FILENAME_MAX, "%s", config_get("plugin:proc:/proc/diskstats", "path to get h/w sector size for partitions", buffer));
152 char tf[FILENAME_MAX + 1], *t;
153 strncpyz(tf, d->disk, FILENAME_MAX);
155 // replace all / with !
157 if(unlikely(*t == '/')) *t = '!';
159 if(likely(d->type == DISK_TYPE_PARTITION))
160 snprintfz(buffer, FILENAME_MAX, path_to_get_hw_sector_size_partitions, d->major, d->minor, tf);
162 snprintfz(buffer, FILENAME_MAX, path_to_get_hw_sector_size, tf);
164 FILE *fpss = fopen(buffer, "r");
166 char buffer2[1024 + 1];
167 char *tmp = fgets(buffer2, 1024, fpss);
170 d->sector_size = atoi(tmp);
171 if(unlikely(d->sector_size <= 0)) {
172 error("Invalid sector size %d for device %s in %s. Assuming 512.", d->sector_size, d->disk, buffer);
173 d->sector_size = 512;
176 else error("Cannot read data for sector size for device %s from %s. Assuming 512.", d->disk, buffer);
180 else error("Cannot read sector size for device %s from %s. Assuming 512.", d->disk, buffer);
186 static inline int is_major_enabled(int major) {
187 static char *major_configs = NULL;
188 static size_t major_size = 0;
190 if(major < 0) return 1;
192 size_t wanted_size = (size_t)major + 1;
194 if(major_size < wanted_size) {
195 major_configs = reallocz(major_configs, wanted_size);
198 for(i = major_size; i < wanted_size ; i++)
199 major_configs[i] = -1;
201 major_size = wanted_size;
204 if(major_configs[major] == -1) {
205 char buffer[CONFIG_MAX_NAME + 1];
206 snprintfz(buffer, CONFIG_MAX_NAME, "performance metrics for disks with major %d", major);
207 major_configs[major] = (char)config_get_boolean("plugin:proc:/proc/diskstats", buffer, 1);
210 return major_configs[major];
213 int do_proc_diskstats(int update_every, usec_t dt) {
216 static procfile *ff = NULL;
217 static int global_enable_new_disks_detected_at_runtime = CONFIG_ONDEMAND_YES,
218 global_enable_performance_for_physical_disks = CONFIG_ONDEMAND_ONDEMAND,
219 global_enable_performance_for_virtual_disks = CONFIG_ONDEMAND_ONDEMAND,
220 global_enable_performance_for_partitions = CONFIG_ONDEMAND_NO,
221 global_do_io = CONFIG_ONDEMAND_ONDEMAND,
222 global_do_ops = CONFIG_ONDEMAND_ONDEMAND,
223 global_do_mops = CONFIG_ONDEMAND_ONDEMAND,
224 global_do_iotime = CONFIG_ONDEMAND_ONDEMAND,
225 global_do_qops = CONFIG_ONDEMAND_ONDEMAND,
226 global_do_util = CONFIG_ONDEMAND_ONDEMAND,
227 global_do_backlog = CONFIG_ONDEMAND_ONDEMAND,
228 globals_initialized = 0;
230 if(unlikely(!globals_initialized)) {
231 global_enable_new_disks_detected_at_runtime = config_get_boolean("plugin:proc:/proc/diskstats", "enable new disks detected at runtime", global_enable_new_disks_detected_at_runtime);
233 global_enable_performance_for_physical_disks = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "performance metrics for physical disks", global_enable_performance_for_physical_disks);
234 global_enable_performance_for_virtual_disks = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "performance metrics for virtual disks", global_enable_performance_for_virtual_disks);
235 global_enable_performance_for_partitions = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "performance metrics for partitions", global_enable_performance_for_partitions);
237 global_do_io = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "bandwidth for all disks", global_do_io);
238 global_do_ops = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "operations for all disks", global_do_ops);
239 global_do_mops = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "merged operations for all disks", global_do_mops);
240 global_do_iotime = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "i/o time for all disks", global_do_iotime);
241 global_do_qops = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "queued operations for all disks", global_do_qops);
242 global_do_util = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "utilization percentage for all disks", global_do_util);
243 global_do_backlog = config_get_boolean_ondemand("plugin:proc:/proc/diskstats", "backlog for all disks", global_do_backlog);
245 check_for_new_mountpoints_every = (int)config_get_number("plugin:proc:/proc/diskstats", "check for new mount points every", check_for_new_mountpoints_every);
246 if(check_for_new_mountpoints_every < update_every)
247 check_for_new_mountpoints_every = update_every;
249 globals_initialized = 1;
252 // --------------------------------------------------------------------------
253 // this is smart enough not to reload it every time
257 // --------------------------------------------------------------------------
260 char filename[FILENAME_MAX + 1];
261 snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/diskstats");
262 ff = procfile_open(config_get("plugin:proc:/proc/diskstats", "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
264 if(unlikely(!ff)) return 0;
266 ff = procfile_readall(ff);
267 if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
269 uint32_t lines = procfile_lines(ff), l;
271 for(l = 0; l < lines ;l++) {
272 // --------------------------------------------------------------------------
276 unsigned long major = 0, minor = 0;
278 collected_number reads = 0, mreads = 0, readsectors = 0, readms = 0,
279 writes = 0, mwrites = 0, writesectors = 0, writems = 0,
280 queued_ios = 0, busy_ms = 0, backlog_ms = 0;
282 collected_number last_reads = 0, last_readsectors = 0, last_readms = 0,
283 last_writes = 0, last_writesectors = 0, last_writems = 0,
286 uint32_t words = procfile_linewords(ff, l);
287 if(unlikely(words < 14)) continue;
289 major = strtoul(procfile_lineword(ff, l, 0), NULL, 10);
290 minor = strtoul(procfile_lineword(ff, l, 1), NULL, 10);
291 disk = procfile_lineword(ff, l, 2);
293 // # of reads completed # of writes completed
294 // This is the total number of reads or writes completed successfully.
295 reads = strtoull(procfile_lineword(ff, l, 3), NULL, 10); // rd_ios
296 writes = strtoull(procfile_lineword(ff, l, 7), NULL, 10); // wr_ios
298 // # of reads merged # of writes merged
299 // Reads and writes which are adjacent to each other may be merged for
300 // efficiency. Thus two 4K reads may become one 8K read before it is
301 // ultimately handed to the disk, and so it will be counted (and queued)
302 mreads = strtoull(procfile_lineword(ff, l, 4), NULL, 10); // rd_merges_or_rd_sec
303 mwrites = strtoull(procfile_lineword(ff, l, 8), NULL, 10); // wr_merges
305 // # of sectors read # of sectors written
306 // This is the total number of sectors read or written successfully.
307 readsectors = strtoull(procfile_lineword(ff, l, 5), NULL, 10); // rd_sec_or_wr_ios
308 writesectors = strtoull(procfile_lineword(ff, l, 9), NULL, 10); // wr_sec
310 // # of milliseconds spent reading # of milliseconds spent writing
311 // This is the total number of milliseconds spent by all reads or writes (as
312 // measured from __make_request() to end_that_request_last()).
313 readms = strtoull(procfile_lineword(ff, l, 6), NULL, 10); // rd_ticks_or_wr_sec
314 writems = strtoull(procfile_lineword(ff, l, 10), NULL, 10); // wr_ticks
316 // # of I/Os currently in progress
317 // The only field that should go to zero. Incremented as requests are
318 // given to appropriate struct request_queue and decremented as they finish.
319 queued_ios = strtoull(procfile_lineword(ff, l, 11), NULL, 10); // ios_pgr
321 // # of milliseconds spent doing I/Os
322 // This field increases so long as field queued_ios is nonzero.
323 busy_ms = strtoull(procfile_lineword(ff, l, 12), NULL, 10); // tot_ticks
325 // weighted # of milliseconds spent doing I/Os
326 // This field is incremented at each I/O start, I/O completion, I/O
327 // merge, or read of these stats by the number of I/Os in progress
328 // (field queued_ios) times the number of milliseconds spent doing I/O since the
329 // last update of this field. This can provide an easy measure of both
330 // I/O completion time and the backlog that may be accumulating.
331 backlog_ms = strtoull(procfile_lineword(ff, l, 13), NULL, 10); // rq_ticks
334 // --------------------------------------------------------------------------
335 // remove slashes from disk names
337 for(s = disk; *s ;s++)
338 if(*s == '/') *s = '_';
340 // --------------------------------------------------------------------------
341 // get a disk structure for the disk
343 struct disk *d = get_disk(major, minor, disk);
346 // --------------------------------------------------------------------------
347 // Set its family based on mount point
349 char *family = d->mount_point;
350 if(!family) family = disk;
353 // --------------------------------------------------------------------------
354 // Check the configuration for the device
356 if(unlikely(!d->configured)) {
357 char var_name[4096 + 1];
358 snprintfz(var_name, 4096, "plugin:proc:/proc/diskstats:%s", disk);
360 int def_enable = config_get_boolean_ondemand(var_name, "enable", global_enable_new_disks_detected_at_runtime);
361 if(unlikely(def_enable == CONFIG_ONDEMAND_NO)) {
362 // the user does not want any metrics for this disk
363 d->do_io = CONFIG_ONDEMAND_NO;
364 d->do_ops = CONFIG_ONDEMAND_NO;
365 d->do_mops = CONFIG_ONDEMAND_NO;
366 d->do_iotime = CONFIG_ONDEMAND_NO;
367 d->do_qops = CONFIG_ONDEMAND_NO;
368 d->do_util = CONFIG_ONDEMAND_NO;
369 d->do_backlog = CONFIG_ONDEMAND_NO;
372 // this disk is enabled
373 // check its direct settings
375 int def_performance = CONFIG_ONDEMAND_ONDEMAND;
377 // since this is 'on demand' we can figure the performance settings
378 // based on the type of disk
381 case DISK_TYPE_PHYSICAL:
382 def_performance = global_enable_performance_for_physical_disks;
385 case DISK_TYPE_PARTITION:
386 def_performance = global_enable_performance_for_partitions;
389 case DISK_TYPE_CONTAINER:
390 def_performance = global_enable_performance_for_virtual_disks;
394 // check if we have to disable performance for this disk
396 def_performance = is_major_enabled((int)major);
398 // ------------------------------------------------------------
399 // now we have def_performance and def_space
403 // check the user configuration (this will also show our 'on demand' decision)
404 def_performance = config_get_boolean_ondemand(var_name, "enable performance metrics", def_performance);
406 int ddo_io = CONFIG_ONDEMAND_NO,
407 ddo_ops = CONFIG_ONDEMAND_NO,
408 ddo_mops = CONFIG_ONDEMAND_NO,
409 ddo_iotime = CONFIG_ONDEMAND_NO,
410 ddo_qops = CONFIG_ONDEMAND_NO,
411 ddo_util = CONFIG_ONDEMAND_NO,
412 ddo_backlog = CONFIG_ONDEMAND_NO;
414 // we enable individual performance charts only when def_performance is not disabled
415 if(unlikely(def_performance != CONFIG_ONDEMAND_NO)) {
416 ddo_io = global_do_io,
417 ddo_ops = global_do_ops,
418 ddo_mops = global_do_mops,
419 ddo_iotime = global_do_iotime,
420 ddo_qops = global_do_qops,
421 ddo_util = global_do_util,
422 ddo_backlog = global_do_backlog;
425 d->do_io = config_get_boolean_ondemand(var_name, "bandwidth", ddo_io);
426 d->do_ops = config_get_boolean_ondemand(var_name, "operations", ddo_ops);
427 d->do_mops = config_get_boolean_ondemand(var_name, "merged operations", ddo_mops);
428 d->do_iotime = config_get_boolean_ondemand(var_name, "i/o time", ddo_iotime);
429 d->do_qops = config_get_boolean_ondemand(var_name, "queued operations", ddo_qops);
430 d->do_util = config_get_boolean_ondemand(var_name, "utilization percentage", ddo_util);
431 d->do_backlog = config_get_boolean_ondemand(var_name, "backlog", ddo_backlog);
439 // --------------------------------------------------------------------------
440 // Do performance metrics
442 if(d->do_io == CONFIG_ONDEMAND_YES || (d->do_io == CONFIG_ONDEMAND_ONDEMAND && (readsectors || writesectors))) {
443 d->do_io = CONFIG_ONDEMAND_YES;
445 st = rrdset_find_bytype(RRD_TYPE_DISK, disk);
447 st = rrdset_create(RRD_TYPE_DISK, disk, NULL, family, "disk.io", "Disk I/O Bandwidth", "kilobytes/s", 2000, update_every, RRDSET_TYPE_AREA);
449 rrddim_add(st, "reads", NULL, d->sector_size, 1024, RRDDIM_INCREMENTAL);
450 rrddim_add(st, "writes", NULL, d->sector_size * -1, 1024, RRDDIM_INCREMENTAL);
452 else rrdset_next(st);
454 last_readsectors = rrddim_set(st, "reads", readsectors);
455 last_writesectors = rrddim_set(st, "writes", writesectors);
459 // --------------------------------------------------------------------
461 if(d->do_ops == CONFIG_ONDEMAND_YES || (d->do_ops == CONFIG_ONDEMAND_ONDEMAND && (reads || writes))) {
462 d->do_ops = CONFIG_ONDEMAND_YES;
464 st = rrdset_find_bytype("disk_ops", disk);
466 st = rrdset_create("disk_ops", disk, NULL, family, "disk.ops", "Disk Completed I/O Operations", "operations/s", 2001, update_every, RRDSET_TYPE_LINE);
469 rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_INCREMENTAL);
470 rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_INCREMENTAL);
472 else rrdset_next(st);
474 last_reads = rrddim_set(st, "reads", reads);
475 last_writes = rrddim_set(st, "writes", writes);
479 // --------------------------------------------------------------------
481 if(d->do_qops == CONFIG_ONDEMAND_YES || (d->do_qops == CONFIG_ONDEMAND_ONDEMAND && queued_ios)) {
482 d->do_qops = CONFIG_ONDEMAND_YES;
484 st = rrdset_find_bytype("disk_qops", disk);
486 st = rrdset_create("disk_qops", disk, NULL, family, "disk.qops", "Disk Current I/O Operations", "operations", 2002, update_every, RRDSET_TYPE_LINE);
489 rrddim_add(st, "operations", NULL, 1, 1, RRDDIM_ABSOLUTE);
491 else rrdset_next(st);
493 rrddim_set(st, "operations", queued_ios);
497 // --------------------------------------------------------------------
499 if(d->do_backlog == CONFIG_ONDEMAND_YES || (d->do_backlog == CONFIG_ONDEMAND_ONDEMAND && backlog_ms)) {
500 d->do_backlog = CONFIG_ONDEMAND_YES;
502 st = rrdset_find_bytype("disk_backlog", disk);
504 st = rrdset_create("disk_backlog", disk, NULL, family, "disk.backlog", "Disk Backlog", "backlog (ms)", 2003, update_every, RRDSET_TYPE_AREA);
507 rrddim_add(st, "backlog", NULL, 1, 10, RRDDIM_INCREMENTAL);
509 else rrdset_next(st);
511 rrddim_set(st, "backlog", backlog_ms);
515 // --------------------------------------------------------------------
517 if(d->do_util == CONFIG_ONDEMAND_YES || (d->do_util == CONFIG_ONDEMAND_ONDEMAND && busy_ms)) {
518 d->do_util = CONFIG_ONDEMAND_YES;
520 st = rrdset_find_bytype("disk_util", disk);
522 st = rrdset_create("disk_util", disk, NULL, family, "disk.util", "Disk Utilization Time", "% of time working", 2004, update_every, RRDSET_TYPE_AREA);
525 rrddim_add(st, "utilization", NULL, 1, 10, RRDDIM_INCREMENTAL);
527 else rrdset_next(st);
529 last_busy_ms = rrddim_set(st, "utilization", busy_ms);
533 // --------------------------------------------------------------------
535 if(d->do_mops == CONFIG_ONDEMAND_YES || (d->do_mops == CONFIG_ONDEMAND_ONDEMAND && (mreads || mwrites))) {
536 d->do_mops = CONFIG_ONDEMAND_YES;
538 st = rrdset_find_bytype("disk_mops", disk);
540 st = rrdset_create("disk_mops", disk, NULL, family, "disk.mops", "Disk Merged Operations", "merged operations/s", 2021, update_every, RRDSET_TYPE_LINE);
543 rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_INCREMENTAL);
544 rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_INCREMENTAL);
546 else rrdset_next(st);
548 rrddim_set(st, "reads", mreads);
549 rrddim_set(st, "writes", mwrites);
553 // --------------------------------------------------------------------
555 if(d->do_iotime == CONFIG_ONDEMAND_YES || (d->do_iotime == CONFIG_ONDEMAND_ONDEMAND && (readms || writems))) {
556 d->do_iotime = CONFIG_ONDEMAND_YES;
558 st = rrdset_find_bytype("disk_iotime", disk);
560 st = rrdset_create("disk_iotime", disk, NULL, family, "disk.iotime", "Disk Total I/O Time", "milliseconds/s", 2022, update_every, RRDSET_TYPE_LINE);
563 rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_INCREMENTAL);
564 rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_INCREMENTAL);
566 else rrdset_next(st);
568 last_readms = rrddim_set(st, "reads", readms);
569 last_writems = rrddim_set(st, "writes", writems);
573 // --------------------------------------------------------------------
574 // calculate differential charts
575 // only if this is not the first time we run
578 if( (d->do_iotime == CONFIG_ONDEMAND_YES || (d->do_iotime == CONFIG_ONDEMAND_ONDEMAND && (readms || writems))) &&
579 (d->do_ops == CONFIG_ONDEMAND_YES || (d->do_ops == CONFIG_ONDEMAND_ONDEMAND && (reads || writes)))) {
580 st = rrdset_find_bytype("disk_await", disk);
582 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);
585 rrddim_add(st, "reads", NULL, 1, 1, RRDDIM_ABSOLUTE);
586 rrddim_add(st, "writes", NULL, -1, 1, RRDDIM_ABSOLUTE);
588 else rrdset_next(st);
590 rrddim_set(st, "reads", (reads - last_reads) ? (readms - last_readms) / (reads - last_reads) : 0);
591 rrddim_set(st, "writes", (writes - last_writes) ? (writems - last_writems) / (writes - last_writes) : 0);
595 if( (d->do_io == CONFIG_ONDEMAND_YES || (d->do_io == CONFIG_ONDEMAND_ONDEMAND && (readsectors || writesectors))) &&
596 (d->do_ops == CONFIG_ONDEMAND_YES || (d->do_ops == CONFIG_ONDEMAND_ONDEMAND && (reads || writes)))) {
597 st = rrdset_find_bytype("disk_avgsz", disk);
599 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);
602 rrddim_add(st, "reads", NULL, d->sector_size, 1024, RRDDIM_ABSOLUTE);
603 rrddim_add(st, "writes", NULL, d->sector_size * -1, 1024, RRDDIM_ABSOLUTE);
605 else rrdset_next(st);
607 rrddim_set(st, "reads", (reads - last_reads) ? (readsectors - last_readsectors) / (reads - last_reads) : 0);
608 rrddim_set(st, "writes", (writes - last_writes) ? (writesectors - last_writesectors) / (writes - last_writes) : 0);
612 if( (d->do_util == CONFIG_ONDEMAND_YES || (d->do_util == CONFIG_ONDEMAND_ONDEMAND && busy_ms)) &&
613 (d->do_ops == CONFIG_ONDEMAND_YES || (d->do_ops == CONFIG_ONDEMAND_ONDEMAND && (reads || writes)))) {
614 st = rrdset_find_bytype("disk_svctm", disk);
616 st = rrdset_create("disk_svctm", disk, NULL, family, "disk.svctm", "Average Service Time", "ms per operation", 2007, update_every, RRDSET_TYPE_LINE);
619 rrddim_add(st, "svctm", NULL, 1, 1, RRDDIM_ABSOLUTE);
621 else rrdset_next(st);
623 rrddim_set(st, "svctm", ((reads - last_reads) + (writes - last_writes)) ? (busy_ms - last_busy_ms) / ((reads - last_reads) + (writes - last_writes)) : 0);