proc_net_snmp.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "plugin_proc.h"
  3. #define PLUGIN_PROC_MODULE_NET_SNMP_NAME "/proc/net/snmp"
  4. #define RRD_TYPE_NET_SNMP "ipv4"
  5. static struct proc_net_snmp {
  6. // kernel_uint_t ip_Forwarding;
  7. kernel_uint_t ip_DefaultTTL;
  8. kernel_uint_t ip_InReceives;
  9. kernel_uint_t ip_InHdrErrors;
  10. kernel_uint_t ip_InAddrErrors;
  11. kernel_uint_t ip_ForwDatagrams;
  12. kernel_uint_t ip_InUnknownProtos;
  13. kernel_uint_t ip_InDiscards;
  14. kernel_uint_t ip_InDelivers;
  15. kernel_uint_t ip_OutRequests;
  16. kernel_uint_t ip_OutDiscards;
  17. kernel_uint_t ip_OutNoRoutes;
  18. kernel_uint_t ip_ReasmTimeout;
  19. kernel_uint_t ip_ReasmReqds;
  20. kernel_uint_t ip_ReasmOKs;
  21. kernel_uint_t ip_ReasmFails;
  22. kernel_uint_t ip_FragOKs;
  23. kernel_uint_t ip_FragFails;
  24. kernel_uint_t ip_FragCreates;
  25. kernel_uint_t icmp_InMsgs;
  26. kernel_uint_t icmp_OutMsgs;
  27. kernel_uint_t icmp_InErrors;
  28. kernel_uint_t icmp_OutErrors;
  29. kernel_uint_t icmp_InCsumErrors;
  30. kernel_uint_t icmpmsg_InEchoReps;
  31. kernel_uint_t icmpmsg_OutEchoReps;
  32. kernel_uint_t icmpmsg_InDestUnreachs;
  33. kernel_uint_t icmpmsg_OutDestUnreachs;
  34. kernel_uint_t icmpmsg_InRedirects;
  35. kernel_uint_t icmpmsg_OutRedirects;
  36. kernel_uint_t icmpmsg_InEchos;
  37. kernel_uint_t icmpmsg_OutEchos;
  38. kernel_uint_t icmpmsg_InRouterAdvert;
  39. kernel_uint_t icmpmsg_OutRouterAdvert;
  40. kernel_uint_t icmpmsg_InRouterSelect;
  41. kernel_uint_t icmpmsg_OutRouterSelect;
  42. kernel_uint_t icmpmsg_InTimeExcds;
  43. kernel_uint_t icmpmsg_OutTimeExcds;
  44. kernel_uint_t icmpmsg_InParmProbs;
  45. kernel_uint_t icmpmsg_OutParmProbs;
  46. kernel_uint_t icmpmsg_InTimestamps;
  47. kernel_uint_t icmpmsg_OutTimestamps;
  48. kernel_uint_t icmpmsg_InTimestampReps;
  49. kernel_uint_t icmpmsg_OutTimestampReps;
  50. //kernel_uint_t tcp_RtoAlgorithm;
  51. //kernel_uint_t tcp_RtoMin;
  52. //kernel_uint_t tcp_RtoMax;
  53. ssize_t tcp_MaxConn;
  54. kernel_uint_t tcp_ActiveOpens;
  55. kernel_uint_t tcp_PassiveOpens;
  56. kernel_uint_t tcp_AttemptFails;
  57. kernel_uint_t tcp_EstabResets;
  58. kernel_uint_t tcp_CurrEstab;
  59. kernel_uint_t tcp_InSegs;
  60. kernel_uint_t tcp_OutSegs;
  61. kernel_uint_t tcp_RetransSegs;
  62. kernel_uint_t tcp_InErrs;
  63. kernel_uint_t tcp_OutRsts;
  64. kernel_uint_t tcp_InCsumErrors;
  65. kernel_uint_t udp_InDatagrams;
  66. kernel_uint_t udp_NoPorts;
  67. kernel_uint_t udp_InErrors;
  68. kernel_uint_t udp_OutDatagrams;
  69. kernel_uint_t udp_RcvbufErrors;
  70. kernel_uint_t udp_SndbufErrors;
  71. kernel_uint_t udp_InCsumErrors;
  72. kernel_uint_t udp_IgnoredMulti;
  73. kernel_uint_t udplite_InDatagrams;
  74. kernel_uint_t udplite_NoPorts;
  75. kernel_uint_t udplite_InErrors;
  76. kernel_uint_t udplite_OutDatagrams;
  77. kernel_uint_t udplite_RcvbufErrors;
  78. kernel_uint_t udplite_SndbufErrors;
  79. kernel_uint_t udplite_InCsumErrors;
  80. kernel_uint_t udplite_IgnoredMulti;
  81. } snmp_root = { 0 };
  82. int do_proc_net_snmp(int update_every, usec_t dt) {
  83. (void)dt;
  84. static procfile *ff = NULL;
  85. static int do_ip_packets = -1, do_ip_fragsout = -1, do_ip_fragsin = -1, do_ip_errors = -1,
  86. do_tcp_sockets = -1, do_tcp_packets = -1, do_tcp_errors = -1, do_tcp_handshake = -1, do_tcp_opens = -1,
  87. do_udp_packets = -1, do_udp_errors = -1, do_icmp_packets = -1, do_icmpmsg = -1, do_udplite_packets = -1;
  88. static uint32_t hash_ip = 0, hash_icmp = 0, hash_tcp = 0, hash_udp = 0, hash_icmpmsg = 0, hash_udplite = 0;
  89. static ARL_BASE *arl_ip = NULL,
  90. *arl_icmp = NULL,
  91. *arl_icmpmsg = NULL,
  92. *arl_tcp = NULL,
  93. *arl_udp = NULL,
  94. *arl_udplite = NULL;
  95. static RRDVAR *tcp_max_connections_var = NULL;
  96. if(unlikely(!arl_ip)) {
  97. do_ip_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 packets", CONFIG_BOOLEAN_AUTO);
  98. do_ip_fragsout = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 fragments sent", CONFIG_BOOLEAN_AUTO);
  99. do_ip_fragsin = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 fragments assembly", CONFIG_BOOLEAN_AUTO);
  100. do_ip_errors = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 errors", CONFIG_BOOLEAN_AUTO);
  101. do_tcp_sockets = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 TCP connections", CONFIG_BOOLEAN_AUTO);
  102. do_tcp_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 TCP packets", CONFIG_BOOLEAN_AUTO);
  103. do_tcp_errors = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 TCP errors", CONFIG_BOOLEAN_AUTO);
  104. do_tcp_opens = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 TCP opens", CONFIG_BOOLEAN_AUTO);
  105. do_tcp_handshake = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 TCP handshake issues", CONFIG_BOOLEAN_AUTO);
  106. do_udp_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 UDP packets", CONFIG_BOOLEAN_AUTO);
  107. do_udp_errors = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 UDP errors", CONFIG_BOOLEAN_AUTO);
  108. do_icmp_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 ICMP packets", CONFIG_BOOLEAN_AUTO);
  109. do_icmpmsg = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 ICMP messages", CONFIG_BOOLEAN_AUTO);
  110. do_udplite_packets = config_get_boolean_ondemand("plugin:proc:/proc/net/snmp", "ipv4 UDPLite packets", CONFIG_BOOLEAN_AUTO);
  111. hash_ip = simple_hash("Ip");
  112. hash_tcp = simple_hash("Tcp");
  113. hash_udp = simple_hash("Udp");
  114. hash_icmp = simple_hash("Icmp");
  115. hash_icmpmsg = simple_hash("IcmpMsg");
  116. hash_udplite = simple_hash("UdpLite");
  117. arl_ip = arl_create("snmp/Ip", arl_callback_str2kernel_uint_t, 60);
  118. // arl_expect(arl_ip, "Forwarding", &snmp_root.ip_Forwarding);
  119. arl_expect(arl_ip, "DefaultTTL", &snmp_root.ip_DefaultTTL);
  120. arl_expect(arl_ip, "InReceives", &snmp_root.ip_InReceives);
  121. arl_expect(arl_ip, "InHdrErrors", &snmp_root.ip_InHdrErrors);
  122. arl_expect(arl_ip, "InAddrErrors", &snmp_root.ip_InAddrErrors);
  123. arl_expect(arl_ip, "ForwDatagrams", &snmp_root.ip_ForwDatagrams);
  124. arl_expect(arl_ip, "InUnknownProtos", &snmp_root.ip_InUnknownProtos);
  125. arl_expect(arl_ip, "InDiscards", &snmp_root.ip_InDiscards);
  126. arl_expect(arl_ip, "InDelivers", &snmp_root.ip_InDelivers);
  127. arl_expect(arl_ip, "OutRequests", &snmp_root.ip_OutRequests);
  128. arl_expect(arl_ip, "OutDiscards", &snmp_root.ip_OutDiscards);
  129. arl_expect(arl_ip, "OutNoRoutes", &snmp_root.ip_OutNoRoutes);
  130. arl_expect(arl_ip, "ReasmTimeout", &snmp_root.ip_ReasmTimeout);
  131. arl_expect(arl_ip, "ReasmReqds", &snmp_root.ip_ReasmReqds);
  132. arl_expect(arl_ip, "ReasmOKs", &snmp_root.ip_ReasmOKs);
  133. arl_expect(arl_ip, "ReasmFails", &snmp_root.ip_ReasmFails);
  134. arl_expect(arl_ip, "FragOKs", &snmp_root.ip_FragOKs);
  135. arl_expect(arl_ip, "FragFails", &snmp_root.ip_FragFails);
  136. arl_expect(arl_ip, "FragCreates", &snmp_root.ip_FragCreates);
  137. arl_icmp = arl_create("snmp/Icmp", arl_callback_str2kernel_uint_t, 60);
  138. arl_expect(arl_icmp, "InMsgs", &snmp_root.icmp_InMsgs);
  139. arl_expect(arl_icmp, "OutMsgs", &snmp_root.icmp_OutMsgs);
  140. arl_expect(arl_icmp, "InErrors", &snmp_root.icmp_InErrors);
  141. arl_expect(arl_icmp, "OutErrors", &snmp_root.icmp_OutErrors);
  142. arl_expect(arl_icmp, "InCsumErrors", &snmp_root.icmp_InCsumErrors);
  143. arl_icmpmsg = arl_create("snmp/Icmpmsg", arl_callback_str2kernel_uint_t, 60);
  144. arl_expect(arl_icmpmsg, "InType0", &snmp_root.icmpmsg_InEchoReps);
  145. arl_expect(arl_icmpmsg, "OutType0", &snmp_root.icmpmsg_OutEchoReps);
  146. arl_expect(arl_icmpmsg, "InType3", &snmp_root.icmpmsg_InDestUnreachs);
  147. arl_expect(arl_icmpmsg, "OutType3", &snmp_root.icmpmsg_OutDestUnreachs);
  148. arl_expect(arl_icmpmsg, "InType5", &snmp_root.icmpmsg_InRedirects);
  149. arl_expect(arl_icmpmsg, "OutType5", &snmp_root.icmpmsg_OutRedirects);
  150. arl_expect(arl_icmpmsg, "InType8", &snmp_root.icmpmsg_InEchos);
  151. arl_expect(arl_icmpmsg, "OutType8", &snmp_root.icmpmsg_OutEchos);
  152. arl_expect(arl_icmpmsg, "InType9", &snmp_root.icmpmsg_InRouterAdvert);
  153. arl_expect(arl_icmpmsg, "OutType9", &snmp_root.icmpmsg_OutRouterAdvert);
  154. arl_expect(arl_icmpmsg, "InType10", &snmp_root.icmpmsg_InRouterSelect);
  155. arl_expect(arl_icmpmsg, "OutType10", &snmp_root.icmpmsg_OutRouterSelect);
  156. arl_expect(arl_icmpmsg, "InType11", &snmp_root.icmpmsg_InTimeExcds);
  157. arl_expect(arl_icmpmsg, "OutType11", &snmp_root.icmpmsg_OutTimeExcds);
  158. arl_expect(arl_icmpmsg, "InType12", &snmp_root.icmpmsg_InParmProbs);
  159. arl_expect(arl_icmpmsg, "OutType12", &snmp_root.icmpmsg_OutParmProbs);
  160. arl_expect(arl_icmpmsg, "InType13", &snmp_root.icmpmsg_InTimestamps);
  161. arl_expect(arl_icmpmsg, "OutType13", &snmp_root.icmpmsg_OutTimestamps);
  162. arl_expect(arl_icmpmsg, "InType14", &snmp_root.icmpmsg_InTimestampReps);
  163. arl_expect(arl_icmpmsg, "OutType14", &snmp_root.icmpmsg_OutTimestampReps);
  164. arl_tcp = arl_create("snmp/Tcp", arl_callback_str2kernel_uint_t, 60);
  165. // arl_expect(arl_tcp, "RtoAlgorithm", &snmp_root.tcp_RtoAlgorithm);
  166. // arl_expect(arl_tcp, "RtoMin", &snmp_root.tcp_RtoMin);
  167. // arl_expect(arl_tcp, "RtoMax", &snmp_root.tcp_RtoMax);
  168. arl_expect_custom(arl_tcp, "MaxConn", arl_callback_ssize_t, &snmp_root.tcp_MaxConn);
  169. arl_expect(arl_tcp, "ActiveOpens", &snmp_root.tcp_ActiveOpens);
  170. arl_expect(arl_tcp, "PassiveOpens", &snmp_root.tcp_PassiveOpens);
  171. arl_expect(arl_tcp, "AttemptFails", &snmp_root.tcp_AttemptFails);
  172. arl_expect(arl_tcp, "EstabResets", &snmp_root.tcp_EstabResets);
  173. arl_expect(arl_tcp, "CurrEstab", &snmp_root.tcp_CurrEstab);
  174. arl_expect(arl_tcp, "InSegs", &snmp_root.tcp_InSegs);
  175. arl_expect(arl_tcp, "OutSegs", &snmp_root.tcp_OutSegs);
  176. arl_expect(arl_tcp, "RetransSegs", &snmp_root.tcp_RetransSegs);
  177. arl_expect(arl_tcp, "InErrs", &snmp_root.tcp_InErrs);
  178. arl_expect(arl_tcp, "OutRsts", &snmp_root.tcp_OutRsts);
  179. arl_expect(arl_tcp, "InCsumErrors", &snmp_root.tcp_InCsumErrors);
  180. arl_udp = arl_create("snmp/Udp", arl_callback_str2kernel_uint_t, 60);
  181. arl_expect(arl_udp, "InDatagrams", &snmp_root.udp_InDatagrams);
  182. arl_expect(arl_udp, "NoPorts", &snmp_root.udp_NoPorts);
  183. arl_expect(arl_udp, "InErrors", &snmp_root.udp_InErrors);
  184. arl_expect(arl_udp, "OutDatagrams", &snmp_root.udp_OutDatagrams);
  185. arl_expect(arl_udp, "RcvbufErrors", &snmp_root.udp_RcvbufErrors);
  186. arl_expect(arl_udp, "SndbufErrors", &snmp_root.udp_SndbufErrors);
  187. arl_expect(arl_udp, "InCsumErrors", &snmp_root.udp_InCsumErrors);
  188. arl_expect(arl_udp, "IgnoredMulti", &snmp_root.udp_IgnoredMulti);
  189. arl_udplite = arl_create("snmp/Udplite", arl_callback_str2kernel_uint_t, 60);
  190. arl_expect(arl_udplite, "InDatagrams", &snmp_root.udplite_InDatagrams);
  191. arl_expect(arl_udplite, "NoPorts", &snmp_root.udplite_NoPorts);
  192. arl_expect(arl_udplite, "InErrors", &snmp_root.udplite_InErrors);
  193. arl_expect(arl_udplite, "OutDatagrams", &snmp_root.udplite_OutDatagrams);
  194. arl_expect(arl_udplite, "RcvbufErrors", &snmp_root.udplite_RcvbufErrors);
  195. arl_expect(arl_udplite, "SndbufErrors", &snmp_root.udplite_SndbufErrors);
  196. arl_expect(arl_udplite, "InCsumErrors", &snmp_root.udplite_InCsumErrors);
  197. arl_expect(arl_udplite, "IgnoredMulti", &snmp_root.udplite_IgnoredMulti);
  198. tcp_max_connections_var = rrdvar_custom_host_variable_create(localhost, "tcp_max_connections");
  199. }
  200. if(unlikely(!ff)) {
  201. char filename[FILENAME_MAX + 1];
  202. snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/net/snmp");
  203. ff = procfile_open(config_get("plugin:proc:/proc/net/snmp", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
  204. if(unlikely(!ff)) return 1;
  205. }
  206. ff = procfile_readall(ff);
  207. if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
  208. size_t lines = procfile_lines(ff), l;
  209. size_t words, w;
  210. for(l = 0; l < lines ;l++) {
  211. char *key = procfile_lineword(ff, l, 0);
  212. uint32_t hash = simple_hash(key);
  213. if(unlikely(hash == hash_ip && strcmp(key, "Ip") == 0)) {
  214. size_t h = l++;
  215. if(strcmp(procfile_lineword(ff, l, 0), "Ip") != 0) {
  216. error("Cannot read Ip line from /proc/net/snmp.");
  217. break;
  218. }
  219. words = procfile_linewords(ff, l);
  220. if(words < 3) {
  221. error("Cannot read /proc/net/snmp Ip line. Expected 3+ params, read %zu.", words);
  222. continue;
  223. }
  224. arl_begin(arl_ip);
  225. for(w = 1; w < words ; w++) {
  226. if (unlikely(arl_check(arl_ip, procfile_lineword(ff, h, w), procfile_lineword(ff, l, w)) != 0))
  227. break;
  228. }
  229. // --------------------------------------------------------------------
  230. if(do_ip_packets == CONFIG_BOOLEAN_YES || (do_ip_packets == CONFIG_BOOLEAN_AUTO &&
  231. (snmp_root.ip_OutRequests ||
  232. snmp_root.ip_InReceives ||
  233. snmp_root.ip_ForwDatagrams ||
  234. snmp_root.ip_InDelivers ||
  235. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  236. do_ip_packets = CONFIG_BOOLEAN_YES;
  237. static RRDSET *st = NULL;
  238. static RRDDIM *rd_InReceives = NULL,
  239. *rd_OutRequests = NULL,
  240. *rd_ForwDatagrams = NULL,
  241. *rd_InDelivers = NULL;
  242. if(unlikely(!st)) {
  243. st = rrdset_create_localhost(
  244. RRD_TYPE_NET_SNMP
  245. , "packets"
  246. , NULL
  247. , "packets"
  248. , NULL
  249. , "IPv4 Packets"
  250. , "packets/s"
  251. , PLUGIN_PROC_NAME
  252. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  253. , NETDATA_CHART_PRIO_IPV4_PACKETS
  254. , update_every
  255. , RRDSET_TYPE_LINE
  256. );
  257. rd_InReceives = rrddim_add(st, "InReceives", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  258. rd_OutRequests = rrddim_add(st, "OutRequests", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  259. rd_ForwDatagrams = rrddim_add(st, "ForwDatagrams", "forwarded", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  260. rd_InDelivers = rrddim_add(st, "InDelivers", "delivered", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  261. }
  262. else rrdset_next(st);
  263. rrddim_set_by_pointer(st, rd_OutRequests, (collected_number)snmp_root.ip_OutRequests);
  264. rrddim_set_by_pointer(st, rd_InReceives, (collected_number)snmp_root.ip_InReceives);
  265. rrddim_set_by_pointer(st, rd_ForwDatagrams, (collected_number)snmp_root.ip_ForwDatagrams);
  266. rrddim_set_by_pointer(st, rd_InDelivers, (collected_number)snmp_root.ip_InDelivers);
  267. rrdset_done(st);
  268. }
  269. // --------------------------------------------------------------------
  270. if(do_ip_fragsout == CONFIG_BOOLEAN_YES || (do_ip_fragsout == CONFIG_BOOLEAN_AUTO &&
  271. (snmp_root.ip_FragOKs ||
  272. snmp_root.ip_FragFails ||
  273. snmp_root.ip_FragCreates ||
  274. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  275. do_ip_fragsout = CONFIG_BOOLEAN_YES;
  276. static RRDSET *st = NULL;
  277. static RRDDIM *rd_FragOKs = NULL,
  278. *rd_FragFails = NULL,
  279. *rd_FragCreates = NULL;
  280. if(unlikely(!st)) {
  281. st = rrdset_create_localhost(
  282. RRD_TYPE_NET_SNMP
  283. , "fragsout"
  284. , NULL
  285. , "fragments"
  286. , NULL
  287. , "IPv4 Fragments Sent"
  288. , "packets/s"
  289. , PLUGIN_PROC_NAME
  290. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  291. , NETDATA_CHART_PRIO_IPV4_FRAGMENTS
  292. , update_every
  293. , RRDSET_TYPE_LINE
  294. );
  295. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  296. rd_FragOKs = rrddim_add(st, "FragOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  297. rd_FragFails = rrddim_add(st, "FragFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  298. rd_FragCreates = rrddim_add(st, "FragCreates", "created", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  299. }
  300. else rrdset_next(st);
  301. rrddim_set_by_pointer(st, rd_FragOKs, (collected_number)snmp_root.ip_FragOKs);
  302. rrddim_set_by_pointer(st, rd_FragFails, (collected_number)snmp_root.ip_FragFails);
  303. rrddim_set_by_pointer(st, rd_FragCreates, (collected_number)snmp_root.ip_FragCreates);
  304. rrdset_done(st);
  305. }
  306. // --------------------------------------------------------------------
  307. if(do_ip_fragsin == CONFIG_BOOLEAN_YES || (do_ip_fragsin == CONFIG_BOOLEAN_AUTO &&
  308. (snmp_root.ip_ReasmOKs ||
  309. snmp_root.ip_ReasmFails ||
  310. snmp_root.ip_ReasmReqds ||
  311. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  312. do_ip_fragsin = CONFIG_BOOLEAN_YES;
  313. static RRDSET *st = NULL;
  314. static RRDDIM *rd_ReasmOKs = NULL,
  315. *rd_ReasmFails = NULL,
  316. *rd_ReasmReqds = NULL;
  317. if(unlikely(!st)) {
  318. st = rrdset_create_localhost(
  319. RRD_TYPE_NET_SNMP
  320. , "fragsin"
  321. , NULL
  322. , "fragments"
  323. , NULL
  324. , "IPv4 Fragments Reassembly"
  325. , "packets/s"
  326. , PLUGIN_PROC_NAME
  327. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  328. , NETDATA_CHART_PRIO_IPV4_FRAGMENTS + 1
  329. , update_every
  330. , RRDSET_TYPE_LINE
  331. );
  332. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  333. rd_ReasmOKs = rrddim_add(st, "ReasmOKs", "ok", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  334. rd_ReasmFails = rrddim_add(st, "ReasmFails", "failed", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  335. rd_ReasmReqds = rrddim_add(st, "ReasmReqds", "all", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  336. }
  337. else rrdset_next(st);
  338. rrddim_set_by_pointer(st, rd_ReasmOKs, (collected_number)snmp_root.ip_ReasmOKs);
  339. rrddim_set_by_pointer(st, rd_ReasmFails, (collected_number)snmp_root.ip_ReasmFails);
  340. rrddim_set_by_pointer(st, rd_ReasmReqds, (collected_number)snmp_root.ip_ReasmReqds);
  341. rrdset_done(st);
  342. }
  343. // --------------------------------------------------------------------
  344. if(do_ip_errors == CONFIG_BOOLEAN_YES || (do_ip_errors == CONFIG_BOOLEAN_AUTO &&
  345. (snmp_root.ip_InDiscards ||
  346. snmp_root.ip_OutDiscards ||
  347. snmp_root.ip_InHdrErrors ||
  348. snmp_root.ip_InAddrErrors ||
  349. snmp_root.ip_InUnknownProtos ||
  350. snmp_root.ip_OutNoRoutes ||
  351. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  352. do_ip_errors = CONFIG_BOOLEAN_YES;
  353. static RRDSET *st = NULL;
  354. static RRDDIM *rd_InDiscards = NULL,
  355. *rd_OutDiscards = NULL,
  356. *rd_InHdrErrors = NULL,
  357. *rd_OutNoRoutes = NULL,
  358. *rd_InAddrErrors = NULL,
  359. *rd_InUnknownProtos = NULL;
  360. if(unlikely(!st)) {
  361. st = rrdset_create_localhost(
  362. RRD_TYPE_NET_SNMP
  363. , "errors"
  364. , NULL
  365. , "errors"
  366. , NULL
  367. , "IPv4 Errors"
  368. , "packets/s"
  369. , PLUGIN_PROC_NAME
  370. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  371. , NETDATA_CHART_PRIO_IPV4_ERRORS
  372. , update_every
  373. , RRDSET_TYPE_LINE
  374. );
  375. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  376. rd_InDiscards = rrddim_add(st, "InDiscards", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  377. rd_OutDiscards = rrddim_add(st, "OutDiscards", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  378. rd_InHdrErrors = rrddim_add(st, "InHdrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  379. rd_OutNoRoutes = rrddim_add(st, "OutNoRoutes", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  380. rd_InAddrErrors = rrddim_add(st, "InAddrErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  381. rd_InUnknownProtos = rrddim_add(st, "InUnknownProtos", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  382. }
  383. else rrdset_next(st);
  384. rrddim_set_by_pointer(st, rd_InDiscards, (collected_number)snmp_root.ip_InDiscards);
  385. rrddim_set_by_pointer(st, rd_OutDiscards, (collected_number)snmp_root.ip_OutDiscards);
  386. rrddim_set_by_pointer(st, rd_InHdrErrors, (collected_number)snmp_root.ip_InHdrErrors);
  387. rrddim_set_by_pointer(st, rd_InAddrErrors, (collected_number)snmp_root.ip_InAddrErrors);
  388. rrddim_set_by_pointer(st, rd_InUnknownProtos, (collected_number)snmp_root.ip_InUnknownProtos);
  389. rrddim_set_by_pointer(st, rd_OutNoRoutes, (collected_number)snmp_root.ip_OutNoRoutes);
  390. rrdset_done(st);
  391. }
  392. }
  393. else if(unlikely(hash == hash_icmp && strcmp(key, "Icmp") == 0)) {
  394. size_t h = l++;
  395. if(strcmp(procfile_lineword(ff, l, 0), "Icmp") != 0) {
  396. error("Cannot read Icmp line from /proc/net/snmp.");
  397. break;
  398. }
  399. words = procfile_linewords(ff, l);
  400. if(words < 3) {
  401. error("Cannot read /proc/net/snmp Icmp line. Expected 3+ params, read %zu.", words);
  402. continue;
  403. }
  404. arl_begin(arl_icmp);
  405. for(w = 1; w < words ; w++) {
  406. if (unlikely(arl_check(arl_icmp, procfile_lineword(ff, h, w), procfile_lineword(ff, l, w)) != 0))
  407. break;
  408. }
  409. // --------------------------------------------------------------------
  410. if(do_icmp_packets == CONFIG_BOOLEAN_YES || (do_icmp_packets == CONFIG_BOOLEAN_AUTO &&
  411. (snmp_root.icmp_InMsgs ||
  412. snmp_root.icmp_OutMsgs ||
  413. snmp_root.icmp_InErrors ||
  414. snmp_root.icmp_OutErrors ||
  415. snmp_root.icmp_InCsumErrors ||
  416. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  417. do_icmp_packets = CONFIG_BOOLEAN_YES;
  418. {
  419. static RRDSET *st_packets = NULL;
  420. static RRDDIM *rd_InMsgs = NULL,
  421. *rd_OutMsgs = NULL;
  422. if(unlikely(!st_packets)) {
  423. st_packets = rrdset_create_localhost(
  424. RRD_TYPE_NET_SNMP
  425. , "icmp"
  426. , NULL
  427. , "icmp"
  428. , NULL
  429. , "IPv4 ICMP Packets"
  430. , "packets/s"
  431. , PLUGIN_PROC_NAME
  432. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  433. , NETDATA_CHART_PRIO_IPV4_ICMP
  434. , update_every
  435. , RRDSET_TYPE_LINE
  436. );
  437. rd_InMsgs = rrddim_add(st_packets, "InMsgs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  438. rd_OutMsgs = rrddim_add(st_packets, "OutMsgs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  439. }
  440. else rrdset_next(st_packets);
  441. rrddim_set_by_pointer(st_packets, rd_InMsgs, (collected_number)snmp_root.icmp_InMsgs);
  442. rrddim_set_by_pointer(st_packets, rd_OutMsgs, (collected_number)snmp_root.icmp_OutMsgs);
  443. rrdset_done(st_packets);
  444. }
  445. {
  446. static RRDSET *st_errors = NULL;
  447. static RRDDIM *rd_InErrors = NULL,
  448. *rd_OutErrors = NULL,
  449. *rd_InCsumErrors = NULL;
  450. if(unlikely(!st_errors)) {
  451. st_errors = rrdset_create_localhost(
  452. RRD_TYPE_NET_SNMP
  453. , "icmp_errors"
  454. , NULL
  455. , "icmp"
  456. , NULL
  457. , "IPv4 ICMP Errors"
  458. , "packets/s"
  459. , PLUGIN_PROC_NAME
  460. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  461. , NETDATA_CHART_PRIO_IPV4_ICMP + 1
  462. , update_every
  463. , RRDSET_TYPE_LINE
  464. );
  465. rd_InErrors = rrddim_add(st_errors, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  466. rd_OutErrors = rrddim_add(st_errors, "OutErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  467. rd_InCsumErrors = rrddim_add(st_errors, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  468. }
  469. else rrdset_next(st_errors);
  470. rrddim_set_by_pointer(st_errors, rd_InErrors, (collected_number)snmp_root.icmp_InErrors);
  471. rrddim_set_by_pointer(st_errors, rd_OutErrors, (collected_number)snmp_root.icmp_OutErrors);
  472. rrddim_set_by_pointer(st_errors, rd_InCsumErrors, (collected_number)snmp_root.icmp_InCsumErrors);
  473. rrdset_done(st_errors);
  474. }
  475. }
  476. }
  477. else if(unlikely(hash == hash_icmpmsg && strcmp(key, "IcmpMsg") == 0)) {
  478. size_t h = l++;
  479. if(strcmp(procfile_lineword(ff, l, 0), "IcmpMsg") != 0) {
  480. error("Cannot read IcmpMsg line from /proc/net/snmp.");
  481. break;
  482. }
  483. words = procfile_linewords(ff, l);
  484. if(words < 2) {
  485. error("Cannot read /proc/net/snmp IcmpMsg line. Expected 2+ params, read %zu.", words);
  486. continue;
  487. }
  488. arl_begin(arl_icmpmsg);
  489. for(w = 1; w < words ; w++) {
  490. if (unlikely(arl_check(arl_icmpmsg, procfile_lineword(ff, h, w), procfile_lineword(ff, l, w)) != 0))
  491. break;
  492. }
  493. // --------------------------------------------------------------------
  494. if(do_icmpmsg == CONFIG_BOOLEAN_YES || (do_icmpmsg == CONFIG_BOOLEAN_AUTO &&
  495. (snmp_root.icmpmsg_InEchoReps ||
  496. snmp_root.icmpmsg_OutEchoReps ||
  497. snmp_root.icmpmsg_InDestUnreachs ||
  498. snmp_root.icmpmsg_OutDestUnreachs ||
  499. snmp_root.icmpmsg_InRedirects ||
  500. snmp_root.icmpmsg_OutRedirects ||
  501. snmp_root.icmpmsg_InEchos ||
  502. snmp_root.icmpmsg_OutEchos ||
  503. snmp_root.icmpmsg_InRouterAdvert ||
  504. snmp_root.icmpmsg_OutRouterAdvert ||
  505. snmp_root.icmpmsg_InRouterSelect ||
  506. snmp_root.icmpmsg_OutRouterSelect ||
  507. snmp_root.icmpmsg_InTimeExcds ||
  508. snmp_root.icmpmsg_OutTimeExcds ||
  509. snmp_root.icmpmsg_InParmProbs ||
  510. snmp_root.icmpmsg_OutParmProbs ||
  511. snmp_root.icmpmsg_InTimestamps ||
  512. snmp_root.icmpmsg_OutTimestamps ||
  513. snmp_root.icmpmsg_InTimestampReps ||
  514. snmp_root.icmpmsg_OutTimestampReps ||
  515. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  516. do_icmpmsg = CONFIG_BOOLEAN_YES;
  517. static RRDSET *st = NULL;
  518. static RRDDIM *rd_InEchoReps = NULL,
  519. *rd_OutEchoReps = NULL,
  520. *rd_InDestUnreachs = NULL,
  521. *rd_OutDestUnreachs = NULL,
  522. *rd_InRedirects = NULL,
  523. *rd_OutRedirects = NULL,
  524. *rd_InEchos = NULL,
  525. *rd_OutEchos = NULL,
  526. *rd_InRouterAdvert = NULL,
  527. *rd_OutRouterAdvert = NULL,
  528. *rd_InRouterSelect = NULL,
  529. *rd_OutRouterSelect = NULL,
  530. *rd_InTimeExcds = NULL,
  531. *rd_OutTimeExcds = NULL,
  532. *rd_InParmProbs = NULL,
  533. *rd_OutParmProbs = NULL,
  534. *rd_InTimestamps = NULL,
  535. *rd_OutTimestamps = NULL,
  536. *rd_InTimestampReps = NULL,
  537. *rd_OutTimestampReps = NULL;
  538. if(unlikely(!st)) {
  539. st = rrdset_create_localhost(
  540. RRD_TYPE_NET_SNMP
  541. , "icmpmsg"
  542. , NULL
  543. , "icmp"
  544. , NULL
  545. , "IPv4 ICMP Messages"
  546. , "packets/s"
  547. , PLUGIN_PROC_NAME
  548. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  549. , NETDATA_CHART_PRIO_IPV4_ICMP + 2
  550. , update_every
  551. , RRDSET_TYPE_LINE
  552. );
  553. rd_InEchoReps = rrddim_add(st, "InType0", "InEchoReps", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  554. rd_OutEchoReps = rrddim_add(st, "OutType0", "OutEchoReps", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  555. rd_InDestUnreachs = rrddim_add(st, "InType3", "InDestUnreachs", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  556. rd_OutDestUnreachs = rrddim_add(st, "OutType3", "OutDestUnreachs", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  557. rd_InRedirects = rrddim_add(st, "InType5", "InRedirects", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  558. rd_OutRedirects = rrddim_add(st, "OutType5", "OutRedirects", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  559. rd_InEchos = rrddim_add(st, "InType8", "InEchos", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  560. rd_OutEchos = rrddim_add(st, "OutType8", "OutEchos", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  561. rd_InRouterAdvert = rrddim_add(st, "InType9", "InRouterAdvert", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  562. rd_OutRouterAdvert = rrddim_add(st, "OutType9", "OutRouterAdvert", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  563. rd_InRouterSelect = rrddim_add(st, "InType10", "InRouterSelect", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  564. rd_OutRouterSelect = rrddim_add(st, "OutType10", "OutRouterSelect", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  565. rd_InTimeExcds = rrddim_add(st, "InType11", "InTimeExcds", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  566. rd_OutTimeExcds = rrddim_add(st, "OutType11", "OutTimeExcds", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  567. rd_InParmProbs = rrddim_add(st, "InType12", "InParmProbs", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  568. rd_OutParmProbs = rrddim_add(st, "OutType12", "OutParmProbs", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  569. rd_InTimestamps = rrddim_add(st, "InType13", "InTimestamps", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  570. rd_OutTimestamps = rrddim_add(st, "OutType13", "OutTimestamps", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  571. rd_InTimestampReps = rrddim_add(st, "InType14", "InTimestampReps", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  572. rd_OutTimestampReps = rrddim_add(st, "OutType14", "OutTimestampReps", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  573. }
  574. else rrdset_next(st);
  575. rrddim_set_by_pointer(st, rd_InEchoReps, (collected_number)snmp_root.icmpmsg_InEchoReps);
  576. rrddim_set_by_pointer(st, rd_OutEchoReps, (collected_number)snmp_root.icmpmsg_OutEchoReps);
  577. rrddim_set_by_pointer(st, rd_InDestUnreachs, (collected_number)snmp_root.icmpmsg_InDestUnreachs);
  578. rrddim_set_by_pointer(st, rd_OutDestUnreachs, (collected_number)snmp_root.icmpmsg_OutDestUnreachs);
  579. rrddim_set_by_pointer(st, rd_InRedirects, (collected_number)snmp_root.icmpmsg_InRedirects);
  580. rrddim_set_by_pointer(st, rd_OutRedirects, (collected_number)snmp_root.icmpmsg_OutRedirects);
  581. rrddim_set_by_pointer(st, rd_InEchos, (collected_number)snmp_root.icmpmsg_InEchos);
  582. rrddim_set_by_pointer(st, rd_OutEchos, (collected_number)snmp_root.icmpmsg_OutEchos);
  583. rrddim_set_by_pointer(st, rd_InRouterAdvert, (collected_number)snmp_root.icmpmsg_InRouterAdvert);
  584. rrddim_set_by_pointer(st, rd_OutRouterAdvert, (collected_number)snmp_root.icmpmsg_OutRouterAdvert);
  585. rrddim_set_by_pointer(st, rd_InRouterSelect, (collected_number)snmp_root.icmpmsg_InRouterSelect);
  586. rrddim_set_by_pointer(st, rd_OutRouterSelect, (collected_number)snmp_root.icmpmsg_OutRouterSelect);
  587. rrddim_set_by_pointer(st, rd_InTimeExcds, (collected_number)snmp_root.icmpmsg_InTimeExcds);
  588. rrddim_set_by_pointer(st, rd_OutTimeExcds, (collected_number)snmp_root.icmpmsg_OutTimeExcds);
  589. rrddim_set_by_pointer(st, rd_InParmProbs, (collected_number)snmp_root.icmpmsg_InParmProbs);
  590. rrddim_set_by_pointer(st, rd_OutParmProbs, (collected_number)snmp_root.icmpmsg_OutParmProbs);
  591. rrddim_set_by_pointer(st, rd_InTimestamps, (collected_number)snmp_root.icmpmsg_InTimestamps);
  592. rrddim_set_by_pointer(st, rd_OutTimestamps, (collected_number)snmp_root.icmpmsg_OutTimestamps);
  593. rrddim_set_by_pointer(st, rd_InTimestampReps, (collected_number)snmp_root.icmpmsg_InTimestampReps);
  594. rrddim_set_by_pointer(st, rd_OutTimestampReps, (collected_number)snmp_root.icmpmsg_OutTimestampReps);
  595. rrdset_done(st);
  596. }
  597. }
  598. else if(unlikely(hash == hash_tcp && strcmp(key, "Tcp") == 0)) {
  599. size_t h = l++;
  600. if(strcmp(procfile_lineword(ff, l, 0), "Tcp") != 0) {
  601. error("Cannot read Tcp line from /proc/net/snmp.");
  602. break;
  603. }
  604. words = procfile_linewords(ff, l);
  605. if(words < 3) {
  606. error("Cannot read /proc/net/snmp Tcp line. Expected 3+ params, read %zu.", words);
  607. continue;
  608. }
  609. arl_begin(arl_tcp);
  610. for(w = 1; w < words ; w++) {
  611. if (unlikely(arl_check(arl_tcp, procfile_lineword(ff, h, w), procfile_lineword(ff, l, w)) != 0))
  612. break;
  613. }
  614. // --------------------------------------------------------------------
  615. // this is smart enough to update it, only when it is changed
  616. rrdvar_custom_host_variable_set(localhost, tcp_max_connections_var, snmp_root.tcp_MaxConn);
  617. // --------------------------------------------------------------------
  618. // see http://net-snmp.sourceforge.net/docs/mibs/tcp.html
  619. if(do_tcp_sockets == CONFIG_BOOLEAN_YES || (do_tcp_sockets == CONFIG_BOOLEAN_AUTO &&
  620. (snmp_root.tcp_CurrEstab ||
  621. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  622. do_tcp_sockets = CONFIG_BOOLEAN_YES;
  623. static RRDSET *st = NULL;
  624. static RRDDIM *rd_CurrEstab = NULL;
  625. if(unlikely(!st)) {
  626. st = rrdset_create_localhost(
  627. RRD_TYPE_NET_SNMP
  628. , "tcpsock"
  629. , NULL
  630. , "tcp"
  631. , NULL
  632. , "IPv4 TCP Connections"
  633. , "active connections"
  634. , PLUGIN_PROC_NAME
  635. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  636. , NETDATA_CHART_PRIO_IPV4_TCP
  637. , update_every
  638. , RRDSET_TYPE_LINE
  639. );
  640. rd_CurrEstab = rrddim_add(st, "CurrEstab", "connections", 1, 1, RRD_ALGORITHM_ABSOLUTE);
  641. }
  642. else rrdset_next(st);
  643. rrddim_set_by_pointer(st, rd_CurrEstab, (collected_number)snmp_root.tcp_CurrEstab);
  644. rrdset_done(st);
  645. }
  646. // --------------------------------------------------------------------
  647. if(do_tcp_packets == CONFIG_BOOLEAN_YES || (do_tcp_packets == CONFIG_BOOLEAN_AUTO &&
  648. (snmp_root.tcp_InSegs ||
  649. snmp_root.tcp_OutSegs ||
  650. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  651. do_tcp_packets = CONFIG_BOOLEAN_YES;
  652. static RRDSET *st = NULL;
  653. static RRDDIM *rd_InSegs = NULL,
  654. *rd_OutSegs = NULL;
  655. if(unlikely(!st)) {
  656. st = rrdset_create_localhost(
  657. RRD_TYPE_NET_SNMP
  658. , "tcppackets"
  659. , NULL
  660. , "tcp"
  661. , NULL
  662. , "IPv4 TCP Packets"
  663. , "packets/s"
  664. , PLUGIN_PROC_NAME
  665. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  666. , NETDATA_CHART_PRIO_IPV4_TCP + 4
  667. , update_every
  668. , RRDSET_TYPE_LINE
  669. );
  670. rd_InSegs = rrddim_add(st, "InSegs", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  671. rd_OutSegs = rrddim_add(st, "OutSegs", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  672. }
  673. else rrdset_next(st);
  674. rrddim_set_by_pointer(st, rd_InSegs, (collected_number)snmp_root.tcp_InSegs);
  675. rrddim_set_by_pointer(st, rd_OutSegs, (collected_number)snmp_root.tcp_OutSegs);
  676. rrdset_done(st);
  677. }
  678. // --------------------------------------------------------------------
  679. if(do_tcp_errors == CONFIG_BOOLEAN_YES || (do_tcp_errors == CONFIG_BOOLEAN_AUTO &&
  680. (snmp_root.tcp_InErrs ||
  681. snmp_root.tcp_InCsumErrors ||
  682. snmp_root.tcp_RetransSegs ||
  683. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  684. do_tcp_errors = CONFIG_BOOLEAN_YES;
  685. static RRDSET *st = NULL;
  686. static RRDDIM *rd_InErrs = NULL,
  687. *rd_InCsumErrors = NULL,
  688. *rd_RetransSegs = NULL;
  689. if(unlikely(!st)) {
  690. st = rrdset_create_localhost(
  691. RRD_TYPE_NET_SNMP
  692. , "tcperrors"
  693. , NULL
  694. , "tcp"
  695. , NULL
  696. , "IPv4 TCP Errors"
  697. , "packets/s"
  698. , PLUGIN_PROC_NAME
  699. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  700. , NETDATA_CHART_PRIO_IPV4_TCP + 20
  701. , update_every
  702. , RRDSET_TYPE_LINE
  703. );
  704. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  705. rd_InErrs = rrddim_add(st, "InErrs", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  706. rd_InCsumErrors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  707. rd_RetransSegs = rrddim_add(st, "RetransSegs", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  708. }
  709. else rrdset_next(st);
  710. rrddim_set_by_pointer(st, rd_InErrs, (collected_number)snmp_root.tcp_InErrs);
  711. rrddim_set_by_pointer(st, rd_InCsumErrors, (collected_number)snmp_root.tcp_InCsumErrors);
  712. rrddim_set_by_pointer(st, rd_RetransSegs, (collected_number)snmp_root.tcp_RetransSegs);
  713. rrdset_done(st);
  714. }
  715. // --------------------------------------------------------------------
  716. if(do_tcp_opens == CONFIG_BOOLEAN_YES || (do_tcp_opens == CONFIG_BOOLEAN_AUTO &&
  717. (snmp_root.tcp_ActiveOpens ||
  718. snmp_root.tcp_PassiveOpens ||
  719. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  720. do_tcp_opens = CONFIG_BOOLEAN_YES;
  721. static RRDSET *st = NULL;
  722. static RRDDIM *rd_ActiveOpens = NULL,
  723. *rd_PassiveOpens = NULL;
  724. if(unlikely(!st)) {
  725. st = rrdset_create_localhost(
  726. RRD_TYPE_NET_SNMP
  727. , "tcpopens"
  728. , NULL
  729. , "tcp"
  730. , NULL
  731. , "IPv4 TCP Opens"
  732. , "connections/s"
  733. , PLUGIN_PROC_NAME
  734. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  735. , NETDATA_CHART_PRIO_IPV4_TCP + 5
  736. , update_every
  737. , RRDSET_TYPE_LINE
  738. );
  739. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  740. rd_ActiveOpens = rrddim_add(st, "ActiveOpens", "active", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  741. rd_PassiveOpens = rrddim_add(st, "PassiveOpens", "passive", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  742. }
  743. else rrdset_next(st);
  744. rrddim_set_by_pointer(st, rd_ActiveOpens, (collected_number)snmp_root.tcp_ActiveOpens);
  745. rrddim_set_by_pointer(st, rd_PassiveOpens, (collected_number)snmp_root.tcp_PassiveOpens);
  746. rrdset_done(st);
  747. }
  748. // --------------------------------------------------------------------
  749. if(do_tcp_handshake == CONFIG_BOOLEAN_YES || (do_tcp_handshake == CONFIG_BOOLEAN_AUTO &&
  750. (snmp_root.tcp_EstabResets ||
  751. snmp_root.tcp_OutRsts ||
  752. snmp_root.tcp_AttemptFails ||
  753. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  754. do_tcp_handshake = CONFIG_BOOLEAN_YES;
  755. static RRDSET *st = NULL;
  756. static RRDDIM *rd_EstabResets = NULL,
  757. *rd_OutRsts = NULL,
  758. *rd_AttemptFails = NULL,
  759. *rd_TCPSynRetrans = NULL;
  760. if(unlikely(!st)) {
  761. st = rrdset_create_localhost(
  762. RRD_TYPE_NET_SNMP
  763. , "tcphandshake"
  764. , NULL
  765. , "tcp"
  766. , NULL
  767. , "IPv4 TCP Handshake Issues"
  768. , "events/s"
  769. , PLUGIN_PROC_NAME
  770. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  771. , NETDATA_CHART_PRIO_IPV4_TCP + 30
  772. , update_every
  773. , RRDSET_TYPE_LINE
  774. );
  775. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  776. rd_EstabResets = rrddim_add(st, "EstabResets", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  777. rd_OutRsts = rrddim_add(st, "OutRsts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  778. rd_AttemptFails = rrddim_add(st, "AttemptFails", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  779. rd_TCPSynRetrans = rrddim_add(st, "TCPSynRetrans", "SynRetrans", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  780. }
  781. else rrdset_next(st);
  782. rrddim_set_by_pointer(st, rd_EstabResets, (collected_number)snmp_root.tcp_EstabResets);
  783. rrddim_set_by_pointer(st, rd_OutRsts, (collected_number)snmp_root.tcp_OutRsts);
  784. rrddim_set_by_pointer(st, rd_AttemptFails, (collected_number)snmp_root.tcp_AttemptFails);
  785. rrddim_set_by_pointer(st, rd_TCPSynRetrans, tcpext_TCPSynRetrans);
  786. rrdset_done(st);
  787. }
  788. }
  789. else if(unlikely(hash == hash_udp && strcmp(key, "Udp") == 0)) {
  790. size_t h = l++;
  791. if(strcmp(procfile_lineword(ff, l, 0), "Udp") != 0) {
  792. error("Cannot read Udp line from /proc/net/snmp.");
  793. break;
  794. }
  795. words = procfile_linewords(ff, l);
  796. if(words < 3) {
  797. error("Cannot read /proc/net/snmp Udp line. Expected 3+ params, read %zu.", words);
  798. continue;
  799. }
  800. arl_begin(arl_udp);
  801. for(w = 1; w < words ; w++) {
  802. if (unlikely(arl_check(arl_udp, procfile_lineword(ff, h, w), procfile_lineword(ff, l, w)) != 0))
  803. break;
  804. }
  805. // --------------------------------------------------------------------
  806. // see http://net-snmp.sourceforge.net/docs/mibs/udp.html
  807. if(do_udp_packets == CONFIG_BOOLEAN_YES || (do_udp_packets == CONFIG_BOOLEAN_AUTO &&
  808. (snmp_root.udp_InDatagrams ||
  809. snmp_root.udp_OutDatagrams ||
  810. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  811. do_udp_packets = CONFIG_BOOLEAN_YES;
  812. static RRDSET *st = NULL;
  813. static RRDDIM *rd_InDatagrams = NULL,
  814. *rd_OutDatagrams = NULL;
  815. if(unlikely(!st)) {
  816. st = rrdset_create_localhost(
  817. RRD_TYPE_NET_SNMP
  818. , "udppackets"
  819. , NULL
  820. , "udp"
  821. , NULL
  822. , "IPv4 UDP Packets"
  823. , "packets/s"
  824. , PLUGIN_PROC_NAME
  825. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  826. , NETDATA_CHART_PRIO_IPV4_UDP
  827. , update_every
  828. , RRDSET_TYPE_LINE
  829. );
  830. rd_InDatagrams = rrddim_add(st, "InDatagrams", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  831. rd_OutDatagrams = rrddim_add(st, "OutDatagrams", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  832. }
  833. else rrdset_next(st);
  834. rrddim_set_by_pointer(st, rd_InDatagrams, (collected_number)snmp_root.udp_InDatagrams);
  835. rrddim_set_by_pointer(st, rd_OutDatagrams, (collected_number)snmp_root.udp_OutDatagrams);
  836. rrdset_done(st);
  837. }
  838. // --------------------------------------------------------------------
  839. if(do_udp_errors == CONFIG_BOOLEAN_YES || (do_udp_errors == CONFIG_BOOLEAN_AUTO &&
  840. (snmp_root.udp_InErrors ||
  841. snmp_root.udp_NoPorts ||
  842. snmp_root.udp_RcvbufErrors ||
  843. snmp_root.udp_SndbufErrors ||
  844. snmp_root.udp_InCsumErrors ||
  845. snmp_root.udp_IgnoredMulti ||
  846. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  847. do_udp_errors = CONFIG_BOOLEAN_YES;
  848. static RRDSET *st = NULL;
  849. static RRDDIM *rd_RcvbufErrors = NULL,
  850. *rd_SndbufErrors = NULL,
  851. *rd_InErrors = NULL,
  852. *rd_NoPorts = NULL,
  853. *rd_InCsumErrors = NULL,
  854. *rd_IgnoredMulti = NULL;
  855. if(unlikely(!st)) {
  856. st = rrdset_create_localhost(
  857. RRD_TYPE_NET_SNMP
  858. , "udperrors"
  859. , NULL
  860. , "udp"
  861. , NULL
  862. , "IPv4 UDP Errors"
  863. , "events/s"
  864. , PLUGIN_PROC_NAME
  865. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  866. , NETDATA_CHART_PRIO_IPV4_UDP + 10
  867. , update_every
  868. , RRDSET_TYPE_LINE
  869. );
  870. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  871. rd_RcvbufErrors = rrddim_add(st, "RcvbufErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  872. rd_SndbufErrors = rrddim_add(st, "SndbufErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  873. rd_InErrors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  874. rd_NoPorts = rrddim_add(st, "NoPorts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  875. rd_InCsumErrors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  876. rd_IgnoredMulti = rrddim_add(st, "IgnoredMulti", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  877. }
  878. else rrdset_next(st);
  879. rrddim_set_by_pointer(st, rd_InErrors, (collected_number)snmp_root.udp_InErrors);
  880. rrddim_set_by_pointer(st, rd_NoPorts, (collected_number)snmp_root.udp_NoPorts);
  881. rrddim_set_by_pointer(st, rd_RcvbufErrors, (collected_number)snmp_root.udp_RcvbufErrors);
  882. rrddim_set_by_pointer(st, rd_SndbufErrors, (collected_number)snmp_root.udp_SndbufErrors);
  883. rrddim_set_by_pointer(st, rd_InCsumErrors, (collected_number)snmp_root.udp_InCsumErrors);
  884. rrddim_set_by_pointer(st, rd_IgnoredMulti, (collected_number)snmp_root.udp_IgnoredMulti);
  885. rrdset_done(st);
  886. }
  887. }
  888. else if(unlikely(hash == hash_udplite && strcmp(key, "UdpLite") == 0)) {
  889. size_t h = l++;
  890. if(strcmp(procfile_lineword(ff, l, 0), "UdpLite") != 0) {
  891. error("Cannot read UdpLite line from /proc/net/snmp.");
  892. break;
  893. }
  894. words = procfile_linewords(ff, l);
  895. if(words < 3) {
  896. error("Cannot read /proc/net/snmp UdpLite line. Expected 3+ params, read %zu.", words);
  897. continue;
  898. }
  899. arl_begin(arl_udplite);
  900. for(w = 1; w < words ; w++) {
  901. if (unlikely(arl_check(arl_udplite, procfile_lineword(ff, h, w), procfile_lineword(ff, l, w)) != 0))
  902. break;
  903. }
  904. // --------------------------------------------------------------------
  905. if(do_udplite_packets == CONFIG_BOOLEAN_YES || (do_udplite_packets == CONFIG_BOOLEAN_AUTO &&
  906. (snmp_root.udplite_InDatagrams ||
  907. snmp_root.udplite_OutDatagrams ||
  908. snmp_root.udplite_NoPorts ||
  909. snmp_root.udplite_InErrors ||
  910. snmp_root.udplite_InCsumErrors ||
  911. snmp_root.udplite_RcvbufErrors ||
  912. snmp_root.udplite_SndbufErrors ||
  913. snmp_root.udplite_IgnoredMulti ||
  914. netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) {
  915. do_udplite_packets = CONFIG_BOOLEAN_YES;
  916. {
  917. static RRDSET *st = NULL;
  918. static RRDDIM *rd_InDatagrams = NULL,
  919. *rd_OutDatagrams = NULL;
  920. if(unlikely(!st)) {
  921. st = rrdset_create_localhost(
  922. RRD_TYPE_NET_SNMP
  923. , "udplite"
  924. , NULL
  925. , "udplite"
  926. , NULL
  927. , "IPv4 UDPLite Packets"
  928. , "packets/s"
  929. , PLUGIN_PROC_NAME
  930. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  931. , NETDATA_CHART_PRIO_IPV4_UDPLITE
  932. , update_every
  933. , RRDSET_TYPE_LINE
  934. );
  935. rd_InDatagrams = rrddim_add(st, "InDatagrams", "received", 1, 1, RRD_ALGORITHM_INCREMENTAL);
  936. rd_OutDatagrams = rrddim_add(st, "OutDatagrams", "sent", -1, 1, RRD_ALGORITHM_INCREMENTAL);
  937. }
  938. else rrdset_next(st);
  939. rrddim_set_by_pointer(st, rd_InDatagrams, (collected_number)snmp_root.udplite_InDatagrams);
  940. rrddim_set_by_pointer(st, rd_OutDatagrams, (collected_number)snmp_root.udplite_OutDatagrams);
  941. rrdset_done(st);
  942. }
  943. {
  944. static RRDSET *st = NULL;
  945. static RRDDIM *rd_RcvbufErrors = NULL,
  946. *rd_SndbufErrors = NULL,
  947. *rd_InErrors = NULL,
  948. *rd_NoPorts = NULL,
  949. *rd_InCsumErrors = NULL,
  950. *rd_IgnoredMulti = NULL;
  951. if(unlikely(!st)) {
  952. st = rrdset_create_localhost(
  953. RRD_TYPE_NET_SNMP
  954. , "udplite_errors"
  955. , NULL
  956. , "udplite"
  957. , NULL
  958. , "IPv4 UDPLite Errors"
  959. , "packets/s"
  960. , PLUGIN_PROC_NAME
  961. , PLUGIN_PROC_MODULE_NET_SNMP_NAME
  962. , NETDATA_CHART_PRIO_IPV4_UDPLITE + 10
  963. , update_every
  964. , RRDSET_TYPE_LINE);
  965. rd_RcvbufErrors = rrddim_add(st, "RcvbufErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  966. rd_SndbufErrors = rrddim_add(st, "SndbufErrors", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  967. rd_InErrors = rrddim_add(st, "InErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  968. rd_NoPorts = rrddim_add(st, "NoPorts", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  969. rd_InCsumErrors = rrddim_add(st, "InCsumErrors", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  970. rd_IgnoredMulti = rrddim_add(st, "IgnoredMulti", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  971. }
  972. else rrdset_next(st);
  973. rrddim_set_by_pointer(st, rd_NoPorts, (collected_number)snmp_root.udplite_NoPorts);
  974. rrddim_set_by_pointer(st, rd_InErrors, (collected_number)snmp_root.udplite_InErrors);
  975. rrddim_set_by_pointer(st, rd_InCsumErrors, (collected_number)snmp_root.udplite_InCsumErrors);
  976. rrddim_set_by_pointer(st, rd_RcvbufErrors, (collected_number)snmp_root.udplite_RcvbufErrors);
  977. rrddim_set_by_pointer(st, rd_SndbufErrors, (collected_number)snmp_root.udplite_SndbufErrors);
  978. rrddim_set_by_pointer(st, rd_IgnoredMulti, (collected_number)snmp_root.udplite_IgnoredMulti);
  979. rrdset_done(st);
  980. }
  981. }
  982. }
  983. }
  984. return 0;
  985. }