| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "plugin_macos.h" |
| 4 | |
| 5 | #include <CoreFoundation/CoreFoundation.h> |
| 6 | #include <IOKit/IOKitLib.h> |
| 7 | #include <IOKit/storage/IOBlockStorageDriver.h> |
| 8 | #include <IOKit/IOBSD.h> |
| 9 | // NEEDED BY do_space, do_inodes |
| 10 | #include <sys/mount.h> |
| 11 | // NEEDED BY: struct ifaddrs, getifaddrs() |
| 12 | #include <net/if.h> |
| 13 | #include <ifaddrs.h> |
| 14 | |
| 15 | // NEEDED BY: do_bandwidth |
| 16 | #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) |
| 17 | |
| 18 | #define MAXDRIVENAME 31 |
| 19 | |
| 20 | #define KILO_FACTOR 1024 |
| 21 | #define MEGA_FACTOR 1048576 // 1024 * 1024 |
| 22 | #define GIGA_FACTOR 1073741824 // 1024 * 1024 * 1024 |
| 23 | |
| 24 | int do_macos_iokit(int update_every, usec_t dt) { |
| 25 | (void)dt; |
| 26 | |
| 27 | static SIMPLE_PATTERN *excluded_mountpoints = NULL; |
| 28 | static SIMPLE_PATTERN *disabled_net_interfaces = NULL; |
| 29 | |
| 30 | static int do_io = -1, do_space = -1, do_inodes = -1, do_bandwidth = -1; |
| 31 | |
| 32 | if (unlikely(do_io == -1)) { |
| 33 | do_io = inicfg_get_boolean(&netdata_config, "plugin:macos:iokit", "disk i/o", 1); |
| 34 | do_space = inicfg_get_boolean(&netdata_config, "plugin:macos:sysctl", "space usage for all disks", 1); |
| 35 | do_inodes = inicfg_get_boolean(&netdata_config, "plugin:macos:sysctl", "inodes usage for all disks", 1); |
| 36 | do_bandwidth = inicfg_get_boolean(&netdata_config, "plugin:macos:sysctl", "bandwidth", 1); |
| 37 | |
| 38 | excluded_mountpoints = simple_pattern_create( |
| 39 | inicfg_get( |
| 40 | &netdata_config, |
| 41 | "plugin:macos:iokit", |
| 42 | "exclude mountpoints by path", |
| 43 | "/System/Volumes/* /private/var/folders/* /Volumes/Recovery"), |
| 44 | NULL, |
| 45 | SIMPLE_PATTERN_EXACT, |
| 46 | true); |
| 47 | disabled_net_interfaces = simple_pattern_create( |
| 48 | inicfg_get( |
| 49 | &netdata_config, |
| 50 | "plugin:macos:iokit", |
| 51 | "disable by default network interfaces matching", |
| 52 | "lo* awdl* llw* anpi* gif* bridge* ap*"), |
| 53 | NULL, |
| 54 | SIMPLE_PATTERN_EXACT, |
| 55 | true); |
| 56 | } |
| 57 | |
| 58 | RRDSET *st; |
| 59 | |
| 60 | mach_port_t main_port; |
| 61 | io_registry_entry_t drive, drive_media; |
| 62 | io_iterator_t drive_list; |
| 63 | CFDictionaryRef properties, statistics; |
| 64 | CFStringRef name; |
| 65 | CFNumberRef number; |
| 66 | kern_return_t status; |
| 67 | collected_number total_disk_reads = 0; |
| 68 | collected_number total_disk_writes = 0; |
| 69 | struct diskstat { |
| 70 | char name[MAXDRIVENAME]; |
| 71 | collected_number bytes_read; |
| 72 | collected_number bytes_write; |
| 73 | collected_number reads; |
| 74 | collected_number writes; |
| 75 | collected_number time_read; |
| 76 | collected_number time_write; |
| 77 | collected_number latency_read; |
| 78 | collected_number latency_write; |
| 79 | } diskstat; |
| 80 | struct cur_diskstat { |
| 81 | collected_number duration_read_ns; |
| 82 | collected_number duration_write_ns; |
| 83 | collected_number busy_time_ns; |
| 84 | } cur_diskstat; |
| 85 | struct prev_diskstat { |
| 86 | collected_number bytes_read; |
| 87 | collected_number bytes_write; |
| 88 | collected_number operations_read; |
| 89 | collected_number operations_write; |
| 90 | collected_number duration_read_ns; |
| 91 | collected_number duration_write_ns; |
| 92 | collected_number busy_time_ns; |
| 93 | } prev_diskstat; |
| 94 | |
| 95 | // NEEDED BY: do_space, do_inodes |
| 96 | struct statfs *mntbuf; |
| 97 | int mntsize, i; |
| 98 | |
| 99 | // NEEDED BY: do_bandwidth |
| 100 | struct ifaddrs *ifa, *ifap; |
| 101 | |
| 102 | #if !defined(MAC_OS_VERSION_12_0) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_12_0) |
| 103 | #define IOMainPort IOMasterPort |
| 104 | #endif |
| 105 | |
| 106 | /* Get ports and services for drive statistics. */ |
| 107 | if (unlikely(IOMainPort(bootstrap_port, &main_port))) { |
| 108 | collector_error("MACOS: IOMasterPort() failed"); |
| 109 | do_io = 0; |
| 110 | collector_error("DISABLED: system.io"); |
| 111 | /* Get the list of all drive objects. */ |
| 112 | } else if (unlikely(IOServiceGetMatchingServices(main_port, IOServiceMatching("IOBlockStorageDriver"), &drive_list))) { |
| 113 | collector_error("MACOS: IOServiceGetMatchingServices() failed"); |
| 114 | do_io = 0; |
| 115 | collector_error("DISABLED: system.io"); |
| 116 | } else { |
| 117 | while ((drive = IOIteratorNext(drive_list)) != 0) { |
| 118 | properties = 0; |
| 119 | statistics = 0; |
| 120 | number = 0; |
| 121 | memset(&diskstat, 0, sizeof(diskstat)); |
| 122 | |
| 123 | /* Get drive media object. */ |
| 124 | status = IORegistryEntryGetChildEntry(drive, kIOServicePlane, &drive_media); |
| 125 | if (unlikely(status != KERN_SUCCESS)) { |
| 126 | IOObjectRelease(drive); |
| 127 | continue; |
| 128 | } |
| 129 | |
| 130 | /* Get drive media properties. */ |
| 131 | if (likely(!IORegistryEntryCreateCFProperties(drive_media, (CFMutableDictionaryRef *)&properties, kCFAllocatorDefault, 0))) { |
| 132 | /* Get disk name. */ |
| 133 | if (likely(name = (CFStringRef)CFDictionaryGetValue(properties, CFSTR(kIOBSDNameKey)))) { |
| 134 | CFStringGetCString(name, diskstat.name, MAXDRIVENAME, kCFStringEncodingUTF8); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | /* Release. */ |
| 139 | CFRelease(properties); |
| 140 | IOObjectRelease(drive_media); |
| 141 | |
| 142 | if(unlikely(!*diskstat.name)) { |
| 143 | IOObjectRelease(drive); |
| 144 | continue; |
| 145 | } |
| 146 | |
| 147 | /* Obtain the properties for this drive object. */ |
| 148 | if (unlikely(IORegistryEntryCreateCFProperties(drive, (CFMutableDictionaryRef *)&properties, kCFAllocatorDefault, 0))) { |
| 149 | IOObjectRelease(drive); |
| 150 | collector_error("MACOS: IORegistryEntryCreateCFProperties() failed"); |
| 151 | do_io = 0; |
| 152 | collector_error("DISABLED: system.io"); |
| 153 | break; |
| 154 | } else if (likely(properties)) { |
| 155 | /* Obtain the statistics from the drive properties. */ |
| 156 | if (likely(statistics = (CFDictionaryRef)CFDictionaryGetValue(properties, CFSTR(kIOBlockStorageDriverStatisticsKey)))) { |
| 157 | |
| 158 | // -------------------------------------------------------------------- |
| 159 | |
| 160 | /* Get bytes read. */ |
| 161 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesReadKey)))) { |
| 162 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.bytes_read); |
| 163 | total_disk_reads += diskstat.bytes_read; |
| 164 | } |
| 165 | |
| 166 | /* Get bytes written. */ |
| 167 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsBytesWrittenKey)))) { |
| 168 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.bytes_write); |
| 169 | total_disk_writes += diskstat.bytes_write; |
| 170 | } |
| 171 | |
| 172 | st = rrdset_find_active_bytype_localhost("disk", diskstat.name); |
| 173 | if (unlikely(!st)) { |
| 174 | st = rrdset_create_localhost( |
| 175 | "disk" |
| 176 | , diskstat.name |
| 177 | , NULL |
| 178 | , "io" |
| 179 | , "disk.io" |
| 180 | , "Disk I/O Bandwidth" |
| 181 | , "KiB/s" |
| 182 | , "macos.plugin" |
| 183 | , "iokit" |
| 184 | , 2000 |
| 185 | , update_every |
| 186 | , RRDSET_TYPE_AREA |
| 187 | ); |
| 188 | |
| 189 | rrddim_add(st, "reads", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL); |
| 190 | rrddim_add(st, "writes", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL); |
| 191 | rrdlabels_add(st->rrdlabels, "device", diskstat.name, RRDLABEL_SRC_AUTO); |
| 192 | } |
| 193 | |
| 194 | prev_diskstat.bytes_read = rrddim_set(st, "reads", diskstat.bytes_read); |
| 195 | prev_diskstat.bytes_write = rrddim_set(st, "writes", diskstat.bytes_write); |
| 196 | rrdset_done(st); |
| 197 | |
| 198 | /* Get number of reads. */ |
| 199 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsReadsKey)))) { |
| 200 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.reads); |
| 201 | } |
| 202 | |
| 203 | /* Get number of writes. */ |
| 204 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsWritesKey)))) { |
| 205 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.writes); |
| 206 | } |
| 207 | |
| 208 | st = rrdset_find_active_bytype_localhost("disk_ops", diskstat.name); |
| 209 | if (unlikely(!st)) { |
| 210 | st = rrdset_create_localhost( |
| 211 | "disk_ops" |
| 212 | , diskstat.name |
| 213 | , NULL |
| 214 | , "ops" |
| 215 | , "disk.ops" |
| 216 | , "Disk Completed I/O Operations" |
| 217 | , "operations/s" |
| 218 | , "macos.plugin" |
| 219 | , "iokit" |
| 220 | , 2001 |
| 221 | , update_every |
| 222 | , RRDSET_TYPE_LINE |
| 223 | ); |
| 224 | |
| 225 | rrddim_add(st, "reads", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 226 | rrddim_add(st, "writes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 227 | rrdlabels_add(st->rrdlabels, "device", diskstat.name, RRDLABEL_SRC_AUTO); |
| 228 | } |
| 229 | |
| 230 | prev_diskstat.operations_read = rrddim_set(st, "reads", diskstat.reads); |
| 231 | prev_diskstat.operations_write = rrddim_set(st, "writes", diskstat.writes); |
| 232 | rrdset_done(st); |
| 233 | |
| 234 | /* Get reads time. */ |
| 235 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsTotalReadTimeKey)))) { |
| 236 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.time_read); |
| 237 | } |
| 238 | |
| 239 | /* Get writes time. */ |
| 240 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsTotalWriteTimeKey)))) { |
| 241 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.time_write); |
| 242 | } |
| 243 | |
| 244 | st = rrdset_find_active_bytype_localhost("disk_util", diskstat.name); |
| 245 | if (unlikely(!st)) { |
| 246 | st = rrdset_create_localhost( |
| 247 | "disk_util" |
| 248 | , diskstat.name |
| 249 | , NULL |
| 250 | , "utilization" |
| 251 | , "disk.util" |
| 252 | , "Disk Utilization Time" |
| 253 | , "% of time working" |
| 254 | , "macos.plugin" |
| 255 | , "iokit" |
| 256 | , 2004 |
| 257 | , update_every |
| 258 | , RRDSET_TYPE_AREA |
| 259 | ); |
| 260 | |
| 261 | rrddim_add(st, "utilization", NULL, 1, 10000000, RRD_ALGORITHM_INCREMENTAL); |
| 262 | rrdlabels_add(st->rrdlabels, "device", diskstat.name, RRDLABEL_SRC_AUTO); |
| 263 | } |
| 264 | |
| 265 | cur_diskstat.busy_time_ns = (diskstat.time_read + diskstat.time_write); |
| 266 | prev_diskstat.busy_time_ns = rrddim_set(st, "utilization", cur_diskstat.busy_time_ns); |
| 267 | rrdset_done(st); |
| 268 | |
| 269 | /* Get reads latency. */ |
| 270 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsLatentReadTimeKey)))) { |
| 271 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.latency_read); |
| 272 | } |
| 273 | |
| 274 | /* Get writes latency. */ |
| 275 | if (likely(number = (CFNumberRef)CFDictionaryGetValue(statistics, CFSTR(kIOBlockStorageDriverStatisticsLatentWriteTimeKey)))) { |
| 276 | CFNumberGetValue(number, kCFNumberSInt64Type, &diskstat.latency_write); |
| 277 | } |
| 278 | |
| 279 | st = rrdset_find_active_bytype_localhost("disk_iotime", diskstat.name); |
| 280 | if (unlikely(!st)) { |
| 281 | st = rrdset_create_localhost( |
| 282 | "disk_iotime" |
| 283 | , diskstat.name |
| 284 | , NULL |
| 285 | , "utilization" |
| 286 | , "disk.iotime" |
| 287 | , "Disk Total I/O Time" |
| 288 | , "milliseconds/s" |
| 289 | , "macos.plugin" |
| 290 | , "iokit" |
| 291 | , 2022 |
| 292 | , update_every |
| 293 | , RRDSET_TYPE_LINE |
| 294 | ); |
| 295 | |
| 296 | rrddim_add(st, "reads", NULL, 1, 1000000, RRD_ALGORITHM_INCREMENTAL); |
| 297 | rrddim_add(st, "writes", NULL, -1, 1000000, RRD_ALGORITHM_INCREMENTAL); |
| 298 | rrdlabels_add(st->rrdlabels, "device", diskstat.name, RRDLABEL_SRC_AUTO); |
| 299 | } |
| 300 | |
| 301 | cur_diskstat.duration_read_ns = diskstat.time_read + diskstat.latency_read; |
| 302 | cur_diskstat.duration_write_ns = diskstat.time_write + diskstat.latency_write; |
| 303 | prev_diskstat.duration_read_ns = rrddim_set(st, "reads", cur_diskstat.duration_read_ns); |
| 304 | prev_diskstat.duration_write_ns = rrddim_set(st, "writes", cur_diskstat.duration_write_ns); |
| 305 | rrdset_done(st); |
| 306 | |
| 307 | // calculate differential charts |
| 308 | // only if this is not the first time we run |
| 309 | |
| 310 | if (likely(dt)) { |
| 311 | st = rrdset_find_active_bytype_localhost("disk_await", diskstat.name); |
| 312 | if (unlikely(!st)) { |
| 313 | st = rrdset_create_localhost( |
| 314 | "disk_await" |
| 315 | , diskstat.name |
| 316 | , NULL |
| 317 | , "latency" |
| 318 | , "disk.await" |
| 319 | , "Average Completed I/O Operation Time" |
| 320 | , "milliseconds/operation" |
| 321 | , "macos.plugin" |
| 322 | , "iokit" |
| 323 | , 2005 |
| 324 | , update_every |
| 325 | , RRDSET_TYPE_LINE |
| 326 | ); |
| 327 | |
| 328 | rrddim_add(st, "reads", NULL, 1, 1000000, RRD_ALGORITHM_ABSOLUTE); |
| 329 | rrddim_add(st, "writes", NULL, -1, 1000000, RRD_ALGORITHM_ABSOLUTE); |
| 330 | rrdlabels_add(st->rrdlabels, "device", diskstat.name, RRDLABEL_SRC_AUTO); |
| 331 | } |
| 332 | |
| 333 | rrddim_set(st, "reads", (diskstat.reads - prev_diskstat.operations_read) ? |
| 334 | (cur_diskstat.duration_read_ns - prev_diskstat.duration_read_ns) / (diskstat.reads - prev_diskstat.operations_read) : 0); |
| 335 | rrddim_set(st, "writes", (diskstat.writes - prev_diskstat.operations_write) ? |
| 336 | (cur_diskstat.duration_write_ns - prev_diskstat.duration_write_ns) / (diskstat.writes - prev_diskstat.operations_write) : 0); |
| 337 | rrdset_done(st); |
| 338 | |
| 339 | st = rrdset_find_active_bytype_localhost("disk_avgsz", diskstat.name); |
| 340 | if (unlikely(!st)) { |
| 341 | st = rrdset_create_localhost( |
| 342 | "disk_avgsz" |
| 343 | , diskstat.name |
| 344 | , NULL |
| 345 | , "io" |
| 346 | , "disk.avgsz" |
| 347 | , "Average Completed I/O Operation Bandwidth" |
| 348 | , "KiB/operation" |
| 349 | , "macos.plugin" |
| 350 | , "iokit" |
| 351 | , 2006 |
| 352 | , update_every |
| 353 | , RRDSET_TYPE_AREA |
| 354 | ); |
| 355 | |
| 356 | rrddim_add(st, "reads", NULL, 1, 1024, RRD_ALGORITHM_ABSOLUTE); |
| 357 | rrddim_add(st, "writes", NULL, -1, 1024, RRD_ALGORITHM_ABSOLUTE); |
| 358 | rrdlabels_add(st->rrdlabels, "device", diskstat.name, RRDLABEL_SRC_AUTO); |
| 359 | } |
| 360 | |
| 361 | rrddim_set(st, "reads", (diskstat.reads - prev_diskstat.operations_read) ? |
| 362 | (diskstat.bytes_read - prev_diskstat.bytes_read) / (diskstat.reads - prev_diskstat.operations_read) : 0); |
| 363 | rrddim_set(st, "writes", (diskstat.writes - prev_diskstat.operations_write) ? |
| 364 | (diskstat.bytes_write - prev_diskstat.bytes_write) / (diskstat.writes - prev_diskstat.operations_write) : 0); |
| 365 | rrdset_done(st); |
| 366 | |
| 367 | st = rrdset_find_active_bytype_localhost("disk_svctm", diskstat.name); |
| 368 | if (unlikely(!st)) { |
| 369 | st = rrdset_create_localhost( |
| 370 | "disk_svctm" |
| 371 | , diskstat.name |
| 372 | , NULL |
| 373 | , "latency" |
| 374 | , "disk.svctm" |
| 375 | , "Average Service Time" |
| 376 | , "milliseconds/operation" |
| 377 | , "macos.plugin" |
| 378 | , "iokit" |
| 379 | , 2007 |
| 380 | , update_every |
| 381 | , RRDSET_TYPE_LINE |
| 382 | ); |
| 383 | |
| 384 | rrddim_add(st, "svctm", NULL, 1, 1000000, RRD_ALGORITHM_ABSOLUTE); |
| 385 | rrdlabels_add(st->rrdlabels, "device", diskstat.name, RRDLABEL_SRC_AUTO); |
| 386 | } |
| 387 | |
| 388 | rrddim_set(st, "svctm", ((diskstat.reads - prev_diskstat.operations_read) + (diskstat.writes - prev_diskstat.operations_write)) ? |
| 389 | (cur_diskstat.busy_time_ns - prev_diskstat.busy_time_ns) / ((diskstat.reads - prev_diskstat.operations_read) + (diskstat.writes - prev_diskstat.operations_write)) : 0); |
| 390 | rrdset_done(st); |
| 391 | } |
| 392 | } |
| 393 | |
| 394 | /* Release. */ |
| 395 | CFRelease(properties); |
| 396 | } |
| 397 | |
| 398 | /* Release. */ |
| 399 | IOObjectRelease(drive); |
| 400 | } |
| 401 | IOIteratorReset(drive_list); |
| 402 | |
| 403 | /* Release. */ |
| 404 | IOObjectRelease(drive_list); |
| 405 | } |
| 406 | |
| 407 | if (likely(do_io)) { |
| 408 | st = rrdset_find_active_bytype_localhost("system", "io"); |
| 409 | if (unlikely(!st)) { |
| 410 | st = rrdset_create_localhost( |
| 411 | "system" |
| 412 | , "io" |
| 413 | , NULL |
| 414 | , "disk" |
| 415 | , NULL |
| 416 | , "Disk I/O" |
| 417 | , "KiB/s" |
| 418 | , "macos.plugin" |
| 419 | , "iokit" |
| 420 | , 150 |
| 421 | , update_every |
| 422 | , RRDSET_TYPE_AREA |
| 423 | ); |
| 424 | rrddim_add(st, "in", NULL, 1, 1024, RRD_ALGORITHM_INCREMENTAL); |
| 425 | rrddim_add(st, "out", NULL, -1, 1024, RRD_ALGORITHM_INCREMENTAL); |
| 426 | } |
| 427 | |
| 428 | rrddim_set(st, "in", total_disk_reads); |
| 429 | rrddim_set(st, "out", total_disk_writes); |
| 430 | rrdset_done(st); |
| 431 | } |
| 432 | |
| 433 | // Can be merged with FreeBSD plugin |
| 434 | |
| 435 | if (likely(do_space || do_inodes)) { |
| 436 | // there is no mount info in sysctl MIBs |
| 437 | if (unlikely(!(mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)))) { |
| 438 | collector_error("MACOS: getmntinfo() failed"); |
| 439 | do_space = 0; |
| 440 | collector_error("DISABLED: disk_space.X"); |
| 441 | do_inodes = 0; |
| 442 | collector_error("DISABLED: disk_inodes.X"); |
| 443 | } else { |
| 444 | for (i = 0; i < mntsize; i++) { |
| 445 | if (mntbuf[i].f_flags == MNT_RDONLY || |
| 446 | mntbuf[i].f_blocks == 0 || |
| 447 | // taken from gnulib/mountlist.c and shortened to FreeBSD related fstypes |
| 448 | strcmp(mntbuf[i].f_fstypename, "autofs") == 0 || |
| 449 | strcmp(mntbuf[i].f_fstypename, "procfs") == 0 || |
| 450 | strcmp(mntbuf[i].f_fstypename, "subfs") == 0 || |
| 451 | strcmp(mntbuf[i].f_fstypename, "devfs") == 0 || |
| 452 | strcmp(mntbuf[i].f_fstypename, "none") == 0) |
| 453 | continue; |
| 454 | |
| 455 | if (simple_pattern_matches(excluded_mountpoints, mntbuf[i].f_mntonname)) { |
| 456 | continue; |
| 457 | } |
| 458 | |
| 459 | // -------------------------------------------------------------------------- |
| 460 | |
| 461 | if (likely(do_space)) { |
| 462 | st = rrdset_find_active_bytype_localhost("disk_space", mntbuf[i].f_mntonname); |
| 463 | if (unlikely(!st)) { |
| 464 | st = rrdset_create_localhost( |
| 465 | "disk_space" |
| 466 | , mntbuf[i].f_mntonname |
| 467 | , NULL |
| 468 | , "used space" |
| 469 | , "disk.space" |
| 470 | , "Disk Space Usage" |
| 471 | , "GiB" |
| 472 | , "macos.plugin" |
| 473 | , "iokit" |
| 474 | , 2023 |
| 475 | , update_every |
| 476 | , RRDSET_TYPE_STACKED |
| 477 | ); |
| 478 | |
| 479 | rrddim_add(st, "avail", NULL, mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 480 | rrddim_add(st, "used", NULL, mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 481 | rrddim_add(st, "reserved_for_root", "reserved for root", mntbuf[i].f_bsize, GIGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 482 | rrdlabels_add(st->rrdlabels, "mount_point", mntbuf[i].f_mntonname, RRDLABEL_SRC_AUTO); |
| 483 | rrdlabels_add(st->rrdlabels, "filesystem", mntbuf[i].f_fstypename, RRDLABEL_SRC_AUTO); |
| 484 | } |
| 485 | |
| 486 | rrddim_set(st, "avail", (collected_number) mntbuf[i].f_bavail); |
| 487 | rrddim_set(st, "used", (collected_number) (mntbuf[i].f_blocks - mntbuf[i].f_bfree)); |
| 488 | rrddim_set(st, "reserved_for_root", (collected_number) (mntbuf[i].f_bfree - mntbuf[i].f_bavail)); |
| 489 | rrdset_done(st); |
| 490 | } |
| 491 | |
| 492 | // -------------------------------------------------------------------------- |
| 493 | |
| 494 | if (likely(do_inodes)) { |
| 495 | st = rrdset_find_active_bytype_localhost("disk_inodes", mntbuf[i].f_mntonname); |
| 496 | if (unlikely(!st)) { |
| 497 | st = rrdset_create_localhost( |
| 498 | "disk_inodes" |
| 499 | , mntbuf[i].f_mntonname |
| 500 | , NULL |
| 501 | , "used inodes" |
| 502 | , "disk.inodes" |
| 503 | , "Disk Files (inodes) Usage" |
| 504 | , "inodes" |
| 505 | , "macos.plugin" |
| 506 | , "iokit" |
| 507 | , 2024 |
| 508 | , update_every |
| 509 | , RRDSET_TYPE_STACKED |
| 510 | ); |
| 511 | |
| 512 | rrddim_add(st, "avail", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 513 | rrddim_add(st, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 514 | rrddim_add(st, "reserved_for_root", "reserved for root", 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 515 | rrdlabels_add(st->rrdlabels, "mount_point", mntbuf[i].f_mntonname, RRDLABEL_SRC_AUTO); |
| 516 | rrdlabels_add(st->rrdlabels, "filesystem", mntbuf[i].f_fstypename, RRDLABEL_SRC_AUTO); |
| 517 | } |
| 518 | |
| 519 | rrddim_set(st, "avail", (collected_number) mntbuf[i].f_ffree); |
| 520 | rrddim_set(st, "used", (collected_number) (mntbuf[i].f_files - mntbuf[i].f_ffree)); |
| 521 | rrdset_done(st); |
| 522 | } |
| 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | // Can be merged with FreeBSD plugin |
| 528 | |
| 529 | if (likely(do_bandwidth)) { |
| 530 | if (unlikely(getifaddrs(&ifap))) { |
| 531 | collector_error("MACOS: getifaddrs()"); |
| 532 | do_bandwidth = 0; |
| 533 | collector_error("DISABLED: system.ipv4"); |
| 534 | } else { |
| 535 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
| 536 | if (ifa->ifa_addr->sa_family != AF_LINK) |
| 537 | continue; |
| 538 | |
| 539 | if (simple_pattern_matches(disabled_net_interfaces, ifa->ifa_name)) { |
| 540 | continue; |
| 541 | } |
| 542 | |
| 543 | st = rrdset_find_active_bytype_localhost("net", ifa->ifa_name); |
| 544 | if (unlikely(!st)) { |
| 545 | st = rrdset_create_localhost( |
| 546 | "net" |
| 547 | , ifa->ifa_name |
| 548 | , NULL |
| 549 | , "traffic" |
| 550 | , "net.net" |
| 551 | , "Bandwidth" |
| 552 | , "kilobits/s" |
| 553 | , "macos.plugin" |
| 554 | , "iokit" |
| 555 | , 7000 |
| 556 | , update_every |
| 557 | , RRDSET_TYPE_AREA |
| 558 | ); |
| 559 | |
| 560 | rrddim_add(st, "received", NULL, 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 561 | rrddim_add(st, "sent", NULL, -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 562 | rrdlabels_add(st->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 563 | } |
| 564 | |
| 565 | rrddim_set(st, "received", IFA_DATA(ibytes)); |
| 566 | rrddim_set(st, "sent", IFA_DATA(obytes)); |
| 567 | rrdset_done(st); |
| 568 | |
| 569 | st = rrdset_find_active_bytype_localhost("net_packets", ifa->ifa_name); |
| 570 | if (unlikely(!st)) { |
| 571 | st = rrdset_create_localhost( |
| 572 | "net_packets" |
| 573 | , ifa->ifa_name |
| 574 | , NULL |
| 575 | , "packets" |
| 576 | , "net.packets" |
| 577 | , "Packets" |
| 578 | , "packets/s" |
| 579 | , "macos.plugin" |
| 580 | , "iokit" |
| 581 | , 7001 |
| 582 | , update_every |
| 583 | , RRDSET_TYPE_LINE |
| 584 | ); |
| 585 | |
| 586 | rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 587 | rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 588 | rrddim_add(st, "multicast_received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 589 | rrddim_add(st, "multicast_sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 590 | rrdlabels_add(st->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 591 | } |
| 592 | |
| 593 | rrddim_set(st, "received", IFA_DATA(ipackets)); |
| 594 | rrddim_set(st, "sent", IFA_DATA(opackets)); |
| 595 | rrddim_set(st, "multicast_received", IFA_DATA(imcasts)); |
| 596 | rrddim_set(st, "multicast_sent", IFA_DATA(omcasts)); |
| 597 | rrdset_done(st); |
| 598 | |
| 599 | st = rrdset_find_active_bytype_localhost("net_errors", ifa->ifa_name); |
| 600 | if (unlikely(!st)) { |
| 601 | st = rrdset_create_localhost( |
| 602 | "net_errors" |
| 603 | , ifa->ifa_name |
| 604 | , NULL |
| 605 | , "errors" |
| 606 | , "net.errors" |
| 607 | , "Interface Errors" |
| 608 | , "errors/s" |
| 609 | , "macos.plugin" |
| 610 | , "iokit" |
| 611 | , 7002 |
| 612 | , update_every |
| 613 | , RRDSET_TYPE_LINE |
| 614 | ); |
| 615 | |
| 616 | rrddim_add(st, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 617 | rrddim_add(st, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 618 | rrdlabels_add(st->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 619 | } |
| 620 | |
| 621 | rrddim_set(st, "inbound", IFA_DATA(ierrors)); |
| 622 | rrddim_set(st, "outbound", IFA_DATA(oerrors)); |
| 623 | rrdset_done(st); |
| 624 | |
| 625 | st = rrdset_find_active_bytype_localhost("net_drops", ifa->ifa_name); |
| 626 | if (unlikely(!st)) { |
| 627 | st = rrdset_create_localhost( |
| 628 | "net_drops" |
| 629 | , ifa->ifa_name |
| 630 | , NULL |
| 631 | , "drops" |
| 632 | , "net.drops" |
| 633 | , "Interface Drops" |
| 634 | , "drops/s" |
| 635 | , "macos.plugin" |
| 636 | , "iokit" |
| 637 | , 7003 |
| 638 | , update_every |
| 639 | , RRDSET_TYPE_LINE |
| 640 | ); |
| 641 | |
| 642 | rrddim_add(st, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 643 | rrdlabels_add(st->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 644 | } |
| 645 | |
| 646 | rrddim_set(st, "inbound", IFA_DATA(iqdrops)); |
| 647 | rrdset_done(st); |
| 648 | |
| 649 | st = rrdset_find_active_bytype_localhost("net_events", ifa->ifa_name); |
| 650 | if (unlikely(!st)) { |
| 651 | st = rrdset_create_localhost( |
| 652 | "net_events" |
| 653 | , ifa->ifa_name |
| 654 | , NULL |
| 655 | , "errors" |
| 656 | , "net.events" |
| 657 | , "Network Interface Events" |
| 658 | , "events/s" |
| 659 | , "macos.plugin" |
| 660 | , "iokit" |
| 661 | , 7006 |
| 662 | , update_every |
| 663 | , RRDSET_TYPE_LINE |
| 664 | ); |
| 665 | |
| 666 | rrddim_add(st, "frames", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 667 | rrddim_add(st, "collisions", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 668 | rrddim_add(st, "carrier", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 669 | rrdlabels_add(st->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 670 | } |
| 671 | |
| 672 | rrddim_set(st, "collisions", IFA_DATA(collisions)); |
| 673 | rrdset_done(st); |
| 674 | } |
| 675 | |
| 676 | freeifaddrs(ifap); |
| 677 | } |
| 678 | } |
| 679 | |
| 680 | return 0; |
| 681 | } |