proc_net_sctp_snmp.c 17 KB

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