]> arthur.barton.de Git - netdata.git/blob - src/proc_net_rpc_nfsd.c
added nfsd statistics (v2, v3 and v4)
[netdata.git] / src / proc_net_rpc_nfsd.c
1 #include <inttypes.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "log.h"
7 #include "config.h"
8 #include "procfile.h"
9 #include "rrd.h"
10 #include "plugin_proc.h"
11
12 struct nfsd_procs {
13         char name[30];
14         unsigned long long proc2;
15         unsigned long long proc3;
16         unsigned long long proc4;
17         int present2;
18         int present3;
19         int present4;
20 };
21
22 struct nfsd_procs nfsd_proc_values[] = {
23         { "null", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
24         { "getattr", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
25         { "setattr", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
26         { "lookup", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
27         { "access", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
28         { "readlink", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
29         { "read", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
30         { "write", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
31         { "create", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
32         { "mkdir", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
33         { "symlink", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
34         { "mknod", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
35         { "remove", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
36         { "rmdir", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
37         { "rename", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
38         { "link", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
39         { "readdir", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
40         { "readdirplus", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
41         { "fsstat", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
42         { "fsinfo", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
43         { "pathconf", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
44         { "commit", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
45         { "", 0ULL, 0ULL, 0ULL, 0, 0, 0 },
46 };
47
48 struct nfsd4_ops {
49         char name[30];
50         unsigned long long value;
51         int present;
52 };
53
54 struct nfsd4_ops nfsd4_ops_values[] = {
55         { "access", 0ULL, 0},
56         { "close", 0ULL, 0},
57         { "commit", 0ULL, 0},
58         { "create", 0ULL, 0},
59         { "delegpurge", 0ULL, 0},
60         { "delegreturn", 0ULL, 0},
61         { "getattr", 0ULL, 0},
62         { "getfh", 0ULL, 0},
63         { "link", 0ULL, 0},
64         { "lock", 0ULL, 0},
65         { "lockt", 0ULL, 0},
66         { "locku", 0ULL, 0},
67         { "lookup", 0ULL, 0},
68         { "lookupp", 0ULL, 0},
69         { "nverify", 0ULL, 0},
70         { "open", 0ULL, 0},
71         { "openattr", 0ULL, 0},
72         { "open_confirm", 0ULL, 0},
73         { "open_downgrade", 0ULL, 0},
74         { "putfh", 0ULL, 0},
75         { "putpubfh", 0ULL, 0},
76         { "putrootfh", 0ULL, 0},
77         { "read", 0ULL, 0},
78         { "readdir", 0ULL, 0},
79         { "readlink", 0ULL, 0},
80         { "remove", 0ULL, 0},
81         { "rename", 0ULL, 0},
82         { "renew", 0ULL, 0},
83         { "restorefh", 0ULL, 0},
84         { "savefh", 0ULL, 0},
85         { "secinfo", 0ULL, 0},
86         { "setattr", 0ULL, 0},
87         { "setclientid", 0ULL, 0},
88         { "setclientid_confirm", 0ULL, 0},
89         { "verify", 0ULL, 0},
90         { "write", 0ULL, 0},
91         { "release_lockowner", 0ULL, 0},
92
93         /* nfs41 */
94         { "backchannel_ctl", 0ULL, 0},
95         { "bind_conn_to_session", 0ULL, 0},
96         { "exchange_id", 0ULL, 0},
97         { "create_session", 0ULL, 0},
98         { "destroy_session", 0ULL, 0},
99         { "free_stateid", 0ULL, 0},
100         { "get_dir_delegation", 0ULL, 0},
101         { "getdeviceinfo", 0ULL, 0},
102         { "getdevicelist", 0ULL, 0},
103         { "layoutcommit", 0ULL, 0},
104         { "layoutget", 0ULL, 0},
105         { "layoutreturn", 0ULL, 0},
106         { "secinfo_no_name", 0ULL, 0},
107         { "sequence", 0ULL, 0},
108         { "set_ssv", 0ULL, 0},
109         { "test_stateid", 0ULL, 0},
110         { "want_delegation", 0ULL, 0},
111         { "destroy_clientid", 0ULL, 0},
112         { "reclaim_complete", 0ULL, 0},
113
114         /* nfs42 */
115         { "allocate", 0ULL, 0},
116         { "copy", 0ULL, 0},
117         { "copy_notify", 0ULL, 0},
118         { "deallocate", 0ULL, 0},
119         { "io_advise", 0ULL, 0},
120         { "layouterror", 0ULL, 0},
121         { "layoutstats", 0ULL, 0},
122         { "offload_cancel", 0ULL, 0},
123         { "offload_status", 0ULL, 0},
124         { "read_plus", 0ULL, 0},
125         { "seek", 0ULL, 0},
126         { "write_same", 0ULL, 0},
127
128         /* termination */
129         { "", 0ULL, 0 }
130 };
131
132
133 int do_proc_net_rpc_nfsd(int update_every, unsigned long long dt) {
134         static procfile *ff = NULL;
135         static int do_rc = -1, do_fh = -1, do_io = -1, do_th = -1, do_ra = -1, do_net = -1, do_rpc = -1, do_proc2 = -1, do_proc3 = -1, do_proc4 = -1, do_proc4ops = -1;
136         static int ra_warning = 0, th_warning = 0, proc2_warning = 0, proc3_warning = 0, proc4_warning = 0, proc4ops_warning = 0;
137
138         if(dt) {};
139
140         if(!ff) ff = procfile_open("/proc/net/rpc/nfsd", " \t");
141         if(!ff) return 1;
142
143         ff = procfile_readall(ff);
144         if(!ff) return 0; // we return 0, so that we will retry to open it next time
145
146         if(do_rc == -1) do_rc = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "read cache", 1);
147         if(do_fh == -1) do_fh = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "file handles", 1);
148         if(do_io == -1) do_io = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "I/O", 1);
149         if(do_th == -1) do_th = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "threads", 1);
150         if(do_ra == -1) do_ra = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "read ahead", 1);
151         if(do_net == -1) do_net = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "network", 1);
152         if(do_rpc == -1) do_rpc = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "rpc", 1);
153         if(do_proc2 == -1) do_proc2 = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "NFS v2 procedures", 1);
154         if(do_proc3 == -1) do_proc3 = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "NFS v3 procedures", 1);
155         if(do_proc4 == -1) do_proc4 = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "NFS v4 procedures", 1);
156         if(do_proc4ops == -1) do_proc4ops = config_get_boolean("plugin:proc:/proc/net/rpc/nfsd", "NFS v4 operations", 1);
157
158         // if they are enabled, reset them to 1
159         // later we do them =2 to avoid doing strcmp for all lines
160         if(do_rc) do_rc = 1;
161         if(do_fh) do_fh = 1;
162         if(do_io) do_io = 1;
163         if(do_th) do_th = 1;
164         if(do_ra) do_ra = 1;
165         if(do_net) do_net = 1;
166         if(do_rpc) do_rpc = 1;
167         if(do_proc2) do_proc2 = 1;
168         if(do_proc3) do_proc3 = 1;
169         if(do_proc4) do_proc4 = 1;
170         if(do_proc4ops) do_proc4ops = 1;
171
172         uint32_t lines = procfile_lines(ff), l;
173         uint32_t words;
174
175         char *type;
176         unsigned long long rc_hits = 0, rc_misses = 0, rc_nocache = 0;
177         unsigned long long fh_stale = 0, fh_total_lookups = 0, fh_anonymous_lookups = 0, fh_dir_not_in_dcache = 0, fh_non_dir_not_in_dcache = 0;
178         unsigned long long io_read = 0, io_write = 0;
179         unsigned long long th_threads = 0, th_fullcnt = 0, th_hist10 = 0, th_hist20 = 0, th_hist30 = 0, th_hist40 = 0, th_hist50 = 0, th_hist60 = 0, th_hist70 = 0, th_hist80 = 0, th_hist90 = 0, th_hist100 = 0;
180         unsigned long long ra_size = 0, ra_hist10 = 0, ra_hist20 = 0, ra_hist30 = 0, ra_hist40 = 0, ra_hist50 = 0, ra_hist60 = 0, ra_hist70 = 0, ra_hist80 = 0, ra_hist90 = 0, ra_hist100 = 0, ra_none = 0;
181         unsigned long long net_count = 0, net_udp_count = 0, net_tcp_count = 0, net_tcp_connections = 0;
182         unsigned long long rpc_count = 0, rpc_bad_format = 0, rpc_bad_auth = 0, rpc_bad_client = 0;
183
184         for(l = 0; l < lines ;l++) {
185                 words = procfile_linewords(ff, l);
186                 if(!words) continue;
187
188                 type            = procfile_lineword(ff, l, 0);
189
190                 if(do_rc == 1 && strcmp(type, "rc") == 0) {
191                         if(words < 4) {
192                                 error("%s line of /proc/net/rpc/nfsd has %d words, expected %d", type, words, 4);
193                                 continue;
194                         }
195                         
196                         rc_hits = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
197                         rc_misses = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
198                         rc_nocache = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
199                         do_rc = 2;
200                 }
201                 else if(do_fh == 1 && strcmp(type, "fh") == 0) {
202                         if(words < 6) {
203                                 error("%s line of /proc/net/rpc/nfsd has %d words, expected %d", type, words, 6);
204                                 continue;
205                         }
206                         
207                         fh_stale = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
208                         fh_total_lookups = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
209                         fh_anonymous_lookups = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
210                         fh_dir_not_in_dcache = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
211                         fh_non_dir_not_in_dcache = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
212
213                         do_fh = 2;
214                 }
215                 else if(do_io == 1 && strcmp(type, "io") == 0) {
216                         if(words < 3) {
217                                 error("%s line of /proc/net/rpc/nfsd has %d words, expected %d", type, words, 3);
218                                 continue;
219                         }
220                         
221                         io_read = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
222                         io_write = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
223
224                         do_io = 2;
225                 }
226                 else if(do_th == 1 && strcmp(type, "th") == 0) {
227                         if(words < 13) {
228                                 error("%s line of /proc/net/rpc/nfsd has %d words, expected %d", type, words, 13);
229                                 continue;
230                         }
231                         
232                         th_threads = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
233                         th_fullcnt = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
234                         th_hist10 = (unsigned long long)(atof(procfile_lineword(ff, l, 3)) * 1000.0);
235                         th_hist20 = (unsigned long long)(atof(procfile_lineword(ff, l, 4)) * 1000.0);
236                         th_hist30 = (unsigned long long)(atof(procfile_lineword(ff, l, 5)) * 1000.0);
237                         th_hist40 = (unsigned long long)(atof(procfile_lineword(ff, l, 6)) * 1000.0);
238                         th_hist50 = (unsigned long long)(atof(procfile_lineword(ff, l, 7)) * 1000.0);
239                         th_hist60 = (unsigned long long)(atof(procfile_lineword(ff, l, 8)) * 1000.0);
240                         th_hist70 = (unsigned long long)(atof(procfile_lineword(ff, l, 9)) * 1000.0);
241                         th_hist80 = (unsigned long long)(atof(procfile_lineword(ff, l, 10)) * 1000.0);
242                         th_hist90 = (unsigned long long)(atof(procfile_lineword(ff, l, 11)) * 1000.0);
243                         th_hist100 = (unsigned long long)(atof(procfile_lineword(ff, l, 12)) * 1000.0);
244
245                         // threads histogram has been disabled on recent kernels
246                         // http://permalink.gmane.org/gmane.linux.nfs/24528
247                         unsigned long long sum = th_hist10 + th_hist20 + th_hist30 + th_hist40 + th_hist50 + th_hist60 + th_hist70 + th_hist80 + th_hist90 + th_hist100;
248                         if(sum == 0ULL) {
249                                 if(!th_warning) {
250                                         info("Disabling /proc/net/rpc/nfsd threads histogram. It seems useless on this machine. It will be enabled if it is found with data in it.");
251                                         th_warning = 1;
252                                 }
253                                 do_th = -1;
254                         }
255                         else do_th = 2;
256                 }
257                 else if(do_ra == 1 && strcmp(type, "ra") == 0) {
258                         if(words < 13) {
259                                 error("%s line of /proc/net/rpc/nfsd has %d words, expected %d", type, words, 13);
260                                 continue;
261                         }
262                         
263                         ra_size = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
264                         ra_hist10 = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
265                         ra_hist20 = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
266                         ra_hist30 = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
267                         ra_hist40 = strtoull(procfile_lineword(ff, l, 5), NULL, 10);
268                         ra_hist50 = strtoull(procfile_lineword(ff, l, 6), NULL, 10);
269                         ra_hist60 = strtoull(procfile_lineword(ff, l, 7), NULL, 10);
270                         ra_hist70 = strtoull(procfile_lineword(ff, l, 8), NULL, 10);
271                         ra_hist80 = strtoull(procfile_lineword(ff, l, 9), NULL, 10);
272                         ra_hist90 = strtoull(procfile_lineword(ff, l, 10), NULL, 10);
273                         ra_hist100 = strtoull(procfile_lineword(ff, l, 11), NULL, 10);
274                         ra_none = strtoull(procfile_lineword(ff, l, 12), NULL, 10);
275
276                         unsigned long long sum = ra_hist10 + ra_hist20 + ra_hist30 + ra_hist40 + ra_hist50 + ra_hist60 + ra_hist70 + ra_hist80 + ra_hist90 + ra_hist100 + ra_none;
277                         if(sum == 0ULL) {
278                                 if(!ra_warning) {
279                                         info("Disabling /proc/net/rpc/nfsd read ahead histogram. It seems useless on this machine. It will be enabled if it is found with data in it.");
280                                         ra_warning = 1;
281                                 }
282                                 do_ra = -1;
283                         }
284                         else do_ra = 2;
285                 }
286                 else if(do_net == 1 && strcmp(type, "net") == 0) {
287                         if(words < 5) {
288                                 error("%s line of /proc/net/rpc/nfsd has %d words, expected %d", type, words, 5);
289                                 continue;
290                         }
291                         
292                         net_count = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
293                         net_udp_count = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
294                         net_tcp_count = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
295                         net_tcp_connections = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
296
297                         do_net = 2;
298                 }
299                 else if(do_rpc == 1 && strcmp(type, "rpc") == 0) {
300                         if(words < 6) {
301                                 error("%s line of /proc/net/rpc/nfsd has %d words, expected %d", type, words, 6);
302                                 continue;
303                         }
304                         
305                         rpc_count = strtoull(procfile_lineword(ff, l, 1), NULL, 10);
306                         rpc_bad_format = strtoull(procfile_lineword(ff, l, 2), NULL, 10);
307                         rpc_bad_auth = strtoull(procfile_lineword(ff, l, 3), NULL, 10);
308                         rpc_bad_client = strtoull(procfile_lineword(ff, l, 4), NULL, 10);
309
310                         do_rpc = 2;
311                 }
312                 else if(do_proc2 == 1 && strcmp(type, "proc2") == 0) {
313                         // the first number is the count of numbers present
314                         // so we start for word 2
315
316                         unsigned long long sum = 0;
317                         unsigned int i, j;
318                         for(i = 0, j = 2; j < words && nfsd_proc_values[i].name[0] ; i++, j++) {
319                                 nfsd_proc_values[i].proc2 = strtoull(procfile_lineword(ff, l, j), NULL, 10);
320                                 nfsd_proc_values[i].present2 = 1;
321                                 sum += nfsd_proc_values[i].proc2;
322                         }
323
324                         if(sum == 0ULL) {
325                                 if(!proc2_warning) {
326                                         error("Disabling /proc/net/rpc/nfsd v2 procedure calls chart. It seems useless on this machine. It will be enabled if it is found with data in it.");
327                                         proc2_warning = 1;
328                                 }
329                                 do_proc2 = 0;
330                         }
331                         else do_proc2 = 2;
332                 }
333                 else if(do_proc3 == 1 && strcmp(type, "proc3") == 0) {
334                         // the first number is the count of numbers present
335                         // so we start for word 2
336
337                         unsigned long long sum = 0;
338                         unsigned int i, j;
339                         for(i = 0, j = 2; j < words && nfsd_proc_values[i].name[0] ; i++, j++) {
340                                 nfsd_proc_values[i].proc3 = strtoull(procfile_lineword(ff, l, j), NULL, 10);
341                                 nfsd_proc_values[i].present3 = 1;
342                                 sum += nfsd_proc_values[i].proc3;
343                         }
344
345                         if(sum == 0ULL) {
346                                 if(!proc3_warning) {
347                                         info("Disabling /proc/net/rpc/nfsd v3 procedure calls chart. It seems useless on this machine. It will be enabled if it is found with data in it.");
348                                         proc3_warning = 1;
349                                 }
350                                 do_proc3 = 0;
351                         }
352                         else do_proc3 = 2;
353                 }
354                 else if(do_proc4 == 1 && strcmp(type, "proc4") == 0) {
355                         // the first number is the count of numbers present
356                         // so we start for word 2
357
358                         unsigned long long sum = 0;
359                         unsigned int i, j;
360                         for(i = 0, j = 2; j < words && nfsd_proc_values[i].name[0] ; i++, j++) {
361                                 nfsd_proc_values[i].proc4 = strtoull(procfile_lineword(ff, l, j), NULL, 10);
362                                 nfsd_proc_values[i].present4 = 1;
363                                 sum += nfsd_proc_values[i].proc4;
364                         }
365
366                         if(sum == 0ULL) {
367                                 if(!proc4_warning) {
368                                         info("Disabling /proc/net/rpc/nfsd v4 procedure calls chart. It seems useless on this machine. It will be enabled if it is found with data in it.");
369                                         proc4_warning = 1;
370                                 }
371                                 do_proc4 = 0;
372                         }
373                         else do_proc4 = 2;
374                 }
375                 else if(do_proc4ops == 1 && strcmp(type, "proc4ops") == 0) {
376                         // the first number is the count of numbers present
377                         // so we start for word 2
378
379                         unsigned long long sum = 0;
380                         unsigned int i, j;
381                         for(i = 0, j = 2; j < words && nfsd4_ops_values[i].name[0] ; i++, j++) {
382                                 nfsd4_ops_values[i].value = strtoull(procfile_lineword(ff, l, j), NULL, 10);
383                                 nfsd4_ops_values[i].present = 1;
384                                 sum += nfsd4_ops_values[i].value;
385                         }
386
387                         if(sum == 0ULL) {
388                                 if(!proc4ops_warning) {
389                                         info("Disabling /proc/net/rpc/nfsd v4 operations chart. It seems useless on this machine. It will be enabled if it is found with data in it.");
390                                         proc4ops_warning = 1;
391                                 }
392                                 do_proc4ops = 0;
393                         }
394                         else do_proc4ops = 2;
395                 }
396         }
397
398         RRD_STATS *st;
399
400         // --------------------------------------------------------------------
401
402         if(do_rc == 2) {
403                 st = rrd_stats_find_bytype("nfsd", "readcache");
404                 if(!st) {
405                         st = rrd_stats_create("nfsd", "readcache", NULL, "nfsd", "Read Cache", "reads/s", 5000, update_every, CHART_TYPE_STACKED);
406
407                         rrd_stats_dimension_add(st, "hits", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
408                         rrd_stats_dimension_add(st, "misses", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
409                         rrd_stats_dimension_add(st, "nocache", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
410                 }
411                 else rrd_stats_next(st);
412
413                 rrd_stats_dimension_set(st, "hits", rc_hits);
414                 rrd_stats_dimension_set(st, "misses", rc_misses);
415                 rrd_stats_dimension_set(st, "nocache", rc_nocache);
416                 rrd_stats_done(st);
417         }
418
419         // --------------------------------------------------------------------
420
421         if(do_fh == 2) {
422                 st = rrd_stats_find_bytype("nfsd", "filehandles");
423                 if(!st) {
424                         st = rrd_stats_create("nfsd", "filehandles", NULL, "nfsd", "File Handles", "handles/s", 5001, update_every, CHART_TYPE_LINE);
425
426                         rrd_stats_dimension_add(st, "stale", NULL, 1, update_every, RRD_DIMENSION_ABSOLUTE);
427                         rrd_stats_dimension_add(st, "total_lookups", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
428                         rrd_stats_dimension_add(st, "anonymous_lookups", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
429                         rrd_stats_dimension_add(st, "dir_not_in_dcache", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
430                         rrd_stats_dimension_add(st, "non_dir_not_in_dcache", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
431                 }
432                 else rrd_stats_next(st);
433
434                 rrd_stats_dimension_set(st, "stale", fh_stale);
435                 rrd_stats_dimension_set(st, "total_lookups", fh_total_lookups);
436                 rrd_stats_dimension_set(st, "anonymous_lookups", fh_anonymous_lookups);
437                 rrd_stats_dimension_set(st, "dir_not_in_dcache", fh_dir_not_in_dcache);
438                 rrd_stats_dimension_set(st, "non_dir_not_in_dcache", fh_non_dir_not_in_dcache);
439                 rrd_stats_done(st);
440         }
441
442         // --------------------------------------------------------------------
443
444         if(do_io == 2) {
445                 st = rrd_stats_find_bytype("nfsd", "io");
446                 if(!st) {
447                         st = rrd_stats_create("nfsd", "io", NULL, "nfsd", "I/O", "kilobytes/s", 5002, update_every, CHART_TYPE_AREA);
448
449                         rrd_stats_dimension_add(st, "read", NULL, 1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
450                         rrd_stats_dimension_add(st, "write", NULL, -1, 1000 * update_every, RRD_DIMENSION_INCREMENTAL);
451                 }
452                 else rrd_stats_next(st);
453
454                 rrd_stats_dimension_set(st, "read", io_read);
455                 rrd_stats_dimension_set(st, "write", io_write);
456                 rrd_stats_done(st);
457         }
458
459         // --------------------------------------------------------------------
460
461         if(do_th == 2) {
462                 st = rrd_stats_find_bytype("nfsd", "threads");
463                 if(!st) {
464                         st = rrd_stats_create("nfsd", "threads", NULL, "nfsd", "Threads", "threads", 5003, update_every, CHART_TYPE_LINE);
465
466                         rrd_stats_dimension_add(st, "threads", NULL, 1, 1, RRD_DIMENSION_ABSOLUTE);
467                 }
468                 else rrd_stats_next(st);
469
470                 rrd_stats_dimension_set(st, "threads", th_threads);
471                 rrd_stats_done(st);
472
473                 st = rrd_stats_find_bytype("nfsd", "threads_fullcnt");
474                 if(!st) {
475                         st = rrd_stats_create("nfsd", "threads_fullcnt", NULL, "nfsd", "Threads Full Count", "ops/s", 5004, update_every, CHART_TYPE_LINE);
476
477                         rrd_stats_dimension_add(st, "full_count", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
478                 }
479                 else rrd_stats_next(st);
480
481                 rrd_stats_dimension_set(st, "full_count", th_fullcnt);
482                 rrd_stats_done(st);
483
484                 st = rrd_stats_find_bytype("nfsd", "threads_histogram");
485                 if(!st) {
486                         st = rrd_stats_create("nfsd", "threads_histogram", NULL, "nfsd", "Threads Usage Histogram", "percentage", 5005, update_every, CHART_TYPE_LINE);
487
488                         rrd_stats_dimension_add(st, "0%-10%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
489                         rrd_stats_dimension_add(st, "10%-20%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
490                         rrd_stats_dimension_add(st, "20%-30%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
491                         rrd_stats_dimension_add(st, "30%-40%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
492                         rrd_stats_dimension_add(st, "40%-50%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
493                         rrd_stats_dimension_add(st, "50%-60%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
494                         rrd_stats_dimension_add(st, "60%-70%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
495                         rrd_stats_dimension_add(st, "70%-80%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
496                         rrd_stats_dimension_add(st, "80%-90%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
497                         rrd_stats_dimension_add(st, "90%-100%", NULL, 1, 1000, RRD_DIMENSION_ABSOLUTE);
498                 }
499                 else rrd_stats_next(st);
500
501                 rrd_stats_dimension_set(st, "0%-10%", th_hist10);
502                 rrd_stats_dimension_set(st, "10%-20%", th_hist20);
503                 rrd_stats_dimension_set(st, "20%-30%", th_hist30);
504                 rrd_stats_dimension_set(st, "30%-40%", th_hist40);
505                 rrd_stats_dimension_set(st, "40%-50%", th_hist50);
506                 rrd_stats_dimension_set(st, "50%-60%", th_hist60);
507                 rrd_stats_dimension_set(st, "60%-70%", th_hist70);
508                 rrd_stats_dimension_set(st, "70%-80%", th_hist80);
509                 rrd_stats_dimension_set(st, "80%-90%", th_hist90);
510                 rrd_stats_dimension_set(st, "90%-100%", th_hist100);
511                 rrd_stats_done(st);
512         }
513
514         // --------------------------------------------------------------------
515
516         if(do_ra == 2) {
517                 st = rrd_stats_find_bytype("nfsd", "readahead");
518                 if(!st) {
519                         st = rrd_stats_create("nfsd", "readahead", NULL, "nfsd", "Read Ahead Depth", "reads/s", 5005, update_every, CHART_TYPE_STACKED);
520
521                         rrd_stats_dimension_add(st, "10%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
522                         rrd_stats_dimension_add(st, "20%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
523                         rrd_stats_dimension_add(st, "30%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
524                         rrd_stats_dimension_add(st, "40%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
525                         rrd_stats_dimension_add(st, "50%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
526                         rrd_stats_dimension_add(st, "60%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
527                         rrd_stats_dimension_add(st, "70%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
528                         rrd_stats_dimension_add(st, "80%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
529                         rrd_stats_dimension_add(st, "90%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
530                         rrd_stats_dimension_add(st, "100%", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
531                         rrd_stats_dimension_add(st, "misses", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
532                 }
533                 else rrd_stats_next(st);
534
535                 // ignore ra_size
536                 if(ra_size) {};
537
538                 rrd_stats_dimension_set(st, "10%", ra_hist10);
539                 rrd_stats_dimension_set(st, "20%", ra_hist20);
540                 rrd_stats_dimension_set(st, "30%", ra_hist30);
541                 rrd_stats_dimension_set(st, "40%", ra_hist40);
542                 rrd_stats_dimension_set(st, "50%", ra_hist50);
543                 rrd_stats_dimension_set(st, "60%", ra_hist60);
544                 rrd_stats_dimension_set(st, "70%", ra_hist70);
545                 rrd_stats_dimension_set(st, "80%", ra_hist80);
546                 rrd_stats_dimension_set(st, "90%", ra_hist90);
547                 rrd_stats_dimension_set(st, "100%", ra_hist100);
548                 rrd_stats_dimension_set(st, "misses", ra_none);
549                 rrd_stats_done(st);
550         }
551
552         // --------------------------------------------------------------------
553
554         if(do_net == 2) {
555                 st = rrd_stats_find_bytype("nfsd", "net");
556                 if(!st) {
557                         st = rrd_stats_create("nfsd", "net", NULL, "nfsd", "Network Reads", "reads/s", 5007, update_every, CHART_TYPE_STACKED);
558
559                         rrd_stats_dimension_add(st, "udp", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
560                         rrd_stats_dimension_add(st, "tcp", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
561                 }
562                 else rrd_stats_next(st);
563
564                 // ignore net_count, net_tcp_connections
565                 if(net_count) {};
566                 if(net_tcp_connections) {};
567
568                 rrd_stats_dimension_set(st, "udp", net_udp_count);
569                 rrd_stats_dimension_set(st, "tcp", net_tcp_count);
570                 rrd_stats_done(st);
571         }
572
573         // --------------------------------------------------------------------
574
575         if(do_rpc == 2) {
576                 st = rrd_stats_find_bytype("nfsd", "rpc");
577                 if(!st) {
578                         st = rrd_stats_create("nfsd", "rpc", NULL, "nfsd", "Remote Procedure Calls", "calls/s", 5008, update_every, CHART_TYPE_LINE);
579
580                         rrd_stats_dimension_add(st, "all", NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
581                         rrd_stats_dimension_add(st, "bad_format", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
582                         rrd_stats_dimension_add(st, "bad_auth", NULL, -1, update_every, RRD_DIMENSION_INCREMENTAL);
583                 }
584                 else rrd_stats_next(st);
585
586                 // ignore rpc_bad_client
587                 if(rpc_bad_client) {};
588
589                 rrd_stats_dimension_set(st, "all", rpc_count);
590                 rrd_stats_dimension_set(st, "bad_format", rpc_bad_format);
591                 rrd_stats_dimension_set(st, "bad_auth", rpc_bad_auth);
592                 rrd_stats_done(st);
593         }
594
595         // --------------------------------------------------------------------
596
597         if(do_proc2 == 2) {
598                 unsigned int i;
599                 st = rrd_stats_find_bytype("nfsd", "proc2");
600                 if(!st) {
601                         st = rrd_stats_create("nfsd", "proc2", NULL, "nfsd", "NFS v2 Calls", "calls/s", 5009, update_every, CHART_TYPE_STACKED);
602
603                         for(i = 0; nfsd_proc_values[i].present2 ; i++)
604                                 rrd_stats_dimension_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
605                 }
606                 else rrd_stats_next(st);
607
608                 for(i = 0; nfsd_proc_values[i].present2 ; i++)
609                         rrd_stats_dimension_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc2);
610                 
611                 rrd_stats_done(st);
612         }
613
614         // --------------------------------------------------------------------
615
616         if(do_proc3 == 2) {
617                 unsigned int i;
618                 st = rrd_stats_find_bytype("nfsd", "proc3");
619                 if(!st) {
620                         st = rrd_stats_create("nfsd", "proc3", NULL, "nfsd", "NFS v3 Calls", "calls/s", 5010, update_every, CHART_TYPE_STACKED);
621
622                         for(i = 0; nfsd_proc_values[i].present3 ; i++)
623                                 rrd_stats_dimension_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
624                 }
625                 else rrd_stats_next(st);
626
627                 for(i = 0; nfsd_proc_values[i].present3 ; i++)
628                         rrd_stats_dimension_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc3);
629                 
630                 rrd_stats_done(st);
631         }
632
633         // --------------------------------------------------------------------
634
635         if(do_proc4 == 2) {
636                 unsigned int i;
637                 st = rrd_stats_find_bytype("nfsd", "proc4");
638                 if(!st) {
639                         st = rrd_stats_create("nfsd", "proc4", NULL, "nfsd", "NFS v4 Calls", "calls/s", 5011, update_every, CHART_TYPE_STACKED);
640
641                         for(i = 0; nfsd_proc_values[i].present4 ; i++)
642                                 rrd_stats_dimension_add(st, nfsd_proc_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
643                 }
644                 else rrd_stats_next(st);
645
646                 for(i = 0; nfsd_proc_values[i].present4 ; i++)
647                         rrd_stats_dimension_set(st, nfsd_proc_values[i].name, nfsd_proc_values[i].proc4);
648                 
649                 rrd_stats_done(st);
650         }
651
652         // --------------------------------------------------------------------
653
654         if(do_proc4ops == 2) {
655                 unsigned int i;
656                 st = rrd_stats_find_bytype("nfsd", "proc4ops");
657                 if(!st) {
658                         st = rrd_stats_create("nfsd", "proc4ops", NULL, "nfsd", "NFS v4 Operations", "operations/s", 5012, update_every, CHART_TYPE_STACKED);
659
660                         for(i = 0; nfsd4_ops_values[i].present ; i++)
661                                 rrd_stats_dimension_add(st, nfsd4_ops_values[i].name, NULL, 1, update_every, RRD_DIMENSION_INCREMENTAL);
662                 }
663                 else rrd_stats_next(st);
664
665                 for(i = 0; nfsd4_ops_values[i].present ; i++)
666                         rrd_stats_dimension_set(st, nfsd4_ops_values[i].name, nfsd4_ops_values[i].value);
667                 
668                 rrd_stats_done(st);
669         }
670
671         return 0;
672 }