3 * Copyright (C) 2005,2006 Jason Pepas
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; only version 2 of the License is applicable.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 * Jason Pepas <cell at ices.utexas.edu>
20 * Florian octo Forster <octo at verplant.org>
33 see http://www.missioncriticallinux.com/orph/NFS-Statistics
36 rpc_stat.netcnt Not used; always zero.
37 rpc_stat.netudpcnt Not used; always zero.
38 rpc_stat.nettcpcnt Not used; always zero.
39 rpc_stat.nettcpconn Not used; always zero.
42 rpc_stat.rpccnt The number of RPC calls.
43 rpc_stat.rpcretrans The number of retransmitted RPC calls.
44 rpc_stat.rpcauthrefresh The number of credential refreshes.
49 Procedure NFS Version NFS Version 3
50 Number Procedures Procedures
76 static const char *nfs2_procedures_names[] =
97 static size_t nfs2_procedures_names_num = STATIC_ARRAY_SIZE (nfs2_procedures_names);
99 static const char *nfs3_procedures_names[] =
124 static size_t nfs3_procedures_names_num = STATIC_ARRAY_SIZE (nfs3_procedures_names);
127 static const char *nfs4_procedures_names[] =
165 "setclientid_confirm",
169 static size_t nfs4_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_procedures_names);
173 extern kstat_ctl_t *kc;
174 static kstat_t *nfs2_ksp_client;
175 static kstat_t *nfs2_ksp_server;
176 static kstat_t *nfs3_ksp_client;
177 static kstat_t *nfs3_ksp_server;
178 static kstat_t *nfs4_ksp_client;
179 static kstat_t *nfs4_ksp_server;
182 /* Possibly TODO: NFSv4 statistics */
185 static int nfs_init (void)
189 /* #endif KERNEL_LINUX */
192 static int nfs_init (void)
194 kstat_t *ksp_chain = NULL;
196 nfs2_ksp_client = NULL;
197 nfs2_ksp_server = NULL;
198 nfs3_ksp_client = NULL;
199 nfs3_ksp_server = NULL;
200 nfs4_ksp_client = NULL;
201 nfs4_ksp_server = NULL;
206 for (ksp_chain = kc->kc_chain; ksp_chain != NULL;
207 ksp_chain = ksp_chain->ks_next)
209 if (strncmp (ksp_chain->ks_module, "nfs", 3) != 0)
211 else if (strncmp (ksp_chain->ks_name, "rfsproccnt_v2", 13) == 0)
212 nfs2_ksp_server = ksp_chain;
213 else if (strncmp (ksp_chain->ks_name, "rfsproccnt_v3", 13) == 0)
214 nfs3_ksp_server = ksp_chain;
215 else if (strncmp (ksp_chain->ks_name, "rfsproccnt_v4", 13) == 0)
216 nfs4_ksp_server = ksp_chain;
217 else if (strncmp (ksp_chain->ks_name, "rfsreqcnt_v2", 12) == 0)
218 nfs2_ksp_client = ksp_chain;
219 else if (strncmp (ksp_chain->ks_name, "rfsreqcnt_v3", 12) == 0)
220 nfs3_ksp_client = ksp_chain;
221 else if (strncmp (ksp_chain->ks_name, "rfsreqcnt_v4", 12) == 0)
222 nfs4_ksp_client = ksp_chain;
229 static void nfs_procedures_submit (const char *plugin_instance,
230 const char **type_instances,
231 value_t *values, size_t values_num)
233 value_list_t vl = VALUE_LIST_INIT;
237 sstrncpy(vl.host, hostname_g, sizeof (vl.host));
238 sstrncpy(vl.plugin, "nfs", sizeof (vl.plugin));
239 sstrncpy(vl.plugin_instance, plugin_instance,
240 sizeof (vl.plugin_instance));
241 sstrncpy(vl.type, "nfs_procedure", sizeof (vl.type));
243 for (i = 0; i < values_num; i++)
245 vl.values = values + i;
246 sstrncpy (vl.type_instance, type_instances[i],
247 sizeof (vl.type_instance));
248 plugin_dispatch_values_secure (&vl);
250 } /* void nfs_procedures_submit */
253 static int nfs_submit_fields (int nfs_version, const char *instance,
254 char **fields, size_t fields_num,
255 const char **proc_names, size_t proc_names_num)
257 char plugin_instance[DATA_MAX_NAME_LEN];
258 value_t values[fields_num];
261 if (fields_num != proc_names_num)
263 WARNING ("nfs plugin: Wrong number of fields for "
264 "NFSv%i %s statistics. Expected %zu, got %zu.",
265 nfs_version, instance,
266 proc_names_num, fields_num);
270 ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s",
271 nfs_version, instance);
273 for (i = 0; i < proc_names_num; i++)
274 (void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE);
276 nfs_procedures_submit (plugin_instance, proc_names, values,
282 static void nfs_read_linux (FILE *fh, char *inst)
292 while (fgets (buffer, sizeof (buffer), fh) != NULL)
294 fields_num = strsplit (buffer,
295 fields, STATIC_ARRAY_SIZE (fields));
300 if (strcmp (fields[0], "proc2") == 0)
302 nfs_submit_fields (/* version = */ 2, inst,
303 fields + 2, (size_t) (fields_num - 2),
304 nfs2_procedures_names,
305 nfs2_procedures_names_num);
307 else if (strncmp (fields[0], "proc3", 5) == 0)
309 nfs_submit_fields (/* version = */ 3, inst,
310 fields + 2, (size_t) (fields_num - 2),
311 nfs3_procedures_names,
312 nfs3_procedures_names_num);
314 } /* while (fgets) */
315 } /* void nfs_read_linux */
316 #endif /* KERNEL_LINUX */
319 static int nfs_read_kstat (kstat_t *ksp, int nfs_version, char *inst,
320 const char **proc_names, size_t proc_names_num)
322 char plugin_instance[DATA_MAX_NAME_LEN];
323 value_t values[proc_names_num];
329 ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s",
332 kstat_read(kc, ksp, NULL);
333 for (i = 0; i < proc_names_num; i++)
334 values[i] = (derive_t) get_kstat_value (ksp, proc_names[i]);
336 nfs_procedures_submit (plugin_instance, proc_names, values,
342 static int nfs_read (void)
346 if ((fh = fopen ("/proc/net/rpc/nfs", "r")) != NULL)
348 nfs_read_linux (fh, "client");
352 if ((fh = fopen ("/proc/net/rpc/nfsd", "r")) != NULL)
354 nfs_read_linux (fh, "server");
360 /* #endif KERNEL_LINUX */
363 static int nfs_read (void)
365 nfs_read_kstat (nfs2_ksp_client, /* version = */ 2, "client",
366 nfs2_procedures_names, nfs2_procedures_names_num);
367 nfs_read_kstat (nfs2_ksp_server, /* version = */ 2, "server",
368 nfs2_procedures_names, nfs2_procedures_names_num);
369 nfs_read_kstat (nfs3_ksp_client, /* version = */ 3, "client",
370 nfs3_procedures_names, nfs3_procedures_names_num);
371 nfs_read_kstat (nfs3_ksp_server, /* version = */ 3, "server",
372 nfs3_procedures_names, nfs3_procedures_names_num);
373 nfs_read_kstat (nfs4_ksp_client, /* version = */ 4, "client",
374 nfs4_procedures_names, nfs4_procedures_names_num);
375 nfs_read_kstat (nfs4_ksp_server, /* version = */ 4, "server",
376 nfs4_procedures_names, nfs4_procedures_names_num);
380 #endif /* HAVE_LIBKSTAT */
382 void module_register (void)
384 plugin_register_init ("nfs", nfs_init);
385 plugin_register_read ("nfs", nfs_read);
386 } /* void module_register */