forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proc_net_sctp_snmp.c
352 lines (305 loc) · 15.9 KB
/
proc_net_sctp_snmp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
// SPDX-License-Identifier: GPL-3.0-or-later
#include "plugin_proc.h"
#define PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME "/proc/net/sctp/snmp"
int do_proc_net_sctp_snmp(int update_every, usec_t dt) {
(void)dt;
static procfile *ff = NULL;
static int
do_associations = -1,
do_transitions = -1,
do_packet_errors = -1,
do_packets = -1,
do_fragmentation = -1,
do_chunk_types = -1;
static ARL_BASE *arl_base = NULL;
static unsigned long long SctpCurrEstab = 0ULL;
static unsigned long long SctpActiveEstabs = 0ULL;
static unsigned long long SctpPassiveEstabs = 0ULL;
static unsigned long long SctpAborteds = 0ULL;
static unsigned long long SctpShutdowns = 0ULL;
static unsigned long long SctpOutOfBlues = 0ULL;
static unsigned long long SctpChecksumErrors = 0ULL;
static unsigned long long SctpOutCtrlChunks = 0ULL;
static unsigned long long SctpOutOrderChunks = 0ULL;
static unsigned long long SctpOutUnorderChunks = 0ULL;
static unsigned long long SctpInCtrlChunks = 0ULL;
static unsigned long long SctpInOrderChunks = 0ULL;
static unsigned long long SctpInUnorderChunks = 0ULL;
static unsigned long long SctpFragUsrMsgs = 0ULL;
static unsigned long long SctpReasmUsrMsgs = 0ULL;
static unsigned long long SctpOutSCTPPacks = 0ULL;
static unsigned long long SctpInSCTPPacks = 0ULL;
static unsigned long long SctpT1InitExpireds = 0ULL;
static unsigned long long SctpT1CookieExpireds = 0ULL;
static unsigned long long SctpT2ShutdownExpireds = 0ULL;
static unsigned long long SctpT3RtxExpireds = 0ULL;
static unsigned long long SctpT4RtoExpireds = 0ULL;
static unsigned long long SctpT5ShutdownGuardExpireds = 0ULL;
static unsigned long long SctpDelaySackExpireds = 0ULL;
static unsigned long long SctpAutocloseExpireds = 0ULL;
static unsigned long long SctpT3Retransmits = 0ULL;
static unsigned long long SctpPmtudRetransmits = 0ULL;
static unsigned long long SctpFastRetransmits = 0ULL;
static unsigned long long SctpInPktSoftirq = 0ULL;
static unsigned long long SctpInPktBacklog = 0ULL;
static unsigned long long SctpInPktDiscards = 0ULL;
static unsigned long long SctpInDataChunkDiscards = 0ULL;
if(unlikely(!arl_base)) {
do_associations = config_get_boolean_ondemand("plugin:proc:/proc/net/sctp/snmp", "established associations", CONFIG_BOOLEAN_AUTO);
do_transitions = config_get_boolean_ondemand("plugin:proc:/proc/net/sctp/snmp", "association transitions", CONFIG_BOOLEAN_AUTO);
do_fragmentation = config_get_boolean_ondemand("plugin:proc:/proc/net/sctp/snmp", "fragmentation", CONFIG_BOOLEAN_AUTO);
do_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/sctp/snmp", "packets", CONFIG_BOOLEAN_AUTO);
do_packet_errors = config_get_boolean_ondemand("plugin:proc:/proc/net/sctp/snmp", "packet errors", CONFIG_BOOLEAN_AUTO);
do_chunk_types = config_get_boolean_ondemand("plugin:proc:/proc/net/sctp/snmp", "chunk types", CONFIG_BOOLEAN_AUTO);
arl_base = arl_create("sctp", NULL, 60);
arl_expect(arl_base, "SctpCurrEstab", &SctpCurrEstab);
arl_expect(arl_base, "SctpActiveEstabs", &SctpActiveEstabs);
arl_expect(arl_base, "SctpPassiveEstabs", &SctpPassiveEstabs);
arl_expect(arl_base, "SctpAborteds", &SctpAborteds);
arl_expect(arl_base, "SctpShutdowns", &SctpShutdowns);
arl_expect(arl_base, "SctpOutOfBlues", &SctpOutOfBlues);
arl_expect(arl_base, "SctpChecksumErrors", &SctpChecksumErrors);
arl_expect(arl_base, "SctpOutCtrlChunks", &SctpOutCtrlChunks);
arl_expect(arl_base, "SctpOutOrderChunks", &SctpOutOrderChunks);
arl_expect(arl_base, "SctpOutUnorderChunks", &SctpOutUnorderChunks);
arl_expect(arl_base, "SctpInCtrlChunks", &SctpInCtrlChunks);
arl_expect(arl_base, "SctpInOrderChunks", &SctpInOrderChunks);
arl_expect(arl_base, "SctpInUnorderChunks", &SctpInUnorderChunks);
arl_expect(arl_base, "SctpFragUsrMsgs", &SctpFragUsrMsgs);
arl_expect(arl_base, "SctpReasmUsrMsgs", &SctpReasmUsrMsgs);
arl_expect(arl_base, "SctpOutSCTPPacks", &SctpOutSCTPPacks);
arl_expect(arl_base, "SctpInSCTPPacks", &SctpInSCTPPacks);
arl_expect(arl_base, "SctpT1InitExpireds", &SctpT1InitExpireds);
arl_expect(arl_base, "SctpT1CookieExpireds", &SctpT1CookieExpireds);
arl_expect(arl_base, "SctpT2ShutdownExpireds", &SctpT2ShutdownExpireds);
arl_expect(arl_base, "SctpT3RtxExpireds", &SctpT3RtxExpireds);
arl_expect(arl_base, "SctpT4RtoExpireds", &SctpT4RtoExpireds);
arl_expect(arl_base, "SctpT5ShutdownGuardExpireds", &SctpT5ShutdownGuardExpireds);
arl_expect(arl_base, "SctpDelaySackExpireds", &SctpDelaySackExpireds);
arl_expect(arl_base, "SctpAutocloseExpireds", &SctpAutocloseExpireds);
arl_expect(arl_base, "SctpT3Retransmits", &SctpT3Retransmits);
arl_expect(arl_base, "SctpPmtudRetransmits", &SctpPmtudRetransmits);
arl_expect(arl_base, "SctpFastRetransmits", &SctpFastRetransmits);
arl_expect(arl_base, "SctpInPktSoftirq", &SctpInPktSoftirq);
arl_expect(arl_base, "SctpInPktBacklog", &SctpInPktBacklog);
arl_expect(arl_base, "SctpInPktDiscards", &SctpInPktDiscards);
arl_expect(arl_base, "SctpInDataChunkDiscards", &SctpInDataChunkDiscards);
}
if(unlikely(!ff)) {
char filename[FILENAME_MAX + 1];
snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/net/sctp/snmp");
ff = procfile_open(config_get("plugin:proc:/proc/net/sctp/snmp", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
if(unlikely(!ff))
return 1;
}
ff = procfile_readall(ff);
if(unlikely(!ff))
return 0; // we return 0, so that we will retry to open it next time
size_t lines = procfile_lines(ff), l;
arl_begin(arl_base);
for(l = 0; l < lines ;l++) {
size_t words = procfile_linewords(ff, l);
if(unlikely(words < 2)) {
if(unlikely(words)) error("Cannot read /proc/net/sctp/snmp line %zu. Expected 2 params, read %zu.", l, words);
continue;
}
if(unlikely(arl_check(arl_base,
procfile_lineword(ff, l, 0),
procfile_lineword(ff, l, 1)))) break;
}
// --------------------------------------------------------------------
if(do_associations == CONFIG_BOOLEAN_YES || (do_associations == CONFIG_BOOLEAN_AUTO && SctpCurrEstab)) {
do_associations = CONFIG_BOOLEAN_YES;
static RRDSET *st = NULL;
static RRDDIM *rd_established = NULL;
if(unlikely(!st)) {
st = rrdset_create_localhost(
"sctp"
, "established"
, NULL
, "associations"
, NULL
, "SCTP current total number of established associations"
, "associations"
, PLUGIN_PROC_NAME
, PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
, NETDATA_CHART_PRIO_SCTP
, update_every
, RRDSET_TYPE_LINE
);
rd_established = rrddim_add(st, "SctpCurrEstab", "established", 1, 1, RRD_ALGORITHM_ABSOLUTE);
}
else rrdset_next(st);
rrddim_set_by_pointer(st, rd_established, SctpCurrEstab);
rrdset_done(st);
}
// --------------------------------------------------------------------
if(do_transitions == CONFIG_BOOLEAN_YES || (do_transitions == CONFIG_BOOLEAN_AUTO && (SctpActiveEstabs || SctpPassiveEstabs || SctpAborteds || SctpShutdowns))) {
do_transitions = CONFIG_BOOLEAN_YES;
static RRDSET *st = NULL;
static RRDDIM *rd_active = NULL,
*rd_passive = NULL,
*rd_aborted = NULL,
*rd_shutdown = NULL;
if(unlikely(!st)) {
st = rrdset_create_localhost(
"sctp"
, "transitions"
, NULL
, "transitions"
, NULL
, "SCTP Association Transitions"
, "transitions/s"
, PLUGIN_PROC_NAME
, PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
, NETDATA_CHART_PRIO_SCTP + 10
, update_every
, RRDSET_TYPE_LINE
);
rd_active = rrddim_add(st, "SctpActiveEstabs", "active", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_passive = rrddim_add(st, "SctpPassiveEstabs", "passive", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_aborted = rrddim_add(st, "SctpAborteds", "aborted", -1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_shutdown = rrddim_add(st, "SctpShutdowns", "shutdown", -1, 1, RRD_ALGORITHM_INCREMENTAL);
}
else rrdset_next(st);
rrddim_set_by_pointer(st, rd_active, SctpActiveEstabs);
rrddim_set_by_pointer(st, rd_passive, SctpPassiveEstabs);
rrddim_set_by_pointer(st, rd_aborted, SctpAborteds);
rrddim_set_by_pointer(st, rd_shutdown, SctpShutdowns);
rrdset_done(st);
}
// --------------------------------------------------------------------
if(do_packets == CONFIG_BOOLEAN_YES || (do_packets == CONFIG_BOOLEAN_AUTO && (SctpInSCTPPacks || SctpOutSCTPPacks))) {
do_packets = CONFIG_BOOLEAN_YES;
static RRDSET *st = NULL;
static RRDDIM *rd_received = NULL,
*rd_sent = NULL;
if(unlikely(!st)) {
st = rrdset_create_localhost(
"sctp"
, "packets"
, NULL
, "packets"
, NULL
, "SCTP Packets"
, "packets/s"
, PLUGIN_PROC_NAME
, PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
, NETDATA_CHART_PRIO_SCTP + 20
, update_every
, RRDSET_TYPE_LINE
);
rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
rd_received = rrddim_add(st, "SctpInSCTPPacks", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_sent = rrddim_add(st, "SctpOutSCTPPacks", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
}
else rrdset_next(st);
rrddim_set_by_pointer(st, rd_received, SctpInSCTPPacks);
rrddim_set_by_pointer(st, rd_sent, SctpOutSCTPPacks);
rrdset_done(st);
}
// --------------------------------------------------------------------
if(do_packet_errors == CONFIG_BOOLEAN_YES || (do_packet_errors == CONFIG_BOOLEAN_AUTO && (SctpOutOfBlues || SctpChecksumErrors))) {
do_packet_errors = CONFIG_BOOLEAN_YES;
static RRDSET *st = NULL;
static RRDDIM *rd_invalid = NULL,
*rd_csum = NULL;
if(unlikely(!st)) {
st = rrdset_create_localhost(
"sctp"
, "packet_errors"
, NULL
, "packets"
, NULL
, "SCTP Packet Errors"
, "packets/s"
, PLUGIN_PROC_NAME
, PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
, NETDATA_CHART_PRIO_SCTP + 30
, update_every
, RRDSET_TYPE_LINE
);
rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
rd_invalid = rrddim_add(st, "SctpOutOfBlues", "invalid", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_csum = rrddim_add(st, "SctpChecksumErrors", "checksum", 1, 1, RRD_ALGORITHM_INCREMENTAL);
}
else rrdset_next(st);
rrddim_set_by_pointer(st, rd_invalid, SctpOutOfBlues);
rrddim_set_by_pointer(st, rd_csum, SctpChecksumErrors);
rrdset_done(st);
}
// --------------------------------------------------------------------
if(do_fragmentation == CONFIG_BOOLEAN_YES || (do_fragmentation == CONFIG_BOOLEAN_AUTO && (SctpFragUsrMsgs || SctpReasmUsrMsgs))) {
do_fragmentation = CONFIG_BOOLEAN_YES;
static RRDSET *st = NULL;
static RRDDIM *rd_fragmented = NULL,
*rd_reassembled = NULL;
if(unlikely(!st)) {
st = rrdset_create_localhost(
"sctp"
, "fragmentation"
, NULL
, "fragmentation"
, NULL
, "SCTP Fragmentation"
, "packets/s"
, PLUGIN_PROC_NAME
, PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
, NETDATA_CHART_PRIO_SCTP + 40
, update_every
, RRDSET_TYPE_LINE);
rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
rd_reassembled = rrddim_add(st, "SctpReasmUsrMsgs", "reassembled", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_fragmented = rrddim_add(st, "SctpFragUsrMsgs", "fragmented", -1, 1, RRD_ALGORITHM_INCREMENTAL);
}
else rrdset_next(st);
rrddim_set_by_pointer(st, rd_reassembled, SctpReasmUsrMsgs);
rrddim_set_by_pointer(st, rd_fragmented, SctpFragUsrMsgs);
rrdset_done(st);
}
// --------------------------------------------------------------------
if(do_chunk_types == CONFIG_BOOLEAN_YES || (do_chunk_types == CONFIG_BOOLEAN_AUTO
&& (SctpInCtrlChunks || SctpInOrderChunks || SctpInUnorderChunks || SctpOutCtrlChunks || SctpOutOrderChunks || SctpOutUnorderChunks))) {
do_chunk_types = CONFIG_BOOLEAN_YES;
static RRDSET *st = NULL;
static RRDDIM
*rd_InCtrl = NULL,
*rd_InOrder = NULL,
*rd_InUnorder = NULL,
*rd_OutCtrl = NULL,
*rd_OutOrder = NULL,
*rd_OutUnorder = NULL;
if(unlikely(!st)) {
st = rrdset_create_localhost(
"sctp"
, "chunks"
, NULL
, "chunks"
, NULL
, "SCTP Chunk Types"
, "chunks/s"
, PLUGIN_PROC_NAME
, PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
, NETDATA_CHART_PRIO_SCTP + 50
, update_every
, RRDSET_TYPE_LINE
);
rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
rd_InCtrl = rrddim_add(st, "SctpInCtrlChunks", "InCtrl", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_InOrder = rrddim_add(st, "SctpInOrderChunks", "InOrder", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_InUnorder = rrddim_add(st, "SctpInUnorderChunks", "InUnorder", 1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_OutCtrl = rrddim_add(st, "SctpOutCtrlChunks", "OutCtrl", -1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_OutOrder = rrddim_add(st, "SctpOutOrderChunks", "OutOrder", -1, 1, RRD_ALGORITHM_INCREMENTAL);
rd_OutUnorder = rrddim_add(st, "SctpOutUnorderChunks", "OutUnorder", -1, 1, RRD_ALGORITHM_INCREMENTAL);
}
else rrdset_next(st);
rrddim_set_by_pointer(st, rd_InCtrl, SctpInCtrlChunks);
rrddim_set_by_pointer(st, rd_InOrder, SctpInOrderChunks);
rrddim_set_by_pointer(st, rd_InUnorder, SctpInUnorderChunks);
rrddim_set_by_pointer(st, rd_OutCtrl, SctpOutCtrlChunks);
rrddim_set_by_pointer(st, rd_OutOrder, SctpOutOrderChunks);
rrddim_set_by_pointer(st, rd_OutUnorder, SctpOutUnorderChunks);
rrdset_done(st);
}
return 0;
}