| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #include "plugin_freebsd.h" |
| 4 | |
| 5 | #include <ifaddrs.h> |
| 6 | |
| 7 | struct cgroup_network_interface { |
| 8 | char *name; |
| 9 | uint32_t hash; |
| 10 | size_t len; |
| 11 | |
| 12 | // flags |
| 13 | int configured; |
| 14 | int enabled; |
| 15 | int updated; |
| 16 | |
| 17 | int do_bandwidth; |
| 18 | int do_packets; |
| 19 | int do_errors; |
| 20 | int do_drops; |
| 21 | int do_events; |
| 22 | |
| 23 | // charts and dimensions |
| 24 | |
| 25 | RRDSET *st_bandwidth; |
| 26 | RRDDIM *rd_bandwidth_in; |
| 27 | RRDDIM *rd_bandwidth_out; |
| 28 | |
| 29 | RRDSET *st_packets; |
| 30 | RRDDIM *rd_packets_in; |
| 31 | RRDDIM *rd_packets_out; |
| 32 | RRDDIM *rd_packets_m_in; |
| 33 | RRDDIM *rd_packets_m_out; |
| 34 | |
| 35 | RRDSET *st_errors; |
| 36 | RRDDIM *rd_errors_in; |
| 37 | RRDDIM *rd_errors_out; |
| 38 | |
| 39 | RRDSET *st_drops; |
| 40 | RRDDIM *rd_drops_in; |
| 41 | RRDDIM *rd_drops_out; |
| 42 | |
| 43 | RRDSET *st_events; |
| 44 | RRDDIM *rd_events_coll; |
| 45 | |
| 46 | struct cgroup_network_interface *next; |
| 47 | }; |
| 48 | |
| 49 | static struct cgroup_network_interface *network_interfaces_root = NULL, *network_interfaces_last_used = NULL; |
| 50 | |
| 51 | static size_t network_interfaces_added = 0, network_interfaces_found = 0; |
| 52 | |
| 53 | static void network_interface_free(struct cgroup_network_interface *ifm) { |
| 54 | if (likely(ifm->st_bandwidth)) |
| 55 | rrdset_is_obsolete___safe_from_collector_thread(ifm->st_bandwidth); |
| 56 | if (likely(ifm->st_packets)) |
| 57 | rrdset_is_obsolete___safe_from_collector_thread(ifm->st_packets); |
| 58 | if (likely(ifm->st_errors)) |
| 59 | rrdset_is_obsolete___safe_from_collector_thread(ifm->st_errors); |
| 60 | if (likely(ifm->st_drops)) |
| 61 | rrdset_is_obsolete___safe_from_collector_thread(ifm->st_drops); |
| 62 | if (likely(ifm->st_events)) |
| 63 | rrdset_is_obsolete___safe_from_collector_thread(ifm->st_events); |
| 64 | |
| 65 | network_interfaces_added--; |
| 66 | freez(ifm->name); |
| 67 | freez(ifm); |
| 68 | } |
| 69 | |
| 70 | static void network_interfaces_cleanup() { |
| 71 | if (likely(network_interfaces_found == network_interfaces_added)) return; |
| 72 | |
| 73 | struct cgroup_network_interface *ifm = network_interfaces_root, *last = NULL; |
| 74 | while(ifm) { |
| 75 | if (unlikely(!ifm->updated)) { |
| 76 | // collector_info("Removing network interface '%s', linked after '%s'", ifm->name, last?last->name:"ROOT"); |
| 77 | |
| 78 | if (network_interfaces_last_used == ifm) |
| 79 | network_interfaces_last_used = last; |
| 80 | |
| 81 | struct cgroup_network_interface *t = ifm; |
| 82 | |
| 83 | if (ifm == network_interfaces_root || !last) |
| 84 | network_interfaces_root = ifm = ifm->next; |
| 85 | |
| 86 | else |
| 87 | last->next = ifm = ifm->next; |
| 88 | |
| 89 | t->next = NULL; |
| 90 | network_interface_free(t); |
| 91 | } |
| 92 | else { |
| 93 | last = ifm; |
| 94 | ifm->updated = 0; |
| 95 | ifm = ifm->next; |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | static struct cgroup_network_interface *get_network_interface(const char *name) { |
| 101 | struct cgroup_network_interface *ifm; |
| 102 | |
| 103 | uint32_t hash = simple_hash(name); |
| 104 | |
| 105 | // search it, from the last position to the end |
| 106 | for(ifm = network_interfaces_last_used ; ifm ; ifm = ifm->next) { |
| 107 | if (unlikely(hash == ifm->hash && !strcmp(name, ifm->name))) { |
| 108 | network_interfaces_last_used = ifm->next; |
| 109 | return ifm; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // search it from the beginning to the last position we used |
| 114 | for(ifm = network_interfaces_root ; ifm != network_interfaces_last_used ; ifm = ifm->next) { |
| 115 | if (unlikely(hash == ifm->hash && !strcmp(name, ifm->name))) { |
| 116 | network_interfaces_last_used = ifm->next; |
| 117 | return ifm; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // create a new one |
| 122 | ifm = callocz(1, sizeof(struct cgroup_network_interface)); |
| 123 | ifm->name = strdupz(name); |
| 124 | ifm->hash = simple_hash(ifm->name); |
| 125 | ifm->len = strlen(ifm->name); |
| 126 | network_interfaces_added++; |
| 127 | |
| 128 | // link it to the end |
| 129 | if (network_interfaces_root) { |
| 130 | struct cgroup_network_interface *e; |
| 131 | for(e = network_interfaces_root; e->next ; e = e->next) ; |
| 132 | e->next = ifm; |
| 133 | } |
| 134 | else |
| 135 | network_interfaces_root = ifm; |
| 136 | |
| 137 | return ifm; |
| 138 | } |
| 139 | |
| 140 | // -------------------------------------------------------------------------------------------------------------------- |
| 141 | // getifaddrs |
| 142 | |
| 143 | int do_getifaddrs(int update_every, usec_t dt) { |
| 144 | (void)dt; |
| 145 | |
| 146 | #define DEFAULT_EXCLUDED_INTERFACES "lo*" |
| 147 | #define DEFAULT_PHYSICAL_INTERFACES "igb* ix* cxl* em* ixl* ixlv* bge* ixgbe* vtnet* vmx* re* igc* dwc*" |
| 148 | #define CONFIG_SECTION_GETIFADDRS "plugin:freebsd:getifaddrs" |
| 149 | |
| 150 | static int enable_new_interfaces = -1; |
| 151 | static int do_bandwidth_ipv4 = -1, do_bandwidth_ipv6 = -1, do_bandwidth = -1, do_packets = -1, do_bandwidth_net = -1, do_packets_net = -1, |
| 152 | do_errors = -1, do_drops = -1, do_events = -1; |
| 153 | static SIMPLE_PATTERN *excluded_interfaces = NULL, *physical_interfaces = NULL; |
| 154 | |
| 155 | if (unlikely(enable_new_interfaces == -1)) { |
| 156 | enable_new_interfaces = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, |
| 157 | "enable new interfaces detected at runtime", |
| 158 | CONFIG_BOOLEAN_AUTO); |
| 159 | |
| 160 | do_bandwidth_net = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "total bandwidth for physical interfaces", |
| 161 | CONFIG_BOOLEAN_AUTO); |
| 162 | do_packets_net = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "total packets for physical interfaces", |
| 163 | CONFIG_BOOLEAN_AUTO); |
| 164 | do_bandwidth_ipv4 = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv4 interfaces", |
| 165 | CONFIG_BOOLEAN_AUTO); |
| 166 | do_bandwidth_ipv6 = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv6 interfaces", |
| 167 | CONFIG_BOOLEAN_AUTO); |
| 168 | do_bandwidth = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "bandwidth for all interfaces", |
| 169 | CONFIG_BOOLEAN_AUTO); |
| 170 | do_packets = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "packets for all interfaces", |
| 171 | CONFIG_BOOLEAN_AUTO); |
| 172 | do_errors = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "errors for all interfaces", |
| 173 | CONFIG_BOOLEAN_AUTO); |
| 174 | do_drops = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "drops for all interfaces", |
| 175 | CONFIG_BOOLEAN_AUTO); |
| 176 | do_events = inicfg_get_boolean_ondemand(&netdata_config, CONFIG_SECTION_GETIFADDRS, "collisions for all interfaces", |
| 177 | CONFIG_BOOLEAN_AUTO); |
| 178 | |
| 179 | excluded_interfaces = simple_pattern_create( |
| 180 | inicfg_get(&netdata_config, CONFIG_SECTION_GETIFADDRS, "disable by default interfaces matching", DEFAULT_EXCLUDED_INTERFACES), |
| 181 | NULL, |
| 182 | SIMPLE_PATTERN_EXACT, |
| 183 | true); |
| 184 | physical_interfaces = simple_pattern_create( |
| 185 | inicfg_get(&netdata_config, CONFIG_SECTION_GETIFADDRS, "set physical interfaces for system.net", DEFAULT_PHYSICAL_INTERFACES), |
| 186 | NULL, |
| 187 | SIMPLE_PATTERN_EXACT, |
| 188 | true); |
| 189 | } |
| 190 | |
| 191 | if (likely(do_bandwidth_ipv4 || do_bandwidth_ipv6 || do_bandwidth || do_packets || do_errors || do_bandwidth_net || do_packets_net || |
| 192 | do_drops || do_events)) { |
| 193 | struct ifaddrs *ifap; |
| 194 | |
| 195 | if (unlikely(getifaddrs(&ifap))) { |
| 196 | collector_error("FREEBSD: getifaddrs() failed"); |
| 197 | do_bandwidth_net = 0; |
| 198 | collector_error("DISABLED: system.net chart"); |
| 199 | do_packets_net = 0; |
| 200 | collector_error("DISABLED: system.packets chart"); |
| 201 | do_bandwidth_ipv4 = 0; |
| 202 | collector_error("DISABLED: system.ipv4 chart"); |
| 203 | do_bandwidth_ipv6 = 0; |
| 204 | collector_error("DISABLED: system.ipv6 chart"); |
| 205 | do_bandwidth = 0; |
| 206 | collector_error("DISABLED: net.* charts"); |
| 207 | do_packets = 0; |
| 208 | collector_error("DISABLED: net_packets.* charts"); |
| 209 | do_errors = 0; |
| 210 | collector_error("DISABLED: net_errors.* charts"); |
| 211 | do_drops = 0; |
| 212 | collector_error("DISABLED: net_drops.* charts"); |
| 213 | do_events = 0; |
| 214 | collector_error("DISABLED: net_events.* charts"); |
| 215 | collector_error("DISABLED: getifaddrs module"); |
| 216 | return 1; |
| 217 | } else { |
| 218 | #define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s) |
| 219 | struct ifaddrs *ifa; |
| 220 | struct iftot { |
| 221 | u_long ift_ibytes; |
| 222 | u_long ift_obytes; |
| 223 | u_long ift_ipackets; |
| 224 | u_long ift_opackets; |
| 225 | u_long ift_imcasts; |
| 226 | u_long ift_omcasts; |
| 227 | } iftot = {0, 0, 0, 0, 0, 0}; |
| 228 | |
| 229 | if (likely(do_bandwidth_net)) { |
| 230 | |
| 231 | iftot.ift_ibytes = iftot.ift_obytes = 0; |
| 232 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
| 233 | if (ifa->ifa_addr->sa_family != AF_LINK) |
| 234 | continue; |
| 235 | if (!simple_pattern_matches(physical_interfaces, ifa->ifa_name)) |
| 236 | continue; |
| 237 | iftot.ift_ibytes += IFA_DATA(ibytes); |
| 238 | iftot.ift_obytes += IFA_DATA(obytes); |
| 239 | } |
| 240 | |
| 241 | static RRDSET *st = NULL; |
| 242 | static RRDDIM *rd_in = NULL, *rd_out = NULL; |
| 243 | |
| 244 | if (unlikely(!st)) { |
| 245 | st = rrdset_create_localhost("system", |
| 246 | "net", |
| 247 | NULL, |
| 248 | "network", |
| 249 | NULL, |
| 250 | "Network Traffic", |
| 251 | "kilobits/s", |
| 252 | "freebsd.plugin", |
| 253 | "getifaddrs", |
| 254 | NETDATA_CHART_PRIO_SYSTEM_NET, |
| 255 | update_every, |
| 256 | RRDSET_TYPE_AREA |
| 257 | ); |
| 258 | |
| 259 | rd_in = rrddim_add(st, "InOctets", "received", 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 260 | rd_out = rrddim_add(st, "OutOctets", "sent", -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 261 | } |
| 262 | |
| 263 | rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes); |
| 264 | rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes); |
| 265 | rrdset_done(st); |
| 266 | } |
| 267 | |
| 268 | if (likely(do_packets_net)) { |
| 269 | iftot.ift_ipackets = iftot.ift_opackets = iftot.ift_imcasts = iftot.ift_omcasts = 0; |
| 270 | |
| 271 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
| 272 | if (ifa->ifa_addr->sa_family != AF_LINK) |
| 273 | continue; |
| 274 | if (!simple_pattern_matches(physical_interfaces, ifa->ifa_name)) |
| 275 | continue; |
| 276 | iftot.ift_ipackets += IFA_DATA(ipackets); |
| 277 | iftot.ift_opackets += IFA_DATA(opackets); |
| 278 | iftot.ift_imcasts += IFA_DATA(imcasts); |
| 279 | iftot.ift_omcasts += IFA_DATA(omcasts); |
| 280 | } |
| 281 | |
| 282 | static RRDSET *st = NULL; |
| 283 | static RRDDIM *rd_packets_in = NULL, *rd_packets_out = NULL, *rd_packets_m_in = NULL, *rd_packets_m_out = NULL; |
| 284 | |
| 285 | if (unlikely(!st)) { |
| 286 | st = rrdset_create_localhost("system", |
| 287 | "packets", |
| 288 | NULL, |
| 289 | "network", |
| 290 | NULL, |
| 291 | "Network Packets", |
| 292 | "packets/s", |
| 293 | "freebsd.plugin", |
| 294 | "getifaddrs", |
| 295 | NETDATA_CHART_PRIO_SYSTEM_PACKETS, |
| 296 | update_every, |
| 297 | RRDSET_TYPE_LINE |
| 298 | ); |
| 299 | |
| 300 | rd_packets_in = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 301 | rd_packets_out = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 302 | rd_packets_m_in = rrddim_add(st, "multicast_received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 303 | rd_packets_m_out = rrddim_add(st, "multicast_sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 304 | } |
| 305 | |
| 306 | rrddim_set_by_pointer(st, rd_packets_in, iftot.ift_ipackets); |
| 307 | rrddim_set_by_pointer(st, rd_packets_out, iftot.ift_opackets); |
| 308 | rrddim_set_by_pointer(st, rd_packets_m_in, iftot.ift_imcasts); |
| 309 | rrddim_set_by_pointer(st, rd_packets_m_out, iftot.ift_omcasts); |
| 310 | rrdset_done(st); |
| 311 | } |
| 312 | |
| 313 | if (likely(do_bandwidth_ipv4)) { |
| 314 | iftot.ift_ibytes = iftot.ift_obytes = 0; |
| 315 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
| 316 | if (ifa->ifa_addr->sa_family != AF_INET) |
| 317 | continue; |
| 318 | iftot.ift_ibytes += IFA_DATA(ibytes); |
| 319 | iftot.ift_obytes += IFA_DATA(obytes); |
| 320 | } |
| 321 | |
| 322 | static RRDSET *st = NULL; |
| 323 | static RRDDIM *rd_in = NULL, *rd_out = NULL; |
| 324 | |
| 325 | if (unlikely(!st)) { |
| 326 | st = rrdset_create_localhost("system", |
| 327 | "ipv4", |
| 328 | NULL, |
| 329 | "network", |
| 330 | NULL, |
| 331 | "IPv4 Bandwidth", |
| 332 | "kilobits/s", |
| 333 | "freebsd.plugin", |
| 334 | "getifaddrs", |
| 335 | NETDATA_CHART_PRIO_SYSTEM_IPV4, |
| 336 | update_every, |
| 337 | RRDSET_TYPE_AREA |
| 338 | ); |
| 339 | |
| 340 | rd_in = rrddim_add(st, "InOctets", "received", 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 341 | rd_out = rrddim_add(st, "OutOctets", "sent", -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 342 | } |
| 343 | |
| 344 | rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes); |
| 345 | rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes); |
| 346 | rrdset_done(st); |
| 347 | } |
| 348 | |
| 349 | if (likely(do_bandwidth_ipv6)) { |
| 350 | iftot.ift_ibytes = iftot.ift_obytes = 0; |
| 351 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
| 352 | if (ifa->ifa_addr->sa_family != AF_INET6) |
| 353 | continue; |
| 354 | iftot.ift_ibytes += IFA_DATA(ibytes); |
| 355 | iftot.ift_obytes += IFA_DATA(obytes); |
| 356 | } |
| 357 | |
| 358 | static RRDSET *st = NULL; |
| 359 | static RRDDIM *rd_in = NULL, *rd_out = NULL; |
| 360 | |
| 361 | if (unlikely(!st)) { |
| 362 | st = rrdset_create_localhost("system", |
| 363 | "ipv6", |
| 364 | NULL, |
| 365 | "network", |
| 366 | NULL, |
| 367 | "IPv6 Bandwidth", |
| 368 | "kilobits/s", |
| 369 | "freebsd.plugin", |
| 370 | "getifaddrs", |
| 371 | NETDATA_CHART_PRIO_SYSTEM_IPV6, |
| 372 | update_every, |
| 373 | RRDSET_TYPE_AREA |
| 374 | ); |
| 375 | |
| 376 | rd_in = rrddim_add(st, "received", NULL, 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 377 | rd_out = rrddim_add(st, "sent", NULL, -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 378 | } |
| 379 | |
| 380 | rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes); |
| 381 | rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes); |
| 382 | rrdset_done(st); |
| 383 | } |
| 384 | |
| 385 | network_interfaces_found = 0; |
| 386 | |
| 387 | for (ifa = ifap; ifa; ifa = ifa->ifa_next) { |
| 388 | if (ifa->ifa_addr->sa_family != AF_LINK) |
| 389 | continue; |
| 390 | |
| 391 | struct cgroup_network_interface *ifm = get_network_interface(ifa->ifa_name); |
| 392 | ifm->updated = 1; |
| 393 | network_interfaces_found++; |
| 394 | |
| 395 | if (unlikely(!ifm->configured)) { |
| 396 | char var_name[4096 + 1]; |
| 397 | |
| 398 | // this is the first time we see this network interface |
| 399 | |
| 400 | // remember we configured it |
| 401 | ifm->configured = 1; |
| 402 | |
| 403 | ifm->enabled = enable_new_interfaces; |
| 404 | |
| 405 | if (likely(ifm->enabled)) |
| 406 | ifm->enabled = !simple_pattern_matches(excluded_interfaces, ifa->ifa_name); |
| 407 | |
| 408 | snprintfz(var_name, 4096, "%s:%s", CONFIG_SECTION_GETIFADDRS, ifa->ifa_name); |
| 409 | ifm->enabled = inicfg_get_boolean_ondemand(&netdata_config, var_name, "enabled", ifm->enabled); |
| 410 | |
| 411 | if (unlikely(ifm->enabled == CONFIG_BOOLEAN_NO)) |
| 412 | continue; |
| 413 | |
| 414 | ifm->do_bandwidth = inicfg_get_boolean_ondemand(&netdata_config, var_name, "bandwidth", do_bandwidth); |
| 415 | ifm->do_packets = inicfg_get_boolean_ondemand(&netdata_config, var_name, "packets", do_packets); |
| 416 | ifm->do_errors = inicfg_get_boolean_ondemand(&netdata_config, var_name, "errors", do_errors); |
| 417 | ifm->do_drops = inicfg_get_boolean_ondemand(&netdata_config, var_name, "drops", do_drops); |
| 418 | ifm->do_events = inicfg_get_boolean_ondemand(&netdata_config, var_name, "events", do_events); |
| 419 | } |
| 420 | |
| 421 | if (unlikely(!ifm->enabled)) |
| 422 | continue; |
| 423 | |
| 424 | if (ifm->do_bandwidth == CONFIG_BOOLEAN_YES || ifm->do_bandwidth == CONFIG_BOOLEAN_AUTO) { |
| 425 | if (unlikely(!ifm->st_bandwidth)) { |
| 426 | ifm->st_bandwidth = rrdset_create_localhost("net", |
| 427 | ifa->ifa_name, |
| 428 | NULL, |
| 429 | "traffik", |
| 430 | "net.net", |
| 431 | "Bandwidth", |
| 432 | "kilobits/s", |
| 433 | "freebsd.plugin", |
| 434 | "getifaddrs", |
| 435 | NETDATA_CHART_PRIO_FIRST_NET_IFACE, |
| 436 | update_every, |
| 437 | RRDSET_TYPE_AREA |
| 438 | ); |
| 439 | |
| 440 | ifm->rd_bandwidth_in = rrddim_add(ifm->st_bandwidth, "received", NULL, 8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 441 | ifm->rd_bandwidth_out = rrddim_add(ifm->st_bandwidth, "sent", NULL, -8, BITS_IN_A_KILOBIT, RRD_ALGORITHM_INCREMENTAL); |
| 442 | rrdlabels_add(ifm->st_bandwidth->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 443 | } |
| 444 | |
| 445 | rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_in, IFA_DATA(ibytes)); |
| 446 | rrddim_set_by_pointer(ifm->st_bandwidth, ifm->rd_bandwidth_out, IFA_DATA(obytes)); |
| 447 | rrdset_done(ifm->st_bandwidth); |
| 448 | } |
| 449 | |
| 450 | if (ifm->do_packets == CONFIG_BOOLEAN_YES || ifm->do_packets == CONFIG_BOOLEAN_AUTO) { |
| 451 | if (unlikely(!ifm->st_packets)) { |
| 452 | ifm->st_packets = rrdset_create_localhost("net_packets", |
| 453 | ifa->ifa_name, |
| 454 | NULL, |
| 455 | "packets", |
| 456 | "net.packets", |
| 457 | "Packets", |
| 458 | "packets/s", |
| 459 | "freebsd.plugin", |
| 460 | "getifaddrs", |
| 461 | NETDATA_CHART_PRIO_FIRST_NET_PACKETS, |
| 462 | update_every, |
| 463 | RRDSET_TYPE_LINE |
| 464 | ); |
| 465 | |
| 466 | ifm->rd_packets_in = rrddim_add(ifm->st_packets, "received", NULL, 1, 1, |
| 467 | RRD_ALGORITHM_INCREMENTAL); |
| 468 | ifm->rd_packets_out = rrddim_add(ifm->st_packets, "sent", NULL, -1, 1, |
| 469 | RRD_ALGORITHM_INCREMENTAL); |
| 470 | ifm->rd_packets_m_in = rrddim_add(ifm->st_packets, "multicast_received", NULL, 1, 1, |
| 471 | RRD_ALGORITHM_INCREMENTAL); |
| 472 | ifm->rd_packets_m_out = rrddim_add(ifm->st_packets, "multicast_sent", NULL, -1, 1, |
| 473 | RRD_ALGORITHM_INCREMENTAL); |
| 474 | rrdlabels_add(ifm->st_packets->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 475 | } |
| 476 | |
| 477 | rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_in, IFA_DATA(ipackets)); |
| 478 | rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_out, IFA_DATA(opackets)); |
| 479 | rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_in, IFA_DATA(imcasts)); |
| 480 | rrddim_set_by_pointer(ifm->st_packets, ifm->rd_packets_m_out, IFA_DATA(omcasts)); |
| 481 | rrdset_done(ifm->st_packets); |
| 482 | } |
| 483 | |
| 484 | if (ifm->do_errors == CONFIG_BOOLEAN_YES || ifm->do_errors == CONFIG_BOOLEAN_AUTO) { |
| 485 | if (unlikely(!ifm->st_errors)) { |
| 486 | ifm->st_errors = rrdset_create_localhost("net_errors", |
| 487 | ifa->ifa_name, |
| 488 | NULL, |
| 489 | "errors", |
| 490 | "net.errors", |
| 491 | "Interface Errors", |
| 492 | "errors/s", |
| 493 | "freebsd.plugin", |
| 494 | "getifaddrs", |
| 495 | NETDATA_CHART_PRIO_FIRST_NET_ERRORS, |
| 496 | update_every, |
| 497 | RRDSET_TYPE_LINE |
| 498 | ); |
| 499 | |
| 500 | ifm->rd_errors_in = rrddim_add(ifm->st_errors, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 501 | ifm->rd_errors_out = rrddim_add(ifm->st_errors, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 502 | rrdlabels_add(ifm->st_errors->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 503 | } |
| 504 | |
| 505 | rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_in, IFA_DATA(ierrors)); |
| 506 | rrddim_set_by_pointer(ifm->st_errors, ifm->rd_errors_out, IFA_DATA(oerrors)); |
| 507 | rrdset_done(ifm->st_errors); |
| 508 | } |
| 509 | |
| 510 | if (ifm->do_drops == CONFIG_BOOLEAN_YES || ifm->do_drops == CONFIG_BOOLEAN_AUTO) { |
| 511 | if (unlikely(!ifm->st_drops)) { |
| 512 | ifm->st_drops = rrdset_create_localhost("net_drops", |
| 513 | ifa->ifa_name, |
| 514 | NULL, |
| 515 | "drops", |
| 516 | "net.drops", |
| 517 | "Interface Drops", |
| 518 | "drops/s", |
| 519 | "freebsd.plugin", |
| 520 | "getifaddrs", |
| 521 | NETDATA_CHART_PRIO_FIRST_NET_DROPS, |
| 522 | update_every, |
| 523 | RRDSET_TYPE_LINE |
| 524 | ); |
| 525 | |
| 526 | ifm->rd_drops_in = rrddim_add(ifm->st_drops, "inbound", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 527 | #if __FreeBSD__ >= 11 |
| 528 | ifm->rd_drops_out = rrddim_add(ifm->st_drops, "outbound", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); |
| 529 | #endif |
| 530 | rrdlabels_add(ifm->st_drops->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 531 | } |
| 532 | |
| 533 | rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_in, IFA_DATA(iqdrops)); |
| 534 | #if __FreeBSD__ >= 11 |
| 535 | rrddim_set_by_pointer(ifm->st_drops, ifm->rd_drops_out, IFA_DATA(oqdrops)); |
| 536 | #endif |
| 537 | rrdset_done(ifm->st_drops); |
| 538 | } |
| 539 | |
| 540 | if (ifm->do_events == CONFIG_BOOLEAN_YES || ifm->do_events == CONFIG_BOOLEAN_AUTO) { |
| 541 | if (unlikely(!ifm->st_events)) { |
| 542 | ifm->st_events = rrdset_create_localhost("net_events", |
| 543 | ifa->ifa_name, |
| 544 | NULL, |
| 545 | "errors", |
| 546 | "net.events", |
| 547 | "Network Interface Events", |
| 548 | "events/s", |
| 549 | "freebsd.plugin", |
| 550 | "getifaddrs", |
| 551 | NETDATA_CHART_PRIO_FIRST_NET_EVENTS, |
| 552 | update_every, |
| 553 | RRDSET_TYPE_LINE |
| 554 | ); |
| 555 | |
| 556 | ifm->rd_events_coll = rrddim_add(ifm->st_events, "collisions", NULL, -1, 1, |
| 557 | RRD_ALGORITHM_INCREMENTAL); |
| 558 | rrdlabels_add(ifm->st_events->rrdlabels, "device", ifa->ifa_name, RRDLABEL_SRC_AUTO); |
| 559 | } |
| 560 | |
| 561 | rrddim_set_by_pointer(ifm->st_events, ifm->rd_events_coll, IFA_DATA(collisions)); |
| 562 | rrdset_done(ifm->st_events); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | freeifaddrs(ifap); |
| 567 | } |
| 568 | } else { |
| 569 | collector_error("DISABLED: getifaddrs module"); |
| 570 | return 1; |
| 571 | } |
| 572 | |
| 573 | network_interfaces_cleanup(); |
| 574 | |
| 575 | return 0; |
| 576 | } |