feat(proc/proc_net_dev): add dim per operstate to the "Interface Operational State" chart (#13167)
Ilya Mashchenko committed
Jun 17, 2022 at 12:51 UTC
1aab506fcb53ae42e2c37dfa11ba0192ad5292e9
2 files changed
+54
-16
collectors/proc.plugin/proc_net_dev.c
+53
-14
@@ -7,19 +7,33 @@
7
8
#define STATE_LENGTH_MAX 32
9
10
-// As defined in https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
11
-const char *operstate_names[] = { "unknown", "notpresent", "down", "lowerlayerdown", "testing", "dormant", "up" };
10
+enum {
11
+ NETDEV_OPERSTATE_UNKNOWN,
12
+ NETDEV_OPERSTATE_NOTPRESENT,
13
+ NETDEV_OPERSTATE_DOWN,
14
+ NETDEV_OPERSTATE_LOWERLAYERDOWN,
15
+ NETDEV_OPERSTATE_TESTING,
16
+ NETDEV_OPERSTATE_DORMANT,
17
+ NETDEV_OPERSTATE_UP
18
+};
19
20
static inline int get_operstate(char *operstate)
21
{
15
- int i;
16
-
17
- for (i = 0; i < (int) (sizeof(operstate_names) / sizeof(char *)); i++) {
18
- if (!strcmp(operstate, operstate_names[i])) {
19
- return i;
20
- }
21
- }
22
- return 0;
22
+ // As defined in https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
23
+ if (!strcmp(operstate, "up"))
24
+ return NETDEV_OPERSTATE_UP;
25
+ if (!strcmp(operstate, "down"))
26
+ return NETDEV_OPERSTATE_DOWN;
27
+ if (!strcmp(operstate, "notpresent"))
28
+ return NETDEV_OPERSTATE_NOTPRESENT;
29
+ if (!strcmp(operstate, "lowerlayerdown"))
30
+ return NETDEV_OPERSTATE_LOWERLAYERDOWN;
31
+ if (!strcmp(operstate, "testing"))
32
+ return NETDEV_OPERSTATE_TESTING;
33
+ if (!strcmp(operstate, "dormant"))
34
+ return NETDEV_OPERSTATE_DORMANT;
35
+
36
+ return NETDEV_OPERSTATE_UNKNOWN;
37
}
38
39
// ----------------------------------------------------------------------------
@@ -154,7 +168,13 @@ static struct netdev {
168
169
RRDDIM *rd_speed;
170
RRDDIM *rd_duplex;
157
- RRDDIM *rd_operstate;
171
+ RRDDIM *rd_operstate_unknown;
172
+ RRDDIM *rd_operstate_notpresent;
173
+ RRDDIM *rd_operstate_down;
174
+ RRDDIM *rd_operstate_lowerlayerdown;
175
+ RRDDIM *rd_operstate_testing;
176
+ RRDDIM *rd_operstate_dormant;
177
+ RRDDIM *rd_operstate_up;
178
RRDDIM *rd_carrier;
179
RRDDIM *rd_mtu;
180
@@ -220,10 +240,17 @@ static void netdev_charts_release(struct netdev *d) {
240
241
d->rd_speed = NULL;
242
d->rd_duplex = NULL;
223
- d->rd_operstate = NULL;
243
d->rd_carrier = NULL;
244
d->rd_mtu = NULL;
245
246
+ d->rd_operstate_unknown = NULL;
247
+ d->rd_operstate_notpresent = NULL;
248
+ d->rd_operstate_down = NULL;
249
+ d->rd_operstate_lowerlayerdown = NULL;
250
+ d->rd_operstate_testing = NULL;
251
+ d->rd_operstate_dormant = NULL;
252
+ d->rd_operstate_up = NULL;
253
+
254
d->chart_var_speed = NULL;
255
}
256
@@ -1015,11 +1042,23 @@ int do_proc_net_dev(int update_every, usec_t dt) {
1042
1043
rrdset_update_rrdlabels(d->st_operstate, d->chart_labels);
1044
1018
- d->rd_operstate = rrddim_add(d->st_operstate, "state", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1045
+ d->rd_operstate_up = rrddim_add(d->st_operstate, "up", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1046
+ d->rd_operstate_down = rrddim_add(d->st_operstate, "down", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1047
+ d->rd_operstate_notpresent = rrddim_add(d->st_operstate, "notpresent", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1048
+ d->rd_operstate_lowerlayerdown = rrddim_add(d->st_operstate, "lowerlayerdown", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1049
+ d->rd_operstate_testing = rrddim_add(d->st_operstate, "testing", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1050
+ d->rd_operstate_dormant = rrddim_add(d->st_operstate, "dormant", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1051
+ d->rd_operstate_unknown = rrddim_add(d->st_operstate, "unknown", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE);
1052
}
1053
else rrdset_next(d->st_operstate);
1054
1022
- rrddim_set_by_pointer(d->st_operstate, d->rd_operstate, (collected_number)d->operstate);
1055
+ rrddim_set_by_pointer(d->st_operstate, d->rd_operstate_up, (collected_number)(d->operstate == NETDEV_OPERSTATE_UP));
1056
+ rrddim_set_by_pointer(d->st_operstate, d->rd_operstate_down, (collected_number)(d->operstate == NETDEV_OPERSTATE_DOWN));
1057
+ rrddim_set_by_pointer(d->st_operstate, d->rd_operstate_notpresent, (collected_number)(d->operstate == NETDEV_OPERSTATE_NOTPRESENT));
1058
+ rrddim_set_by_pointer(d->st_operstate, d->rd_operstate_lowerlayerdown, (collected_number)(d->operstate == NETDEV_OPERSTATE_LOWERLAYERDOWN));
1059
+ rrddim_set_by_pointer(d->st_operstate, d->rd_operstate_testing, (collected_number)(d->operstate == NETDEV_OPERSTATE_TESTING));
1060
+ rrddim_set_by_pointer(d->st_operstate, d->rd_operstate_dormant, (collected_number)(d->operstate == NETDEV_OPERSTATE_DORMANT));
1061
+ rrddim_set_by_pointer(d->st_operstate, d->rd_operstate_unknown, (collected_number)(d->operstate == NETDEV_OPERSTATE_UNKNOWN));
1062
rrdset_done(d->st_operstate);
1063
}
1064
web/gui/dashboard_info.js
+1
-2
@@ -1133,8 +1133,7 @@ const netOperstateInfo = '<p>The current ' +
1133
'<b>LowerLayerDown</b> - the interface is down due to state of lower-layer interface(s). ' +
1134
'<b>Testing</b> - the interface is in testing mode, e.g. cable test. It can’t be used for normal traffic until tests complete. ' +
1135
'<b>Dormant</b> - the interface is L1 up, but waiting for an external event, e.g. for a protocol to establish. ' +
1136
- '<b>Up</b> - the interface is ready to pass packets and can be used.</p>' +
1137
- '<p><b>State map</b>: 0 - unknown, 1 - notpresent, 2 - down, 3 - lowerlayerdown, 4 - testing, 5 - dormant, 6 - up.</p>'
1136
+ '<b>Up</b> - the interface is ready to pass packets and can be used.</p>'
1137
const netCarrierInfo = '<p>The current physical link state of the interface.</p>' +
1138
'<p><b>State map</b>: 0 - down, 1 - up.</p>'
1139
const netSpeedInfo = 'The interface\'s latest or current speed that the network adapter ' +