proc_net_sctp_snmp.c 17 KB

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