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>
21 * Cosmin Ioiart <cioiart at gmail.com>
34 see http://www.missioncriticallinux.com/orph/NFS-Statistics
37 rpc_stat.netcnt Not used; always zero.
38 rpc_stat.netudpcnt Not used; always zero.
39 rpc_stat.nettcpcnt Not used; always zero.
40 rpc_stat.nettcpconn Not used; always zero.
43 rpc_stat.rpccnt The number of RPC calls.
44 rpc_stat.rpcretrans The number of retransmitted RPC calls.
45 rpc_stat.rpcauthrefresh The number of credential refreshes.
50 Procedure NFS Version NFS Version 3
51 Number Procedures Procedures
77 static const char *nfs2_procedures_names[] =
98 static size_t nfs2_procedures_names_num = STATIC_ARRAY_SIZE (nfs2_procedures_names);
100 static const char *nfs3_procedures_names[] =
125 static size_t nfs3_procedures_names_num = STATIC_ARRAY_SIZE (nfs3_procedures_names);
128 static const char *nfs4_procedures_names[] =
166 "setclientid_confirm",
170 static size_t nfs4_procedures_names_num = STATIC_ARRAY_SIZE (nfs4_procedures_names);
174 extern kstat_ctl_t *kc;
175 static kstat_t *nfs2_ksp_client;
176 static kstat_t *nfs2_ksp_server;
177 static kstat_t *nfs3_ksp_client;
178 static kstat_t *nfs3_ksp_server;
179 static kstat_t *nfs4_ksp_client;
180 static kstat_t *nfs4_ksp_server;
183 /* Possibly TODO: NFSv4 statistics */
186 static int nfs_init (void)
190 /* #endif KERNEL_LINUX */
193 static int nfs_init (void)
195 kstat_t *ksp_chain = NULL;
197 nfs2_ksp_client = NULL;
198 nfs2_ksp_server = NULL;
199 nfs3_ksp_client = NULL;
200 nfs3_ksp_server = NULL;
201 nfs4_ksp_client = NULL;
202 nfs4_ksp_server = NULL;
207 for (ksp_chain = kc->kc_chain; ksp_chain != NULL;
208 ksp_chain = ksp_chain->ks_next)
210 if (strncmp (ksp_chain->ks_module, "nfs", 3) != 0)
212 else if (strncmp (ksp_chain->ks_name, "rfsproccnt_v2", 13) == 0)
213 nfs2_ksp_server = ksp_chain;
214 else if (strncmp (ksp_chain->ks_name, "rfsproccnt_v3", 13) == 0)
215 nfs3_ksp_server = ksp_chain;
216 else if (strncmp (ksp_chain->ks_name, "rfsproccnt_v4", 13) == 0)
217 nfs4_ksp_server = ksp_chain;
218 else if (strncmp (ksp_chain->ks_name, "rfsreqcnt_v2", 12) == 0)
219 nfs2_ksp_client = ksp_chain;
220 else if (strncmp (ksp_chain->ks_name, "rfsreqcnt_v3", 12) == 0)
221 nfs3_ksp_client = ksp_chain;
222 else if (strncmp (ksp_chain->ks_name, "rfsreqcnt_v4", 12) == 0)
223 nfs4_ksp_client = ksp_chain;
230 static void nfs_procedures_submit (const char *plugin_instance,
231 const char **type_instances,
232 value_t *values, size_t values_num)
234 value_list_t vl = VALUE_LIST_INIT;
238 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
239 sstrncpy (vl.plugin, "nfs", sizeof (vl.plugin));
240 sstrncpy (vl.plugin_instance, plugin_instance,
241 sizeof (vl.plugin_instance));
242 sstrncpy (vl.type, "nfs_procedure", sizeof (vl.type));
244 for (i = 0; i < values_num; i++)
246 vl.values = values + i;
247 sstrncpy (vl.type_instance, type_instances[i],
248 sizeof (vl.type_instance));
249 plugin_dispatch_values_secure (&vl);
251 } /* void nfs_procedures_submit */
254 static int nfs_submit_fields (int nfs_version, const char *instance,
255 char **fields, size_t fields_num,
256 const char **proc_names, size_t proc_names_num)
258 char plugin_instance[DATA_MAX_NAME_LEN];
259 value_t values[fields_num];
262 if (fields_num != proc_names_num)
264 WARNING ("nfs plugin: Wrong number of fields for "
265 "NFSv%i %s statistics. Expected %zu, got %zu.",
266 nfs_version, instance,
267 proc_names_num, fields_num);
271 ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s",
272 nfs_version, instance);
274 for (i = 0; i < proc_names_num; i++)
275 (void) parse_value (fields[i], &values[i], DS_TYPE_DERIVE);
277 nfs_procedures_submit (plugin_instance, proc_names, values,
283 static void nfs_read_linux (FILE *fh, char *inst)
293 while (fgets (buffer, sizeof (buffer), fh) != NULL)
295 fields_num = strsplit (buffer,
296 fields, STATIC_ARRAY_SIZE (fields));
301 if (strcmp (fields[0], "proc2") == 0)
303 nfs_submit_fields (/* version = */ 2, inst,
304 fields + 2, (size_t) (fields_num - 2),
305 nfs2_procedures_names,
306 nfs2_procedures_names_num);
308 else if (strncmp (fields[0], "proc3", 5) == 0)
310 nfs_submit_fields (/* version = */ 3, inst,
311 fields + 2, (size_t) (fields_num - 2),
312 nfs3_procedures_names,
313 nfs3_procedures_names_num);
315 } /* while (fgets) */
316 } /* void nfs_read_linux */
317 #endif /* KERNEL_LINUX */
320 static int nfs_read_kstat (kstat_t *ksp, int nfs_version, char *inst,
321 const char **proc_names, size_t proc_names_num)
323 char plugin_instance[DATA_MAX_NAME_LEN];
324 value_t values[proc_names_num];
330 ssnprintf (plugin_instance, sizeof (plugin_instance), "v%i%s",
333 kstat_read(kc, ksp, NULL);
334 for (i = 0; i < proc_names_num; i++)
335 values[i].counter = (derive_t) get_kstat_value (ksp, proc_names[i]);
337 nfs_procedures_submit (plugin_instance, proc_names, values,
343 static int nfs_read (void)
347 if ((fh = fopen ("/proc/net/rpc/nfs", "r")) != NULL)
349 nfs_read_linux (fh, "client");
353 if ((fh = fopen ("/proc/net/rpc/nfsd", "r")) != NULL)
355 nfs_read_linux (fh, "server");
361 /* #endif KERNEL_LINUX */
364 static int nfs_read (void)
366 nfs_read_kstat (nfs2_ksp_client, /* version = */ 2, "client",
367 nfs2_procedures_names, nfs2_procedures_names_num);
368 nfs_read_kstat (nfs2_ksp_server, /* version = */ 2, "server",
369 nfs2_procedures_names, nfs2_procedures_names_num);
370 nfs_read_kstat (nfs3_ksp_client, /* version = */ 3, "client",
371 nfs3_procedures_names, nfs3_procedures_names_num);
372 nfs_read_kstat (nfs3_ksp_server, /* version = */ 3, "server",
373 nfs3_procedures_names, nfs3_procedures_names_num);
374 nfs_read_kstat (nfs4_ksp_client, /* version = */ 4, "client",
375 nfs4_procedures_names, nfs4_procedures_names_num);
376 nfs_read_kstat (nfs4_ksp_server, /* version = */ 4, "server",
377 nfs4_procedures_names, nfs4_procedures_names_num);
381 #endif /* HAVE_LIBKSTAT */
383 void module_register (void)
385 plugin_register_init ("nfs", nfs_init);
386 plugin_register_read ("nfs", nfs_read);
387 } /* void module_register */