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