Add network interfaces charts to FreeBSD plugin
Vladimir Kobal committed
Dec 14, 2016 at 15:52 UTC
a627f7009e2b4bd3bd895731a42a413b56256bd8
1 file changed
+94
-3
src/freebsd_sysctl.c
+94
-3
@@ -23,6 +23,9 @@
23
// FreeBSD calculates load averages once every 5 seconds
24
#define MIN_LOADAVG_UPDATE_EVERY 5
25
26
+// NEEDED BY: do_bandwidth
27
+#define IFA_DATA(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
28
+
29
int do_freebsd_sysctl(int update_every, usec_t dt) {
30
(void)dt;
31
@@ -1074,12 +1077,12 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
1077
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
1078
if (ifa->ifa_addr->sa_family != AF_INET6)
1079
continue;
1077
- iftot.ift_ibytes += (((struct if_data *)ifa->ifa_data)->ifi_ibytes);
1078
- iftot.ift_obytes += (((struct if_data *)ifa->ifa_data)->ifi_obytes);
1080
+ iftot.ift_ibytes += IFA_DATA(ibytes);
1081
+ iftot.ift_obytes += IFA_DATA(obytes);
1082
}
1083
1084
st = rrdset_find("system.ipv6");
1082
- if(unlikely(!st)) {
1085
+ if (unlikely(!st)) {
1086
st = rrdset_create("system", "ipv6", NULL, "network", NULL, "IPv6 Bandwidth", "kilobits/s", 500, update_every, RRDSET_TYPE_AREA);
1087
1088
rrddim_add(st, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
@@ -1091,6 +1094,94 @@ int do_freebsd_sysctl(int update_every, usec_t dt) {
1094
rrddim_set(st, "received", iftot.ift_ibytes);
1095
rrdset_done(st);
1096
1097
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
1098
+ if (ifa->ifa_addr->sa_family != AF_LINK)
1099
+ continue;
1100
+
1101
+ // --------------------------------------------------------------------
1102
+
1103
+ st = rrdset_find_bytype("net", ifa->ifa_name);
1104
+ if (unlikely(!st)) {
1105
+ st = rrdset_create("net", ifa->ifa_name, NULL, ifa->ifa_name, "net.net", "Bandwidth", "kilobits/s", 7000, update_every, RRDSET_TYPE_AREA);
1106
+
1107
+ rrddim_add(st, "received", NULL, 8, 1024, RRDDIM_INCREMENTAL);
1108
+ rrddim_add(st, "sent", NULL, -8, 1024, RRDDIM_INCREMENTAL);
1109
+ }
1110
+ else rrdset_next(st);
1111
+
1112
+ rrddim_set(st, "received", IFA_DATA(ibytes));
1113
+ rrddim_set(st, "sent", IFA_DATA(obytes));
1114
+ rrdset_done(st);
1115
+
1116
+ // --------------------------------------------------------------------
1117
+
1118
+ st = rrdset_find_bytype("net_packets", ifa->ifa_name);
1119
+ if (unlikely(!st)) {
1120
+ st = rrdset_create("net_packets", ifa->ifa_name, NULL, ifa->ifa_name, "net.packets", "Packets", "packets/s", 7001, update_every, RRDSET_TYPE_LINE);
1121
+ st->isdetail = 1;
1122
+
1123
+ rrddim_add(st, "received", NULL, 1, 1, RRDDIM_INCREMENTAL);
1124
+ rrddim_add(st, "sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
1125
+ rrddim_add(st, "multicast_received", NULL, 1, 1, RRDDIM_INCREMENTAL);
1126
+ rrddim_add(st, "multicast_sent", NULL, -1, 1, RRDDIM_INCREMENTAL);
1127
+ }
1128
+ else rrdset_next(st);
1129
+
1130
+ rrddim_set(st, "received", IFA_DATA(ipackets));
1131
+ rrddim_set(st, "sent", IFA_DATA(opackets));
1132
+ rrddim_set(st, "multicast_received", IFA_DATA(imcasts));
1133
+ rrddim_set(st, "multicast_sent", IFA_DATA(omcasts));
1134
+ rrdset_done(st);
1135
+
1136
+ // --------------------------------------------------------------------
1137
+
1138
+ st = rrdset_find_bytype("net_errors", ifa->ifa_name);
1139
+ if (unlikely(!st)) {
1140
+ st = rrdset_create("net_errors", ifa->ifa_name, NULL, ifa->ifa_name, "net.errors", "Interface Errors", "errors/s", 7002, update_every, RRDSET_TYPE_LINE);
1141
+ st->isdetail = 1;
1142
+
1143
+ rrddim_add(st, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
1144
+ rrddim_add(st, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
1145
+ }
1146
+ else rrdset_next(st);
1147
+
1148
+ rrddim_set(st, "inbound", IFA_DATA(ierrors));
1149
+ rrddim_set(st, "outbound", IFA_DATA(oerrors));
1150
+ rrdset_done(st);
1151
+
1152
+ // --------------------------------------------------------------------
1153
+
1154
+ st = rrdset_find_bytype("net_drops", ifa->ifa_name);
1155
+ if (unlikely(!st)) {
1156
+ st = rrdset_create("net_drops", ifa->ifa_name, NULL, ifa->ifa_name, "net.drops", "Interface Drops", "drops/s", 7003, update_every, RRDSET_TYPE_LINE);
1157
+ st->isdetail = 1;
1158
+
1159
+ rrddim_add(st, "inbound", NULL, 1, 1, RRDDIM_INCREMENTAL);
1160
+ rrddim_add(st, "outbound", NULL, -1, 1, RRDDIM_INCREMENTAL);
1161
+ }
1162
+ else rrdset_next(st);
1163
+
1164
+ rrddim_set(st, "inbound", IFA_DATA(iqdrops));
1165
+ rrddim_set(st, "outbound", IFA_DATA(oqdrops));
1166
+ rrdset_done(st);
1167
+
1168
+ // --------------------------------------------------------------------
1169
+
1170
+ st = rrdset_find_bytype("net_events", ifa->ifa_name);
1171
+ if (unlikely(!st)) {
1172
+ st = rrdset_create("net_events", ifa->ifa_name, NULL, ifa->ifa_name, "net.events", "Network Interface Events", "events/s", 7006, update_every, RRDSET_TYPE_LINE);
1173
+ st->isdetail = 1;
1174
+
1175
+ rrddim_add(st, "frames", NULL, 1, 1, RRDDIM_INCREMENTAL);
1176
+ rrddim_add(st, "collisions", NULL, -1, 1, RRDDIM_INCREMENTAL);
1177
+ rrddim_add(st, "carrier", NULL, -1, 1, RRDDIM_INCREMENTAL);
1178
+ }
1179
+ else rrdset_next(st);
1180
+
1181
+ rrddim_set(st, "collisions", IFA_DATA(collisions));
1182
+ rrdset_done(st);
1183
+ }
1184
+
1185
freeifaddrs(ifap);
1186
}
1187
}