| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "plugin_freebsd.h" |
| 4 | |
| 5 | #include <sys/vmmeter.h> |
| 6 | #include <vm/vm_param.h> |
| 7 | |
| 8 | #define _KERNEL |
| 9 | #include <sys/sem.h> |
| 10 | #include <sys/shm.h> |
| 11 | #include <sys/msg.h> |
| 12 | #undef _KERNEL |
| 13 | |
| 14 | #include <net/netisr.h> |
| 15 | |
| 16 | #include <netinet/ip.h> |
| 17 | #include <netinet/ip_var.h> |
| 18 | #include <netinet/ip_icmp.h> |
| 19 | #include <netinet/icmp_var.h> |
| 20 | #include <netinet6/ip6_var.h> |
| 21 | #include <netinet/icmp6.h> |
| 22 | #include <netinet/tcp_var.h> |
| 23 | #include <netinet/tcp_fsm.h> |
| 24 | #include <netinet/udp.h> |
| 25 | #include <netinet/udp_var.h> |
| 26 | |
| 27 | #define _COMMON_PLUGIN_NAME "freebsd.plugin" |
| 28 | #define _COMMON_PLUGIN_MODULE_NAME "freebsd" |
| 29 | #include "../common-contexts/common-contexts.h" |
| 30 | |
| 31 | // -------------------------------------------------------------------------------------------------------------------- |
| 32 | // common definitions and variables |
| 33 | |
| 34 | int system_pagesize = PAGE_SIZE; |
| 35 | int number_of_cpus = 1; |
| 36 | #if __FreeBSD_version >= 1200029 |
| 37 | struct __vmmeter { |
| 38 | uint64_t v_swtch; |
| 39 | uint64_t v_trap; |
| 40 | uint64_t v_syscall; |
| 41 | uint64_t v_intr; |
| 42 | uint64_t v_soft; |
| 43 | uint64_t v_vm_faults; |
| 44 | uint64_t v_io_faults; |
| 45 | uint64_t v_cow_faults; |
| 46 | uint64_t v_cow_optim; |
| 47 | uint64_t v_zfod; |
| 48 | uint64_t v_ozfod; |
| 49 | uint64_t v_swapin; |
| 50 | uint64_t v_swapout; |
| 51 | uint64_t v_swappgsin; |
| 52 | uint64_t v_swappgsout; |
| 53 | uint64_t v_vnodein; |
| 54 | uint64_t v_vnodeout; |
| 55 | uint64_t v_vnodepgsin; |
| 56 | uint64_t v_vnodepgsout; |
| 57 | uint64_t v_intrans; |
| 58 | uint64_t v_reactivated; |
| 59 | uint64_t v_pdwakeups; |
| 60 | uint64_t v_pdpages; |
| 61 | uint64_t v_pdshortfalls; |
| 62 | uint64_t v_dfree; |
| 63 | uint64_t v_pfree; |
| 64 | uint64_t v_tfree; |
| 65 | uint64_t v_forks; |
| 66 | uint64_t v_vforks; |
| 67 | uint64_t v_rforks; |
| 68 | uint64_t v_kthreads; |
| 69 | uint64_t v_forkpages; |
| 70 | uint64_t v_vforkpages; |
| 71 | uint64_t v_rforkpages; |
| 72 | uint64_t v_kthreadpages; |
| 73 | u_int v_page_size; |
| 74 | u_int v_page_count; |
| 75 | u_int v_free_reserved; |
| 76 | u_int v_free_target; |
| 77 | u_int v_free_min; |
| 78 | u_int v_free_count; |
| 79 | u_int v_wire_count; |
| 80 | u_int v_active_count; |
| 81 | u_int v_inactive_target; |
| 82 | u_int v_inactive_count; |
| 83 | u_int v_laundry_count; |
| 84 | u_int v_pageout_free_min; |
| 85 | u_int v_interrupt_free_min; |
| 86 | u_int v_free_severe; |
| 87 | }; |
| 88 | typedef struct __vmmeter vmmeter_t; |
| 89 | #else |
| 90 | typedef struct vmmeter vmmeter_t; |
| 91 | #endif |
| 92 | |
| 93 | #if (__FreeBSD_version >= 1101516 && __FreeBSD_version < 1200000) || __FreeBSD_version >= 1200015 |
| 94 | #define NETDATA_COLLECT_LAUNDRY 1 |
| 95 | #endif |
| 96 | |
| 97 | // FreeBSD plugin initialization |
| 98 | |
| 99 | int freebsd_plugin_init() |
| 100 | { |
| 101 | system_pagesize = getpagesize(); |
| 102 | if (system_pagesize <= 0) { |
| 103 | collector_error("FREEBSD: can't get system page size"); |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | if (unlikely(GETSYSCTL_BY_NAME("kern.smp.cpus", number_of_cpus))) { |
| 108 | collector_error("FREEBSD: can't get number of cpus"); |
| 109 | return 1; |
| 110 | } |
| 111 | |
| 112 | if (unlikely(!number_of_cpus)) { |
| 113 | collector_error("FREEBSD: wrong number of cpus"); |
| 114 | return 1; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | // vm.loadavg |
| 121 | |
| 122 | // FreeBSD calculates load averages once every 5 seconds |
| 123 | #define MIN_LOADAVG_UPDATE_EVERY 5 |
| 124 | |
| 125 | int do_vm_loadavg(int update_every, usec_t dt){ |
| 126 | static usec_t next_loadavg_dt = 0; |
| 127 | |
| 128 | if (next_loadavg_dt <= dt) { |
| 129 | static int mib[2] = {0, 0}; |
| 130 | struct loadavg sysload; |
| 131 | |
| 132 | if (unlikely(GETSYSCTL_SIMPLE("vm.loadavg", mib, sysload))) { |
| 133 | collector_error("DISABLED: system.load chart"); |
| 134 | collector_error("DISABLED: vm.loadavg module"); |
| 135 | return 1; |
| 136 | } else { |
| 137 | static RRDSET *st = NULL; |
| 138 | static RRDDIM *rd_load1 = NULL, *rd_load2 = NULL, *rd_load3 = NULL; |
| 139 | |
| 140 | if (unlikely(!st)) { |
| 141 | st = rrdset_create_localhost( |
| 142 | "system", |
| 143 | "load", |
| 144 | NULL, |
| 145 | "load", |
| 146 | NULL, |
| 147 | "System Load Average", |
| 148 | "load", |
| 149 | "freebsd.plugin", |
| 150 | "vm.loadavg", |
| 151 | NETDATA_CHART_PRIO_SYSTEM_LOAD, |
| 152 | (update_every < MIN_LOADAVG_UPDATE_EVERY) ? |
| 153 | MIN_LOADAVG_UPDATE_EVERY : update_every, RRDSET_TYPE_LINE |
| 154 | ); |
| 155 | rd_load1 = rrddim_add(st, "load1", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); |
| 156 | rd_load2 = rrddim_add(st, "load5", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); |
| 157 | rd_load3 = rrddim_add(st, "load15", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); |
| 158 | } |
| 159 | |
| 160 | rrddim_set_by_pointer(st, rd_load1, (collected_number) ((double) sysload.ldavg[0] / sysload.fscale * 1000)); |
| 161 | rrddim_set_by_pointer(st, rd_load2, (collected_number) ((double) sysload.ldavg[1] / sysload.fscale * 1000)); |
| 162 | rrddim_set_by_pointer(st, rd_load3, (collected_number) ((double) sysload.ldavg[2] / sysload.fscale * 1000)); |
| 163 | rrdset_done(st); |
| 164 | |
| 165 | next_loadavg_dt = st->update_every * USEC_PER_SEC; |
| 166 | } |
| 167 | } |
| 168 | else |
| 169 | next_loadavg_dt -= dt; |
| 170 | |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | // vm.vmtotal |
| 175 | |
| 176 | int do_vm_vmtotal(int update_every, usec_t dt) { |
| 177 | (void)dt; |
| 178 | static int do_all_processes = -1, do_processes = -1, do_mem_real = -1; |
| 179 | |
| 180 | if (unlikely(do_all_processes == -1)) { |
| 181 | do_all_processes = inicfg_get_boolean(&netdata_config, "plugin:freebsd:vm.vmtotal", "enable total processes", 1); |
| 182 | do_processes = inicfg_get_boolean(&netdata_config, "plugin:freebsd:vm.vmtotal", "processes running", 1); |
| 183 | do_mem_real = inicfg_get_boolean(&netdata_config, "plugin:freebsd:vm.vmtotal", "real memory", 1); |
| 184 | } |
| 185 | |
| 186 | if (likely(do_all_processes | do_processes | do_mem_real)) { |
| 187 | static int mib[2] = {0, 0}; |
| 188 | struct vmtotal vmtotal_data; |
| 189 | |
| 190 | if (unlikely(GETSYSCTL_SIMPLE("vm.vmtotal", mib, vmtotal_data))) { |
| 191 | do_all_processes = 0; |
| 192 | collector_error("DISABLED: system.active_processes chart"); |
| 193 | do_processes = 0; |
| 194 | collector_error("DISABLED: system.processes chart"); |
| 195 | do_mem_real = 0; |
| 196 | collector_error("DISABLED: mem.real chart"); |
| 197 | collector_error("DISABLED: vm.vmtotal module"); |
| 198 | return 1; |
| 199 | } else { |
| 200 | if (likely(do_all_processes)) { |
| 201 | static RRDSET *st = NULL; |
| 202 | static RRDDIM *rd = NULL; |
| 203 | |
| 204 | if (unlikely(!st)) { |
| 205 | st = rrdset_create_localhost( |
| 206 | "system", |
| 207 | "active_processes", |
| 208 | NULL, |
| 209 | "processes", |
| 210 | NULL, |
| 211 | "System Active Processes", |
| 212 | "processes", |
| 213 | "freebsd.plugin", |
| 214 | "vm.vmtotal", |
| 215 | NETDATA_CHART_PRIO_SYSTEM_ACTIVE_PROCESSES, |
| 216 | update_every, |
| 217 | RRDSET_TYPE_LINE |
| 218 | ); |
| 219 | rd = rrddim_add(st, "active", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 220 | } |
| 221 | |
| 222 | rrddim_set_by_pointer(st, rd, (vmtotal_data.t_rq + vmtotal_data.t_dw + vmtotal_data.t_pw + vmtotal_data.t_sl + vmtotal_data.t_sw)); |
| 223 | rrdset_done(st); |
| 224 | } |
| 225 | |
| 226 | if (likely(do_processes)) { |
| 227 | static RRDSET *st = NULL; |
| 228 | static RRDDIM *rd_running = NULL, *rd_blocked = NULL; |
| 229 | |
| 230 | if (unlikely(!st)) { |
| 231 | st = rrdset_create_localhost( |
| 232 | "system", |
| 233 | "processes", |
| 234 | NULL, |
| 235 | "processes", |
| 236 | NULL, |
| 237 | "System Processes", |
| 238 | "processes", |
| 239 | "freebsd.plugin", |
| 240 | "vm.vmtotal", |
| 241 | NETDATA_CHART_PRIO_SYSTEM_PROCESSES, |
| 242 | update_every, |
| 243 | RRDSET_TYPE_LINE |
| 244 | ); |
| 245 | |
| 246 | rd_running = rrddim_add(st, "running", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 247 | rd_blocked = rrddim_add(st, "blocked", NULL, -1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 248 | } |
| 249 | |
| 250 | rrddim_set_by_pointer(st, rd_running, vmtotal_data.t_rq); |
| 251 | rrddim_set_by_pointer(st, rd_blocked, (vmtotal_data.t_dw + vmtotal_data.t_pw)); |
| 252 | rrdset_done(st); |
| 253 | } |
| 254 | |
| 255 | if (likely(do_mem_real)) { |
| 256 | static RRDSET *st = NULL; |
| 257 | static RRDDIM *rd = NULL; |
| 258 | |
| 259 | if (unlikely(!st)) { |
| 260 | st = rrdset_create_localhost( |
| 261 | "mem", |
| 262 | "real", |
| 263 | NULL, |
| 264 | "system", |
| 265 | NULL, |
| 266 | "Total Real Memory In Use", |
| 267 | "MiB", |
| 268 | "freebsd.plugin", |
| 269 | "vm.vmtotal", |
| 270 | NETDATA_CHART_PRIO_MEM_SYSTEM_COMMITTED, |
| 271 | update_every, |
| 272 | RRDSET_TYPE_AREA |
| 273 | ); |
| 274 | |
| 275 | rd = rrddim_add(st, "used", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 276 | } |
| 277 | |
| 278 | rrddim_set_by_pointer(st, rd, vmtotal_data.t_rm); |
| 279 | rrdset_done(st); |
| 280 | } |
| 281 | } |
| 282 | } else { |
| 283 | collector_error("DISABLED: vm.vmtotal module"); |
| 284 | return 1; |
| 285 | } |
| 286 | |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | // kern.cp_time |
| 291 | |
| 292 | int do_kern_cp_time(int update_every, usec_t dt) { |
| 293 | (void)dt; |
| 294 | |
| 295 | if (unlikely(CPUSTATES != 5)) { |
| 296 | collector_error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES); |
| 297 | collector_error("DISABLED: system.cpu chart"); |
| 298 | collector_error("DISABLED: kern.cp_time module"); |
| 299 | return 1; |
| 300 | } else { |
| 301 | static int mib[2] = {0, 0}; |
| 302 | long cp_time[CPUSTATES]; |
| 303 | |
| 304 | if (unlikely(GETSYSCTL_SIMPLE("kern.cp_time", mib, cp_time))) { |
| 305 | collector_error("DISABLED: system.cpu chart"); |
| 306 | collector_error("DISABLED: kern.cp_time module"); |
| 307 | return 1; |
| 308 | } else { |
| 309 | static RRDSET *st = NULL; |
| 310 | static RRDDIM *rd_nice = NULL, *rd_system = NULL, *rd_user = NULL, *rd_interrupt = NULL, *rd_idle = NULL; |
| 311 | |
| 312 | if (unlikely(!st)) { |
| 313 | st = rrdset_create_localhost( |
| 314 | "system", |
| 315 | "cpu", |
| 316 | NULL, |
| 317 | "cpu", |
| 318 | "system.cpu", |
| 319 | "Total CPU utilization", |
| 320 | "percentage", |
| 321 | "freebsd.plugin", |
| 322 | "kern.cp_time", |
| 323 | NETDATA_CHART_PRIO_SYSTEM_CPU, |
| 324 | update_every, |
| 325 | RRDSET_TYPE_STACKED |
| 326 | ); |
| 327 | |
| 328 | rd_nice = rrddim_add(st, "nice", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 329 | rd_system = rrddim_add(st, "system", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 330 | rd_user = rrddim_add(st, "user", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 331 | rd_interrupt = rrddim_add(st, "interrupt", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 332 | rd_idle = rrddim_add(st, "idle", NULL, 1, 1, RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 333 | rrddim_hide(st, "idle"); |
| 334 | } |
| 335 | |
| 336 | rrddim_set_by_pointer(st, rd_nice, cp_time[1]); |
| 337 | rrddim_set_by_pointer(st, rd_system, cp_time[2]); |
| 338 | rrddim_set_by_pointer(st, rd_user, cp_time[0]); |
| 339 | rrddim_set_by_pointer(st, rd_interrupt, cp_time[3]); |
| 340 | rrddim_set_by_pointer(st, rd_idle, cp_time[4]); |
| 341 | rrdset_done(st); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
| 348 | // kern.cp_times |
| 349 | |
| 350 | int do_kern_cp_times(int update_every, usec_t dt) { |
| 351 | (void)dt; |
| 352 | |
| 353 | if (unlikely(CPUSTATES != 5)) { |
| 354 | collector_error("FREEBSD: There are %d CPU states (5 was expected)", CPUSTATES); |
| 355 | collector_error("DISABLED: cpu.cpuXX charts"); |
| 356 | collector_error("DISABLED: kern.cp_times module"); |
| 357 | return 1; |
| 358 | } else { |
| 359 | static int mib[2] = {0, 0}; |
| 360 | long cp_time[CPUSTATES]; |
| 361 | static long *pcpu_cp_time = NULL; |
| 362 | static int old_number_of_cpus = 0; |
| 363 | |
| 364 | if(unlikely(number_of_cpus != old_number_of_cpus)) |
| 365 | pcpu_cp_time = reallocz(pcpu_cp_time, sizeof(cp_time) * number_of_cpus); |
| 366 | if (unlikely(GETSYSCTL_WSIZE("kern.cp_times", mib, pcpu_cp_time, sizeof(cp_time) * number_of_cpus))) { |
| 367 | collector_error("DISABLED: cpu.cpuXX charts"); |
| 368 | collector_error("DISABLED: kern.cp_times module"); |
| 369 | return 1; |
| 370 | } else { |
| 371 | int i; |
| 372 | static struct cpu_chart { |
| 373 | char cpuid[MAX_INT_DIGITS + 4]; |
| 374 | RRDSET *st; |
| 375 | RRDDIM *rd_user; |
| 376 | RRDDIM *rd_nice; |
| 377 | RRDDIM *rd_system; |
| 378 | RRDDIM *rd_interrupt; |
| 379 | RRDDIM *rd_idle; |
| 380 | } *all_cpu_charts = NULL; |
| 381 | |
| 382 | if(unlikely(number_of_cpus > old_number_of_cpus)) { |
| 383 | all_cpu_charts = reallocz(all_cpu_charts, sizeof(struct cpu_chart) * number_of_cpus); |
| 384 | memset(&all_cpu_charts[old_number_of_cpus], 0, sizeof(struct cpu_chart) * (number_of_cpus - old_number_of_cpus)); |
| 385 | } |
| 386 | |
| 387 | for (i = 0; i < number_of_cpus; i++) { |
| 388 | if (unlikely(!all_cpu_charts[i].st)) { |
| 389 | snprintfz(all_cpu_charts[i].cpuid, MAX_INT_DIGITS, "cpu%d", i); |
| 390 | all_cpu_charts[i].st = rrdset_create_localhost( |
| 391 | "cpu", |
| 392 | all_cpu_charts[i].cpuid, |
| 393 | NULL, |
| 394 | "utilization", |
| 395 | "cpu.cpu", |
| 396 | "Core utilization", |
| 397 | "percentage", |
| 398 | "freebsd.plugin", |
| 399 | "kern.cp_times", |
| 400 | NETDATA_CHART_PRIO_CPU_PER_CORE, |
| 401 | update_every, |
| 402 | RRDSET_TYPE_STACKED |
| 403 | ); |
| 404 | |
| 405 | all_cpu_charts[i].rd_nice = rrddim_add(all_cpu_charts[i].st, "nice", NULL, 1, 1, |
| 406 | RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 407 | all_cpu_charts[i].rd_system = rrddim_add(all_cpu_charts[i].st, "system", NULL, 1, 1, |
| 408 | RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 409 | all_cpu_charts[i].rd_user = rrddim_add(all_cpu_charts[i].st, "user", NULL, 1, 1, |
| 410 | RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 411 | all_cpu_charts[i].rd_interrupt = rrddim_add(all_cpu_charts[i].st, "interrupt", NULL, 1, 1, |
| 412 | RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 413 | all_cpu_charts[i].rd_idle = rrddim_add(all_cpu_charts[i].st, "idle", NULL, 1, 1, |
| 414 | RRD_ALGORITHM_PCENT_OVER_DIFF_TOTAL); |
| 415 | rrddim_hide(all_cpu_charts[i].st, "idle"); |
| 416 | } |
| 417 | |
| 418 | rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_nice, pcpu_cp_time[i * 5 + 1]); |
| 419 | rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_system, pcpu_cp_time[i * 5 + 2]); |
| 420 | rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_user, pcpu_cp_time[i * 5 + 0]); |
| 421 | rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_interrupt, pcpu_cp_time[i * 5 + 3]); |
| 422 | rrddim_set_by_pointer(all_cpu_charts[i].st, all_cpu_charts[i].rd_idle, pcpu_cp_time[i * 5 + 4]); |
| 423 | rrdset_done(all_cpu_charts[i].st); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | old_number_of_cpus = number_of_cpus; |
| 428 | } |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | // dev.cpu.temperature |
| 434 | |
| 435 | int do_dev_cpu_temperature(int update_every, usec_t dt) { |
| 436 | (void)dt; |
| 437 | |
| 438 | int i; |
| 439 | static int *mib = NULL; |
| 440 | static int *pcpu_temperature = NULL; |
| 441 | static int old_number_of_cpus = 0; |
| 442 | char char_mib[MAX_INT_DIGITS + 21]; |
| 443 | char char_rd[MAX_INT_DIGITS + 9]; |
| 444 | |
| 445 | if (unlikely(number_of_cpus != old_number_of_cpus)) { |
| 446 | pcpu_temperature = reallocz(pcpu_temperature, sizeof(int) * number_of_cpus); |
| 447 | mib = reallocz(mib, sizeof(int) * number_of_cpus * 4); |
| 448 | if (unlikely(number_of_cpus > old_number_of_cpus)) |
| 449 | memset(&mib[old_number_of_cpus * 4], 0, sizeof(int) * (number_of_cpus - old_number_of_cpus) * 4); |
| 450 | } |
| 451 | for (i = 0; i < number_of_cpus; i++) { |
| 452 | if (unlikely(!(mib[i * 4]))) |
| 453 | sprintf(char_mib, "dev.cpu.%d.temperature", i); |
| 454 | if (unlikely(getsysctl_simple(char_mib, &mib[i * 4], 4, &pcpu_temperature[i], sizeof(int)))) { |
| 455 | collector_error("DISABLED: cpu.temperature chart"); |
| 456 | collector_error("DISABLED: dev.cpu.temperature module"); |
| 457 | return 1; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | static RRDSET *st; |
| 462 | static RRDDIM **rd_pcpu_temperature; |
| 463 | |
| 464 | if (unlikely(number_of_cpus != old_number_of_cpus)) { |
| 465 | rd_pcpu_temperature = reallocz(rd_pcpu_temperature, sizeof(RRDDIM *) * number_of_cpus); |
| 466 | if (unlikely(number_of_cpus > old_number_of_cpus)) |
| 467 | memset(&rd_pcpu_temperature[old_number_of_cpus], 0, sizeof(RRDDIM *) * (number_of_cpus - old_number_of_cpus)); |
| 468 | } |
| 469 | |
| 470 | if (unlikely(!st)) { |
| 471 | st = rrdset_create_localhost( |
| 472 | "cpu", |
| 473 | "temperature", |
| 474 | NULL, |
| 475 | "temperature", |
| 476 | "cpu.temperature", |
| 477 | "Core temperature", |
| 478 | "Celsius", |
| 479 | "freebsd.plugin", |
| 480 | "dev.cpu.temperature", |
| 481 | NETDATA_CHART_PRIO_CPU_TEMPERATURE, |
| 482 | update_every, |
| 483 | RRDSET_TYPE_LINE |
| 484 | ); |
| 485 | } |
| 486 | |
| 487 | for (i = 0; i < number_of_cpus; i++) { |
| 488 | if (unlikely(!rd_pcpu_temperature[i])) { |
| 489 | sprintf(char_rd, "cpu%d.temp", i); |
| 490 | rd_pcpu_temperature[i] = rrddim_add(st, char_rd, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 491 | } |
| 492 | |
| 493 | rrddim_set_by_pointer(st, rd_pcpu_temperature[i], (collected_number) ((double)pcpu_temperature[i] / 10 - 273.15)); |
| 494 | } |
| 495 | |
| 496 | rrdset_done(st); |
| 497 | |
| 498 | old_number_of_cpus = number_of_cpus; |
| 499 | |
| 500 | return 0; |
| 501 | } |
| 502 | |
| 503 | // dev.cpu.0.freq |
| 504 | |
| 505 | int do_dev_cpu_0_freq(int update_every, usec_t dt) { |
| 506 | (void)dt; |
| 507 | static int mib[4] = {0, 0, 0, 0}; |
| 508 | int cpufreq; |
| 509 | |
| 510 | if (unlikely(GETSYSCTL_SIMPLE("dev.cpu.0.freq", mib, cpufreq))) { |
| 511 | collector_error("DISABLED: cpu.scaling_cur_freq chart"); |
| 512 | collector_error("DISABLED: dev.cpu.0.freq module"); |
| 513 | return 1; |
| 514 | } else { |
| 515 | static RRDSET *st = NULL; |
| 516 | static RRDDIM *rd = NULL; |
| 517 | |
| 518 | if (unlikely(!st)) { |
| 519 | st = rrdset_create_localhost( |
| 520 | "cpu", |
| 521 | "scaling_cur_freq", |
| 522 | NULL, |
| 523 | "cpufreq", |
| 524 | NULL, |
| 525 | "Current CPU Scaling Frequency", |
| 526 | "MHz", |
| 527 | "freebsd.plugin", |
| 528 | "dev.cpu.0.freq", |
| 529 | NETDATA_CHART_PRIO_CPUFREQ_SCALING_CUR_FREQ, |
| 530 | update_every, |
| 531 | RRDSET_TYPE_LINE |
| 532 | ); |
| 533 | |
| 534 | rd = rrddim_add(st, "frequency", NULL, 1, 1000, RRD_ALGORITHM_ABSOLUTE); |
| 535 | } |
| 536 | |
| 537 | rrddim_set_by_pointer(st, rd, cpufreq); |
| 538 | rrdset_done(st); |
| 539 | } |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
| 544 | // -------------------------------------------------------------------------------------------------------------------- |
| 545 | // hw.intrcnt |
| 546 | |
| 547 | int do_hw_intcnt(int update_every, usec_t dt) { |
| 548 | (void)dt; |
| 549 | static int mib_hw_intrcnt[2] = {0, 0}; |
| 550 | size_t intrcnt_size = 0; |
| 551 | |
| 552 | if (unlikely(GETSYSCTL_SIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt_size))) { |
| 553 | collector_error("DISABLED: system.intr chart"); |
| 554 | collector_error("DISABLED: system.interrupts chart"); |
| 555 | collector_error("DISABLED: hw.intrcnt module"); |
| 556 | return 1; |
| 557 | } else { |
| 558 | unsigned long nintr = 0; |
| 559 | static unsigned long old_nintr = 0; |
| 560 | static unsigned long *intrcnt = NULL; |
| 561 | |
| 562 | nintr = intrcnt_size / sizeof(u_long); |
| 563 | if (unlikely(nintr != old_nintr)) |
| 564 | intrcnt = reallocz(intrcnt, nintr * sizeof(u_long)); |
| 565 | if (unlikely(GETSYSCTL_WSIZE("hw.intrcnt", mib_hw_intrcnt, intrcnt, nintr * sizeof(u_long)))) { |
| 566 | collector_error("DISABLED: system.intr chart"); |
| 567 | collector_error("DISABLED: system.interrupts chart"); |
| 568 | collector_error("DISABLED: hw.intrcnt module"); |
| 569 | return 1; |
| 570 | } else { |
| 571 | unsigned long long totalintr = 0; |
| 572 | unsigned long i; |
| 573 | |
| 574 | for (i = 0; i < nintr; i++) |
| 575 | totalintr += intrcnt[i]; |
| 576 | |
| 577 | static RRDSET *st_intr = NULL; |
| 578 | static RRDDIM *rd_intr = NULL; |
| 579 | |
| 580 | common_interrupts(totalintr, update_every, "hw.intrcnt"); |
| 581 | |
| 582 | size_t size; |
| 583 | static int mib_hw_intrnames[2] = {0, 0}; |
| 584 | static char *intrnames = NULL; |
| 585 | |
| 586 | if (unlikely(GETSYSCTL_SIZE("hw.intrnames", mib_hw_intrnames, size))) { |
| 587 | collector_error("DISABLED: system.intr chart"); |
| 588 | collector_error("DISABLED: system.interrupts chart"); |
| 589 | collector_error("DISABLED: hw.intrcnt module"); |
| 590 | return 1; |
| 591 | } else { |
| 592 | if (unlikely(nintr != old_nintr)) |
| 593 | intrnames = reallocz(intrnames, size); |
| 594 | if (unlikely(GETSYSCTL_WSIZE("hw.intrnames", mib_hw_intrnames, intrnames, size))) { |
| 595 | collector_error("DISABLED: system.intr chart"); |
| 596 | collector_error("DISABLED: system.interrupts chart"); |
| 597 | collector_error("DISABLED: hw.intrcnt module"); |
| 598 | return 1; |
| 599 | } else { |
| 600 | static RRDSET *st_interrupts = NULL; |
| 601 | |
| 602 | if (unlikely(!st_interrupts)) { |
| 603 | st_interrupts = rrdset_create_localhost( |
| 604 | "system", |
| 605 | "interrupts", |
| 606 | NULL, |
| 607 | "interrupts", |
| 608 | NULL, |
| 609 | "System interrupts", |
| 610 | "interrupts/s", |
| 611 | "freebsd.plugin", |
| 612 | "hw.intrcnt", |
| 613 | NETDATA_CHART_PRIO_SYSTEM_INTERRUPTS, |
| 614 | update_every, |
| 615 | RRDSET_TYPE_STACKED |
| 616 | ); |
| 617 | } |
| 618 | |
| 619 | for (i = 0; i < nintr; i++) { |
| 620 | void *p; |
| 621 | |
| 622 | p = intrnames + i * (strlen(intrnames) + 1); |
| 623 | if (unlikely((intrcnt[i] != 0) && (*(char *) p != 0))) { |
| 624 | RRDDIM *rd_interrupts = rrddim_find_active(st_interrupts, p); |
| 625 | |
| 626 | if (unlikely(!rd_interrupts)) |
| 627 | rd_interrupts = rrddim_add(st_interrupts, p, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 628 | |
| 629 | rrddim_set_by_pointer(st_interrupts, rd_interrupts, intrcnt[i]); |
| 630 | } |
| 631 | } |
| 632 | rrdset_done(st_interrupts); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | old_nintr = nintr; |
| 638 | } |
| 639 | |
| 640 | return 0; |
| 641 | } |
| 642 | |
| 643 | // vm.stats.sys.v_intr |
| 644 | |
| 645 | int do_vm_stats_sys_v_intr(int update_every, usec_t dt) { |
| 646 | (void)dt; |
| 647 | static int mib[4] = {0, 0, 0, 0}; |
| 648 | u_int int_number; |
| 649 | |
| 650 | if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_intr", mib, int_number))) { |
| 651 | collector_error("DISABLED: system.dev_intr chart"); |
| 652 | collector_error("DISABLED: vm.stats.sys.v_intr module"); |
| 653 | return 1; |
| 654 | } else { |
| 655 | static RRDSET *st = NULL; |
| 656 | static RRDDIM *rd = NULL; |
| 657 | |
| 658 | if (unlikely(!st)) { |
| 659 | st = rrdset_create_localhost( |
| 660 | "system", |
| 661 | "dev_intr", |
| 662 | NULL, |
| 663 | "interrupts", |
| 664 | NULL, |
| 665 | "Device Interrupts", |
| 666 | "interrupts/s", |
| 667 | "freebsd.plugin", |
| 668 | "vm.stats.sys.v_intr", |
| 669 | NETDATA_CHART_PRIO_SYSTEM_DEV_INTR, |
| 670 | update_every, |
| 671 | RRDSET_TYPE_LINE |
| 672 | ); |
| 673 | |
| 674 | rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 675 | } |
| 676 | |
| 677 | rrddim_set_by_pointer(st, rd, int_number); |
| 678 | rrdset_done(st); |
| 679 | } |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | // vm.stats.sys.v_soft |
| 685 | |
| 686 | int do_vm_stats_sys_v_soft(int update_every, usec_t dt) { |
| 687 | (void)dt; |
| 688 | static int mib[4] = {0, 0, 0, 0}; |
| 689 | u_int soft_intr_number; |
| 690 | |
| 691 | if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_soft", mib, soft_intr_number))) { |
| 692 | collector_error("DISABLED: system.dev_intr chart"); |
| 693 | collector_error("DISABLED: vm.stats.sys.v_soft module"); |
| 694 | return 1; |
| 695 | } else { |
| 696 | static RRDSET *st = NULL; |
| 697 | static RRDDIM *rd = NULL; |
| 698 | |
| 699 | if (unlikely(!st)) { |
| 700 | st = rrdset_create_localhost( |
| 701 | "system", |
| 702 | "soft_intr", |
| 703 | NULL, |
| 704 | "interrupts", |
| 705 | NULL, |
| 706 | "Software Interrupts", |
| 707 | "interrupts/s", |
| 708 | "freebsd.plugin", |
| 709 | "vm.stats.sys.v_soft", |
| 710 | NETDATA_CHART_PRIO_SYSTEM_SOFT_INTR, |
| 711 | update_every, |
| 712 | RRDSET_TYPE_LINE |
| 713 | ); |
| 714 | |
| 715 | rd = rrddim_add(st, "interrupts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 716 | } |
| 717 | |
| 718 | rrddim_set_by_pointer(st, rd, soft_intr_number); |
| 719 | rrdset_done(st); |
| 720 | } |
| 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | // vm.stats.sys.v_swtch |
| 726 | |
| 727 | int do_vm_stats_sys_v_swtch(int update_every, usec_t dt) { |
| 728 | (void)dt; |
| 729 | static int mib[4] = {0, 0, 0, 0}; |
| 730 | u_int ctxt_number; |
| 731 | |
| 732 | if (unlikely(GETSYSCTL_SIMPLE("vm.stats.sys.v_swtch", mib, ctxt_number))) { |
| 733 | collector_error("DISABLED: system.ctxt chart"); |
| 734 | collector_error("DISABLED: vm.stats.sys.v_swtch module"); |
| 735 | return 1; |
| 736 | } else { |
| 737 | static RRDSET *st = NULL; |
| 738 | static RRDDIM *rd = NULL; |
| 739 | |
| 740 | if (unlikely(!st)) { |
| 741 | st = rrdset_create_localhost( |
| 742 | "system", |
| 743 | "ctxt", |
| 744 | NULL, |
| 745 | "processes", |
| 746 | NULL, |
| 747 | "CPU Context Switches", |
| 748 | "context switches/s", |
| 749 | "freebsd.plugin", |
| 750 | "vm.stats.sys.v_swtch", |
| 751 | NETDATA_CHART_PRIO_SYSTEM_CTXT, |
| 752 | update_every, |
| 753 | RRDSET_TYPE_LINE |
| 754 | ); |
| 755 | |
| 756 | rd = rrddim_add(st, "switches", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 757 | } |
| 758 | |
| 759 | rrddim_set_by_pointer(st, rd, ctxt_number); |
| 760 | rrdset_done(st); |
| 761 | } |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | // vm.stats.vm.v_forks |
| 767 | |
| 768 | int do_vm_stats_sys_v_forks(int update_every, usec_t dt) { |
| 769 | (void)dt; |
| 770 | static int mib[4] = {0, 0, 0, 0}; |
| 771 | u_int forks_number; |
| 772 | |
| 773 | if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_forks", mib, forks_number))) { |
| 774 | collector_error("DISABLED: system.forks chart"); |
| 775 | collector_error("DISABLED: vm.stats.sys.v_swtch module"); |
| 776 | return 1; |
| 777 | } else { |
| 778 | |
| 779 | // -------------------------------------------------------------------- |
| 780 | |
| 781 | static RRDSET *st = NULL; |
| 782 | static RRDDIM *rd = NULL; |
| 783 | |
| 784 | if (unlikely(!st)) { |
| 785 | st = rrdset_create_localhost( |
| 786 | "system", |
| 787 | "forks", |
| 788 | NULL, |
| 789 | "processes", |
| 790 | NULL, |
| 791 | "Started Processes", |
| 792 | "processes/s", |
| 793 | "freebsd.plugin", |
| 794 | "vm.stats.sys.v_swtch", |
| 795 | NETDATA_CHART_PRIO_SYSTEM_FORKS, |
| 796 | update_every, |
| 797 | RRDSET_TYPE_LINE |
| 798 | ); |
| 799 | |
| 800 | rd = rrddim_add(st, "started", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 801 | } |
| 802 | |
| 803 | rrddim_set_by_pointer(st, rd, forks_number); |
| 804 | rrdset_done(st); |
| 805 | } |
| 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | // vm.swap_info |
| 811 | |
| 812 | int do_vm_swap_info(int update_every, usec_t dt) { |
| 813 | (void)dt; |
| 814 | static int mib[3] = {0, 0, 0}; |
| 815 | |
| 816 | if (unlikely(getsysctl_mib("vm.swap_info", mib, 2))) { |
| 817 | collector_error("DISABLED: mem.swap chart"); |
| 818 | collector_error("DISABLED: vm.swap_info module"); |
| 819 | return 1; |
| 820 | } else { |
| 821 | int i; |
| 822 | struct xswdev xsw; |
| 823 | struct total_xsw { |
| 824 | collected_number bytes_used; |
| 825 | collected_number bytes_total; |
| 826 | } total_xsw = {0, 0}; |
| 827 | |
| 828 | for (i = 0; ; i++) { |
| 829 | size_t size; |
| 830 | |
| 831 | mib[2] = i; |
| 832 | size = sizeof(xsw); |
| 833 | if (unlikely(sysctl(mib, 3, &xsw, &size, NULL, 0) == -1 )) { |
| 834 | if (unlikely(errno != ENOENT)) { |
| 835 | collector_error("FREEBSD: sysctl(%s...) failed: %s", "vm.swap_info", strerror(errno)); |
| 836 | collector_error("DISABLED: mem.swap chart"); |
| 837 | collector_error("DISABLED: vm.swap_info module"); |
| 838 | return 1; |
| 839 | } else { |
| 840 | if (unlikely(size != sizeof(xsw))) { |
| 841 | collector_error("FREEBSD: sysctl(%s...) expected %lu, got %lu", "vm.swap_info", (unsigned long)sizeof(xsw), (unsigned long)size); |
| 842 | collector_error("DISABLED: mem.swap chart"); |
| 843 | collector_error("DISABLED: vm.swap_info module"); |
| 844 | return 1; |
| 845 | } else break; |
| 846 | } |
| 847 | } |
| 848 | total_xsw.bytes_used += xsw.xsw_used; |
| 849 | total_xsw.bytes_total += xsw.xsw_nblks; |
| 850 | } |
| 851 | |
| 852 | static RRDSET *st = NULL; |
| 853 | static RRDDIM *rd_free = NULL, *rd_used = NULL; |
| 854 | |
| 855 | if (unlikely(!st)) { |
| 856 | st = rrdset_create_localhost( |
| 857 | "mem", |
| 858 | "swap", |
| 859 | NULL, |
| 860 | "swap", |
| 861 | NULL, |
| 862 | "System Swap", |
| 863 | "MiB", |
| 864 | "freebsd.plugin", |
| 865 | "vm.swap_info", |
| 866 | NETDATA_CHART_PRIO_MEM_SWAP, |
| 867 | update_every, |
| 868 | RRDSET_TYPE_STACKED |
| 869 | ); |
| 870 | |
| 871 | rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 872 | rd_used = rrddim_add(st, "used", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 873 | } |
| 874 | |
| 875 | rrddim_set_by_pointer(st, rd_free, total_xsw.bytes_total - total_xsw.bytes_used); |
| 876 | rrddim_set_by_pointer(st, rd_used, total_xsw.bytes_used); |
| 877 | rrdset_done(st); |
| 878 | } |
| 879 | |
| 880 | return 0; |
| 881 | } |
| 882 | |
| 883 | // system.ram |
| 884 | |
| 885 | int do_system_ram(int update_every, usec_t dt) { |
| 886 | (void)dt; |
| 887 | static int mib_active_count[4] = {0, 0, 0, 0}, |
| 888 | mib_inactive_count[4] = {0, 0, 0, 0}, |
| 889 | mib_wire_count[4] = {0, 0, 0, 0}, |
| 890 | #if __FreeBSD_version < 1200016 |
| 891 | mib_cache_count[4] = {0, 0, 0, 0}, |
| 892 | #endif |
| 893 | mib_vfs_bufspace[2] = {0, 0}, |
| 894 | mib_free_count[4] = {0, 0, 0, 0}; |
| 895 | vmmeter_t vmmeter_data; |
| 896 | size_t vfs_bufspace_count; |
| 897 | |
| 898 | #if defined(NETDATA_COLLECT_LAUNDRY) |
| 899 | static int mib_laundry_count[4] = {0, 0, 0, 0}; |
| 900 | #endif |
| 901 | |
| 902 | if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_active_count", mib_active_count, vmmeter_data.v_active_count) || |
| 903 | GETSYSCTL_SIMPLE("vm.stats.vm.v_inactive_count", mib_inactive_count, vmmeter_data.v_inactive_count) || |
| 904 | GETSYSCTL_SIMPLE("vm.stats.vm.v_wire_count", mib_wire_count, vmmeter_data.v_wire_count) || |
| 905 | #if __FreeBSD_version < 1200016 |
| 906 | GETSYSCTL_SIMPLE("vm.stats.vm.v_cache_count", mib_cache_count, vmmeter_data.v_cache_count) || |
| 907 | #endif |
| 908 | #if defined(NETDATA_COLLECT_LAUNDRY) |
| 909 | GETSYSCTL_SIMPLE("vm.stats.vm.v_laundry_count", mib_laundry_count, vmmeter_data.v_laundry_count) || |
| 910 | #endif |
| 911 | GETSYSCTL_SIMPLE("vfs.bufspace", mib_vfs_bufspace, vfs_bufspace_count) || |
| 912 | GETSYSCTL_SIMPLE("vm.stats.vm.v_free_count", mib_free_count, vmmeter_data.v_free_count))) { |
| 913 | collector_error("DISABLED: system.ram chart"); |
| 914 | collector_error("DISABLED: system.ram module"); |
| 915 | return 1; |
| 916 | } else { |
| 917 | static RRDSET *st = NULL, *st_mem_available = NULL; |
| 918 | static RRDDIM *rd_free = NULL, *rd_active = NULL, *rd_inactive = NULL, *rd_wired = NULL, |
| 919 | *rd_cache = NULL, *rd_buffers = NULL, *rd_avail = NULL; |
| 920 | |
| 921 | #if defined(NETDATA_COLLECT_LAUNDRY) |
| 922 | static RRDDIM *rd_laundry = NULL; |
| 923 | #endif |
| 924 | |
| 925 | if (unlikely(!st)) { |
| 926 | st = rrdset_create_localhost( |
| 927 | "system", |
| 928 | "ram", |
| 929 | NULL, |
| 930 | "ram", |
| 931 | NULL, |
| 932 | "System RAM", |
| 933 | "MiB", |
| 934 | "freebsd.plugin", |
| 935 | "system.ram", |
| 936 | NETDATA_CHART_PRIO_SYSTEM_RAM, |
| 937 | update_every, |
| 938 | RRDSET_TYPE_STACKED |
| 939 | ); |
| 940 | |
| 941 | rd_free = rrddim_add(st, "free", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 942 | rd_active = rrddim_add(st, "active", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 943 | rd_inactive = rrddim_add(st, "inactive", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 944 | rd_wired = rrddim_add(st, "wired", NULL, 1, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 945 | rd_cache = rrddim_add(st, "cache", NULL, 1, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 946 | #if defined(NETDATA_COLLECT_LAUNDRY) |
| 947 | rd_laundry = rrddim_add(st, "laundry", NULL, system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 948 | #endif |
| 949 | rd_buffers = rrddim_add(st, "buffers", NULL, 1, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 950 | } |
| 951 | |
| 952 | rrddim_set_by_pointer(st, rd_free, vmmeter_data.v_free_count); |
| 953 | rrddim_set_by_pointer(st, rd_active, vmmeter_data.v_active_count); |
| 954 | rrddim_set_by_pointer(st, rd_inactive, vmmeter_data.v_inactive_count); |
| 955 | rrddim_set_by_pointer(st, rd_wired, (unsigned long long)vmmeter_data.v_wire_count * (unsigned long long)system_pagesize - zfs_arcstats_shrinkable_cache_size_bytes); |
| 956 | #if __FreeBSD_version < 1200016 |
| 957 | rrddim_set_by_pointer(st, rd_cache, (unsigned long long)vmmeter_data.v_cache_count * (unsigned long long)system_pagesize + zfs_arcstats_shrinkable_cache_size_bytes); |
| 958 | #else |
| 959 | rrddim_set_by_pointer(st, rd_cache, zfs_arcstats_shrinkable_cache_size_bytes); |
| 960 | #endif |
| 961 | #if defined(NETDATA_COLLECT_LAUNDRY) |
| 962 | rrddim_set_by_pointer(st, rd_laundry, vmmeter_data.v_laundry_count); |
| 963 | #endif |
| 964 | rrddim_set_by_pointer(st, rd_buffers, vfs_bufspace_count); |
| 965 | rrdset_done(st); |
| 966 | |
| 967 | if (unlikely(!st_mem_available)) { |
| 968 | st_mem_available = rrdset_create_localhost( |
| 969 | "mem", |
| 970 | "available", |
| 971 | NULL, |
| 972 | "system", |
| 973 | NULL, |
| 974 | "Available RAM for applications", |
| 975 | "MiB", |
| 976 | "freebsd.plugin", |
| 977 | "system.ram", |
| 978 | NETDATA_CHART_PRIO_MEM_SYSTEM_AVAILABLE, |
| 979 | update_every, |
| 980 | RRDSET_TYPE_AREA |
| 981 | ); |
| 982 | |
| 983 | rd_avail = rrddim_add(st_mem_available, "MemAvailable", "avail", system_pagesize, MEGA_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 984 | } |
| 985 | |
| 986 | #if __FreeBSD_version < 1200016 |
| 987 | rrddim_set_by_pointer(st_mem_available, rd_avail, vmmeter_data.v_inactive_count + vmmeter_data.v_free_count + vmmeter_data.v_cache_count + zfs_arcstats_shrinkable_cache_size_bytes / system_pagesize); |
| 988 | #else |
| 989 | rrddim_set_by_pointer(st_mem_available, rd_avail, vmmeter_data.v_inactive_count + vmmeter_data.v_free_count + zfs_arcstats_shrinkable_cache_size_bytes / system_pagesize); |
| 990 | #endif |
| 991 | |
| 992 | rrdset_done(st_mem_available); |
| 993 | } |
| 994 | |
| 995 | return 0; |
| 996 | } |
| 997 | |
| 998 | // vm.stats.vm.v_swappgs |
| 999 | |
| 1000 | int do_vm_stats_sys_v_swappgs(int update_every, usec_t dt) { |
| 1001 | (void)dt; |
| 1002 | static int mib_swappgsin[4] = {0, 0, 0, 0}, mib_swappgsout[4] = {0, 0, 0, 0}; |
| 1003 | vmmeter_t vmmeter_data; |
| 1004 | |
| 1005 | if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsin", mib_swappgsin, vmmeter_data.v_swappgsin) || |
| 1006 | GETSYSCTL_SIMPLE("vm.stats.vm.v_swappgsout", mib_swappgsout, vmmeter_data.v_swappgsout))) { |
| 1007 | collector_error("DISABLED: mem.swapio chart"); |
| 1008 | collector_error("DISABLED: vm.stats.vm.v_swappgs module"); |
| 1009 | return 1; |
| 1010 | } else { |
| 1011 | static RRDSET *st = NULL; |
| 1012 | static RRDDIM *rd_in = NULL, *rd_out = NULL; |
| 1013 | |
| 1014 | if (unlikely(!st)) { |
| 1015 | st = rrdset_create_localhost( |
| 1016 | "mem", |
| 1017 | "swapio", |
| 1018 | NULL, |
| 1019 | "swap", |
| 1020 | NULL, |
| 1021 | "Swap I/O", |
| 1022 | "KiB/s", |
| 1023 | "freebsd.plugin", |
| 1024 | "vm.stats.vm.v_swappgs", |
| 1025 | NETDATA_CHART_PRIO_MEM_SWAPIO, |
| 1026 | update_every, |
| 1027 | RRDSET_TYPE_AREA |
| 1028 | ); |
| 1029 | |
| 1030 | rd_in = rrddim_add(st, "in", NULL, system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL); |
| 1031 | rd_out = rrddim_add(st, "out", NULL, -system_pagesize, KILO_FACTOR, RRD_ALGORITHM_INCREMENTAL); |
| 1032 | } |
| 1033 | |
| 1034 | rrddim_set_by_pointer(st, rd_in, vmmeter_data.v_swappgsin); |
| 1035 | rrddim_set_by_pointer(st, rd_out, vmmeter_data.v_swappgsout); |
| 1036 | rrdset_done(st); |
| 1037 | } |
| 1038 | |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
| 1042 | // vm.stats.vm.v_pgfaults |
| 1043 | |
| 1044 | int do_vm_stats_sys_v_pgfaults(int update_every, usec_t dt) { |
| 1045 | (void)dt; |
| 1046 | static int mib_vm_faults[4] = {0, 0, 0, 0}, mib_io_faults[4] = {0, 0, 0, 0}, mib_cow_faults[4] = {0, 0, 0, 0}, |
| 1047 | mib_cow_optim[4] = {0, 0, 0, 0}, mib_intrans[4] = {0, 0, 0, 0}; |
| 1048 | vmmeter_t vmmeter_data; |
| 1049 | |
| 1050 | if (unlikely(GETSYSCTL_SIMPLE("vm.stats.vm.v_vm_faults", mib_vm_faults, vmmeter_data.v_vm_faults) || |
| 1051 | GETSYSCTL_SIMPLE("vm.stats.vm.v_io_faults", mib_io_faults, vmmeter_data.v_io_faults) || |
| 1052 | GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_faults", mib_cow_faults, vmmeter_data.v_cow_faults) || |
| 1053 | GETSYSCTL_SIMPLE("vm.stats.vm.v_cow_optim", mib_cow_optim, vmmeter_data.v_cow_optim) || |
| 1054 | GETSYSCTL_SIMPLE("vm.stats.vm.v_intrans", mib_intrans, vmmeter_data.v_intrans))) { |
| 1055 | collector_error("DISABLED: mem.pgfaults chart"); |
| 1056 | collector_error("DISABLED: vm.stats.vm.v_pgfaults module"); |
| 1057 | return 1; |
| 1058 | } else { |
| 1059 | static RRDSET *st = NULL; |
| 1060 | static RRDDIM *rd_memory = NULL, *rd_io_requiring = NULL, *rd_cow = NULL, |
| 1061 | *rd_cow_optimized = NULL, *rd_in_transit = NULL; |
| 1062 | |
| 1063 | if (unlikely(!st)) { |
| 1064 | st = rrdset_create_localhost( |
| 1065 | "mem", |
| 1066 | "pgfaults", |
| 1067 | NULL, |
| 1068 | "system", |
| 1069 | NULL, |
| 1070 | "Memory Page Faults", |
| 1071 | "page faults/s", |
| 1072 | "freebsd.plugin", |
| 1073 | "vm.stats.vm.v_pgfaults", |
| 1074 | NETDATA_CHART_PRIO_MEM_SYSTEM_PGFAULTS, |
| 1075 | update_every, |
| 1076 | RRDSET_TYPE_LINE |
| 1077 | ); |
| 1078 | |
| 1079 | rd_memory = rrddim_add(st, "memory", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1080 | rd_io_requiring = rrddim_add(st, "io_requiring", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1081 | rd_cow = rrddim_add(st, "cow", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1082 | rd_cow_optimized = rrddim_add(st, "cow_optimized", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1083 | rd_in_transit = rrddim_add(st, "in_transit", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1084 | } |
| 1085 | |
| 1086 | rrddim_set_by_pointer(st, rd_memory, vmmeter_data.v_vm_faults); |
| 1087 | rrddim_set_by_pointer(st, rd_io_requiring, vmmeter_data.v_io_faults); |
| 1088 | rrddim_set_by_pointer(st, rd_cow, vmmeter_data.v_cow_faults); |
| 1089 | rrddim_set_by_pointer(st, rd_cow_optimized, vmmeter_data.v_cow_optim); |
| 1090 | rrddim_set_by_pointer(st, rd_in_transit, vmmeter_data.v_intrans); |
| 1091 | rrdset_done(st); |
| 1092 | } |
| 1093 | |
| 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | // -------------------------------------------------------------------------------------------------------------------- |
| 1098 | // kern.ipc.sem |
| 1099 | |
| 1100 | int do_kern_ipc_sem(int update_every, usec_t dt) { |
| 1101 | (void)dt; |
| 1102 | static int mib_semmni[3] = {0, 0, 0}; |
| 1103 | struct ipc_sem { |
| 1104 | int semmni; |
| 1105 | collected_number sets; |
| 1106 | collected_number semaphores; |
| 1107 | } ipc_sem = {0, 0, 0}; |
| 1108 | |
| 1109 | if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.semmni", mib_semmni, ipc_sem.semmni))) { |
| 1110 | collector_error("DISABLED: system.ipc_semaphores chart"); |
| 1111 | collector_error("DISABLED: system.ipc_semaphore_arrays chart"); |
| 1112 | collector_error("DISABLED: kern.ipc.sem module"); |
| 1113 | return 1; |
| 1114 | } else { |
| 1115 | static struct semid_kernel *ipc_sem_data = NULL; |
| 1116 | static int old_semmni = 0; |
| 1117 | static int mib_sema[3] = {0, 0, 0}; |
| 1118 | |
| 1119 | if (unlikely(ipc_sem.semmni != old_semmni)) { |
| 1120 | ipc_sem_data = reallocz(ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni); |
| 1121 | old_semmni = ipc_sem.semmni; |
| 1122 | } |
| 1123 | if (unlikely(GETSYSCTL_WSIZE("kern.ipc.sema", mib_sema, ipc_sem_data, sizeof(struct semid_kernel) * ipc_sem.semmni))) { |
| 1124 | collector_error("DISABLED: system.ipc_semaphores chart"); |
| 1125 | collector_error("DISABLED: system.ipc_semaphore_arrays chart"); |
| 1126 | collector_error("DISABLED: kern.ipc.sem module"); |
| 1127 | return 1; |
| 1128 | } else { |
| 1129 | int i; |
| 1130 | |
| 1131 | for (i = 0; i < ipc_sem.semmni; i++) { |
| 1132 | if (unlikely(ipc_sem_data[i].u.sem_perm.mode & SEM_ALLOC)) { |
| 1133 | ipc_sem.sets += 1; |
| 1134 | ipc_sem.semaphores += ipc_sem_data[i].u.sem_nsems; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | static RRDSET *st_semaphore_arrays = NULL; |
| 1139 | static RRDDIM *rd_semaphore_arrays = NULL; |
| 1140 | |
| 1141 | common_semaphore_ipc(ipc_sem.semaphores, 0.0, "kern.ipc.sem", update_every); |
| 1142 | |
| 1143 | if (unlikely(!st_semaphore_arrays)) { |
| 1144 | st_semaphore_arrays = rrdset_create_localhost( |
| 1145 | "system", |
| 1146 | "ipc_semaphore_arrays", |
| 1147 | NULL, |
| 1148 | "ipc semaphores", |
| 1149 | NULL, |
| 1150 | "IPC Semaphore Arrays", |
| 1151 | "arrays", |
| 1152 | "freebsd.plugin", |
| 1153 | "kern.ipc.sem", |
| 1154 | NETDATA_CHART_PRIO_SYSTEM_IPC_SEM_ARRAYS, |
| 1155 | update_every, |
| 1156 | RRDSET_TYPE_AREA |
| 1157 | ); |
| 1158 | |
| 1159 | rd_semaphore_arrays = rrddim_add(st_semaphore_arrays, "arrays", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1160 | } |
| 1161 | |
| 1162 | rrddim_set_by_pointer(st_semaphore_arrays, rd_semaphore_arrays, ipc_sem.sets); |
| 1163 | rrdset_done(st_semaphore_arrays); |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | return 0; |
| 1168 | } |
| 1169 | |
| 1170 | // kern.ipc.shm |
| 1171 | |
| 1172 | int do_kern_ipc_shm(int update_every, usec_t dt) { |
| 1173 | (void)dt; |
| 1174 | static int mib_shmmni[3] = {0, 0, 0}; |
| 1175 | struct ipc_shm { |
| 1176 | u_long shmmni; |
| 1177 | collected_number segs; |
| 1178 | collected_number segsize; |
| 1179 | } ipc_shm = {0, 0, 0}; |
| 1180 | |
| 1181 | if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.shmmni", mib_shmmni, ipc_shm.shmmni))) { |
| 1182 | collector_error("DISABLED: system.ipc_shared_mem_segs chart"); |
| 1183 | collector_error("DISABLED: system.ipc_shared_mem_size chart"); |
| 1184 | collector_error("DISABLED: kern.ipc.shmmodule"); |
| 1185 | return 1; |
| 1186 | } else { |
| 1187 | static struct shmid_kernel *ipc_shm_data = NULL; |
| 1188 | static u_long old_shmmni = 0; |
| 1189 | static int mib_shmsegs[3] = {0, 0, 0}; |
| 1190 | |
| 1191 | if (unlikely(ipc_shm.shmmni != old_shmmni)) { |
| 1192 | ipc_shm_data = reallocz(ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni); |
| 1193 | old_shmmni = ipc_shm.shmmni; |
| 1194 | } |
| 1195 | if (unlikely( |
| 1196 | GETSYSCTL_WSIZE("kern.ipc.shmsegs", mib_shmsegs, ipc_shm_data, sizeof(struct shmid_kernel) * ipc_shm.shmmni))) { |
| 1197 | collector_error("DISABLED: system.ipc_shared_mem_segs chart"); |
| 1198 | collector_error("DISABLED: system.ipc_shared_mem_size chart"); |
| 1199 | collector_error("DISABLED: kern.ipc.shmmodule"); |
| 1200 | return 1; |
| 1201 | } else { |
| 1202 | unsigned long i; |
| 1203 | |
| 1204 | for (i = 0; i < ipc_shm.shmmni; i++) { |
| 1205 | if (unlikely(ipc_shm_data[i].u.shm_perm.mode & 0x0800)) { |
| 1206 | ipc_shm.segs += 1; |
| 1207 | ipc_shm.segsize += ipc_shm_data[i].u.shm_segsz; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | static RRDSET *st_segs = NULL, *st_size = NULL; |
| 1212 | static RRDDIM *rd_segments = NULL, *rd_allocated = NULL; |
| 1213 | |
| 1214 | if (unlikely(!st_segs)) { |
| 1215 | st_segs = rrdset_create_localhost( |
| 1216 | "system", |
| 1217 | "ipc_shared_mem_segs", |
| 1218 | NULL, |
| 1219 | "ipc shared memory", |
| 1220 | NULL, |
| 1221 | "IPC Shared Memory Segments", |
| 1222 | "segments", |
| 1223 | "freebsd.plugin", |
| 1224 | "kern.ipc.shm", |
| 1225 | NETDATA_CHART_PRIO_SYSTEM_IPC_SHARED_MEM_SEGS, |
| 1226 | update_every, |
| 1227 | RRDSET_TYPE_AREA |
| 1228 | ); |
| 1229 | |
| 1230 | rd_segments = rrddim_add(st_segs, "segments", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1231 | } |
| 1232 | |
| 1233 | rrddim_set_by_pointer(st_segs, rd_segments, ipc_shm.segs); |
| 1234 | rrdset_done(st_segs); |
| 1235 | |
| 1236 | if (unlikely(!st_size)) { |
| 1237 | st_size = rrdset_create_localhost( |
| 1238 | "system", |
| 1239 | "ipc_shared_mem_size", |
| 1240 | NULL, |
| 1241 | "ipc shared memory", |
| 1242 | NULL, |
| 1243 | "IPC Shared Memory Segments Size", |
| 1244 | "KiB", |
| 1245 | "freebsd.plugin", |
| 1246 | "kern.ipc.shm", |
| 1247 | NETDATA_CHART_PRIO_SYSTEM_IPC_SHARED_MEM_SIZE, |
| 1248 | update_every, |
| 1249 | RRDSET_TYPE_AREA |
| 1250 | ); |
| 1251 | |
| 1252 | rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, KILO_FACTOR, RRD_ALGORITHM_ABSOLUTE); |
| 1253 | } |
| 1254 | |
| 1255 | rrddim_set_by_pointer(st_size, rd_allocated, ipc_shm.segsize); |
| 1256 | rrdset_done(st_size); |
| 1257 | } |
| 1258 | } |
| 1259 | |
| 1260 | return 0; |
| 1261 | } |
| 1262 | |
| 1263 | // kern.ipc.msq |
| 1264 | |
| 1265 | int do_kern_ipc_msq(int update_every, usec_t dt) { |
| 1266 | (void)dt; |
| 1267 | static int mib_msgmni[3] = {0, 0, 0}; |
| 1268 | struct ipc_msq { |
| 1269 | int msgmni; |
| 1270 | collected_number queues; |
| 1271 | collected_number messages; |
| 1272 | collected_number usedsize; |
| 1273 | collected_number allocsize; |
| 1274 | } ipc_msq = {0, 0, 0, 0, 0}; |
| 1275 | |
| 1276 | if (unlikely(GETSYSCTL_SIMPLE("kern.ipc.msgmni", mib_msgmni, ipc_msq.msgmni))) { |
| 1277 | collector_error("DISABLED: system.ipc_msq_queues chart"); |
| 1278 | collector_error("DISABLED: system.ipc_msq_messages chart"); |
| 1279 | collector_error("DISABLED: system.ipc_msq_size chart"); |
| 1280 | collector_error("DISABLED: kern.ipc.msg module"); |
| 1281 | return 1; |
| 1282 | } else { |
| 1283 | static struct msqid_kernel *ipc_msq_data = NULL; |
| 1284 | static int old_msgmni = 0; |
| 1285 | static int mib_msqids[3] = {0, 0, 0}; |
| 1286 | |
| 1287 | if (unlikely(ipc_msq.msgmni != old_msgmni)) { |
| 1288 | ipc_msq_data = reallocz(ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni); |
| 1289 | old_msgmni = ipc_msq.msgmni; |
| 1290 | } |
| 1291 | if (unlikely( |
| 1292 | GETSYSCTL_WSIZE("kern.ipc.msqids", mib_msqids, ipc_msq_data, sizeof(struct msqid_kernel) * ipc_msq.msgmni))) { |
| 1293 | collector_error("DISABLED: system.ipc_msq_queues chart"); |
| 1294 | collector_error("DISABLED: system.ipc_msq_messages chart"); |
| 1295 | collector_error("DISABLED: system.ipc_msq_size chart"); |
| 1296 | collector_error("DISABLED: kern.ipc.msg module"); |
| 1297 | return 1; |
| 1298 | } else { |
| 1299 | int i; |
| 1300 | |
| 1301 | for (i = 0; i < ipc_msq.msgmni; i++) { |
| 1302 | if (unlikely(ipc_msq_data[i].u.msg_qbytes != 0)) { |
| 1303 | ipc_msq.queues += 1; |
| 1304 | ipc_msq.messages += ipc_msq_data[i].u.msg_qnum; |
| 1305 | ipc_msq.usedsize += ipc_msq_data[i].u.msg_cbytes; |
| 1306 | ipc_msq.allocsize += ipc_msq_data[i].u.msg_qbytes; |
| 1307 | } |
| 1308 | } |
| 1309 | |
| 1310 | static RRDSET *st_queues = NULL, *st_messages = NULL, *st_size = NULL; |
| 1311 | static RRDDIM *rd_queues = NULL, *rd_messages = NULL, *rd_allocated = NULL, *rd_used = NULL; |
| 1312 | |
| 1313 | if (unlikely(!st_queues)) { |
| 1314 | st_queues = rrdset_create_localhost( |
| 1315 | "system", |
| 1316 | "ipc_msq_queues", |
| 1317 | NULL, |
| 1318 | "ipc message queues", |
| 1319 | NULL, |
| 1320 | "Number of IPC Message Queues", |
| 1321 | "queues", |
| 1322 | "freebsd.plugin", |
| 1323 | "kern.ipc.msq", |
| 1324 | NETDATA_CHART_PRIO_SYSTEM_IPC_MSQ_QUEUES, |
| 1325 | update_every, |
| 1326 | RRDSET_TYPE_AREA |
| 1327 | ); |
| 1328 | |
| 1329 | rd_queues = rrddim_add(st_queues, "queues", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1330 | } |
| 1331 | |
| 1332 | rrddim_set_by_pointer(st_queues, rd_queues, ipc_msq.queues); |
| 1333 | rrdset_done(st_queues); |
| 1334 | |
| 1335 | if (unlikely(!st_messages)) { |
| 1336 | st_messages = rrdset_create_localhost( |
| 1337 | "system", |
| 1338 | "ipc_msq_messages", |
| 1339 | NULL, |
| 1340 | "ipc message queues", |
| 1341 | NULL, |
| 1342 | "Number of Messages in IPC Message Queues", |
| 1343 | "messages", |
| 1344 | "freebsd.plugin", |
| 1345 | "kern.ipc.msq", |
| 1346 | NETDATA_CHART_PRIO_SYSTEM_IPC_MSQ_MESSAGES, |
| 1347 | update_every, |
| 1348 | RRDSET_TYPE_AREA |
| 1349 | ); |
| 1350 | |
| 1351 | rd_messages = rrddim_add(st_messages, "messages", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1352 | } |
| 1353 | |
| 1354 | rrddim_set_by_pointer(st_messages, rd_messages, ipc_msq.messages); |
| 1355 | rrdset_done(st_messages); |
| 1356 | |
| 1357 | if (unlikely(!st_size)) { |
| 1358 | st_size = rrdset_create_localhost( |
| 1359 | "system", |
| 1360 | "ipc_msq_size", |
| 1361 | NULL, |
| 1362 | "ipc message queues", |
| 1363 | NULL, |
| 1364 | "Size of IPC Message Queues", |
| 1365 | "bytes", |
| 1366 | "freebsd.plugin", |
| 1367 | "kern.ipc.msq", |
| 1368 | NETDATA_CHART_PRIO_SYSTEM_IPC_MSQ_SIZE, |
| 1369 | update_every, |
| 1370 | RRDSET_TYPE_LINE |
| 1371 | ); |
| 1372 | |
| 1373 | rd_allocated = rrddim_add(st_size, "allocated", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1374 | rd_used = rrddim_add(st_size, "used", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1375 | } |
| 1376 | |
| 1377 | rrddim_set_by_pointer(st_size, rd_allocated, ipc_msq.allocsize); |
| 1378 | rrddim_set_by_pointer(st_size, rd_used, ipc_msq.usedsize); |
| 1379 | rrdset_done(st_size); |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | return 0; |
| 1384 | } |
| 1385 | |
| 1386 | // uptime |
| 1387 | |
| 1388 | int do_uptime(int update_every, usec_t dt) { |
| 1389 | (void)dt; |
| 1390 | struct timespec up_time; |
| 1391 | |
| 1392 | clock_gettime(CLOCK_UPTIME, &up_time); |
| 1393 | |
| 1394 | static RRDSET *st = NULL; |
| 1395 | static RRDDIM *rd = NULL; |
| 1396 | |
| 1397 | if(unlikely(!st)) { |
| 1398 | st = rrdset_create_localhost( |
| 1399 | "system", |
| 1400 | "uptime", |
| 1401 | NULL, |
| 1402 | "uptime", |
| 1403 | NULL, |
| 1404 | "System Uptime", |
| 1405 | "seconds", |
| 1406 | "freebsd.plugin", |
| 1407 | "uptime", |
| 1408 | NETDATA_CHART_PRIO_SYSTEM_UPTIME, |
| 1409 | update_every, |
| 1410 | RRDSET_TYPE_LINE |
| 1411 | ); |
| 1412 | |
| 1413 | rd = rrddim_add(st, "uptime", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1414 | } |
| 1415 | |
| 1416 | rrddim_set_by_pointer(st, rd, up_time.tv_sec); |
| 1417 | rrdset_done(st); |
| 1418 | return 0; |
| 1419 | } |
| 1420 | |
| 1421 | // net.isr |
| 1422 | |
| 1423 | int do_net_isr(int update_every, usec_t dt) { |
| 1424 | (void)dt; |
| 1425 | static int do_netisr = -1, do_netisr_per_core = -1; |
| 1426 | |
| 1427 | if (unlikely(do_netisr == -1)) { |
| 1428 | do_netisr = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.isr", "netisr", 1); |
| 1429 | do_netisr_per_core = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.isr", "netisr per core", 1); |
| 1430 | } |
| 1431 | |
| 1432 | static struct netisr_stats { |
| 1433 | collected_number dispatched; |
| 1434 | collected_number hybrid_dispatched; |
| 1435 | collected_number qdrops; |
| 1436 | collected_number queued; |
| 1437 | } *netisr_stats = NULL; |
| 1438 | |
| 1439 | if (likely(do_netisr || do_netisr_per_core)) { |
| 1440 | static int mib_workstream[3] = {0, 0, 0}, mib_work[3] = {0, 0, 0}; |
| 1441 | size_t netisr_workstream_size = 0, netisr_work_size = 0; |
| 1442 | static struct sysctl_netisr_workstream *netisr_workstream = NULL; |
| 1443 | static struct sysctl_netisr_work *netisr_work = NULL; |
| 1444 | unsigned long num_netisr_workstreams = 0, num_netisr_works = 0; |
| 1445 | int common_error = 0; |
| 1446 | |
| 1447 | if (unlikely(GETSYSCTL_SIZE("net.isr.workstream", mib_workstream, netisr_workstream_size))) { |
| 1448 | common_error = 1; |
| 1449 | } else if (unlikely(GETSYSCTL_SIZE("net.isr.work", mib_work, netisr_work_size))) { |
| 1450 | common_error = 1; |
| 1451 | } else { |
| 1452 | static size_t old_netisr_workstream_size = 0; |
| 1453 | |
| 1454 | num_netisr_workstreams = netisr_workstream_size / sizeof(struct sysctl_netisr_workstream); |
| 1455 | if (unlikely(netisr_workstream_size != old_netisr_workstream_size)) { |
| 1456 | netisr_workstream = reallocz(netisr_workstream, |
| 1457 | num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream)); |
| 1458 | old_netisr_workstream_size = netisr_workstream_size; |
| 1459 | } |
| 1460 | if (unlikely(GETSYSCTL_WSIZE("net.isr.workstream", mib_workstream, netisr_workstream, |
| 1461 | num_netisr_workstreams * sizeof(struct sysctl_netisr_workstream)))){ |
| 1462 | common_error = 1; |
| 1463 | } else { |
| 1464 | static size_t old_netisr_work_size = 0; |
| 1465 | |
| 1466 | num_netisr_works = netisr_work_size / sizeof(struct sysctl_netisr_work); |
| 1467 | if (unlikely(netisr_work_size != old_netisr_work_size)) { |
| 1468 | netisr_work = reallocz(netisr_work, num_netisr_works * sizeof(struct sysctl_netisr_work)); |
| 1469 | old_netisr_work_size = netisr_work_size; |
| 1470 | } |
| 1471 | if (unlikely(GETSYSCTL_WSIZE("net.isr.work", mib_work, netisr_work, |
| 1472 | num_netisr_works * sizeof(struct sysctl_netisr_work)))){ |
| 1473 | common_error = 1; |
| 1474 | } |
| 1475 | } |
| 1476 | } |
| 1477 | if (unlikely(common_error)) { |
| 1478 | do_netisr = 0; |
| 1479 | collector_error("DISABLED: system.softnet_stat chart"); |
| 1480 | do_netisr_per_core = 0; |
| 1481 | collector_error("DISABLED: system.cpuX_softnet_stat chart"); |
| 1482 | common_error = 0; |
| 1483 | collector_error("DISABLED: net.isr module"); |
| 1484 | return 1; |
| 1485 | } else { |
| 1486 | unsigned long i, n; |
| 1487 | int j; |
| 1488 | static int old_number_of_cpus = 0; |
| 1489 | |
| 1490 | if (unlikely(number_of_cpus != old_number_of_cpus)) { |
| 1491 | netisr_stats = reallocz(netisr_stats, (number_of_cpus + 1) * sizeof(struct netisr_stats)); |
| 1492 | old_number_of_cpus = number_of_cpus; |
| 1493 | } |
| 1494 | memset(netisr_stats, 0, (number_of_cpus + 1) * sizeof(struct netisr_stats)); |
| 1495 | for (i = 0; i < num_netisr_workstreams; i++) { |
| 1496 | for (n = 0; n < num_netisr_works; n++) { |
| 1497 | if (netisr_workstream[i].snws_wsid == netisr_work[n].snw_wsid) { |
| 1498 | netisr_stats[netisr_workstream[i].snws_cpu].dispatched += netisr_work[n].snw_dispatched; |
| 1499 | netisr_stats[netisr_workstream[i].snws_cpu].hybrid_dispatched += netisr_work[n].snw_hybrid_dispatched; |
| 1500 | netisr_stats[netisr_workstream[i].snws_cpu].qdrops += netisr_work[n].snw_qdrops; |
| 1501 | netisr_stats[netisr_workstream[i].snws_cpu].queued += netisr_work[n].snw_queued; |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | for (j = 0; j < number_of_cpus; j++) { |
| 1506 | netisr_stats[number_of_cpus].dispatched += netisr_stats[j].dispatched; |
| 1507 | netisr_stats[number_of_cpus].hybrid_dispatched += netisr_stats[j].hybrid_dispatched; |
| 1508 | netisr_stats[number_of_cpus].qdrops += netisr_stats[j].qdrops; |
| 1509 | netisr_stats[number_of_cpus].queued += netisr_stats[j].queued; |
| 1510 | } |
| 1511 | } |
| 1512 | } else { |
| 1513 | collector_error("DISABLED: net.isr module"); |
| 1514 | return 1; |
| 1515 | } |
| 1516 | |
| 1517 | if (likely(do_netisr)) { |
| 1518 | static RRDSET *st = NULL; |
| 1519 | static RRDDIM *rd_dispatched = NULL, *rd_hybrid_dispatched = NULL, *rd_qdrops = NULL, *rd_queued = NULL; |
| 1520 | |
| 1521 | if (unlikely(!st)) { |
| 1522 | st = rrdset_create_localhost( |
| 1523 | "system", |
| 1524 | "softnet_stat", |
| 1525 | NULL, |
| 1526 | "softnet_stat", |
| 1527 | NULL, |
| 1528 | "System softnet_stat", |
| 1529 | "events/s", |
| 1530 | "freebsd.plugin", |
| 1531 | "net.isr", |
| 1532 | NETDATA_CHART_PRIO_SYSTEM_SOFTNET_STAT, |
| 1533 | update_every, |
| 1534 | RRDSET_TYPE_LINE |
| 1535 | ); |
| 1536 | |
| 1537 | rd_dispatched = rrddim_add(st, "dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1538 | rd_hybrid_dispatched = rrddim_add(st, "hybrid_dispatched", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1539 | rd_qdrops = rrddim_add(st, "qdrops", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1540 | rd_queued = rrddim_add(st, "queued", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1541 | } |
| 1542 | |
| 1543 | rrddim_set_by_pointer(st, rd_dispatched, netisr_stats[number_of_cpus].dispatched); |
| 1544 | rrddim_set_by_pointer(st, rd_hybrid_dispatched, netisr_stats[number_of_cpus].hybrid_dispatched); |
| 1545 | rrddim_set_by_pointer(st, rd_qdrops, netisr_stats[number_of_cpus].qdrops); |
| 1546 | rrddim_set_by_pointer(st, rd_queued, netisr_stats[number_of_cpus].queued); |
| 1547 | rrdset_done(st); |
| 1548 | } |
| 1549 | |
| 1550 | if (likely(do_netisr_per_core)) { |
| 1551 | static struct softnet_chart { |
| 1552 | char netisr_cpuid[MAX_INT_DIGITS + 17]; |
| 1553 | RRDSET *st; |
| 1554 | RRDDIM *rd_dispatched; |
| 1555 | RRDDIM *rd_hybrid_dispatched; |
| 1556 | RRDDIM *rd_qdrops; |
| 1557 | RRDDIM *rd_queued; |
| 1558 | } *all_softnet_charts = NULL; |
| 1559 | static int old_number_of_cpus = 0; |
| 1560 | int i; |
| 1561 | |
| 1562 | if(unlikely(number_of_cpus > old_number_of_cpus)) { |
| 1563 | all_softnet_charts = reallocz(all_softnet_charts, sizeof(struct softnet_chart) * number_of_cpus); |
| 1564 | memset(&all_softnet_charts[old_number_of_cpus], 0, sizeof(struct softnet_chart) * (number_of_cpus - old_number_of_cpus)); |
| 1565 | old_number_of_cpus = number_of_cpus; |
| 1566 | } |
| 1567 | |
| 1568 | for (i = 0; i < number_of_cpus ;i++) { |
| 1569 | snprintfz(all_softnet_charts[i].netisr_cpuid, MAX_INT_DIGITS + 17, "cpu%d_softnet_stat", i); |
| 1570 | |
| 1571 | if (unlikely(!all_softnet_charts[i].st)) { |
| 1572 | all_softnet_charts[i].st = rrdset_create_localhost( |
| 1573 | "cpu", |
| 1574 | all_softnet_charts[i].netisr_cpuid, |
| 1575 | NULL, |
| 1576 | "softnet_stat", |
| 1577 | "cpu.softnet_stat", |
| 1578 | "Per CPU netisr statistics", |
| 1579 | "events/s", |
| 1580 | "freebsd.plugin", |
| 1581 | "net.isr", |
| 1582 | NETDATA_CHART_PRIO_SOFTNET_PER_CORE + i, |
| 1583 | update_every, |
| 1584 | RRDSET_TYPE_LINE |
| 1585 | ); |
| 1586 | |
| 1587 | all_softnet_charts[i].rd_dispatched = rrddim_add(all_softnet_charts[i].st, "dispatched", |
| 1588 | NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1589 | all_softnet_charts[i].rd_hybrid_dispatched = rrddim_add(all_softnet_charts[i].st, "hybrid_dispatched", |
| 1590 | NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1591 | all_softnet_charts[i].rd_qdrops = rrddim_add(all_softnet_charts[i].st, "qdrops", |
| 1592 | NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1593 | all_softnet_charts[i].rd_queued = rrddim_add(all_softnet_charts[i].st, "queued", |
| 1594 | NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1595 | } |
| 1596 | |
| 1597 | rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_dispatched, |
| 1598 | netisr_stats[i].dispatched); |
| 1599 | rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_hybrid_dispatched, |
| 1600 | netisr_stats[i].hybrid_dispatched); |
| 1601 | rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_qdrops, |
| 1602 | netisr_stats[i].qdrops); |
| 1603 | rrddim_set_by_pointer(all_softnet_charts[i].st, all_softnet_charts[i].rd_queued, |
| 1604 | netisr_stats[i].queued); |
| 1605 | rrdset_done(all_softnet_charts[i].st); |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
| 1612 | // net.inet.tcp.states |
| 1613 | |
| 1614 | int do_net_inet_tcp_states(int update_every, usec_t dt) { |
| 1615 | (void)dt; |
| 1616 | static int mib[4] = {0, 0, 0, 0}; |
| 1617 | uint64_t tcps_states[TCP_NSTATES]; |
| 1618 | |
| 1619 | // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html |
| 1620 | if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.states", mib, tcps_states))) { |
| 1621 | collector_error("DISABLED: ipv4.tcpsock chart"); |
| 1622 | collector_error("DISABLED: net.inet.tcp.states module"); |
| 1623 | return 1; |
| 1624 | } else { |
| 1625 | static RRDSET *st = NULL; |
| 1626 | static RRDDIM *rd = NULL; |
| 1627 | |
| 1628 | if (unlikely(!st)) { |
| 1629 | st = rrdset_create_localhost( |
| 1630 | "ipv4", |
| 1631 | "tcpsock", |
| 1632 | NULL, |
| 1633 | "tcp", |
| 1634 | NULL, |
| 1635 | "IPv4 TCP Connections", |
| 1636 | "active connections", |
| 1637 | "freebsd.plugin", |
| 1638 | "net.inet.tcp.states", |
| 1639 | 2500, |
| 1640 | update_every, |
| 1641 | RRDSET_TYPE_LINE |
| 1642 | ); |
| 1643 | |
| 1644 | rd = rrddim_add(st, "CurrEstab", "connections", 1, 1, RRD_ALGORITHM_ABSOLUTE); |
| 1645 | } |
| 1646 | |
| 1647 | rrddim_set_by_pointer(st, rd, tcps_states[TCPS_ESTABLISHED]); |
| 1648 | rrdset_done(st); |
| 1649 | } |
| 1650 | |
| 1651 | return 0; |
| 1652 | } |
| 1653 | |
| 1654 | // net.inet.tcp.stats |
| 1655 | |
| 1656 | int do_net_inet_tcp_stats(int update_every, usec_t dt) { |
| 1657 | (void)dt; |
| 1658 | static int do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1, do_tcpext_connaborts = -1, do_tcpext_ofo = -1, |
| 1659 | do_tcpext_syncookies = -1, do_tcpext_listen = -1, do_ecn = -1; |
| 1660 | |
| 1661 | if (unlikely(do_tcp_packets == -1)) { |
| 1662 | do_tcp_packets = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP packets", 1); |
| 1663 | do_tcp_errors = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP errors", 1); |
| 1664 | do_tcp_handshake = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "ipv4 TCP handshake issues", 1); |
| 1665 | do_tcpext_connaborts = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "TCP connection aborts", |
| 1666 | CONFIG_BOOLEAN_AUTO); |
| 1667 | do_tcpext_ofo = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "TCP out-of-order queue", |
| 1668 | CONFIG_BOOLEAN_AUTO); |
| 1669 | do_tcpext_syncookies = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "TCP SYN cookies", |
| 1670 | CONFIG_BOOLEAN_AUTO); |
| 1671 | do_tcpext_listen = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "TCP listen issues", |
| 1672 | CONFIG_BOOLEAN_AUTO); |
| 1673 | do_ecn = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet.tcp.stats", "ECN packets", |
| 1674 | CONFIG_BOOLEAN_AUTO); |
| 1675 | } |
| 1676 | |
| 1677 | // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html |
| 1678 | if (likely(do_tcp_packets || do_tcp_errors || do_tcp_handshake || do_tcpext_connaborts || do_tcpext_ofo || |
| 1679 | do_tcpext_syncookies || do_tcpext_listen || do_ecn)) { |
| 1680 | static int mib[4] = {0, 0, 0, 0}; |
| 1681 | struct tcpstat tcpstat; |
| 1682 | |
| 1683 | if (unlikely(GETSYSCTL_SIMPLE("net.inet.tcp.stats", mib, tcpstat))) { |
| 1684 | do_tcp_packets = 0; |
| 1685 | collector_error("DISABLED: ipv4.tcppackets chart"); |
| 1686 | do_tcp_errors = 0; |
| 1687 | collector_error("DISABLED: ipv4.tcperrors chart"); |
| 1688 | do_tcp_handshake = 0; |
| 1689 | collector_error("DISABLED: ipv4.tcphandshake chart"); |
| 1690 | do_tcpext_connaborts = 0; |
| 1691 | collector_error("DISABLED: ipv4.tcpconnaborts chart"); |
| 1692 | do_tcpext_ofo = 0; |
| 1693 | collector_error("DISABLED: ipv4.tcpofo chart"); |
| 1694 | do_tcpext_syncookies = 0; |
| 1695 | collector_error("DISABLED: ipv4.tcpsyncookies chart"); |
| 1696 | do_tcpext_listen = 0; |
| 1697 | collector_error("DISABLED: ipv4.tcplistenissues chart"); |
| 1698 | do_ecn = 0; |
| 1699 | collector_error("DISABLED: ipv4.ecnpkts chart"); |
| 1700 | collector_error("DISABLED: net.inet.tcp.stats module"); |
| 1701 | return 1; |
| 1702 | } else { |
| 1703 | if (likely(do_tcp_packets)) { |
| 1704 | static RRDSET *st = NULL; |
| 1705 | static RRDDIM *rd_in_segs = NULL, *rd_out_segs = NULL; |
| 1706 | |
| 1707 | if (unlikely(!st)) { |
| 1708 | st = rrdset_create_localhost( |
| 1709 | "ipv4", |
| 1710 | "tcppackets", |
| 1711 | NULL, |
| 1712 | "tcp", |
| 1713 | NULL, |
| 1714 | "IPv4 TCP Packets", |
| 1715 | "packets/s", |
| 1716 | "freebsd.plugin", |
| 1717 | "net.inet.tcp.stats", |
| 1718 | 2600, |
| 1719 | update_every, |
| 1720 | RRDSET_TYPE_LINE |
| 1721 | ); |
| 1722 | |
| 1723 | rd_in_segs = rrddim_add(st, "InSegs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1724 | rd_out_segs = rrddim_add(st, "OutSegs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1725 | } |
| 1726 | |
| 1727 | rrddim_set_by_pointer(st, rd_in_segs, tcpstat.tcps_rcvtotal); |
| 1728 | rrddim_set_by_pointer(st, rd_out_segs, tcpstat.tcps_sndtotal); |
| 1729 | rrdset_done(st); |
| 1730 | } |
| 1731 | |
| 1732 | if (likely(do_tcp_errors)) { |
| 1733 | static RRDSET *st = NULL; |
| 1734 | static RRDDIM *rd_in_errs = NULL, *rd_in_csum_errs = NULL, *rd_retrans_segs = NULL; |
| 1735 | |
| 1736 | if (unlikely(!st)) { |
| 1737 | st = rrdset_create_localhost( |
| 1738 | "ipv4", |
| 1739 | "tcperrors", |
| 1740 | NULL, |
| 1741 | "tcp", |
| 1742 | NULL, |
| 1743 | "IPv4 TCP Errors", |
| 1744 | "packets/s", |
| 1745 | "freebsd.plugin", |
| 1746 | "net.inet.tcp.stats", |
| 1747 | 2700, |
| 1748 | update_every, |
| 1749 | RRDSET_TYPE_LINE |
| 1750 | ); |
| 1751 | |
| 1752 | rd_in_errs = rrddim_add(st, "InErrs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1753 | rd_in_csum_errs = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1754 | rd_retrans_segs = rrddim_add(st, "RetransSegs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1755 | } |
| 1756 | |
| 1757 | #if __FreeBSD__ >= 11 |
| 1758 | rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvreassfull + |
| 1759 | tcpstat.tcps_rcvshort); |
| 1760 | #else |
| 1761 | rrddim_set_by_pointer(st, rd_in_errs, tcpstat.tcps_rcvbadoff + tcpstat.tcps_rcvshort); |
| 1762 | #endif |
| 1763 | rrddim_set_by_pointer(st, rd_in_csum_errs, tcpstat.tcps_rcvbadsum); |
| 1764 | rrddim_set_by_pointer(st, rd_retrans_segs, tcpstat.tcps_sndrexmitpack); |
| 1765 | rrdset_done(st); |
| 1766 | } |
| 1767 | |
| 1768 | if (likely(do_tcp_handshake)) { |
| 1769 | static RRDSET *st = NULL; |
| 1770 | static RRDDIM *rd_estab_resets = NULL, *rd_active_opens = NULL, *rd_passive_opens = NULL, |
| 1771 | *rd_attempt_fails = NULL; |
| 1772 | |
| 1773 | if (unlikely(!st)) { |
| 1774 | st = rrdset_create_localhost( |
| 1775 | "ipv4", |
| 1776 | "tcphandshake", |
| 1777 | NULL, |
| 1778 | "tcp", |
| 1779 | NULL, |
| 1780 | "IPv4 TCP Handshake Issues", |
| 1781 | "events/s", |
| 1782 | "freebsd.plugin", |
| 1783 | "net.inet.tcp.stats", |
| 1784 | 2900, |
| 1785 | update_every, |
| 1786 | RRDSET_TYPE_LINE |
| 1787 | ); |
| 1788 | |
| 1789 | rd_estab_resets = rrddim_add(st, "EstabResets", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1790 | rd_active_opens = rrddim_add(st, "ActiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1791 | rd_passive_opens = rrddim_add(st, "PassiveOpens", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1792 | rd_attempt_fails = rrddim_add(st, "AttemptFails", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1793 | } |
| 1794 | |
| 1795 | rrddim_set_by_pointer(st, rd_estab_resets, tcpstat.tcps_drops); |
| 1796 | rrddim_set_by_pointer(st, rd_active_opens, tcpstat.tcps_connattempt); |
| 1797 | rrddim_set_by_pointer(st, rd_passive_opens, tcpstat.tcps_accepts); |
| 1798 | rrddim_set_by_pointer(st, rd_attempt_fails, tcpstat.tcps_conndrops); |
| 1799 | rrdset_done(st); |
| 1800 | } |
| 1801 | |
| 1802 | if (do_tcpext_connaborts == CONFIG_BOOLEAN_YES || do_tcpext_connaborts == CONFIG_BOOLEAN_AUTO) { |
| 1803 | do_tcpext_connaborts = CONFIG_BOOLEAN_YES; |
| 1804 | |
| 1805 | static RRDSET *st = NULL; |
| 1806 | static RRDDIM *rd_on_data = NULL, *rd_on_close = NULL, *rd_on_memory = NULL, |
| 1807 | *rd_on_timeout = NULL, *rd_on_linger = NULL; |
| 1808 | |
| 1809 | if (unlikely(!st)) { |
| 1810 | st = rrdset_create_localhost( |
| 1811 | "ipv4", |
| 1812 | "tcpconnaborts", |
| 1813 | NULL, |
| 1814 | "tcp", |
| 1815 | NULL, |
| 1816 | "TCP Connection Aborts", |
| 1817 | "connections/s", |
| 1818 | "freebsd.plugin", |
| 1819 | "net.inet.tcp.stats", |
| 1820 | 3010, |
| 1821 | update_every, |
| 1822 | RRDSET_TYPE_LINE |
| 1823 | ); |
| 1824 | |
| 1825 | rd_on_data = rrddim_add(st, "TCPAbortOnData", "baddata", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1826 | rd_on_close = rrddim_add(st, "TCPAbortOnClose", "userclosed", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1827 | rd_on_memory = rrddim_add(st, "TCPAbortOnMemory", "nomemory", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1828 | rd_on_timeout = rrddim_add(st, "TCPAbortOnTimeout", "timeout", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1829 | rd_on_linger = rrddim_add(st, "TCPAbortOnLinger", "linger", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1830 | } |
| 1831 | |
| 1832 | rrddim_set_by_pointer(st, rd_on_data, tcpstat.tcps_rcvpackafterwin); |
| 1833 | rrddim_set_by_pointer(st, rd_on_close, tcpstat.tcps_rcvafterclose); |
| 1834 | rrddim_set_by_pointer(st, rd_on_memory, tcpstat.tcps_rcvmemdrop); |
| 1835 | rrddim_set_by_pointer(st, rd_on_timeout, tcpstat.tcps_persistdrop); |
| 1836 | rrddim_set_by_pointer(st, rd_on_linger, tcpstat.tcps_finwait2_drops); |
| 1837 | rrdset_done(st); |
| 1838 | } |
| 1839 | |
| 1840 | if (do_tcpext_ofo == CONFIG_BOOLEAN_YES || do_tcpext_ofo == CONFIG_BOOLEAN_AUTO) { |
| 1841 | do_tcpext_ofo = CONFIG_BOOLEAN_YES; |
| 1842 | |
| 1843 | static RRDSET *st = NULL; |
| 1844 | static RRDDIM *rd_ofo_queue = NULL; |
| 1845 | |
| 1846 | if (unlikely(!st)) { |
| 1847 | st = rrdset_create_localhost( |
| 1848 | "ipv4", |
| 1849 | "tcpofo", |
| 1850 | NULL, |
| 1851 | "tcp", |
| 1852 | NULL, |
| 1853 | "TCP Out-Of-Order Queue", |
| 1854 | "packets/s", |
| 1855 | "freebsd.plugin", |
| 1856 | "net.inet.tcp.stats", |
| 1857 | 3050, |
| 1858 | update_every, |
| 1859 | RRDSET_TYPE_LINE |
| 1860 | ); |
| 1861 | |
| 1862 | rd_ofo_queue = rrddim_add(st, "TCPOFOQueue", "inqueue", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1863 | } |
| 1864 | |
| 1865 | rrddim_set_by_pointer(st, rd_ofo_queue, tcpstat.tcps_rcvoopack); |
| 1866 | rrdset_done(st); |
| 1867 | } |
| 1868 | |
| 1869 | if (do_tcpext_syncookies == CONFIG_BOOLEAN_YES || do_tcpext_syncookies == CONFIG_BOOLEAN_AUTO) { |
| 1870 | do_tcpext_syncookies = CONFIG_BOOLEAN_YES; |
| 1871 | |
| 1872 | static RRDSET *st = NULL; |
| 1873 | static RRDDIM *rd_recv = NULL, *rd_send = NULL, *rd_failed = NULL; |
| 1874 | |
| 1875 | if (unlikely(!st)) { |
| 1876 | st = rrdset_create_localhost( |
| 1877 | "ipv4", |
| 1878 | "tcpsyncookies", |
| 1879 | NULL, |
| 1880 | "tcp", |
| 1881 | NULL, |
| 1882 | "TCP SYN Cookies", |
| 1883 | "packets/s", |
| 1884 | "freebsd.plugin", |
| 1885 | "net.inet.tcp.stats", |
| 1886 | 3100, |
| 1887 | update_every, |
| 1888 | RRDSET_TYPE_LINE |
| 1889 | ); |
| 1890 | |
| 1891 | rd_recv = rrddim_add(st, "SyncookiesRecv", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1892 | rd_send = rrddim_add(st, "SyncookiesSent", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1893 | rd_failed = rrddim_add(st, "SyncookiesFailed", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1894 | } |
| 1895 | |
| 1896 | rrddim_set_by_pointer(st, rd_recv, tcpstat.tcps_sc_recvcookie); |
| 1897 | rrddim_set_by_pointer(st, rd_send, tcpstat.tcps_sc_sendcookie); |
| 1898 | rrddim_set_by_pointer(st, rd_failed, tcpstat.tcps_sc_zonefail); |
| 1899 | rrdset_done(st); |
| 1900 | } |
| 1901 | |
| 1902 | if (do_tcpext_listen == CONFIG_BOOLEAN_YES || do_tcpext_listen == CONFIG_BOOLEAN_AUTO) { |
| 1903 | do_tcpext_listen = CONFIG_BOOLEAN_YES; |
| 1904 | |
| 1905 | static RRDSET *st_listen = NULL; |
| 1906 | static RRDDIM *rd_overflows = NULL; |
| 1907 | |
| 1908 | if(unlikely(!st_listen)) { |
| 1909 | |
| 1910 | st_listen = rrdset_create_localhost( |
| 1911 | "ipv4", |
| 1912 | "tcplistenissues", |
| 1913 | NULL, |
| 1914 | "tcp", |
| 1915 | NULL, |
| 1916 | "TCP Listen Socket Issues", |
| 1917 | "packets/s", |
| 1918 | "freebsd.plugin", |
| 1919 | "net.inet.tcp.stats", |
| 1920 | 3015, |
| 1921 | update_every, |
| 1922 | RRDSET_TYPE_LINE |
| 1923 | ); |
| 1924 | |
| 1925 | rd_overflows = rrddim_add(st_listen, "ListenOverflows", "overflows", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1926 | } |
| 1927 | |
| 1928 | rrddim_set_by_pointer(st_listen, rd_overflows, tcpstat.tcps_listendrop); |
| 1929 | rrdset_done(st_listen); |
| 1930 | } |
| 1931 | |
| 1932 | if (do_ecn == CONFIG_BOOLEAN_YES || do_ecn == CONFIG_BOOLEAN_AUTO) { |
| 1933 | do_ecn = CONFIG_BOOLEAN_YES; |
| 1934 | |
| 1935 | static RRDSET *st = NULL; |
| 1936 | static RRDDIM *rd_rcvce = NULL, |
| 1937 | #if __FreeBSD_version < 1400074 |
| 1938 | *rd_ect0 = NULL, |
| 1939 | *rd_ect1 = NULL; |
| 1940 | #else |
| 1941 | *rd_rcvect0 = NULL, |
| 1942 | *rd_rcvect1 = NULL, |
| 1943 | *rd_sndect0 = NULL, |
| 1944 | *rd_sndect1 = NULL; |
| 1945 | #endif |
| 1946 | |
| 1947 | if (unlikely(!st)) { |
| 1948 | st = rrdset_create_localhost( |
| 1949 | "ipv4", |
| 1950 | "ecnpkts", |
| 1951 | NULL, |
| 1952 | "ecn", |
| 1953 | NULL, |
| 1954 | "IPv4 ECN Statistics", |
| 1955 | "packets/s", |
| 1956 | "freebsd.plugin", |
| 1957 | "net.inet.tcp.stats", |
| 1958 | 8700, |
| 1959 | update_every, |
| 1960 | RRDSET_TYPE_LINE |
| 1961 | ); |
| 1962 | |
| 1963 | rd_rcvce = rrddim_add(st, "InCEPkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1964 | #if __FreeBSD_version < 1400074 |
| 1965 | rd_ect0 = rrddim_add(st, "ECT0Pkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1966 | rd_ect1 = rrddim_add(st, "ECT1Pkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1967 | #else |
| 1968 | rd_rcvect0 = rrddim_add(st, "InECT0Pkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1969 | rd_rcvect1 = rrddim_add(st, "InECT1Pkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1970 | rd_sndect0 = rrddim_add(st, "OutECT0Pkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1971 | rd_sndect1 = rrddim_add(st, "OutECT1Pkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 1972 | #endif |
| 1973 | } |
| 1974 | |
| 1975 | |
| 1976 | #if __FreeBSD_version < 1400074 |
| 1977 | rrddim_set_by_pointer(st, rd_rcvce, tcpstat.tcps_ecn_ce); |
| 1978 | rrddim_set_by_pointer(st, rd_ect0, tcpstat.tcps_ecn_ect0); |
| 1979 | rrddim_set_by_pointer(st, rd_ect1, tcpstat.tcps_ecn_ect1); |
| 1980 | #else |
| 1981 | rrddim_set_by_pointer(st, rd_rcvce, tcpstat.tcps_ecn_rcvce); |
| 1982 | rrddim_set_by_pointer(st, rd_rcvect0, tcpstat.tcps_ecn_rcvect0); |
| 1983 | rrddim_set_by_pointer(st, rd_rcvect1, tcpstat.tcps_ecn_rcvect1); |
| 1984 | rrddim_set_by_pointer(st, rd_sndect0, tcpstat.tcps_ecn_sndect0); |
| 1985 | rrddim_set_by_pointer(st, rd_sndect1, tcpstat.tcps_ecn_sndect1); |
| 1986 | #endif |
| 1987 | rrdset_done(st); |
| 1988 | } |
| 1989 | } |
| 1990 | } else { |
| 1991 | collector_error("DISABLED: net.inet.tcp.stats module"); |
| 1992 | return 1; |
| 1993 | } |
| 1994 | |
| 1995 | return 0; |
| 1996 | } |
| 1997 | |
| 1998 | // net.inet.udp.stats |
| 1999 | |
| 2000 | int do_net_inet_udp_stats(int update_every, usec_t dt) { |
| 2001 | (void)dt; |
| 2002 | static int do_udp_packets = -1, do_udp_errors = -1; |
| 2003 | |
| 2004 | if (unlikely(do_udp_packets == -1)) { |
| 2005 | do_udp_packets = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.udp.stats", "ipv4 UDP packets", 1); |
| 2006 | do_udp_errors = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.udp.stats", "ipv4 UDP errors", 1); |
| 2007 | } |
| 2008 | |
| 2009 | // see http://net-snmp.sourceforge.net/docs/mibs/udp.html |
| 2010 | if (likely(do_udp_packets || do_udp_errors)) { |
| 2011 | static int mib[4] = {0, 0, 0, 0}; |
| 2012 | struct udpstat udpstat; |
| 2013 | |
| 2014 | if (unlikely(GETSYSCTL_SIMPLE("net.inet.udp.stats", mib, udpstat))) { |
| 2015 | do_udp_packets = 0; |
| 2016 | collector_error("DISABLED: ipv4.udppackets chart"); |
| 2017 | do_udp_errors = 0; |
| 2018 | collector_error("DISABLED: ipv4.udperrors chart"); |
| 2019 | collector_error("DISABLED: net.inet.udp.stats module"); |
| 2020 | return 1; |
| 2021 | } else { |
| 2022 | if (likely(do_udp_packets)) { |
| 2023 | static RRDSET *st = NULL; |
| 2024 | static RRDDIM *rd_in = NULL, *rd_out = NULL; |
| 2025 | |
| 2026 | if (unlikely(!st)) { |
| 2027 | st = rrdset_create_localhost( |
| 2028 | "ipv4", |
| 2029 | "udppackets", |
| 2030 | NULL, |
| 2031 | "udp", |
| 2032 | NULL, |
| 2033 | "IPv4 UDP Packets", |
| 2034 | "packets/s", |
| 2035 | "freebsd.plugin", |
| 2036 | "net.inet.udp.stats", |
| 2037 | 2601, |
| 2038 | update_every, |
| 2039 | RRDSET_TYPE_LINE |
| 2040 | ); |
| 2041 | |
| 2042 | rd_in = rrddim_add(st, "InDatagrams", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2043 | rd_out = rrddim_add(st, "OutDatagrams", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2044 | } |
| 2045 | |
| 2046 | rrddim_set_by_pointer(st, rd_in, udpstat.udps_ipackets); |
| 2047 | rrddim_set_by_pointer(st, rd_out, udpstat.udps_opackets); |
| 2048 | rrdset_done(st); |
| 2049 | } |
| 2050 | |
| 2051 | if (likely(do_udp_errors)) { |
| 2052 | static RRDSET *st = NULL; |
| 2053 | static RRDDIM *rd_in_errors = NULL, *rd_no_ports = NULL, *rd_recv_buf_errors = NULL, |
| 2054 | *rd_in_csum_errors = NULL, *rd_ignored_multi = NULL; |
| 2055 | |
| 2056 | if (unlikely(!st)) { |
| 2057 | st = rrdset_create_localhost( |
| 2058 | "ipv4", |
| 2059 | "udperrors", |
| 2060 | NULL, |
| 2061 | "udp", |
| 2062 | NULL, |
| 2063 | "IPv4 UDP Errors", |
| 2064 | "events/s", |
| 2065 | "freebsd.plugin", |
| 2066 | "net.inet.udp.stats", |
| 2067 | 2701, |
| 2068 | update_every, |
| 2069 | RRDSET_TYPE_LINE |
| 2070 | ); |
| 2071 | |
| 2072 | rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2073 | rd_no_ports = rrddim_add(st, "NoPorts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2074 | rd_recv_buf_errors = rrddim_add(st, "RcvbufErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2075 | rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2076 | rd_ignored_multi = rrddim_add(st, "IgnoredMulti", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2077 | } |
| 2078 | |
| 2079 | rrddim_set_by_pointer(st, rd_in_errors, udpstat.udps_hdrops + udpstat.udps_badlen); |
| 2080 | rrddim_set_by_pointer(st, rd_no_ports, udpstat.udps_noport); |
| 2081 | rrddim_set_by_pointer(st, rd_recv_buf_errors, udpstat.udps_fullsock); |
| 2082 | rrddim_set_by_pointer(st, rd_in_csum_errors, udpstat.udps_badsum + udpstat.udps_nosum); |
| 2083 | rrddim_set_by_pointer(st, rd_ignored_multi, udpstat.udps_filtermcast); |
| 2084 | rrdset_done(st); |
| 2085 | } |
| 2086 | } |
| 2087 | } else { |
| 2088 | collector_error("DISABLED: net.inet.udp.stats module"); |
| 2089 | return 1; |
| 2090 | } |
| 2091 | |
| 2092 | return 0; |
| 2093 | } |
| 2094 | |
| 2095 | // net.inet.icmp.stats |
| 2096 | |
| 2097 | int do_net_inet_icmp_stats(int update_every, usec_t dt) { |
| 2098 | (void)dt; |
| 2099 | static int do_icmp_packets = -1, do_icmp_errors = -1, do_icmpmsg = -1; |
| 2100 | |
| 2101 | if (unlikely(do_icmp_packets == -1)) { |
| 2102 | do_icmp_packets = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP packets", 1); |
| 2103 | do_icmp_errors = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP errors", 1); |
| 2104 | do_icmpmsg = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.icmp.stats", "ipv4 ICMP messages", 1); |
| 2105 | } |
| 2106 | |
| 2107 | if (likely(do_icmp_packets || do_icmp_errors || do_icmpmsg)) { |
| 2108 | static int mib[4] = {0, 0, 0, 0}; |
| 2109 | struct icmpstat icmpstat; |
| 2110 | struct icmp_total { |
| 2111 | u_long msgs_in; |
| 2112 | u_long msgs_out; |
| 2113 | } icmp_total = {0, 0}; |
| 2114 | |
| 2115 | if (unlikely(GETSYSCTL_SIMPLE("net.inet.icmp.stats", mib, icmpstat))) { |
| 2116 | do_icmp_packets = 0; |
| 2117 | collector_error("DISABLED: ipv4.icmp chart"); |
| 2118 | do_icmp_errors = 0; |
| 2119 | collector_error("DISABLED: ipv4.icmp_errors chart"); |
| 2120 | do_icmpmsg = 0; |
| 2121 | collector_error("DISABLED: ipv4.icmpmsg chart"); |
| 2122 | collector_error("DISABLED: net.inet.icmp.stats module"); |
| 2123 | return 1; |
| 2124 | } else { |
| 2125 | int i; |
| 2126 | |
| 2127 | for (i = 0; i <= ICMP_MAXTYPE; i++) { |
| 2128 | icmp_total.msgs_in += icmpstat.icps_inhist[i]; |
| 2129 | icmp_total.msgs_out += icmpstat.icps_outhist[i]; |
| 2130 | } |
| 2131 | icmp_total.msgs_in += icmpstat.icps_badcode + icmpstat.icps_badlen + icmpstat.icps_checksum + icmpstat.icps_tooshort; |
| 2132 | |
| 2133 | if (likely(do_icmp_packets)) { |
| 2134 | static RRDSET *st = NULL; |
| 2135 | static RRDDIM *rd_in = NULL, *rd_out = NULL; |
| 2136 | |
| 2137 | if (unlikely(!st)) { |
| 2138 | st = rrdset_create_localhost( |
| 2139 | "ipv4" |
| 2140 | , "icmp" |
| 2141 | , NULL |
| 2142 | , "icmp" |
| 2143 | , NULL |
| 2144 | , "IPv4 ICMP Packets" |
| 2145 | , "packets/s" |
| 2146 | , "freebsd.plugin" |
| 2147 | , "net.inet.icmp.stats" |
| 2148 | , 2602 |
| 2149 | , update_every |
| 2150 | , RRDSET_TYPE_LINE |
| 2151 | ); |
| 2152 | |
| 2153 | rd_in = rrddim_add(st, "InMsgs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2154 | rd_out = rrddim_add(st, "OutMsgs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2155 | } |
| 2156 | |
| 2157 | rrddim_set_by_pointer(st, rd_in, icmp_total.msgs_in); |
| 2158 | rrddim_set_by_pointer(st, rd_out, icmp_total.msgs_out); |
| 2159 | rrdset_done(st); |
| 2160 | } |
| 2161 | |
| 2162 | if (likely(do_icmp_errors)) { |
| 2163 | static RRDSET *st = NULL; |
| 2164 | static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_csum = NULL; |
| 2165 | |
| 2166 | if (unlikely(!st)) { |
| 2167 | st = rrdset_create_localhost( |
| 2168 | "ipv4" |
| 2169 | , "icmp_errors" |
| 2170 | , NULL |
| 2171 | , "icmp" |
| 2172 | , NULL |
| 2173 | , "IPv4 ICMP Errors" |
| 2174 | , "packets/s" |
| 2175 | , "freebsd.plugin" |
| 2176 | , "net.inet.icmp.stats" |
| 2177 | , 2603 |
| 2178 | , update_every |
| 2179 | , RRDSET_TYPE_LINE |
| 2180 | ); |
| 2181 | |
| 2182 | rd_in = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2183 | rd_out = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2184 | rd_in_csum = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2185 | } |
| 2186 | |
| 2187 | rrddim_set_by_pointer(st, rd_in, icmpstat.icps_badcode + icmpstat.icps_badlen + |
| 2188 | icmpstat.icps_checksum + icmpstat.icps_tooshort); |
| 2189 | rrddim_set_by_pointer(st, rd_out, icmpstat.icps_error); |
| 2190 | rrddim_set_by_pointer(st, rd_in_csum, icmpstat.icps_checksum); |
| 2191 | |
| 2192 | rrdset_done(st); |
| 2193 | } |
| 2194 | |
| 2195 | if (likely(do_icmpmsg)) { |
| 2196 | static RRDSET *st = NULL; |
| 2197 | static RRDDIM *rd_in_reps = NULL, *rd_out_reps = NULL, *rd_in = NULL, *rd_out = NULL; |
| 2198 | |
| 2199 | if (unlikely(!st)) { |
| 2200 | st = rrdset_create_localhost( |
| 2201 | "ipv4" |
| 2202 | , "icmpmsg" |
| 2203 | , NULL |
| 2204 | , "icmp" |
| 2205 | , NULL |
| 2206 | , "IPv4 ICMP Messages" |
| 2207 | , "packets/s" |
| 2208 | , "freebsd.plugin" |
| 2209 | , "net.inet.icmp.stats" |
| 2210 | , 2604 |
| 2211 | , update_every |
| 2212 | , RRDSET_TYPE_LINE |
| 2213 | ); |
| 2214 | |
| 2215 | rd_in_reps = rrddim_add(st, "InEchoReps", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2216 | rd_out_reps = rrddim_add(st, "OutEchoReps", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2217 | rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2218 | rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2219 | } |
| 2220 | |
| 2221 | rrddim_set_by_pointer(st, rd_in_reps, icmpstat.icps_inhist[ICMP_ECHOREPLY]); |
| 2222 | rrddim_set_by_pointer(st, rd_out_reps, icmpstat.icps_outhist[ICMP_ECHOREPLY]); |
| 2223 | rrddim_set_by_pointer(st, rd_in, icmpstat.icps_inhist[ICMP_ECHO]); |
| 2224 | rrddim_set_by_pointer(st, rd_out, icmpstat.icps_outhist[ICMP_ECHO]); |
| 2225 | rrdset_done(st); |
| 2226 | } |
| 2227 | } |
| 2228 | } else { |
| 2229 | collector_error("DISABLED: net.inet.icmp.stats module"); |
| 2230 | return 1; |
| 2231 | } |
| 2232 | |
| 2233 | return 0; |
| 2234 | } |
| 2235 | |
| 2236 | // net.inet.ip.stats |
| 2237 | |
| 2238 | int do_net_inet_ip_stats(int update_every, usec_t dt) { |
| 2239 | (void)dt; |
| 2240 | static int do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1; |
| 2241 | |
| 2242 | if (unlikely(do_ip_packets == -1)) { |
| 2243 | do_ip_packets = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.ip.stats", "ipv4 packets", 1); |
| 2244 | do_ip_fragsout = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.ip.stats", "ipv4 fragments sent", 1); |
| 2245 | do_ip_fragsin = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.ip.stats", "ipv4 fragments assembly", 1); |
| 2246 | do_ip_errors = inicfg_get_boolean(&netdata_config, "plugin:freebsd:net.inet.ip.stats", "ipv4 errors", 1); |
| 2247 | } |
| 2248 | |
| 2249 | // see also http://net-snmp.sourceforge.net/docs/mibs/ip.html |
| 2250 | if (likely(do_ip_packets || do_ip_fragsout || do_ip_fragsin || do_ip_errors)) { |
| 2251 | static int mib[4] = {0, 0, 0, 0}; |
| 2252 | struct ipstat ipstat; |
| 2253 | |
| 2254 | if (unlikely(GETSYSCTL_SIMPLE("net.inet.ip.stats", mib, ipstat))) { |
| 2255 | do_ip_packets = 0; |
| 2256 | collector_error("DISABLED: ipv4.packets chart"); |
| 2257 | do_ip_fragsout = 0; |
| 2258 | collector_error("DISABLED: ipv4.fragsout chart"); |
| 2259 | do_ip_fragsin = 0; |
| 2260 | collector_error("DISABLED: ipv4.fragsin chart"); |
| 2261 | do_ip_errors = 0; |
| 2262 | collector_error("DISABLED: ipv4.errors chart"); |
| 2263 | collector_error("DISABLED: net.inet.ip.stats module"); |
| 2264 | return 1; |
| 2265 | } else { |
| 2266 | if (likely(do_ip_packets)) { |
| 2267 | static RRDSET *st = NULL; |
| 2268 | static RRDDIM *rd_in_receives = NULL, *rd_out_requests = NULL, *rd_forward_datagrams = NULL, |
| 2269 | *rd_in_delivers = NULL; |
| 2270 | |
| 2271 | if (unlikely(!st)) { |
| 2272 | st = rrdset_create_localhost( |
| 2273 | "ipv4", |
| 2274 | "packets", |
| 2275 | NULL, |
| 2276 | "packets", |
| 2277 | NULL, |
| 2278 | "IPv4 Packets", |
| 2279 | "packets/s", |
| 2280 | "freebsd.plugin", |
| 2281 | "net.inet.ip.stats", |
| 2282 | 3000, |
| 2283 | update_every, |
| 2284 | RRDSET_TYPE_LINE |
| 2285 | ); |
| 2286 | |
| 2287 | rd_in_receives = rrddim_add(st, "InReceives", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2288 | rd_out_requests = rrddim_add(st, "OutRequests", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2289 | rd_forward_datagrams = rrddim_add(st, "ForwDatagrams", "forwarded", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2290 | rd_in_delivers = rrddim_add(st, "InDelivers", "delivered", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2291 | } |
| 2292 | |
| 2293 | rrddim_set_by_pointer(st, rd_in_receives, ipstat.ips_total); |
| 2294 | rrddim_set_by_pointer(st, rd_out_requests, ipstat.ips_localout); |
| 2295 | rrddim_set_by_pointer(st, rd_forward_datagrams, ipstat.ips_forward); |
| 2296 | rrddim_set_by_pointer(st, rd_in_delivers, ipstat.ips_delivered); |
| 2297 | rrdset_done(st); |
| 2298 | } |
| 2299 | |
| 2300 | if (likely(do_ip_fragsout)) { |
| 2301 | static RRDSET *st = NULL; |
| 2302 | static RRDDIM *rd_ok = NULL, *rd_fails = NULL, *rd_created = NULL; |
| 2303 | |
| 2304 | if (unlikely(!st)) { |
| 2305 | st = rrdset_create_localhost( |
| 2306 | "ipv4", |
| 2307 | "fragsout", |
| 2308 | NULL, |
| 2309 | "fragments", |
| 2310 | NULL, |
| 2311 | "IPv4 Fragments Sent", |
| 2312 | "packets/s", |
| 2313 | "freebsd.plugin", |
| 2314 | "net.inet.ip.stats", |
| 2315 | 3010, |
| 2316 | update_every, |
| 2317 | RRDSET_TYPE_LINE |
| 2318 | ); |
| 2319 | |
| 2320 | rd_ok = rrddim_add(st, "FragOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2321 | rd_fails = rrddim_add(st, "FragFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2322 | rd_created = rrddim_add(st, "FragCreates", "created", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2323 | } |
| 2324 | |
| 2325 | rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragmented); |
| 2326 | rrddim_set_by_pointer(st, rd_fails, ipstat.ips_cantfrag); |
| 2327 | rrddim_set_by_pointer(st, rd_created, ipstat.ips_ofragments); |
| 2328 | rrdset_done(st); |
| 2329 | } |
| 2330 | |
| 2331 | if (likely(do_ip_fragsin)) { |
| 2332 | static RRDSET *st = NULL; |
| 2333 | static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL; |
| 2334 | |
| 2335 | if (unlikely(!st)) { |
| 2336 | st = rrdset_create_localhost( |
| 2337 | "ipv4", |
| 2338 | "fragsin", |
| 2339 | NULL, |
| 2340 | "fragments", |
| 2341 | NULL, |
| 2342 | "IPv4 Fragments Reassembly", |
| 2343 | "packets/s", |
| 2344 | "freebsd.plugin", |
| 2345 | "net.inet.ip.stats", |
| 2346 | 3011, |
| 2347 | update_every, |
| 2348 | RRDSET_TYPE_LINE |
| 2349 | ); |
| 2350 | |
| 2351 | rd_ok = rrddim_add(st, "ReasmOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2352 | rd_failed = rrddim_add(st, "ReasmFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2353 | rd_all = rrddim_add(st, "ReasmReqds", "all", 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2354 | } |
| 2355 | |
| 2356 | rrddim_set_by_pointer(st, rd_ok, ipstat.ips_fragments); |
| 2357 | rrddim_set_by_pointer(st, rd_failed, ipstat.ips_fragdropped); |
| 2358 | rrddim_set_by_pointer(st, rd_all, ipstat.ips_reassembled); |
| 2359 | rrdset_done(st); |
| 2360 | } |
| 2361 | |
| 2362 | if (likely(do_ip_errors)) { |
| 2363 | static RRDSET *st = NULL; |
| 2364 | static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL, |
| 2365 | *rd_in_hdr_errors = NULL, *rd_out_no_routes = NULL, |
| 2366 | *rd_in_addr_errors = NULL, *rd_in_unknown_protos = NULL; |
| 2367 | |
| 2368 | if (unlikely(!st)) { |
| 2369 | st = rrdset_create_localhost( |
| 2370 | "ipv4", |
| 2371 | "errors", |
| 2372 | NULL, |
| 2373 | "errors", |
| 2374 | NULL, |
| 2375 | "IPv4 Errors", |
| 2376 | "packets/s", |
| 2377 | "freebsd.plugin", |
| 2378 | "net.inet.ip.stats", |
| 2379 | 3002, |
| 2380 | update_every, |
| 2381 | RRDSET_TYPE_LINE |
| 2382 | ); |
| 2383 | |
| 2384 | rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2385 | rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2386 | rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2387 | rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2388 | rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2389 | rd_in_unknown_protos = rrddim_add(st, "InUnknownProtos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2390 | } |
| 2391 | |
| 2392 | rrddim_set_by_pointer(st, rd_in_discards, ipstat.ips_badsum + ipstat.ips_tooshort + |
| 2393 | ipstat.ips_toosmall + ipstat.ips_toolong); |
| 2394 | rrddim_set_by_pointer(st, rd_out_discards, ipstat.ips_odropped); |
| 2395 | rrddim_set_by_pointer(st, rd_in_hdr_errors, ipstat.ips_badhlen + ipstat.ips_badlen + |
| 2396 | ipstat.ips_badoptions + ipstat.ips_badvers); |
| 2397 | rrddim_set_by_pointer(st, rd_out_no_routes, ipstat.ips_noroute); |
| 2398 | rrddim_set_by_pointer(st, rd_in_addr_errors, ipstat.ips_badaddr); |
| 2399 | rrddim_set_by_pointer(st, rd_in_unknown_protos, ipstat.ips_noproto); |
| 2400 | rrdset_done(st); |
| 2401 | } |
| 2402 | } |
| 2403 | } else { |
| 2404 | collector_error("DISABLED: net.inet.ip.stats module"); |
| 2405 | return 1; |
| 2406 | } |
| 2407 | |
| 2408 | return 0; |
| 2409 | } |
| 2410 | |
| 2411 | // net.inet6.ip6.stats |
| 2412 | |
| 2413 | int do_net_inet6_ip6_stats(int update_every, usec_t dt) { |
| 2414 | (void)dt; |
| 2415 | static int do_ip6_packets = -1, do_ip6_fragsout = -1, do_ip6_fragsin = -1, do_ip6_errors = -1; |
| 2416 | |
| 2417 | if (unlikely(do_ip6_packets == -1)) { |
| 2418 | do_ip6_packets = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.ip6.stats", "ipv6 packets", |
| 2419 | CONFIG_BOOLEAN_AUTO); |
| 2420 | do_ip6_fragsout = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments sent", |
| 2421 | CONFIG_BOOLEAN_AUTO); |
| 2422 | do_ip6_fragsin = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.ip6.stats", "ipv6 fragments assembly", |
| 2423 | CONFIG_BOOLEAN_AUTO); |
| 2424 | do_ip6_errors = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.ip6.stats", "ipv6 errors", |
| 2425 | CONFIG_BOOLEAN_AUTO); |
| 2426 | } |
| 2427 | |
| 2428 | if (likely(do_ip6_packets || do_ip6_fragsout || do_ip6_fragsin || do_ip6_errors)) { |
| 2429 | static int mib[4] = {0, 0, 0, 0}; |
| 2430 | struct ip6stat ip6stat; |
| 2431 | |
| 2432 | if (unlikely(GETSYSCTL_SIMPLE("net.inet6.ip6.stats", mib, ip6stat))) { |
| 2433 | do_ip6_packets = 0; |
| 2434 | collector_error("DISABLED: ipv6.packets chart"); |
| 2435 | do_ip6_fragsout = 0; |
| 2436 | collector_error("DISABLED: ipv6.fragsout chart"); |
| 2437 | do_ip6_fragsin = 0; |
| 2438 | collector_error("DISABLED: ipv6.fragsin chart"); |
| 2439 | do_ip6_errors = 0; |
| 2440 | collector_error("DISABLED: ipv6.errors chart"); |
| 2441 | collector_error("DISABLED: net.inet6.ip6.stats module"); |
| 2442 | return 1; |
| 2443 | } else { |
| 2444 | if (do_ip6_packets == CONFIG_BOOLEAN_YES || do_ip6_packets == CONFIG_BOOLEAN_AUTO) { |
| 2445 | do_ip6_packets = CONFIG_BOOLEAN_YES; |
| 2446 | |
| 2447 | static RRDSET *st = NULL; |
| 2448 | static RRDDIM *rd_received = NULL, *rd_sent = NULL, *rd_forwarded = NULL, *rd_delivers = NULL; |
| 2449 | |
| 2450 | if (unlikely(!st)) { |
| 2451 | st = rrdset_create_localhost( |
| 2452 | "ipv6", |
| 2453 | "packets", |
| 2454 | NULL, |
| 2455 | "packets", |
| 2456 | NULL, |
| 2457 | "IPv6 Packets", |
| 2458 | "packets/s", |
| 2459 | "freebsd.plugin", |
| 2460 | "net.inet6.ip6.stats", |
| 2461 | 3000, |
| 2462 | update_every, |
| 2463 | RRDSET_TYPE_LINE |
| 2464 | ); |
| 2465 | |
| 2466 | rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2467 | rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2468 | rd_forwarded = rrddim_add(st, "forwarded", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2469 | rd_delivers = rrddim_add(st, "delivers", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2470 | } |
| 2471 | |
| 2472 | rrddim_set_by_pointer(st, rd_sent, ip6stat.ip6s_localout); |
| 2473 | rrddim_set_by_pointer(st, rd_received, ip6stat.ip6s_total); |
| 2474 | rrddim_set_by_pointer(st, rd_forwarded, ip6stat.ip6s_forward); |
| 2475 | rrddim_set_by_pointer(st, rd_delivers, ip6stat.ip6s_delivered); |
| 2476 | rrdset_done(st); |
| 2477 | } |
| 2478 | |
| 2479 | if (do_ip6_fragsout == CONFIG_BOOLEAN_YES || do_ip6_fragsout == CONFIG_BOOLEAN_AUTO) { |
| 2480 | do_ip6_fragsout = CONFIG_BOOLEAN_YES; |
| 2481 | |
| 2482 | static RRDSET *st = NULL; |
| 2483 | static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_all = NULL; |
| 2484 | |
| 2485 | if (unlikely(!st)) { |
| 2486 | st = rrdset_create_localhost( |
| 2487 | "ipv6", |
| 2488 | "fragsout", |
| 2489 | NULL, |
| 2490 | "fragments", |
| 2491 | NULL, |
| 2492 | "IPv6 Fragments Sent", |
| 2493 | "packets/s", |
| 2494 | "freebsd.plugin", |
| 2495 | "net.inet6.ip6.stats", |
| 2496 | 3010, |
| 2497 | update_every, |
| 2498 | RRDSET_TYPE_LINE |
| 2499 | ); |
| 2500 | |
| 2501 | rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2502 | rd_failed = rrddim_add(st, "failed", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2503 | rd_all = rrddim_add(st, "all", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2504 | } |
| 2505 | |
| 2506 | rrddim_set_by_pointer(st, rd_ok, ip6stat.ip6s_fragmented); |
| 2507 | rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_cantfrag); |
| 2508 | rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_ofragments); |
| 2509 | rrdset_done(st); |
| 2510 | } |
| 2511 | |
| 2512 | if (do_ip6_fragsin == CONFIG_BOOLEAN_YES || do_ip6_fragsin == CONFIG_BOOLEAN_AUTO) { |
| 2513 | do_ip6_fragsin = CONFIG_BOOLEAN_YES; |
| 2514 | |
| 2515 | static RRDSET *st = NULL; |
| 2516 | static RRDDIM *rd_ok = NULL, *rd_failed = NULL, *rd_timeout = NULL, *rd_all = NULL; |
| 2517 | |
| 2518 | if (unlikely(!st)) { |
| 2519 | st = rrdset_create_localhost( |
| 2520 | "ipv6", |
| 2521 | "fragsin", |
| 2522 | NULL, |
| 2523 | "fragments", |
| 2524 | NULL, |
| 2525 | "IPv6 Fragments Reassembly", |
| 2526 | "packets/s", |
| 2527 | "freebsd.plugin", |
| 2528 | "net.inet6.ip6.stats", |
| 2529 | 3011, |
| 2530 | update_every, |
| 2531 | RRDSET_TYPE_LINE |
| 2532 | ); |
| 2533 | |
| 2534 | rd_ok = rrddim_add(st, "ok", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2535 | rd_failed = rrddim_add(st, "failed", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2536 | rd_timeout = rrddim_add(st, "timeout", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2537 | rd_all = rrddim_add(st, "all", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2538 | } |
| 2539 | |
| 2540 | rrddim_set_by_pointer(st, rd_ok, ip6stat.ip6s_reassembled); |
| 2541 | rrddim_set_by_pointer(st, rd_failed, ip6stat.ip6s_fragdropped); |
| 2542 | rrddim_set_by_pointer(st, rd_timeout, ip6stat.ip6s_fragtimeout); |
| 2543 | rrddim_set_by_pointer(st, rd_all, ip6stat.ip6s_fragments); |
| 2544 | rrdset_done(st); |
| 2545 | } |
| 2546 | |
| 2547 | if (do_ip6_errors == CONFIG_BOOLEAN_YES || do_ip6_errors == CONFIG_BOOLEAN_AUTO) { |
| 2548 | do_ip6_errors = CONFIG_BOOLEAN_YES; |
| 2549 | |
| 2550 | static RRDSET *st = NULL; |
| 2551 | static RRDDIM *rd_in_discards = NULL, *rd_out_discards = NULL, |
| 2552 | *rd_in_hdr_errors = NULL, *rd_in_addr_errors = NULL, *rd_in_truncated_pkts = NULL, |
| 2553 | *rd_in_no_routes = NULL, *rd_out_no_routes = NULL; |
| 2554 | |
| 2555 | if (unlikely(!st)) { |
| 2556 | st = rrdset_create_localhost( |
| 2557 | "ipv6", |
| 2558 | "errors", |
| 2559 | NULL, |
| 2560 | "errors", |
| 2561 | NULL, |
| 2562 | "IPv6 Errors", |
| 2563 | "packets/s", |
| 2564 | "freebsd.plugin", |
| 2565 | "net.inet6.ip6.stats", |
| 2566 | 3002, |
| 2567 | update_every, |
| 2568 | RRDSET_TYPE_LINE |
| 2569 | ); |
| 2570 | |
| 2571 | rd_in_discards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2572 | rd_out_discards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2573 | rd_in_hdr_errors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2574 | rd_in_addr_errors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2575 | rd_in_truncated_pkts = rrddim_add(st, "InTruncatedPkts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2576 | rd_in_no_routes = rrddim_add(st, "InNoRoutes", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2577 | rd_out_no_routes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2578 | } |
| 2579 | |
| 2580 | rrddim_set_by_pointer(st, rd_in_discards, ip6stat.ip6s_toosmall); |
| 2581 | rrddim_set_by_pointer(st, rd_out_discards, ip6stat.ip6s_odropped); |
| 2582 | rrddim_set_by_pointer(st, rd_in_hdr_errors, ip6stat.ip6s_badoptions + ip6stat.ip6s_badvers + |
| 2583 | ip6stat.ip6s_exthdrtoolong); |
| 2584 | rrddim_set_by_pointer(st, rd_in_addr_errors, ip6stat.ip6s_sources_none); |
| 2585 | rrddim_set_by_pointer(st, rd_in_truncated_pkts, ip6stat.ip6s_tooshort); |
| 2586 | rrddim_set_by_pointer(st, rd_in_no_routes, ip6stat.ip6s_cantforward); |
| 2587 | rrddim_set_by_pointer(st, rd_out_no_routes, ip6stat.ip6s_noroute); |
| 2588 | rrdset_done(st); |
| 2589 | } |
| 2590 | } |
| 2591 | } else { |
| 2592 | collector_error("DISABLED: net.inet6.ip6.stats module"); |
| 2593 | return 1; |
| 2594 | } |
| 2595 | |
| 2596 | return 0; |
| 2597 | } |
| 2598 | |
| 2599 | // net.inet6.icmp6.stats |
| 2600 | |
| 2601 | int do_net_inet6_icmp6_stats(int update_every, usec_t dt) { |
| 2602 | (void)dt; |
| 2603 | static int do_icmp6 = -1, do_icmp6_redir = -1, do_icmp6_errors = -1, do_icmp6_echos = -1, do_icmp6_router = -1, |
| 2604 | do_icmp6_neighbor = -1, do_icmp6_types = -1; |
| 2605 | |
| 2606 | if (unlikely(do_icmp6 == -1)) { |
| 2607 | do_icmp6 = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.icmp6.stats", "icmp", |
| 2608 | CONFIG_BOOLEAN_AUTO); |
| 2609 | do_icmp6_redir = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.icmp6.stats", "icmp redirects", |
| 2610 | CONFIG_BOOLEAN_AUTO); |
| 2611 | do_icmp6_errors = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.icmp6.stats", "icmp errors", |
| 2612 | CONFIG_BOOLEAN_AUTO); |
| 2613 | do_icmp6_echos = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.icmp6.stats", "icmp echos", |
| 2614 | CONFIG_BOOLEAN_AUTO); |
| 2615 | do_icmp6_router = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.icmp6.stats", "icmp router", |
| 2616 | CONFIG_BOOLEAN_AUTO); |
| 2617 | do_icmp6_neighbor = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.icmp6.stats", "icmp neighbor", |
| 2618 | CONFIG_BOOLEAN_AUTO); |
| 2619 | do_icmp6_types = inicfg_get_boolean_ondemand(&netdata_config, "plugin:freebsd:net.inet6.icmp6.stats", "icmp types", |
| 2620 | CONFIG_BOOLEAN_AUTO); |
| 2621 | } |
| 2622 | |
| 2623 | if (likely(do_icmp6 || do_icmp6_redir || do_icmp6_errors || do_icmp6_echos || do_icmp6_router || do_icmp6_neighbor || do_icmp6_types)) { |
| 2624 | static int mib[4] = {0, 0, 0, 0}; |
| 2625 | struct icmp6stat icmp6stat; |
| 2626 | |
| 2627 | if (unlikely(GETSYSCTL_SIMPLE("net.inet6.icmp6.stats", mib, icmp6stat))) { |
| 2628 | do_icmp6 = 0; |
| 2629 | collector_error("DISABLED: ipv6.icmp chart"); |
| 2630 | do_icmp6_redir = 0; |
| 2631 | collector_error("DISABLED: ipv6.icmpredir chart"); |
| 2632 | do_icmp6_errors = 0; |
| 2633 | collector_error("DISABLED: ipv6.icmperrors chart"); |
| 2634 | do_icmp6_echos = 0; |
| 2635 | collector_error("DISABLED: ipv6.icmpechos chart"); |
| 2636 | do_icmp6_router = 0; |
| 2637 | collector_error("DISABLED: ipv6.icmprouter chart"); |
| 2638 | do_icmp6_neighbor = 0; |
| 2639 | collector_error("DISABLED: ipv6.icmpneighbor chart"); |
| 2640 | do_icmp6_types = 0; |
| 2641 | collector_error("DISABLED: ipv6.icmptypes chart"); |
| 2642 | collector_error("DISABLED: net.inet6.icmp6.stats module"); |
| 2643 | return 1; |
| 2644 | } else { |
| 2645 | int i; |
| 2646 | struct icmp6_total { |
| 2647 | u_long msgs_in; |
| 2648 | u_long msgs_out; |
| 2649 | } icmp6_total = {0, 0}; |
| 2650 | |
| 2651 | for (i = 0; i <= ICMP6_MAXTYPE; i++) { |
| 2652 | icmp6_total.msgs_in += icmp6stat.icp6s_inhist[i]; |
| 2653 | icmp6_total.msgs_out += icmp6stat.icp6s_outhist[i]; |
| 2654 | } |
| 2655 | icmp6_total.msgs_in += icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen + icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort; |
| 2656 | |
| 2657 | // -------------------------------------------------------------------- |
| 2658 | |
| 2659 | if (do_icmp6 == CONFIG_BOOLEAN_YES || do_icmp6 == CONFIG_BOOLEAN_AUTO) { |
| 2660 | do_icmp6 = CONFIG_BOOLEAN_YES; |
| 2661 | |
| 2662 | static RRDSET *st = NULL; |
| 2663 | static RRDDIM *rd_received = NULL, *rd_sent = NULL; |
| 2664 | |
| 2665 | if (unlikely(!st)) { |
| 2666 | st = rrdset_create_localhost( |
| 2667 | "ipv6", |
| 2668 | "icmp", |
| 2669 | NULL, |
| 2670 | "icmp", |
| 2671 | NULL, |
| 2672 | "IPv6 ICMP Messages", |
| 2673 | "messages/s", |
| 2674 | "freebsd.plugin", |
| 2675 | "net.inet6.icmp6.stats", |
| 2676 | 10000, |
| 2677 | update_every, |
| 2678 | RRDSET_TYPE_LINE |
| 2679 | ); |
| 2680 | |
| 2681 | rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2682 | rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2683 | } |
| 2684 | |
| 2685 | rrddim_set_by_pointer(st, rd_received, icmp6_total.msgs_out); |
| 2686 | rrddim_set_by_pointer(st, rd_sent, icmp6_total.msgs_in); |
| 2687 | rrdset_done(st); |
| 2688 | } |
| 2689 | |
| 2690 | if (do_icmp6_redir == CONFIG_BOOLEAN_YES || do_icmp6_redir == CONFIG_BOOLEAN_AUTO) { |
| 2691 | do_icmp6_redir = CONFIG_BOOLEAN_YES; |
| 2692 | |
| 2693 | static RRDSET *st = NULL; |
| 2694 | static RRDDIM *rd_received = NULL, *rd_sent = NULL; |
| 2695 | |
| 2696 | if (unlikely(!st)) { |
| 2697 | st = rrdset_create_localhost( |
| 2698 | "ipv6", |
| 2699 | "icmpredir", |
| 2700 | NULL, |
| 2701 | "icmp", |
| 2702 | NULL, |
| 2703 | "IPv6 ICMP Redirects", |
| 2704 | "redirects/s", |
| 2705 | "freebsd.plugin", |
| 2706 | "net.inet6.icmp6.stats", |
| 2707 | 10050, |
| 2708 | update_every, |
| 2709 | RRDSET_TYPE_LINE |
| 2710 | ); |
| 2711 | |
| 2712 | rd_received = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2713 | rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2714 | } |
| 2715 | |
| 2716 | rrddim_set_by_pointer(st, rd_received, icmp6stat.icp6s_outhist[ND_REDIRECT]); |
| 2717 | rrddim_set_by_pointer(st, rd_sent, icmp6stat.icp6s_inhist[ND_REDIRECT]); |
| 2718 | rrdset_done(st); |
| 2719 | } |
| 2720 | |
| 2721 | if (do_icmp6_errors == CONFIG_BOOLEAN_YES || do_icmp6_errors == CONFIG_BOOLEAN_AUTO) { |
| 2722 | do_icmp6_errors = CONFIG_BOOLEAN_YES; |
| 2723 | |
| 2724 | static RRDSET *st = NULL; |
| 2725 | static RRDDIM *rd_in_errors = NULL, *rd_out_errors = NULL, *rd_in_csum_errors = NULL, |
| 2726 | *rd_in_dest_unreachs = NULL, *rd_in_pkt_too_bigs = NULL, *rd_in_time_excds = NULL, |
| 2727 | *rd_in_parm_problems = NULL, *rd_out_dest_unreachs = NULL, *rd_out_time_excds = NULL, |
| 2728 | *rd_out_parm_problems = NULL; |
| 2729 | |
| 2730 | if (unlikely(!st)) { |
| 2731 | st = rrdset_create_localhost( |
| 2732 | "ipv6", |
| 2733 | "icmperrors", |
| 2734 | NULL, "icmp", |
| 2735 | NULL, |
| 2736 | "IPv6 ICMP Errors", |
| 2737 | "errors/s", |
| 2738 | "freebsd.plugin", |
| 2739 | "net.inet6.icmp6.stats", |
| 2740 | 10100, |
| 2741 | update_every, |
| 2742 | RRDSET_TYPE_LINE |
| 2743 | ); |
| 2744 | |
| 2745 | rd_in_errors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2746 | rd_out_errors = rrddim_add(st, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2747 | rd_in_csum_errors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2748 | rd_in_dest_unreachs = rrddim_add(st, "InDestUnreachs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2749 | rd_in_pkt_too_bigs = rrddim_add(st, "InPktTooBigs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2750 | rd_in_time_excds = rrddim_add(st, "InTimeExcds", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2751 | rd_in_parm_problems = rrddim_add(st, "InParmProblems", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2752 | rd_out_dest_unreachs = rrddim_add(st, "OutDestUnreachs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2753 | rd_out_time_excds = rrddim_add(st, "OutTimeExcds", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2754 | rd_out_parm_problems = rrddim_add(st, "OutParmProblems", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2755 | } |
| 2756 | |
| 2757 | rrddim_set_by_pointer(st, rd_in_errors, icmp6stat.icp6s_badcode + icmp6stat.icp6s_badlen + |
| 2758 | icmp6stat.icp6s_checksum + icmp6stat.icp6s_tooshort); |
| 2759 | rrddim_set_by_pointer(st, rd_out_errors, icmp6stat.icp6s_error); |
| 2760 | rrddim_set_by_pointer(st, rd_in_csum_errors, icmp6stat.icp6s_checksum); |
| 2761 | rrddim_set_by_pointer(st, rd_in_dest_unreachs, icmp6stat.icp6s_inhist[ICMP6_DST_UNREACH]); |
| 2762 | rrddim_set_by_pointer(st, rd_in_pkt_too_bigs, icmp6stat.icp6s_badlen); |
| 2763 | rrddim_set_by_pointer(st, rd_in_time_excds, icmp6stat.icp6s_inhist[ICMP6_TIME_EXCEEDED]); |
| 2764 | rrddim_set_by_pointer(st, rd_in_parm_problems, icmp6stat.icp6s_inhist[ICMP6_PARAM_PROB]); |
| 2765 | rrddim_set_by_pointer(st, rd_out_dest_unreachs, icmp6stat.icp6s_outhist[ICMP6_DST_UNREACH]); |
| 2766 | rrddim_set_by_pointer(st, rd_out_time_excds, icmp6stat.icp6s_outhist[ICMP6_TIME_EXCEEDED]); |
| 2767 | rrddim_set_by_pointer(st, rd_out_parm_problems, icmp6stat.icp6s_outhist[ICMP6_PARAM_PROB]); |
| 2768 | rrdset_done(st); |
| 2769 | } |
| 2770 | |
| 2771 | if (do_icmp6_echos == CONFIG_BOOLEAN_YES || do_icmp6_echos == CONFIG_BOOLEAN_AUTO) { |
| 2772 | do_icmp6_echos = CONFIG_BOOLEAN_YES; |
| 2773 | |
| 2774 | static RRDSET *st = NULL; |
| 2775 | static RRDDIM *rd_in = NULL, *rd_out = NULL, *rd_in_replies = NULL, *rd_out_replies = NULL; |
| 2776 | |
| 2777 | if (unlikely(!st)) { |
| 2778 | st = rrdset_create_localhost( |
| 2779 | "ipv6", |
| 2780 | "icmpechos", |
| 2781 | NULL, |
| 2782 | "icmp", |
| 2783 | NULL, |
| 2784 | "IPv6 ICMP Echo", |
| 2785 | "messages/s", |
| 2786 | "freebsd.plugin", |
| 2787 | "net.inet6.icmp6.stats", |
| 2788 | 10200, |
| 2789 | update_every, |
| 2790 | RRDSET_TYPE_LINE |
| 2791 | ); |
| 2792 | |
| 2793 | rd_in = rrddim_add(st, "InEchos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2794 | rd_out = rrddim_add(st, "OutEchos", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2795 | rd_in_replies = rrddim_add(st, "InEchoReplies", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2796 | rd_out_replies = rrddim_add(st, "OutEchoReplies", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2797 | } |
| 2798 | |
| 2799 | rrddim_set_by_pointer(st, rd_in, icmp6stat.icp6s_inhist[ICMP6_ECHO_REQUEST]); |
| 2800 | rrddim_set_by_pointer(st, rd_out, icmp6stat.icp6s_outhist[ICMP6_ECHO_REQUEST]); |
| 2801 | rrddim_set_by_pointer(st, rd_in_replies, icmp6stat.icp6s_inhist[ICMP6_ECHO_REPLY]); |
| 2802 | rrddim_set_by_pointer(st, rd_out_replies, icmp6stat.icp6s_outhist[ICMP6_ECHO_REPLY]); |
| 2803 | rrdset_done(st); |
| 2804 | } |
| 2805 | |
| 2806 | if (do_icmp6_router == CONFIG_BOOLEAN_YES || do_icmp6_router == CONFIG_BOOLEAN_AUTO) { |
| 2807 | do_icmp6_router = CONFIG_BOOLEAN_YES; |
| 2808 | |
| 2809 | static RRDSET *st = NULL; |
| 2810 | static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL, |
| 2811 | *rd_in_advertisements = NULL, *rd_out_advertisements = NULL; |
| 2812 | |
| 2813 | if (unlikely(!st)) { |
| 2814 | st = rrdset_create_localhost( |
| 2815 | "ipv6", |
| 2816 | "icmprouter", |
| 2817 | NULL, |
| 2818 | "icmp", |
| 2819 | NULL, |
| 2820 | "IPv6 Router Messages", |
| 2821 | "messages/s", |
| 2822 | "freebsd.plugin", |
| 2823 | "net.inet6.icmp6.stats", |
| 2824 | 10400, |
| 2825 | update_every, |
| 2826 | RRDSET_TYPE_LINE |
| 2827 | ); |
| 2828 | |
| 2829 | rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2830 | rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2831 | rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2832 | rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2833 | } |
| 2834 | |
| 2835 | rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_ROUTER_SOLICIT]); |
| 2836 | rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_ROUTER_SOLICIT]); |
| 2837 | rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_ROUTER_ADVERT]); |
| 2838 | rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_ROUTER_ADVERT]); |
| 2839 | rrdset_done(st); |
| 2840 | } |
| 2841 | |
| 2842 | if (do_icmp6_neighbor == CONFIG_BOOLEAN_YES || do_icmp6_neighbor == CONFIG_BOOLEAN_AUTO) { |
| 2843 | do_icmp6_neighbor = CONFIG_BOOLEAN_YES; |
| 2844 | |
| 2845 | static RRDSET *st = NULL; |
| 2846 | static RRDDIM *rd_in_solicits = NULL, *rd_out_solicits = NULL, |
| 2847 | *rd_in_advertisements = NULL, *rd_out_advertisements = NULL; |
| 2848 | |
| 2849 | if (unlikely(!st)) { |
| 2850 | st = rrdset_create_localhost( |
| 2851 | "ipv6", |
| 2852 | "icmpneighbor", |
| 2853 | NULL, |
| 2854 | "icmp", |
| 2855 | NULL, |
| 2856 | "IPv6 Neighbor Messages", |
| 2857 | "messages/s", |
| 2858 | "freebsd.plugin", |
| 2859 | "net.inet6.icmp6.stats", |
| 2860 | 10500, |
| 2861 | update_every, |
| 2862 | RRDSET_TYPE_LINE |
| 2863 | ); |
| 2864 | |
| 2865 | rd_in_solicits = rrddim_add(st, "InSolicits", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2866 | rd_out_solicits = rrddim_add(st, "OutSolicits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2867 | rd_in_advertisements = rrddim_add(st, "InAdvertisements", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2868 | rd_out_advertisements = rrddim_add(st, "OutAdvertisements", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2869 | } |
| 2870 | |
| 2871 | rrddim_set_by_pointer(st, rd_in_solicits, icmp6stat.icp6s_inhist[ND_NEIGHBOR_SOLICIT]); |
| 2872 | rrddim_set_by_pointer(st, rd_out_solicits, icmp6stat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]); |
| 2873 | rrddim_set_by_pointer(st, rd_in_advertisements, icmp6stat.icp6s_inhist[ND_NEIGHBOR_ADVERT]); |
| 2874 | rrddim_set_by_pointer(st, rd_out_advertisements, icmp6stat.icp6s_outhist[ND_NEIGHBOR_ADVERT]); |
| 2875 | rrdset_done(st); |
| 2876 | } |
| 2877 | |
| 2878 | if (do_icmp6_types == CONFIG_BOOLEAN_YES || do_icmp6_types == CONFIG_BOOLEAN_AUTO) { |
| 2879 | do_icmp6_types = CONFIG_BOOLEAN_YES; |
| 2880 | |
| 2881 | static RRDSET *st = NULL; |
| 2882 | static RRDDIM *rd_in_1 = NULL, *rd_in_128 = NULL, *rd_in_129 = NULL, *rd_in_136 = NULL, |
| 2883 | *rd_out_1 = NULL, *rd_out_128 = NULL, *rd_out_129 = NULL, *rd_out_133 = NULL, |
| 2884 | *rd_out_135 = NULL, *rd_out_143 = NULL; |
| 2885 | |
| 2886 | if (unlikely(!st)) { |
| 2887 | st = rrdset_create_localhost( |
| 2888 | "ipv6", |
| 2889 | "icmptypes", |
| 2890 | NULL, |
| 2891 | "icmp", |
| 2892 | NULL, |
| 2893 | "IPv6 ICMP Types", |
| 2894 | "messages/s", |
| 2895 | "freebsd.plugin", |
| 2896 | "net.inet6.icmp6.stats", |
| 2897 | 10700, |
| 2898 | update_every, |
| 2899 | RRDSET_TYPE_LINE |
| 2900 | ); |
| 2901 | |
| 2902 | rd_in_1 = rrddim_add(st, "InType1", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2903 | rd_in_128 = rrddim_add(st, "InType128", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2904 | rd_in_129 = rrddim_add(st, "InType129", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2905 | rd_in_136 = rrddim_add(st, "InType136", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2906 | rd_out_1 = rrddim_add(st, "OutType1", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2907 | rd_out_128 = rrddim_add(st, "OutType128", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2908 | rd_out_129 = rrddim_add(st, "OutType129", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2909 | rd_out_133 = rrddim_add(st, "OutType133", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2910 | rd_out_135 = rrddim_add(st, "OutType135", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2911 | rd_out_143 = rrddim_add(st, "OutType143", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 2912 | } |
| 2913 | |
| 2914 | rrddim_set_by_pointer(st, rd_in_1, icmp6stat.icp6s_inhist[1]); |
| 2915 | rrddim_set_by_pointer(st, rd_in_128, icmp6stat.icp6s_inhist[128]); |
| 2916 | rrddim_set_by_pointer(st, rd_in_129, icmp6stat.icp6s_inhist[129]); |
| 2917 | rrddim_set_by_pointer(st, rd_in_136, icmp6stat.icp6s_inhist[136]); |
| 2918 | rrddim_set_by_pointer(st, rd_out_1, icmp6stat.icp6s_outhist[1]); |
| 2919 | rrddim_set_by_pointer(st, rd_out_128, icmp6stat.icp6s_outhist[128]); |
| 2920 | rrddim_set_by_pointer(st, rd_out_129, icmp6stat.icp6s_outhist[129]); |
| 2921 | rrddim_set_by_pointer(st, rd_out_133, icmp6stat.icp6s_outhist[133]); |
| 2922 | rrddim_set_by_pointer(st, rd_out_135, icmp6stat.icp6s_outhist[135]); |
| 2923 | rrddim_set_by_pointer(st, rd_out_143, icmp6stat.icp6s_outhist[143]); |
| 2924 | rrdset_done(st); |
| 2925 | } |
| 2926 | } |
| 2927 | } else { |
| 2928 | collector_error("DISABLED: net.inet6.icmp6.stats module"); |
| 2929 | return 1; |
| 2930 | } |
| 2931 | |
| 2932 | return 0; |
| 2933 | } |