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