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 #define CONFIG_SECTION_DISKSTATS "plugin:proc:/proc/diskstats"
10 #define DELAULT_EXLUDED_DISKS "loop* ram*"
13 char *disk; // the name of the disk (sda, sdb, etc)
21 // disk options caching
47 #define rrdset_obsolete_and_pointer_null(st) do { if(st) { rrdset_flag_set(st, RRDSET_FLAG_OBSOLETE); st = NULL; } } while(st)
49 static struct disk *get_disk(unsigned long major, unsigned long minor, char *disk) {
50 static char path_to_get_hw_sector_size[FILENAME_MAX + 1] = "";
51 static char path_to_get_hw_sector_size_partitions[FILENAME_MAX + 1] = "";
52 static char path_find_block_device[FILENAME_MAX + 1] = "";
53 static struct mountinfo *disk_mountinfo_root = NULL;
57 // search for it in our RAM list.
58 // this is sequential, but since we just walk through
59 // and the number of disks / partitions in a system
60 // should not be that many, it should be acceptable
61 for(d = disk_root; d ; d = d->next)
62 if(unlikely(d->major == major && d->minor == minor))
66 // create a new disk structure
67 d = (struct disk *)callocz(1, sizeof(struct disk));
69 d->disk = strdupz(disk);
72 d->type = DISK_TYPE_PHYSICAL; // Default type. Changed later if not correct.
74 d->sector_size = 512; // the default, will be changed below
77 // append it to the list
78 if(unlikely(!disk_root))
82 for(last = disk_root; last->next ;last = last->next);
86 // ------------------------------------------------------------------------
87 // find the type of the device
89 char buffer[FILENAME_MAX + 1];
91 // get the default path for finding info about the block device
92 if(unlikely(!path_find_block_device[0])) {
93 snprintfz(buffer, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/dev/block/%lu:%lu/%s");
94 snprintfz(path_find_block_device, FILENAME_MAX, "%s", config_get(CONFIG_SECTION_DISKSTATS, "path to get block device infos", buffer));
97 // find if it is a partition
98 // by checking if /sys/dev/block/MAJOR:MINOR/partition is readable.
99 snprintfz(buffer, FILENAME_MAX, path_find_block_device, major, minor, "partition");
100 if(likely(access(buffer, R_OK) == 0)) {
101 d->type = DISK_TYPE_PARTITION;
104 // find if it is a container
105 // by checking if /sys/dev/block/MAJOR:MINOR/slaves has entries
106 snprintfz(buffer, FILENAME_MAX, path_find_block_device, major, minor, "slaves/");
107 DIR *dirp = opendir(buffer);
108 if(likely(dirp != NULL)) {
110 while( (dp = readdir(dirp)) ) {
111 // . and .. are also files in empty folders.
112 if(unlikely(strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0)) {
116 d->type = DISK_TYPE_CONTAINER;
118 // Stop the loop after we found one file.
121 if(unlikely(closedir(dirp) == -1))
122 error("Unable to close dir %s", buffer);
126 // ------------------------------------------------------------------------
127 // check if we can find its mount point
129 // mountinfo_find() can be called with NULL disk_mountinfo_root
130 struct mountinfo *mi = mountinfo_find(disk_mountinfo_root, d->major, d->minor);
132 // mountinfo_free can be called with NULL
133 mountinfo_free(disk_mountinfo_root);
134 disk_mountinfo_root = mountinfo_read(0);
135 mi = mountinfo_find(disk_mountinfo_root, d->major, d->minor);
139 d->mount_point = strdupz(mi->mount_point);
141 d->mount_point = NULL;
143 // ------------------------------------------------------------------------
144 // find the disk sector size
146 if(unlikely(!path_to_get_hw_sector_size[0])) {
147 snprintfz(buffer, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/block/%s/queue/hw_sector_size");
148 snprintfz(path_to_get_hw_sector_size, FILENAME_MAX, "%s", config_get(CONFIG_SECTION_DISKSTATS, "path to get h/w sector size", buffer));
150 if(unlikely(!path_to_get_hw_sector_size_partitions[0])) {
151 snprintfz(buffer, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/sys/dev/block/%lu:%lu/subsystem/%s/../queue/hw_sector_size");
152 snprintfz(path_to_get_hw_sector_size_partitions, FILENAME_MAX, "%s", config_get(CONFIG_SECTION_DISKSTATS, "path to get h/w sector size for partitions", buffer));
156 char tf[FILENAME_MAX + 1], *t;
157 strncpyz(tf, d->disk, FILENAME_MAX);
159 // replace all / with !
161 if(unlikely(*t == '/')) *t = '!';
163 if(likely(d->type == DISK_TYPE_PARTITION))
164 snprintfz(buffer, FILENAME_MAX, path_to_get_hw_sector_size_partitions, d->major, d->minor, tf);
166 snprintfz(buffer, FILENAME_MAX, path_to_get_hw_sector_size, tf);
168 FILE *fpss = fopen(buffer, "r");
170 char buffer2[1024 + 1];
171 char *tmp = fgets(buffer2, 1024, fpss);
174 d->sector_size = str2i(tmp);
175 if(unlikely(d->sector_size <= 0)) {
176 error("Invalid sector size %d for device %s in %s. Assuming 512.", d->sector_size, d->disk, buffer);
177 d->sector_size = 512;
180 else error("Cannot read data for sector size for device %s from %s. Assuming 512.", d->disk, buffer);
184 else error("Cannot read sector size for device %s from %s. Assuming 512.", d->disk, buffer);
190 static inline int is_major_enabled(int major) {
191 static int8_t *major_configs = NULL;
192 static size_t major_size = 0;
194 if(major < 0) return 1;
196 size_t wanted_size = (size_t)major + 1;
198 if(major_size < wanted_size) {
199 major_configs = reallocz(major_configs, wanted_size * sizeof(int8_t));
202 for(i = major_size; i < wanted_size ; i++)
203 major_configs[i] = -1;
205 major_size = wanted_size;
208 if(major_configs[major] == -1) {
209 char buffer[CONFIG_MAX_NAME + 1];
210 snprintfz(buffer, CONFIG_MAX_NAME, "performance metrics for disks with major %d", major);
211 major_configs[major] = (char)config_get_boolean(CONFIG_SECTION_DISKSTATS, buffer, 1);
214 return (int)major_configs[major];
217 int do_proc_diskstats(int update_every, usec_t dt) {
218 static procfile *ff = NULL;
219 static int global_enable_new_disks_detected_at_runtime = CONFIG_BOOLEAN_YES,
220 global_enable_performance_for_physical_disks = CONFIG_BOOLEAN_AUTO,
221 global_enable_performance_for_virtual_disks = CONFIG_BOOLEAN_AUTO,
222 global_enable_performance_for_partitions = CONFIG_BOOLEAN_NO,
223 global_do_io = CONFIG_BOOLEAN_AUTO,
224 global_do_ops = CONFIG_BOOLEAN_AUTO,
225 global_do_mops = CONFIG_BOOLEAN_AUTO,
226 global_do_iotime = CONFIG_BOOLEAN_AUTO,
227 global_do_qops = CONFIG_BOOLEAN_AUTO,
228 global_do_util = CONFIG_BOOLEAN_AUTO,
229 global_do_backlog = CONFIG_BOOLEAN_AUTO,
230 globals_initialized = 0;
232 if(unlikely(!globals_initialized)) {
233 global_enable_new_disks_detected_at_runtime = config_get_boolean(CONFIG_SECTION_DISKSTATS, "enable new disks detected at runtime", global_enable_new_disks_detected_at_runtime);
234 global_enable_performance_for_physical_disks = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "performance metrics for physical disks", global_enable_performance_for_physical_disks);
235 global_enable_performance_for_virtual_disks = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "performance metrics for virtual disks", global_enable_performance_for_virtual_disks);
236 global_enable_performance_for_partitions = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "performance metrics for partitions", global_enable_performance_for_partitions);
238 global_do_io = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "bandwidth for all disks", global_do_io);
239 global_do_ops = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "operations for all disks", global_do_ops);
240 global_do_mops = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "merged operations for all disks", global_do_mops);
241 global_do_iotime = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "i/o time for all disks", global_do_iotime);
242 global_do_qops = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "queued operations for all disks", global_do_qops);
243 global_do_util = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "utilization percentage for all disks", global_do_util);
244 global_do_backlog = config_get_boolean_ondemand(CONFIG_SECTION_DISKSTATS, "backlog for all disks", global_do_backlog);
246 globals_initialized = 1;
249 // --------------------------------------------------------------------------
252 char filename[FILENAME_MAX + 1];
253 snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/diskstats");
254 ff = procfile_open(config_get(CONFIG_SECTION_DISKSTATS, "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
256 if(unlikely(!ff)) return 0;
258 ff = procfile_readall(ff);
259 if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
261 size_t lines = procfile_lines(ff), l;
263 for(l = 0; l < lines ;l++) {
264 // --------------------------------------------------------------------------
268 unsigned long major = 0, minor = 0;
270 collected_number reads = 0, mreads = 0, readsectors = 0, readms = 0,
271 writes = 0, mwrites = 0, writesectors = 0, writems = 0,
272 queued_ios = 0, busy_ms = 0, backlog_ms = 0;
274 collected_number last_reads = 0, last_readsectors = 0, last_readms = 0,
275 last_writes = 0, last_writesectors = 0, last_writems = 0,
278 size_t words = procfile_linewords(ff, l);
279 if(unlikely(words < 14)) continue;
281 major = str2ul(procfile_lineword(ff, l, 0));
282 minor = str2ul(procfile_lineword(ff, l, 1));
283 disk = procfile_lineword(ff, l, 2);
285 // # of reads completed # of writes completed
286 // This is the total number of reads or writes completed successfully.
287 reads = str2ull(procfile_lineword(ff, l, 3)); // rd_ios
288 writes = str2ull(procfile_lineword(ff, l, 7)); // wr_ios
290 // # of reads merged # of writes merged
291 // Reads and writes which are adjacent to each other may be merged for
292 // efficiency. Thus two 4K reads may become one 8K read before it is
293 // ultimately handed to the disk, and so it will be counted (and queued)
294 mreads = str2ull(procfile_lineword(ff, l, 4)); // rd_merges_or_rd_sec
295 mwrites = str2ull(procfile_lineword(ff, l, 8)); // wr_merges
297 // # of sectors read # of sectors written
298 // This is the total number of sectors read or written successfully.
299 readsectors = str2ull(procfile_lineword(ff, l, 5)); // rd_sec_or_wr_ios
300 writesectors = str2ull(procfile_lineword(ff, l, 9)); // wr_sec
302 // # of milliseconds spent reading # of milliseconds spent writing
303 // This is the total number of milliseconds spent by all reads or writes (as
304 // measured from __make_request() to end_that_request_last()).
305 readms = str2ull(procfile_lineword(ff, l, 6)); // rd_ticks_or_wr_sec
306 writems = str2ull(procfile_lineword(ff, l, 10)); // wr_ticks
308 // # of I/Os currently in progress
309 // The only field that should go to zero. Incremented as requests are
310 // given to appropriate struct request_queue and decremented as they finish.
311 queued_ios = str2ull(procfile_lineword(ff, l, 11)); // ios_pgr
313 // # of milliseconds spent doing I/Os
314 // This field increases so long as field queued_ios is nonzero.
315 busy_ms = str2ull(procfile_lineword(ff, l, 12)); // tot_ticks
317 // weighted # of milliseconds spent doing I/Os
318 // This field is incremented at each I/O start, I/O completion, I/O
319 // merge, or read of these stats by the number of I/Os in progress
320 // (field queued_ios) times the number of milliseconds spent doing I/O since the
321 // last update of this field. This can provide an easy measure of both
322 // I/O completion time and the backlog that may be accumulating.
323 backlog_ms = str2ull(procfile_lineword(ff, l, 13)); // rq_ticks
326 // --------------------------------------------------------------------------
327 // remove slashes from disk names
329 for(s = disk; *s ;s++)
330 if(*s == '/') *s = '_';
332 // --------------------------------------------------------------------------
333 // get a disk structure for the disk
335 struct disk *d = get_disk(major, minor, disk);
338 // --------------------------------------------------------------------------
339 // Set its family based on mount point
341 char *family = d->mount_point;
342 if(!family) family = disk;
345 // --------------------------------------------------------------------------
346 // Check the configuration for the device
348 if(unlikely(!d->configured)) {
351 static SIMPLE_PATTERN *excluded_disks = NULL;
353 if(unlikely(!excluded_disks)) {
354 excluded_disks = simple_pattern_create(
355 config_get(CONFIG_SECTION_DISKSTATS, "exclude disks", DELAULT_EXLUDED_DISKS),
360 int def_enable = global_enable_new_disks_detected_at_runtime;
362 if(def_enable != CONFIG_BOOLEAN_NO && simple_pattern_matches(excluded_disks, disk))
363 def_enable = CONFIG_BOOLEAN_NO;
365 char var_name[4096 + 1];
366 snprintfz(var_name, 4096, "plugin:proc:/proc/diskstats:%s", disk);
368 def_enable = config_get_boolean_ondemand(var_name, "enable", def_enable);
369 if(unlikely(def_enable == CONFIG_BOOLEAN_NO)) {
370 // the user does not want any metrics for this disk
371 d->do_io = CONFIG_BOOLEAN_NO;
372 d->do_ops = CONFIG_BOOLEAN_NO;
373 d->do_mops = CONFIG_BOOLEAN_NO;
374 d->do_iotime = CONFIG_BOOLEAN_NO;
375 d->do_qops = CONFIG_BOOLEAN_NO;
376 d->do_util = CONFIG_BOOLEAN_NO;
377 d->do_backlog = CONFIG_BOOLEAN_NO;
380 // this disk is enabled
381 // check its direct settings
383 int def_performance = CONFIG_BOOLEAN_AUTO;
385 // since this is 'on demand' we can figure the performance settings
386 // based on the type of disk
389 case DISK_TYPE_PHYSICAL:
390 def_performance = global_enable_performance_for_physical_disks;
393 case DISK_TYPE_PARTITION:
394 def_performance = global_enable_performance_for_partitions;
397 case DISK_TYPE_CONTAINER:
398 def_performance = global_enable_performance_for_virtual_disks;
402 // check if we have to disable performance for this disk
404 def_performance = is_major_enabled((int)major);
406 // ------------------------------------------------------------
407 // now we have def_performance and def_space
411 // check the user configuration (this will also show our 'on demand' decision)
412 def_performance = config_get_boolean_ondemand(var_name, "enable performance metrics", def_performance);
414 int ddo_io = CONFIG_BOOLEAN_NO,
415 ddo_ops = CONFIG_BOOLEAN_NO,
416 ddo_mops = CONFIG_BOOLEAN_NO,
417 ddo_iotime = CONFIG_BOOLEAN_NO,
418 ddo_qops = CONFIG_BOOLEAN_NO,
419 ddo_util = CONFIG_BOOLEAN_NO,
420 ddo_backlog = CONFIG_BOOLEAN_NO;
422 // we enable individual performance charts only when def_performance is not disabled
423 if(unlikely(def_performance != CONFIG_BOOLEAN_NO)) {
424 ddo_io = global_do_io,
425 ddo_ops = global_do_ops,
426 ddo_mops = global_do_mops,
427 ddo_iotime = global_do_iotime,
428 ddo_qops = global_do_qops,
429 ddo_util = global_do_util,
430 ddo_backlog = global_do_backlog;
433 d->do_io = config_get_boolean_ondemand(var_name, "bandwidth", ddo_io);
434 d->do_ops = config_get_boolean_ondemand(var_name, "operations", ddo_ops);
435 d->do_mops = config_get_boolean_ondemand(var_name, "merged operations", ddo_mops);
436 d->do_iotime = config_get_boolean_ondemand(var_name, "i/o time", ddo_iotime);
437 d->do_qops = config_get_boolean_ondemand(var_name, "queued operations", ddo_qops);
438 d->do_util = config_get_boolean_ondemand(var_name, "utilization percentage", ddo_util);
439 d->do_backlog = config_get_boolean_ondemand(var_name, "backlog", ddo_backlog);
443 // --------------------------------------------------------------------------
444 // Do performance metrics
446 if(d->do_io == CONFIG_BOOLEAN_YES || (d->do_io == CONFIG_BOOLEAN_AUTO && (readsectors || writesectors))) {
447 d->do_io = CONFIG_BOOLEAN_YES;
449 if(unlikely(!d->st_io)) {
450 d->st_io = rrdset_create_localhost(
456 , "Disk I/O Bandwidth"
463 rrddim_add(d->st_io, "reads", NULL, d->sector_size, 1024, RRD_ALGORITHM_INCREMENTAL);
464 rrddim_add(d->st_io, "writes", NULL, d->sector_size * -1, 1024, RRD_ALGORITHM_INCREMENTAL);
466 else rrdset_next(d->st_io);
468 last_readsectors = rrddim_set(d->st_io, "reads", readsectors);
469 last_writesectors = rrddim_set(d->st_io, "writes", writesectors);
470 rrdset_done(d->st_io);
473 // --------------------------------------------------------------------
475 if(d->do_ops == CONFIG_BOOLEAN_YES || (d->do_ops == CONFIG_BOOLEAN_AUTO && (reads || writes))) {
476 d->do_ops = CONFIG_BOOLEAN_YES;
478 if(unlikely(!d->st_ops)) {
479 d->st_ops = rrdset_create_localhost(
485 , "Disk Completed I/O Operations"
492 rrdset_flag_set(d->st_ops, RRDSET_FLAG_DETAIL);
494 rrddim_add(d->st_ops, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
495 rrddim_add(d->st_ops, "writes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
497 else rrdset_next(d->st_ops);
499 last_reads = rrddim_set(d->st_ops, "reads", reads);
500 last_writes = rrddim_set(d->st_ops, "writes", writes);
501 rrdset_done(d->st_ops);
504 // --------------------------------------------------------------------
506 if(d->do_qops == CONFIG_BOOLEAN_YES || (d->do_qops == CONFIG_BOOLEAN_AUTO && queued_ios)) {
507 d->do_qops = CONFIG_BOOLEAN_YES;
509 if(unlikely(!d->st_qops)) {
510 d->st_qops = rrdset_create_localhost(
516 , "Disk Current I/O Operations"
523 rrdset_flag_set(d->st_qops, RRDSET_FLAG_DETAIL);
525 rrddim_add(d->st_qops, "operations", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
527 else rrdset_next(d->st_qops);
529 rrddim_set(d->st_qops, "operations", queued_ios);
530 rrdset_done(d->st_qops);
533 // --------------------------------------------------------------------
535 if(d->do_backlog == CONFIG_BOOLEAN_YES || (d->do_backlog == CONFIG_BOOLEAN_AUTO && backlog_ms)) {
536 d->do_backlog = CONFIG_BOOLEAN_YES;
538 if(unlikely(!d->st_backlog)) {
539 d->st_backlog = rrdset_create_localhost(
552 rrdset_flag_set(d->st_backlog, RRDSET_FLAG_DETAIL);
554 rrddim_add(d->st_backlog, "backlog", NULL, 1, 10, RRD_ALGORITHM_INCREMENTAL);
556 else rrdset_next(d->st_backlog);
558 rrddim_set(d->st_backlog, "backlog", backlog_ms);
559 rrdset_done(d->st_backlog);
562 // --------------------------------------------------------------------
564 if(d->do_util == CONFIG_BOOLEAN_YES || (d->do_util == CONFIG_BOOLEAN_AUTO && busy_ms)) {
565 d->do_util = CONFIG_BOOLEAN_YES;
567 if(unlikely(!d->st_util)) {
568 d->st_util = rrdset_create_localhost(
574 , "Disk Utilization Time"
575 , "% of time working"
581 rrdset_flag_set(d->st_util, RRDSET_FLAG_DETAIL);
583 rrddim_add(d->st_util, "utilization", NULL, 1, 10, RRD_ALGORITHM_INCREMENTAL);
585 else rrdset_next(d->st_util);
587 last_busy_ms = rrddim_set(d->st_util, "utilization", busy_ms);
588 rrdset_done(d->st_util);
591 // --------------------------------------------------------------------
593 if(d->do_mops == CONFIG_BOOLEAN_YES || (d->do_mops == CONFIG_BOOLEAN_AUTO && (mreads || mwrites))) {
594 d->do_mops = CONFIG_BOOLEAN_YES;
596 if(unlikely(!d->st_mops)) {
597 d->st_mops = rrdset_create_localhost(
603 , "Disk Merged Operations"
604 , "merged operations/s"
610 rrdset_flag_set(d->st_mops, RRDSET_FLAG_DETAIL);
612 rrddim_add(d->st_mops, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
613 rrddim_add(d->st_mops, "writes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
615 else rrdset_next(d->st_mops);
617 rrddim_set(d->st_mops, "reads", mreads);
618 rrddim_set(d->st_mops, "writes", mwrites);
619 rrdset_done(d->st_mops);
622 // --------------------------------------------------------------------
624 if(d->do_iotime == CONFIG_BOOLEAN_YES || (d->do_iotime == CONFIG_BOOLEAN_AUTO && (readms || writems))) {
625 d->do_iotime = CONFIG_BOOLEAN_YES;
627 if(unlikely(!d->st_iotime)) {
628 d->st_iotime = rrdset_create_localhost(
634 , "Disk Total I/O Time"
641 rrdset_flag_set(d->st_iotime, RRDSET_FLAG_DETAIL);
643 rrddim_add(d->st_iotime, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
644 rrddim_add(d->st_iotime, "writes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
646 else rrdset_next(d->st_iotime);
648 last_readms = rrddim_set(d->st_iotime, "reads", readms);
649 last_writems = rrddim_set(d->st_iotime, "writes", writems);
650 rrdset_done(d->st_iotime);
653 // --------------------------------------------------------------------
654 // calculate differential charts
655 // only if this is not the first time we run
658 if( (d->do_iotime == CONFIG_BOOLEAN_YES || (d->do_iotime == CONFIG_BOOLEAN_AUTO && (readms || writems))) &&
659 (d->do_ops == CONFIG_BOOLEAN_YES || (d->do_ops == CONFIG_BOOLEAN_AUTO && (reads || writes)))) {
661 if(unlikely(!d->st_await)) {
662 d->st_await = rrdset_create_localhost(
668 , "Average Completed I/O Operation Time"
675 rrdset_flag_set(d->st_await, RRDSET_FLAG_DETAIL);
677 rrddim_add(d->st_await, "reads", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
678 rrddim_add(d->st_await, "writes", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE);
680 else rrdset_next(d->st_await);
682 rrddim_set(d->st_await, "reads", (reads - last_reads) ? (readms - last_readms) / (reads - last_reads) : 0);
683 rrddim_set(d->st_await, "writes", (writes - last_writes) ? (writems - last_writems) / (writes - last_writes) : 0);
684 rrdset_done(d->st_await);
687 if( (d->do_io == CONFIG_BOOLEAN_YES || (d->do_io == CONFIG_BOOLEAN_AUTO && (readsectors || writesectors))) &&
688 (d->do_ops == CONFIG_BOOLEAN_YES || (d->do_ops == CONFIG_BOOLEAN_AUTO && (reads || writes)))) {
690 if(unlikely(!d->st_avgsz)) {
691 d->st_avgsz = rrdset_create_localhost(
697 , "Average Completed I/O Operation Bandwidth"
698 , "kilobytes per operation"
704 rrdset_flag_set(d->st_avgsz, RRDSET_FLAG_DETAIL);
706 rrddim_add(d->st_avgsz, "reads", NULL, d->sector_size, 1024, RRD_ALGORITHM_ABSOLUTE);
707 rrddim_add(d->st_avgsz, "writes", NULL, d->sector_size * -1, 1024, RRD_ALGORITHM_ABSOLUTE);
709 else rrdset_next(d->st_avgsz);
711 rrddim_set(d->st_avgsz, "reads", (reads - last_reads) ? (readsectors - last_readsectors) / (reads - last_reads) : 0);
712 rrddim_set(d->st_avgsz, "writes", (writes - last_writes) ? (writesectors - last_writesectors) / (writes - last_writes) : 0);
713 rrdset_done(d->st_avgsz);
716 if( (d->do_util == CONFIG_BOOLEAN_YES || (d->do_util == CONFIG_BOOLEAN_AUTO && busy_ms)) &&
717 (d->do_ops == CONFIG_BOOLEAN_YES || (d->do_ops == CONFIG_BOOLEAN_AUTO && (reads || writes)))) {
719 if(unlikely(!d->st_svctm)) {
720 d->st_svctm = rrdset_create_localhost(
726 , "Average Service Time"
733 rrdset_flag_set(d->st_svctm, RRDSET_FLAG_DETAIL);
735 rrddim_add(d->st_svctm, "svctm", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
737 else rrdset_next(d->st_svctm);
739 rrddim_set(d->st_svctm, "svctm", ((reads - last_reads) + (writes - last_writes)) ? (busy_ms - last_busy_ms) / ((reads - last_reads) + (writes - last_writes)) : 0);
740 rrdset_done(d->st_svctm);
745 // cleanup removed disks
747 struct disk *d = disk_root, *last = NULL;
749 if(unlikely(!d->updated)) {
752 rrdset_obsolete_and_pointer_null(d->st_avgsz);
753 rrdset_obsolete_and_pointer_null(d->st_await);
754 rrdset_obsolete_and_pointer_null(d->st_backlog);
755 rrdset_obsolete_and_pointer_null(d->st_io);
756 rrdset_obsolete_and_pointer_null(d->st_iotime);
757 rrdset_obsolete_and_pointer_null(d->st_mops);
758 rrdset_obsolete_and_pointer_null(d->st_ops);
759 rrdset_obsolete_and_pointer_null(d->st_qops);
760 rrdset_obsolete_and_pointer_null(d->st_svctm);
761 rrdset_obsolete_and_pointer_null(d->st_util);
764 disk_root = d = d->next;
768 last->next = d = d->next;
772 freez(t->mount_point);