proc_net_sctp_snmp.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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 && SctpCurrEstab)) {
  112. do_associations = CONFIG_BOOLEAN_YES;
  113. static RRDSET *st = NULL;
  114. static RRDDIM *rd_established = NULL;
  115. if(unlikely(!st)) {
  116. st = rrdset_create_localhost(
  117. "sctp"
  118. , "established"
  119. , NULL
  120. , "associations"
  121. , NULL
  122. , "SCTP current total number of established associations"
  123. , "associations"
  124. , PLUGIN_PROC_NAME
  125. , PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
  126. , NETDATA_CHART_PRIO_SCTP
  127. , update_every
  128. , RRDSET_TYPE_LINE
  129. );
  130. rd_established = rrddim_add(st, "SctpCurrEstab", "established", 1, 1, RRD_ALGORITHM_ABSOLUTE);
  131. }
  132. else rrdset_next(st);
  133. rrddim_set_by_pointer(st, rd_established, SctpCurrEstab);
  134. rrdset_done(st);
  135. }
  136. // --------------------------------------------------------------------
  137. if(do_transitions == CONFIG_BOOLEAN_YES || (do_transitions == CONFIG_BOOLEAN_AUTO && (SctpActiveEstabs || SctpPassiveEstabs || SctpAborteds || SctpShutdowns))) {
  138. do_transitions = CONFIG_BOOLEAN_YES;
  139. static RRDSET *st = NULL;
  140. static RRDDIM *rd_active = NULL,
  141. *rd_passive = NULL,
  142. *rd_aborted = NULL,
  143. *rd_shutdown = NULL;
  144. if(unlikely(!st)) {
  145. st = rrdset_create_localhost(
  146. "sctp"
  147. , "transitions"
  148. , NULL
  149. , "transitions"
  150. , NULL
  151. , "SCTP Association Transitions"
  152. , "transitions/s"
  153. , PLUGIN_PROC_NAME
  154. , PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
  155. , NETDATA_CHART_PRIO_SCTP + 10
  156. , update_every
  157. , RRDSET_TYPE_LINE
  158. );
  159. rd_active = rrddim_add(st, "SctpActiveEstabs", "active", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  160. rd_passive = rrddim_add(st, "SctpPassiveEstabs", "passive", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  161. rd_aborted = rrddim_add(st, "SctpAborteds", "aborted", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  162. rd_shutdown = rrddim_add(st, "SctpShutdowns", "shutdown", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  163. }
  164. else rrdset_next(st);
  165. rrddim_set_by_pointer(st, rd_active, SctpActiveEstabs);
  166. rrddim_set_by_pointer(st, rd_passive, SctpPassiveEstabs);
  167. rrddim_set_by_pointer(st, rd_aborted, SctpAborteds);
  168. rrddim_set_by_pointer(st, rd_shutdown, SctpShutdowns);
  169. rrdset_done(st);
  170. }
  171. // --------------------------------------------------------------------
  172. if(do_packets == CONFIG_BOOLEAN_YES || (do_packets == CONFIG_BOOLEAN_AUTO && (SctpInSCTPPacks || SctpOutSCTPPacks))) {
  173. do_packets = CONFIG_BOOLEAN_YES;
  174. static RRDSET *st = NULL;
  175. static RRDDIM *rd_received = NULL,
  176. *rd_sent = NULL;
  177. if(unlikely(!st)) {
  178. st = rrdset_create_localhost(
  179. "sctp"
  180. , "packets"
  181. , NULL
  182. , "packets"
  183. , NULL
  184. , "SCTP Packets"
  185. , "packets/s"
  186. , PLUGIN_PROC_NAME
  187. , PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
  188. , NETDATA_CHART_PRIO_SCTP + 20
  189. , update_every
  190. , RRDSET_TYPE_LINE
  191. );
  192. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  193. rd_received = rrddim_add(st, "SctpInSCTPPacks", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  194. rd_sent = rrddim_add(st, "SctpOutSCTPPacks", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  195. }
  196. else rrdset_next(st);
  197. rrddim_set_by_pointer(st, rd_received, SctpInSCTPPacks);
  198. rrddim_set_by_pointer(st, rd_sent, SctpOutSCTPPacks);
  199. rrdset_done(st);
  200. }
  201. // --------------------------------------------------------------------
  202. if(do_packet_errors == CONFIG_BOOLEAN_YES || (do_packet_errors == CONFIG_BOOLEAN_AUTO && (SctpOutOfBlues || SctpChecksumErrors))) {
  203. do_packet_errors = CONFIG_BOOLEAN_YES;
  204. static RRDSET *st = NULL;
  205. static RRDDIM *rd_invalid = NULL,
  206. *rd_csum = NULL;
  207. if(unlikely(!st)) {
  208. st = rrdset_create_localhost(
  209. "sctp"
  210. , "packet_errors"
  211. , NULL
  212. , "packets"
  213. , NULL
  214. , "SCTP Packet Errors"
  215. , "packets/s"
  216. , PLUGIN_PROC_NAME
  217. , PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
  218. , NETDATA_CHART_PRIO_SCTP + 30
  219. , update_every
  220. , RRDSET_TYPE_LINE
  221. );
  222. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  223. rd_invalid = rrddim_add(st, "SctpOutOfBlues", "invalid", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  224. rd_csum = rrddim_add(st, "SctpChecksumErrors", "checksum", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  225. }
  226. else rrdset_next(st);
  227. rrddim_set_by_pointer(st, rd_invalid, SctpOutOfBlues);
  228. rrddim_set_by_pointer(st, rd_csum, SctpChecksumErrors);
  229. rrdset_done(st);
  230. }
  231. // --------------------------------------------------------------------
  232. if(do_fragmentation == CONFIG_BOOLEAN_YES || (do_fragmentation == CONFIG_BOOLEAN_AUTO && (SctpFragUsrMsgs || SctpReasmUsrMsgs))) {
  233. do_fragmentation = CONFIG_BOOLEAN_YES;
  234. static RRDSET *st = NULL;
  235. static RRDDIM *rd_fragmented = NULL,
  236. *rd_reassembled = NULL;
  237. if(unlikely(!st)) {
  238. st = rrdset_create_localhost(
  239. "sctp"
  240. , "fragmentation"
  241. , NULL
  242. , "fragmentation"
  243. , NULL
  244. , "SCTP Fragmentation"
  245. , "packets/s"
  246. , PLUGIN_PROC_NAME
  247. , PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
  248. , NETDATA_CHART_PRIO_SCTP + 40
  249. , update_every
  250. , RRDSET_TYPE_LINE);
  251. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  252. rd_reassembled = rrddim_add(st, "SctpReasmUsrMsgs", "reassembled", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  253. rd_fragmented = rrddim_add(st, "SctpFragUsrMsgs", "fragmented", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  254. }
  255. else rrdset_next(st);
  256. rrddim_set_by_pointer(st, rd_reassembled, SctpReasmUsrMsgs);
  257. rrddim_set_by_pointer(st, rd_fragmented, SctpFragUsrMsgs);
  258. rrdset_done(st);
  259. }
  260. // --------------------------------------------------------------------
  261. if(do_chunk_types == CONFIG_BOOLEAN_YES || (do_chunk_types == CONFIG_BOOLEAN_AUTO
  262. && (SctpInCtrlChunks || SctpInOrderChunks || SctpInUnorderChunks || SctpOutCtrlChunks || SctpOutOrderChunks || SctpOutUnorderChunks))) {
  263. do_chunk_types = CONFIG_BOOLEAN_YES;
  264. static RRDSET *st = NULL;
  265. static RRDDIM
  266. *rd_InCtrl = NULL,
  267. *rd_InOrder = NULL,
  268. *rd_InUnorder = NULL,
  269. *rd_OutCtrl = NULL,
  270. *rd_OutOrder = NULL,
  271. *rd_OutUnorder = NULL;
  272. if(unlikely(!st)) {
  273. st = rrdset_create_localhost(
  274. "sctp"
  275. , "chunks"
  276. , NULL
  277. , "chunks"
  278. , NULL
  279. , "SCTP Chunk Types"
  280. , "chunks/s"
  281. , PLUGIN_PROC_NAME
  282. , PLUGIN_PROC_MODULE_NET_SCTP_SNMP_NAME
  283. , NETDATA_CHART_PRIO_SCTP + 50
  284. , update_every
  285. , RRDSET_TYPE_LINE
  286. );
  287. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  288. rd_InCtrl = rrddim_add(st, "SctpInCtrlChunks", "InCtrl", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  289. rd_InOrder = rrddim_add(st, "SctpInOrderChunks", "InOrder", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  290. rd_InUnorder = rrddim_add(st, "SctpInUnorderChunks", "InUnorder", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  291. rd_OutCtrl = rrddim_add(st, "SctpOutCtrlChunks", "OutCtrl", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  292. rd_OutOrder = rrddim_add(st, "SctpOutOrderChunks", "OutOrder", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  293. rd_OutUnorder = rrddim_add(st, "SctpOutUnorderChunks", "OutUnorder", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  294. }
  295. else rrdset_next(st);
  296. rrddim_set_by_pointer(st, rd_InCtrl, SctpInCtrlChunks);
  297. rrddim_set_by_pointer(st, rd_InOrder, SctpInOrderChunks);
  298. rrddim_set_by_pointer(st, rd_InUnorder, SctpInUnorderChunks);
  299. rrddim_set_by_pointer(st, rd_OutCtrl, SctpOutCtrlChunks);
  300. rrddim_set_by_pointer(st, rd_OutOrder, SctpOutOrderChunks);
  301. rrddim_set_by_pointer(st, rd_OutUnorder, SctpOutUnorderChunks);
  302. rrdset_done(st);
  303. }
  304. return 0;
  305. }