freebsd_getifaddrs.c 29 KB

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