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