X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnfs.c;h=f2db895a00d484bf647e1c2a9a7688dd106ca31e;hb=92445ff3363441d0f515de4a3ab92a504cfc0366;hp=d0f33c5238269638d00ae52b8bb462b3489ddb0f;hpb=8822d7c9d8e86358cc4bb86e306ff90e40a15401;p=collectd.git diff --git a/src/nfs.c b/src/nfs.c index d0f33c52..f2db895a 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -4,8 +4,7 @@ * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. + * Free Software Foundation; only version 2 of the License is applicable. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,18 +24,10 @@ #include "common.h" #include "plugin.h" -#define MODULE_NAME "nfs" - -/* #if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) */ -#if KERNEL_LINUX -# define NFS_HAVE_READ 1 -#else -# define NFS_HAVE_READ 0 +#if !KERNEL_LINUX +# error "No applicable input method." #endif -static char *nfs2_procedures_file = "nfs2_procedures-%s.rrd"; -static char *nfs3_procedures_file = "nfs3_procedures-%s.rrd"; - /* see /proc/net/rpc/nfs see http://www.missioncriticallinux.com/orph/NFS-Statistics @@ -82,57 +73,57 @@ Number Procedures Procedures 21 commit */ -static char *nfs2_procedures_ds_def[] = +static const char *nfs2_procedures_names[] = { - "DS:null:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:getattr:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:setattr:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:root:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:lookup:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:readlink:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:read:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:wrcache:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:write:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:create:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:remove:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:rename:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:link:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:symlink:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:mkdir:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:rmdir:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:readdir:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:fsstat:COUNTER:"COLLECTD_HEARTBEAT":0:U", + "null", + "getattr", + "setattr", + "root", + "lookup", + "readlink", + "read", + "wrcache", + "write", + "create", + "remove", + "rename", + "link", + "symlink", + "mkdir", + "rmdir", + "readdir", + "fsstat", NULL }; -static int nfs2_procedures_ds_num = 18; +static int nfs2_procedures_names_num = 18; -static char *nfs3_procedures_ds_def[] = +static const char *nfs3_procedures_names[] = { - "DS:null:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:getattr:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:setattr:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:lookup:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:access:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:readlink:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:read:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:write:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:create:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:mkdir:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:symlink:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:mknod:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:remove:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:rmdir:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:rename:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:link:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:readdir:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:readdirplus:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:fsstat:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:fsinfo:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:pathconf:COUNTER:"COLLECTD_HEARTBEAT":0:U", - "DS:commit:COUNTER:"COLLECTD_HEARTBEAT":0:U", + "null", + "getattr", + "setattr", + "lookup", + "access", + "readlink", + "read", + "write", + "create", + "mkdir", + "symlink", + "mknod", + "remove", + "rmdir", + "rename", + "link", + "readdir", + "readdirplus", + "fsstat", + "fsinfo", + "pathconf", + "commit", NULL }; -static int nfs3_procedures_ds_num = 22; +static int nfs3_procedures_names_num = 22; #if HAVE_LIBKSTAT && 0 extern kstat_ctl_t *kc; @@ -146,7 +137,8 @@ static kstat_t *nfs4_ksp_server; /* Possibly TODO: NFSv4 statistics */ -static void nfs_init (void) +#if 0 +static int nfs_init (void) { #if HAVE_LIBKSTAT && 0 kstat_t *ksp_chain; @@ -181,89 +173,45 @@ static void nfs_init (void) } #endif - return; -} + return (0); +} /* int nfs_init */ +#endif #define BUFSIZE 1024 -static void nfs2_procedures_write (char *host, char *inst, char *val) +static void nfs_procedures_submit (const char *plugin_instance, + unsigned long long *val, const char **names, int len) { - char filename[BUFSIZE]; - - if (snprintf (filename, BUFSIZE, nfs2_procedures_file, inst) > BUFSIZE) - return; - - rrd_update_file (host, filename, val, nfs2_procedures_ds_def, - nfs2_procedures_ds_num); -} - -static void nfs3_procedures_write (char *host, char *inst, char *val) -{ - char filename[BUFSIZE]; - - if (snprintf (filename, BUFSIZE, nfs3_procedures_file, inst) > BUFSIZE) - return; - - rrd_update_file (host, filename, val, nfs3_procedures_ds_def, - nfs3_procedures_ds_num); -} - -#if NFS_HAVE_READ -static void nfs2_procedures_submit (unsigned long long *val, char *inst) -{ - char buf[BUFSIZE]; - int retval = 0; - - retval = snprintf (buf, BUFSIZE, "%u:%llu:%llu:%llu:%llu:%llu:%llu:" - "%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:" - "%llu:%llu:%llu", /* 18x %llu */ - (unsigned int) curtime, - val[0], val[1], val[2], val[3], val[4], val[5], val[6], - val[7], val[8], val[9], val[10], val[11], val[12], - val[13], val[14], val[15], val[16], val[17]); - - - if (retval >= BUFSIZE) - return; - else if (retval < 0) + value_t values[1]; + value_list_t vl = VALUE_LIST_INIT; + int i; + + vl.values = values; + vl.values_len = 1; + vl.time = time (NULL); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "nfs", sizeof (vl.plugin)); + sstrncpy (vl.plugin_instance, plugin_instance, + sizeof (vl.plugin_instance)); + sstrncpy (vl.type, "nfs_procedure", sizeof (vl.type)); + + for (i = 0; i < len; i++) { - syslog (LOG_ERR, "nfs: snprintf's format failed: %s", strerror (errno)); - return; + values[0].counter = val[i]; + sstrncpy (vl.type_instance, names[i], + sizeof (vl.type_instance)); + DEBUG ("%s-%s/nfs_procedure-%s = %llu", + vl.plugin, vl.plugin_instance, + vl.type_instance, val[i]); + plugin_dispatch_values (&vl); } +} /* void nfs_procedures_submit */ - plugin_submit ("nfs2_procedures", inst, buf); -} - -static void nfs3_procedures_submit (unsigned long long *val, char *inst) -{ - char buf[BUFSIZE]; - int retval = 0; - - retval = snprintf(buf, BUFSIZE, "%u:%llu:%llu:%llu:%llu:%llu:%llu:" - "%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:" - "%llu:%llu:%llu:%llu:%llu:%llu:%llu", /* 22x %llu */ - (unsigned int) curtime, - val[0], val[1], val[2], val[3], val[4], val[5], val[6], - val[7], val[8], val[9], val[10], val[11], val[12], - val[13], val[14], val[15], val[16], val[17], val[18], - val[19], val[20], val[21]); - - if (retval >= BUFSIZE) - return; - else if (retval < 0) - { - syslog (LOG_ERR, "nfs: snprintf's format failed: %s", strerror (errno)); - return; - } - - plugin_submit("nfs3_procedures", inst, buf); -} -#endif /* NFS_HAVE_READ */ - -#if KERNEL_LINUX static void nfs_read_stats_file (FILE *fh, char *inst) { char buffer[BUFSIZE]; + char plugin_instance[DATA_MAX_NAME_LEN]; + char *fields[48]; int numfields = 0; @@ -274,30 +222,44 @@ static void nfs_read_stats_file (FILE *fh, char *inst) { numfields = strsplit (buffer, fields, 48); - if (numfields < 2) + if (((numfields - 2) != nfs2_procedures_names_num) + && ((numfields - 2) + != nfs3_procedures_names_num)) continue; - if (strncmp (fields[0], "proc2", 5) == 0) + if (strcmp (fields[0], "proc2") == 0) { int i; unsigned long long *values; - if (numfields - 2 != nfs2_procedures_ds_num) + if ((numfields - 2) != nfs2_procedures_names_num) { - syslog (LOG_WARNING, "nfs: Wrong number of fields (= %i) for NFS2 statistics.", numfields - 2); + WARNING ("nfs plugin: Wrong " + "number of fields (= %i) " + "for NFSv2 statistics.", + numfields - 2); continue; } - if ((values = (unsigned long long *) malloc (nfs2_procedures_ds_num * sizeof (unsigned long long))) == NULL) + ssnprintf (plugin_instance, sizeof (plugin_instance), + "v2%s", inst); + + values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long)); + if (values == NULL) { - syslog (LOG_ERR, "nfs: malloc: %s", strerror (errno)); + char errbuf[1024]; + ERROR ("nfs plugin: malloc " + "failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); continue; } - for (i = 0; i < nfs2_procedures_ds_num; i++) + for (i = 0; i < nfs2_procedures_names_num; i++) values[i] = atoll (fields[i + 2]); - nfs2_procedures_submit (values, inst); + nfs_procedures_submit (plugin_instance, values, + nfs2_procedures_names, + nfs2_procedures_names_num); free (values); } @@ -306,28 +268,39 @@ static void nfs_read_stats_file (FILE *fh, char *inst) int i; unsigned long long *values; - if (numfields - 2 != nfs3_procedures_ds_num) + if ((numfields - 2) != nfs3_procedures_names_num) { - syslog (LOG_WARNING, "nfs: Wrong number of fields (= %i) for NFS3 statistics.", numfields - 2); + WARNING ("nfs plugin: Wrong " + "number of fields (= %i) " + "for NFSv3 statistics.", + numfields - 2); continue; } - if ((values = (unsigned long long *) malloc (nfs3_procedures_ds_num * sizeof (unsigned long long))) == NULL) + ssnprintf (plugin_instance, sizeof (plugin_instance), + "v3%s", inst); + + values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long)); + if (values == NULL) { - syslog (LOG_ERR, "nfs: malloc: %s", strerror (errno)); + char errbuf[1024]; + ERROR ("nfs plugin: malloc " + "failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); continue; } - for (i = 0; i < nfs3_procedures_ds_num; i++) + for (i = 0; i < nfs3_procedures_names_num; i++) values[i] = atoll (fields[i + 2]); - nfs3_procedures_submit (values, inst); + nfs_procedures_submit (plugin_instance, values, + nfs3_procedures_names, + nfs3_procedures_names_num); free (values); } - } -} -#endif /* defined(KERNEL_LINUX) */ + } /* while (fgets (buffer, BUFSIZE, fh) != NULL) */ +} /* void nfs_read_stats_file */ #undef BUFSIZE #if HAVE_LIBKSTAT && 0 @@ -358,10 +331,8 @@ static void nfs2_read_kstat (kstat_t *ksp, char *inst) } #endif -#if NFS_HAVE_READ -static void nfs_read (void) +static int nfs_read (void) { -#if KERNEL_LINUX FILE *fh; if ((fh = fopen ("/proc/net/rpc/nfs", "r")) != NULL) @@ -376,24 +347,17 @@ static void nfs_read (void) fclose (fh); } -/* #endif defined(KERNEL_LINUX) */ - -#elif HAVE_LIBKSTAT && 0 +#if HAVE_LIBKSTAT && 0 if (nfs2_ksp_client != NULL) nfs2_read_kstat (nfs2_ksp_client, "client"); if (nfs2_ksp_server != NULL) nfs2_read_kstat (nfs2_ksp_server, "server"); #endif /* defined(HAVE_LIBKSTAT) */ + + return (0); } -#else -# define nfs_read NULL -#endif /* NFS_HAVE_READ */ void module_register (void) { - plugin_register (MODULE_NAME, nfs_init, nfs_read, NULL); - plugin_register ("nfs2_procedures", NULL, NULL, nfs2_procedures_write); - plugin_register ("nfs3_procedures", NULL, NULL, nfs3_procedures_write); -} - -#undef MODULE_NAME + plugin_register_read ("nfs", nfs_read); +} /* void module_register */