2 #include <CoreFoundation/CoreFoundation.h>
3 #include <IOKit/IOKitLib.h>
4 #include <IOKit/storage/IOBlockStorageDriver.h>
6 int do_macos_iokit(int update_every, usec_t dt) {
11 if (unlikely(do_io == -1)) {
12 do_io = config_get_boolean("plugin:macos:iokit", "disk i/o", 1);
17 mach_port_t master_port;
18 io_registry_entry_t drive;
19 io_iterator_t drive_list;
21 CFDictionaryRef properties, statistics;
23 collected_number total_disk_reads = 0;
24 collected_number total_disk_writes = 0;
26 /* Get ports and services for drive statistics. */
27 if (IOMasterPort(bootstrap_port, &master_port)) {
28 error("MACOS: IOMasterPort() failed");
30 error("DISABLED: system.io");
31 /* Get the list of all drive objects. */
32 } else if (IOServiceGetMatchingServices(master_port, IOServiceMatching("IOBlockStorageDriver"), &drive_list)) {
33 error("MACOS: IOServiceGetMatchingServices() failed");
35 error("DISABLED: system.io");
37 while ((drive = IOIteratorNext(drive_list)) != 0) {
43 /* Obtain the properties for this drive object. */
44 if (IORegistryEntryCreateCFProperties(drive, (CFMutableDictionaryRef *)&properties, kCFAllocatorDefault, 0)) {
45 error("MACOS: IORegistryEntryCreateCFProperties() failed");
47 error("DISABLED: system.io");
49 } else if (properties != 0) {
50 /* Obtain the statistics from the drive properties. */
51 statistics = (CFDictionaryRef)CFDictionaryGetValue(properties, CFSTR(kIOBlockStorageDriverStatisticsKey));
53 if (statistics != 0) {
55 number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey));
57 CFNumberGetValue(number, kCFNumberSInt64Type, &value);
58 total_disk_reads += value;
61 /* Get bytes written. */
62 number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey));
64 CFNumberGetValue(number, kCFNumberSInt64Type, &value);
65 total_disk_writes += value;
70 CFRelease(properties);
74 IOObjectRelease(drive);
76 IOIteratorReset(drive_list);
79 IOObjectRelease(drive_list);
83 st = rrdset_find_bytype("system", "io");
85 st = rrdset_create("system", "io", NULL, "disk", NULL, "Disk I/O", "kilobytes/s", 150, update_every, RRDSET_TYPE_AREA);
86 rrddim_add(st, "in", NULL, 1, 1024, RRDDIM_INCREMENTAL);
87 rrddim_add(st, "out", NULL, -1, 1024, RRDDIM_INCREMENTAL);
91 rrddim_set(st, "in", total_disk_reads);
92 rrddim_set(st, "out", total_disk_writes);