X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fnfs.c;h=f2db895a00d484bf647e1c2a9a7688dd106ca31e;hb=2f712e8af3ae9461df24fe92098b44a0ee07d291;hp=3321630ae991ab6dc9427865eccd3bb9b92eb3ca;hpb=a82ff6683f0011a498b4fc0947833d2e28925b76;p=collectd.git diff --git a/src/nfs.c b/src/nfs.c index 3321630a..f2db895a 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -1,11 +1,10 @@ /** * collectd - src/nfs.c - * Copyright (C) 2005 Jason Pepas + * Copyright (C) 2005,2006 Jason Pepas * * 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 @@ -21,16 +20,13 @@ * Florian octo Forster **/ -#include "nfs.h" - -#if COLLECT_NFS -#define MODULE_NAME "nfs" - -#include "plugin.h" +#include "collectd.h" #include "common.h" +#include "plugin.h" -static char *nfs2_procedures_file = "nfs2_procedures-%s.rrd"; -static char *nfs3_procedures_file = "nfs3_procedures-%s.rrd"; +#if !KERNEL_LINUX +# error "No applicable input method." +#endif /* see /proc/net/rpc/nfs @@ -77,59 +73,59 @@ Number Procedures Procedures 21 commit */ -static char *nfs2_procedures_ds_def[] = +static const char *nfs2_procedures_names[] = { - "DS:null:COUNTER:25:0:U", - "DS:getattr:COUNTER:25:0:U", - "DS:setattr:COUNTER:25:0:U", - "DS:root:COUNTER:25:0:U", - "DS:lookup:COUNTER:25:0:U", - "DS:readlink:COUNTER:25:0:U", - "DS:read:COUNTER:25:0:U", - "DS:wrcache:COUNTER:25:0:U", - "DS:write:COUNTER:25:0:U", - "DS:create:COUNTER:25:0:U", - "DS:remove:COUNTER:25:0:U", - "DS:rename:COUNTER:25:0:U", - "DS:link:COUNTER:25:0:U", - "DS:symlink:COUNTER:25:0:U", - "DS:mkdir:COUNTER:25:0:U", - "DS:rmdir:COUNTER:25:0:U", - "DS:readdir:COUNTER:25:0:U", - "DS:fsstat:COUNTER:25: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:25:0:U", - "DS:getattr:COUNTER:25:0:U", - "DS:setattr:COUNTER:25:0:U", - "DS:lookup:COUNTER:25:0:U", - "DS:access:COUNTER:25:0:U", - "DS:readlink:COUNTER:25:0:U", - "DS:read:COUNTER:25:0:U", - "DS:write:COUNTER:25:0:U", - "DS:create:COUNTER:25:0:U", - "DS:mkdir:COUNTER:25:0:U", - "DS:symlink:COUNTER:25:0:U", - "DS:mknod:COUNTER:25:0:U", - "DS:remove:COUNTER:25:0:U", - "DS:rmdir:COUNTER:25:0:U", - "DS:rename:COUNTER:25:0:U", - "DS:link:COUNTER:25:0:U", - "DS:readdir:COUNTER:25:0:U", - "DS:readdirplus:COUNTER:25:0:U", - "DS:fsstat:COUNTER:25:0:U", - "DS:fsinfo:COUNTER:25:0:U", - "DS:pathconf:COUNTER:25:0:U", - "DS:commit:COUNTER:25: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; -#ifdef HAVE_LIBKSTAT +#if HAVE_LIBKSTAT && 0 extern kstat_ctl_t *kc; static kstat_t *nfs2_ksp_client; static kstat_t *nfs2_ksp_server; @@ -141,9 +137,10 @@ static kstat_t *nfs4_ksp_server; /* Possibly TODO: NFSv4 statistics */ -void nfs_init (void) +#if 0 +static int nfs_init (void) { -#ifdef HAVE_LIBKSTAT +#if HAVE_LIBKSTAT && 0 kstat_t *ksp_chain; nfs2_ksp_client = NULL; @@ -176,87 +173,45 @@ void nfs_init (void) } #endif - return; -} + return (0); +} /* int nfs_init */ +#endif #define BUFSIZE 1024 -void nfs2_procedures_write (char *host, char *inst, char *val) -{ - 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); -} - -void nfs3_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, nfs3_procedures_file, inst) > BUFSIZE) - return; - - rrd_update_file (host, filename, val, nfs3_procedures_ds_def, - nfs3_procedures_ds_num); -} - -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); -} - -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); -} - -#if defined(KERNEL_LINUX) -void nfs_read_stats_file (FILE *fh, char *inst) +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; @@ -267,30 +222,44 @@ 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); } @@ -299,32 +268,43 @@ 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 -#ifdef HAVE_LIBKSTAT -void nfs2_read_kstat (kstat_t *ksp, char *inst) +#if HAVE_LIBKSTAT && 0 +static void nfs2_read_kstat (kstat_t *ksp, char *inst) { unsigned long long values[18]; @@ -351,9 +331,8 @@ void nfs2_read_kstat (kstat_t *ksp, char *inst) } #endif -void nfs_read (void) +static int nfs_read (void) { -#if defined(KERNEL_LINUX) FILE *fh; if ((fh = fopen ("/proc/net/rpc/nfs", "r")) != NULL) @@ -368,22 +347,17 @@ void nfs_read (void) fclose (fh); } -/* #endif defined(KERNEL_LINUX) */ - -#elif defined(HAVE_LIBKSTAT) +#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); } 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 -#endif /* COLLECT_LOAD */ + plugin_register_read ("nfs", nfs_read); +} /* void module_register */