proc_net_rpc_nfs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #include "plugin_proc.h"
  3. #define PLUGIN_PROC_MODULE_NFS_NAME "/proc/net/rpc/nfs"
  4. #define CONFIG_SECTION_PLUGIN_PROC_NFS "plugin:" PLUGIN_PROC_CONFIG_NAME ":" PLUGIN_PROC_MODULE_NFS_NAME
  5. struct nfs_procs {
  6. char name[30];
  7. unsigned long long value;
  8. int present;
  9. RRDDIM *rd;
  10. };
  11. struct nfs_procs nfs_proc2_values[] = {
  12. { "null" , 0ULL, 0, NULL}
  13. , {"getattr" , 0ULL, 0, NULL}
  14. , {"setattr" , 0ULL, 0, NULL}
  15. , {"root" , 0ULL, 0, NULL}
  16. , {"lookup" , 0ULL, 0, NULL}
  17. , {"readlink", 0ULL, 0, NULL}
  18. , {"read" , 0ULL, 0, NULL}
  19. , {"wrcache" , 0ULL, 0, NULL}
  20. , {"write" , 0ULL, 0, NULL}
  21. , {"create" , 0ULL, 0, NULL}
  22. , {"remove" , 0ULL, 0, NULL}
  23. , {"rename" , 0ULL, 0, NULL}
  24. , {"link" , 0ULL, 0, NULL}
  25. , {"symlink" , 0ULL, 0, NULL}
  26. , {"mkdir" , 0ULL, 0, NULL}
  27. , {"rmdir" , 0ULL, 0, NULL}
  28. , {"readdir" , 0ULL, 0, NULL}
  29. , {"fsstat" , 0ULL, 0, NULL}
  30. ,
  31. /* termination */
  32. { "" , 0ULL, 0, NULL}
  33. };
  34. struct nfs_procs nfs_proc3_values[] = {
  35. { "null" , 0ULL, 0, NULL}
  36. , {"getattr" , 0ULL, 0, NULL}
  37. , {"setattr" , 0ULL, 0, NULL}
  38. , {"lookup" , 0ULL, 0, NULL}
  39. , {"access" , 0ULL, 0, NULL}
  40. , {"readlink" , 0ULL, 0, NULL}
  41. , {"read" , 0ULL, 0, NULL}
  42. , {"write" , 0ULL, 0, NULL}
  43. , {"create" , 0ULL, 0, NULL}
  44. , {"mkdir" , 0ULL, 0, NULL}
  45. , {"symlink" , 0ULL, 0, NULL}
  46. , {"mknod" , 0ULL, 0, NULL}
  47. , {"remove" , 0ULL, 0, NULL}
  48. , {"rmdir" , 0ULL, 0, NULL}
  49. , {"rename" , 0ULL, 0, NULL}
  50. , {"link" , 0ULL, 0, NULL}
  51. , {"readdir" , 0ULL, 0, NULL}
  52. , {"readdirplus", 0ULL, 0, NULL}
  53. , {"fsstat" , 0ULL, 0, NULL}
  54. , {"fsinfo" , 0ULL, 0, NULL}
  55. , {"pathconf" , 0ULL, 0, NULL}
  56. , {"commit" , 0ULL, 0, NULL}
  57. ,
  58. /* termination */
  59. { "" , 0ULL, 0, NULL}
  60. };
  61. struct nfs_procs nfs_proc4_values[] = {
  62. { "null" , 0ULL, 0, NULL}
  63. , {"read" , 0ULL, 0, NULL}
  64. , {"write" , 0ULL, 0, NULL}
  65. , {"commit" , 0ULL, 0, NULL}
  66. , {"open" , 0ULL, 0, NULL}
  67. , {"open_conf" , 0ULL, 0, NULL}
  68. , {"open_noat" , 0ULL, 0, NULL}
  69. , {"open_dgrd" , 0ULL, 0, NULL}
  70. , {"close" , 0ULL, 0, NULL}
  71. , {"setattr" , 0ULL, 0, NULL}
  72. , {"fsinfo" , 0ULL, 0, NULL}
  73. , {"renew" , 0ULL, 0, NULL}
  74. , {"setclntid" , 0ULL, 0, NULL}
  75. , {"confirm" , 0ULL, 0, NULL}
  76. , {"lock" , 0ULL, 0, NULL}
  77. , {"lockt" , 0ULL, 0, NULL}
  78. , {"locku" , 0ULL, 0, NULL}
  79. , {"access" , 0ULL, 0, NULL}
  80. , {"getattr" , 0ULL, 0, NULL}
  81. , {"lookup" , 0ULL, 0, NULL}
  82. , {"lookup_root" , 0ULL, 0, NULL}
  83. , {"remove" , 0ULL, 0, NULL}
  84. , {"rename" , 0ULL, 0, NULL}
  85. , {"link" , 0ULL, 0, NULL}
  86. , {"symlink" , 0ULL, 0, NULL}
  87. , {"create" , 0ULL, 0, NULL}
  88. , {"pathconf" , 0ULL, 0, NULL}
  89. , {"statfs" , 0ULL, 0, NULL}
  90. , {"readlink" , 0ULL, 0, NULL}
  91. , {"readdir" , 0ULL, 0, NULL}
  92. , {"server_caps" , 0ULL, 0, NULL}
  93. , {"delegreturn" , 0ULL, 0, NULL}
  94. , {"getacl" , 0ULL, 0, NULL}
  95. , {"setacl" , 0ULL, 0, NULL}
  96. , {"fs_locations" , 0ULL, 0, NULL}
  97. , {"rel_lkowner" , 0ULL, 0, NULL}
  98. , {"secinfo" , 0ULL, 0, NULL}
  99. , {"fsid_present" , 0ULL, 0, NULL}
  100. ,
  101. /* nfsv4.1 client ops */
  102. { "exchange_id" , 0ULL, 0, NULL}
  103. , {"create_session" , 0ULL, 0, NULL}
  104. , {"destroy_session" , 0ULL, 0, NULL}
  105. , {"sequence" , 0ULL, 0, NULL}
  106. , {"get_lease_time" , 0ULL, 0, NULL}
  107. , {"reclaim_comp" , 0ULL, 0, NULL}
  108. , {"layoutget" , 0ULL, 0, NULL}
  109. , {"getdevinfo" , 0ULL, 0, NULL}
  110. , {"layoutcommit" , 0ULL, 0, NULL}
  111. , {"layoutreturn" , 0ULL, 0, NULL}
  112. , {"secinfo_no" , 0ULL, 0, NULL}
  113. , {"test_stateid" , 0ULL, 0, NULL}
  114. , {"free_stateid" , 0ULL, 0, NULL}
  115. , {"getdevicelist" , 0ULL, 0, NULL}
  116. , {"bind_conn_to_ses", 0ULL, 0, NULL}
  117. , {"destroy_clientid", 0ULL, 0, NULL}
  118. ,
  119. /* nfsv4.2 client ops */
  120. { "seek" , 0ULL, 0, NULL}
  121. , {"allocate" , 0ULL, 0, NULL}
  122. , {"deallocate" , 0ULL, 0, NULL}
  123. , {"layoutstats" , 0ULL, 0, NULL}
  124. , {"clone" , 0ULL, 0, NULL}
  125. ,
  126. /* termination */
  127. { "" , 0ULL, 0, NULL}
  128. };
  129. int do_proc_net_rpc_nfs(int update_every, usec_t dt) {
  130. (void)dt;
  131. static procfile *ff = NULL;
  132. static int do_net = -1, do_rpc = -1, do_proc2 = -1, do_proc3 = -1, do_proc4 = -1;
  133. static int proc2_warning = 0, proc3_warning = 0, proc4_warning = 0;
  134. if(!ff) {
  135. char filename[FILENAME_MAX + 1];
  136. snprintfz(filename, FILENAME_MAX, "%s%s", netdata_configured_host_prefix, "/proc/net/rpc/nfs");
  137. ff = procfile_open(config_get(CONFIG_SECTION_PLUGIN_PROC_NFS, "filename to monitor", filename), " \t", PROCFILE_FLAG_DEFAULT);
  138. }
  139. if(!ff) return 1;
  140. ff = procfile_readall(ff);
  141. if(!ff) return 0; // we return 0, so that we will retry to open it next time
  142. if(do_net == -1) do_net = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_NFS, "network", 1);
  143. if(do_rpc == -1) do_rpc = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_NFS, "rpc", 1);
  144. if(do_proc2 == -1) do_proc2 = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_NFS, "NFS v2 procedures", 1);
  145. if(do_proc3 == -1) do_proc3 = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_NFS, "NFS v3 procedures", 1);
  146. if(do_proc4 == -1) do_proc4 = config_get_boolean(CONFIG_SECTION_PLUGIN_PROC_NFS, "NFS v4 procedures", 1);
  147. // if they are enabled, reset them to 1
  148. // later we do them =2 to avoid doing strcmp() for all lines
  149. if(do_net) do_net = 1;
  150. if(do_rpc) do_rpc = 1;
  151. if(do_proc2) do_proc2 = 1;
  152. if(do_proc3) do_proc3 = 1;
  153. if(do_proc4) do_proc4 = 1;
  154. size_t lines = procfile_lines(ff), l;
  155. char *type;
  156. unsigned long long net_count = 0, net_udp_count = 0, net_tcp_count = 0, net_tcp_connections = 0;
  157. unsigned long long rpc_calls = 0, rpc_retransmits = 0, rpc_auth_refresh = 0;
  158. for(l = 0; l < lines ;l++) {
  159. size_t words = procfile_linewords(ff, l);
  160. if(!words) continue;
  161. type = procfile_lineword(ff, l, 0);
  162. if(do_net == 1 && strcmp(type, "net") == 0) {
  163. if(words < 5) {
  164. collector_error("%s line of /proc/net/rpc/nfs has %zu words, expected %d", type, words, 5);
  165. continue;
  166. }
  167. net_count = str2ull(procfile_lineword(ff, l, 1), NULL);
  168. net_udp_count = str2ull(procfile_lineword(ff, l, 2), NULL);
  169. net_tcp_count = str2ull(procfile_lineword(ff, l, 3), NULL);
  170. net_tcp_connections = str2ull(procfile_lineword(ff, l, 4), NULL);
  171. unsigned long long sum = net_count + net_udp_count + net_tcp_count + net_tcp_connections;
  172. if(sum == 0ULL) do_net = -1;
  173. else do_net = 2;
  174. }
  175. else if(do_rpc == 1 && strcmp(type, "rpc") == 0) {
  176. if(words < 4) {
  177. collector_error("%s line of /proc/net/rpc/nfs has %zu words, expected %d", type, words, 6);
  178. continue;
  179. }
  180. rpc_calls = str2ull(procfile_lineword(ff, l, 1), NULL);
  181. rpc_retransmits = str2ull(procfile_lineword(ff, l, 2), NULL);
  182. rpc_auth_refresh = str2ull(procfile_lineword(ff, l, 3), NULL);
  183. unsigned long long sum = rpc_calls + rpc_retransmits + rpc_auth_refresh;
  184. if(sum == 0ULL) do_rpc = -1;
  185. else do_rpc = 2;
  186. }
  187. else if(do_proc2 == 1 && strcmp(type, "proc2") == 0) {
  188. // the first number is the count of numbers present
  189. // so we start for word 2
  190. unsigned long long sum = 0;
  191. unsigned int i, j;
  192. for(i = 0, j = 2; j < words && nfs_proc2_values[i].name[0] ; i++, j++) {
  193. nfs_proc2_values[i].value = str2ull(procfile_lineword(ff, l, j), NULL);
  194. nfs_proc2_values[i].present = 1;
  195. sum += nfs_proc2_values[i].value;
  196. }
  197. if(sum == 0ULL) {
  198. if(!proc2_warning) {
  199. collector_error("Disabling /proc/net/rpc/nfs v2 procedure calls chart. It seems unused on this machine. It will be enabled automatically when found with data in it.");
  200. proc2_warning = 1;
  201. }
  202. do_proc2 = 0;
  203. }
  204. else do_proc2 = 2;
  205. }
  206. else if(do_proc3 == 1 && strcmp(type, "proc3") == 0) {
  207. // the first number is the count of numbers present
  208. // so we start for word 2
  209. unsigned long long sum = 0;
  210. unsigned int i, j;
  211. for(i = 0, j = 2; j < words && nfs_proc3_values[i].name[0] ; i++, j++) {
  212. nfs_proc3_values[i].value = str2ull(procfile_lineword(ff, l, j), NULL);
  213. nfs_proc3_values[i].present = 1;
  214. sum += nfs_proc3_values[i].value;
  215. }
  216. if(sum == 0ULL) {
  217. if(!proc3_warning) {
  218. collector_info("Disabling /proc/net/rpc/nfs v3 procedure calls chart. It seems unused on this machine. It will be enabled automatically when found with data in it.");
  219. proc3_warning = 1;
  220. }
  221. do_proc3 = 0;
  222. }
  223. else do_proc3 = 2;
  224. }
  225. else if(do_proc4 == 1 && strcmp(type, "proc4") == 0) {
  226. // the first number is the count of numbers present
  227. // so we start for word 2
  228. unsigned long long sum = 0;
  229. unsigned int i, j;
  230. for(i = 0, j = 2; j < words && nfs_proc4_values[i].name[0] ; i++, j++) {
  231. nfs_proc4_values[i].value = str2ull(procfile_lineword(ff, l, j), NULL);
  232. nfs_proc4_values[i].present = 1;
  233. sum += nfs_proc4_values[i].value;
  234. }
  235. if(sum == 0ULL) {
  236. if(!proc4_warning) {
  237. collector_info("Disabling /proc/net/rpc/nfs v4 procedure calls chart. It seems unused on this machine. It will be enabled automatically when found with data in it.");
  238. proc4_warning = 1;
  239. }
  240. do_proc4 = 0;
  241. }
  242. else do_proc4 = 2;
  243. }
  244. }
  245. if(do_net == 2) {
  246. static RRDSET *st = NULL;
  247. static RRDDIM *rd_udp = NULL,
  248. *rd_tcp = NULL;
  249. if(unlikely(!st)) {
  250. st = rrdset_create_localhost(
  251. "nfs"
  252. , "net"
  253. , NULL
  254. , "network"
  255. , NULL
  256. , "NFS Client Network"
  257. , "operations/s"
  258. , PLUGIN_PROC_NAME
  259. , PLUGIN_PROC_MODULE_NFS_NAME
  260. , NETDATA_CHART_PRIO_NFS_NET
  261. , update_every
  262. , RRDSET_TYPE_STACKED
  263. );
  264. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  265. rd_udp = rrddim_add(st, "udp", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  266. rd_tcp = rrddim_add(st, "tcp", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  267. }
  268. // ignore net_count, net_tcp_connections
  269. (void)net_count;
  270. (void)net_tcp_connections;
  271. rrddim_set_by_pointer(st, rd_udp, net_udp_count);
  272. rrddim_set_by_pointer(st, rd_tcp, net_tcp_count);
  273. rrdset_done(st);
  274. }
  275. if(do_rpc == 2) {
  276. static RRDSET *st = NULL;
  277. static RRDDIM *rd_calls = NULL,
  278. *rd_retransmits = NULL,
  279. *rd_auth_refresh = NULL;
  280. if(unlikely(!st)) {
  281. st = rrdset_create_localhost(
  282. "nfs"
  283. , "rpc"
  284. , NULL
  285. , "rpc"
  286. , NULL
  287. , "NFS Client Remote Procedure Calls Statistics"
  288. , "calls/s"
  289. , PLUGIN_PROC_NAME
  290. , PLUGIN_PROC_MODULE_NFS_NAME
  291. , NETDATA_CHART_PRIO_NFS_RPC
  292. , update_every
  293. , RRDSET_TYPE_LINE
  294. );
  295. rrdset_flag_set(st, RRDSET_FLAG_DETAIL);
  296. rd_calls = rrddim_add(st, "calls", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  297. rd_retransmits = rrddim_add(st, "retransmits", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  298. rd_auth_refresh = rrddim_add(st, "auth_refresh", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL);
  299. }
  300. rrddim_set_by_pointer(st, rd_calls, rpc_calls);
  301. rrddim_set_by_pointer(st, rd_retransmits, rpc_retransmits);
  302. rrddim_set_by_pointer(st, rd_auth_refresh, rpc_auth_refresh);
  303. rrdset_done(st);
  304. }
  305. if(do_proc2 == 2) {
  306. static RRDSET *st = NULL;
  307. if(unlikely(!st)) {
  308. st = rrdset_create_localhost(
  309. "nfs"
  310. , "proc2"
  311. , NULL
  312. , "nfsv2rpc"
  313. , NULL
  314. , "NFS v2 Client Remote Procedure Calls"
  315. , "calls/s"
  316. , PLUGIN_PROC_NAME
  317. , PLUGIN_PROC_MODULE_NFS_NAME
  318. , NETDATA_CHART_PRIO_NFS_PROC2
  319. , update_every
  320. , RRDSET_TYPE_STACKED
  321. );
  322. }
  323. size_t i;
  324. for(i = 0; nfs_proc2_values[i].present ; i++) {
  325. if(unlikely(!nfs_proc2_values[i].rd))
  326. nfs_proc2_values[i].rd = rrddim_add(st, nfs_proc2_values[i].name, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  327. rrddim_set_by_pointer(st, nfs_proc2_values[i].rd, nfs_proc2_values[i].value);
  328. }
  329. rrdset_done(st);
  330. }
  331. if(do_proc3 == 2) {
  332. static RRDSET *st = NULL;
  333. if(unlikely(!st)) {
  334. st = rrdset_create_localhost(
  335. "nfs"
  336. , "proc3"
  337. , NULL
  338. , "nfsv3rpc"
  339. , NULL
  340. , "NFS v3 Client Remote Procedure Calls"
  341. , "calls/s"
  342. , PLUGIN_PROC_NAME
  343. , PLUGIN_PROC_MODULE_NFS_NAME
  344. , NETDATA_CHART_PRIO_NFS_PROC3
  345. , update_every
  346. , RRDSET_TYPE_STACKED
  347. );
  348. }
  349. size_t i;
  350. for(i = 0; nfs_proc3_values[i].present ; i++) {
  351. if(unlikely(!nfs_proc3_values[i].rd))
  352. nfs_proc3_values[i].rd = rrddim_add(st, nfs_proc3_values[i].name, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  353. rrddim_set_by_pointer(st, nfs_proc3_values[i].rd, nfs_proc3_values[i].value);
  354. }
  355. rrdset_done(st);
  356. }
  357. if(do_proc4 == 2) {
  358. static RRDSET *st = NULL;
  359. if(unlikely(!st)) {
  360. st = rrdset_create_localhost(
  361. "nfs"
  362. , "proc4"
  363. , NULL
  364. , "nfsv4rpc"
  365. , NULL
  366. , "NFS v4 Client Remote Procedure Calls"
  367. , "calls/s"
  368. , PLUGIN_PROC_NAME
  369. , PLUGIN_PROC_MODULE_NFS_NAME
  370. , NETDATA_CHART_PRIO_NFS_PROC4
  371. , update_every
  372. , RRDSET_TYPE_STACKED
  373. );
  374. }
  375. size_t i;
  376. for(i = 0; nfs_proc4_values[i].present ; i++) {
  377. if(unlikely(!nfs_proc4_values[i].rd))
  378. nfs_proc4_values[i].rd = rrddim_add(st, nfs_proc4_values[i].name, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL);
  379. rrddim_set_by_pointer(st, nfs_proc4_values[i].rd, nfs_proc4_values[i].value);
  380. }
  381. rrdset_done(st);
  382. }
  383. return 0;
  384. }