1
-// SPDX-License-Identifier: GPL-3.0+
1
#include "common.h"
2
3
#include <ifaddrs.h>
141
int do_getifaddrs(int update_every, usec_t dt) {
142
(void)dt;
143
145
-#define DELAULT_EXLUDED_INTERFACES "lo*"
144
+#define DEFAULT_EXLUDED_INTERFACES "lo*"
145
+#define DEFAULT_PHYSICAL_INTERFACES "igb* ix* cxl* em* ixl* ixlv* bge* ixgbe*"
146
#define CONFIG_SECTION_GETIFADDRS "plugin:freebsd:getifaddrs"
147
148
static int enable_new_interfaces = -1;
149
- static int do_bandwidth_ipv4 = -1, do_bandwidth_ipv6 = -1, do_bandwidth = -1, do_packets = -1,
149
+ static int do_bandwidth_ipv4 = -1, do_bandwidth_ipv6 = -1, do_bandwidth = -1, do_packets = -1, do_bandwidth_net = -1, do_packets_net = -1,
150
do_errors = -1, do_drops = -1, do_events = -1;
151
- static SIMPLE_PATTERN *excluded_interfaces = NULL;
151
+ static SIMPLE_PATTERN *excluded_interfaces = NULL, *physical_interfaces = NULL;
152
153
if (unlikely(enable_new_interfaces == -1)) {
154
enable_new_interfaces = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS,
155
"enable new interfaces detected at runtime",
156
CONFIG_BOOLEAN_AUTO);
157
-
157
+
158
+ do_bandwidth_net = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for physical interfaces",
159
+ CONFIG_BOOLEAN_AUTO);
160
+ do_packets_net = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total packets for physical interfaces",
161
+ CONFIG_BOOLEAN_AUTO);
162
do_bandwidth_ipv4 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv4 interfaces",
163
CONFIG_BOOLEAN_AUTO);
164
do_bandwidth_ipv6 = config_get_boolean_ondemand(CONFIG_SECTION_GETIFADDRS, "total bandwidth for ipv6 interfaces",
175
CONFIG_BOOLEAN_AUTO);
176
177
excluded_interfaces = simple_pattern_create(
174
- config_get(CONFIG_SECTION_GETIFADDRS, "disable by default interfaces matching", DELAULT_EXLUDED_INTERFACES)
178
+ config_get(CONFIG_SECTION_GETIFADDRS, "disable by default interfaces matching", DEFAULT_EXLUDED_INTERFACES)
179
+ , NULL
180
+ , SIMPLE_PATTERN_EXACT
181
+ );
182
+ physical_interfaces = simple_pattern_create(
183
+ config_get(CONFIG_SECTION_GETIFADDRS, "set physical interfaces for system.net", DEFAULT_PHYSICAL_INTERFACES)
184
, NULL
185
, SIMPLE_PATTERN_EXACT
186
);
187
}
188
180
- if (likely(do_bandwidth_ipv4 || do_bandwidth_ipv6 || do_bandwidth || do_packets || do_errors ||
189
+ if (likely(do_bandwidth_ipv4 || do_bandwidth_ipv6 || do_bandwidth || do_packets || do_errors || do_bandwidth_net || do_packets_net ||
190
do_drops || do_events)) {
191
struct ifaddrs *ifap;
192
193
if (unlikely(getifaddrs(&ifap))) {
194
error("FREEBSD: getifaddrs() failed");
195
+ do_bandwidth_net = 0;
196
+ error("DISABLED: system.net chart");
197
+ do_packets_net = 0;
198
+ error("DISABLED: system.packets chart");
199
do_bandwidth_ipv4 = 0;
200
error("DISABLED: system.ipv4 chart");
201
do_bandwidth_ipv6 = 0;
218
struct iftot {
219
u_long ift_ibytes;
220
u_long ift_obytes;
208
- } iftot = {0, 0};
221
+ u_long ift_ipackets;
222
+ u_long ift_opackets;
223
+ u_long ift_imcasts;
224
+ u_long ift_omcasts;
225
+ } iftot = {0, 0, 0, 0, 0, 0};
226
+
227
+ // --------------------------------------------------------------------
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",
253
+ "getifaddrs",
254
+ 500,
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
+ } else
262
+ rrdset_next(st);
263
+
264
+ rrddim_set_by_pointer(st, rd_in, iftot.ift_ibytes);
265
+ rrddim_set_by_pointer(st, rd_out, iftot.ift_obytes);
266
+ rrdset_done(st);
267
+ }
268
+
269
+ // --------------------------------------------------------------------
270
+
271
+ if (likely(do_packets_net)) {
272
+
273
+ iftot.ift_ipackets = iftot.ift_opackets = iftot.ift_imcasts = iftot.ift_omcasts = 0;
274
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
275
+ if (ifa->ifa_addr->sa_family != AF_LINK)
276
+ continue;
277
+ if (!simple_pattern_matches(physical_interfaces, ifa->ifa_name))
278
+ continue;
279
+ iftot.ift_ipackets += IFA_DATA(ipackets);
280
+ iftot.ift_opackets += IFA_DATA(opackets);
281
+ iftot.ift_imcasts += IFA_DATA(imcasts);
282
+ iftot.ift_omcasts += IFA_DATA(omcasts);
283
+ }
284
+
285
+ static RRDSET *st = NULL;
286
+ static RRDDIM *rd_packets_in = NULL, *rd_packets_out = NULL, *rd_packets_m_in = NULL, *rd_packets_m_out = NULL;
287
+
288
+ if (unlikely(!st)) {
289
+ st = rrdset_create_localhost("system",
290
+ "packets",
291
+ NULL,
292
+ "network",
293
+ NULL,
294
+ "Network Packets",
295
+ "packets/s",
296
+ "freebsd",
297
+ "getifaddrs",
298
+ 7001,
299
+ update_every,
300
+ RRDSET_TYPE_LINE
301
+ );
302
+
303
+ rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
304
+
305
+ rd_packets_in = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
306
+ rd_packets_out = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
307
+ rd_packets_m_in = rrddim_add(st, "multicast_received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
308
+ rd_packets_m_out = rrddim_add(st, "multicast_sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
309
+ } else
310
+ rrdset_next(st);
311
+
312
+ rrddim_set_by_pointer(st, rd_packets_in, iftot.ift_ipackets);
313
+ rrddim_set_by_pointer(st, rd_packets_out, iftot.ift_opackets);
314
+ rrddim_set_by_pointer(st, rd_packets_m_in, iftot.ift_imcasts);
315
+ rrddim_set_by_pointer(st, rd_packets_m_out, iftot.ift_omcasts);
316
+ rrdset_done(st);
317
+ }
318
319
// --------------------------------------------------------------------
320