From: usev6 Date: Fri, 15 Sep 2017 21:05:14 +0000 (+0200) Subject: nfs: Add config options to ignore versions X-Git-Tag: collectd-5.8.0~96^2~1 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=e56e0ec209345beb11f35ad76c4e4cbcac03de5d nfs: Add config options to ignore versions --- diff --git a/src/collectd.conf.in b/src/collectd.conf.in index 9b36e237..dbc5463f 100644 --- a/src/collectd.conf.in +++ b/src/collectd.conf.in @@ -940,6 +940,12 @@ # CacheFlush 1800 @LOAD_PLUGIN_NETWORK@ +# +# IgnoreV2 true +# #IgnoreV3 true +# #IgnoreV4 true +# + # # URL "http://localhost/status?auto" # User "www-user" diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index 80ba758b..298a43b4 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -5166,6 +5166,25 @@ statistics available. Defaults to B. =back +=head2 Plugin C + +The I collects information about the usage of the Network File +System (NFS). It counts the number of procedure calls for each procedure, +grouped by version and whether the system runs as server or client. + +It is possibly to omit metrics for a specific NFS version by setting one or +more of the following options to B (all of them default to B). + +=over 4 + +=item B B|B + +=item B B|B + +=item B B|B + +=back + =head2 Plugin C This plugin collects the number of connections and requests handled by the diff --git a/src/nfs.c b/src/nfs.c index bbe84384..2f628218 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -31,6 +31,12 @@ #include #endif +static const char *config_keys[] = {"IgnoreV2", "IgnoreV3", "IgnoreV4"}; +static int config_keys_num = STATIC_ARRAY_SIZE(config_keys); +static int ignore_v2 = 0; +static int ignore_v3 = 0; +static int ignore_v4 = 0; + /* see /proc/net/rpc/nfs see http://www.missioncriticallinux.com/orph/NFS-Statistics @@ -295,6 +301,19 @@ static kstat_t *nfs4_ksp_client; static kstat_t *nfs4_ksp_server; #endif +static int nfs_config(const char *key, const char *value) { + if (strcasecmp(key, "IgnoreV2") == 0 && IS_TRUE(value)) + ignore_v2 = 1; + else if (strcasecmp(key, "IgnoreV3") == 0 && IS_TRUE(value)) + ignore_v3 = 1; + else if (strcasecmp(key, "IgnoreV4") == 0 && IS_TRUE(value)) + ignore_v4 = 1; + else + return -1; + + return 0; +} + #if KERNEL_LINUX static int nfs_init(void) { return 0; } /* #endif KERNEL_LINUX */ @@ -495,18 +514,18 @@ static void nfs_read_linux(FILE *fh, const char *inst) { if (fields_num < 3) continue; - if (strcmp(fields[0], "proc2") == 0) { + if (strcmp(fields[0], "proc2") == 0 && ignore_v2 == 0) { nfs_submit_fields_safe(/* version = */ 2, inst, fields + 2, (size_t)(fields_num - 2), nfs2_procedures_names, nfs2_procedures_names_num); - } else if (strncmp(fields[0], "proc3", 5) == 0) { + } else if (strncmp(fields[0], "proc3", 5) == 0 && ignore_v3 == 0) { nfs_submit_fields_safe(/* version = */ 3, inst, fields + 2, (size_t)(fields_num - 2), nfs3_procedures_names, nfs3_procedures_names_num); - } else if (strcmp(fields[0], "proc4ops") == 0) { + } else if (strcmp(fields[0], "proc4ops") == 0 && ignore_v4 == 0) { if (inst[0] == 's') nfs_submit_nfs4_server(inst, fields + 2, (size_t)(fields_num - 2)); - } else if (strcmp(fields[0], "proc4") == 0) { + } else if (strcmp(fields[0], "proc4") == 0 && ignore_v4 == 0) { if (inst[0] == 'c') nfs_submit_nfs4_client(inst, fields + 2, (size_t)(fields_num - 2)); } @@ -561,24 +580,31 @@ static int nfs_read(void) { #elif HAVE_LIBKSTAT static int nfs_read(void) { - nfs_read_kstat(nfs2_ksp_client, /* version = */ 2, "client", - nfs2_procedures_names, nfs2_procedures_names_num); - nfs_read_kstat(nfs2_ksp_server, /* version = */ 2, "server", - nfs2_procedures_names, nfs2_procedures_names_num); - nfs_read_kstat(nfs3_ksp_client, /* version = */ 3, "client", - nfs3_procedures_names, nfs3_procedures_names_num); - nfs_read_kstat(nfs3_ksp_server, /* version = */ 3, "server", - nfs3_procedures_names, nfs3_procedures_names_num); - nfs_read_kstat(nfs4_ksp_client, /* version = */ 4, "client", - nfs4_procedures_names, nfs4_procedures_names_num); - nfs_read_kstat(nfs4_ksp_server, /* version = */ 4, "server", - nfs4_procedures_names, nfs4_procedures_names_num); + if (ignore_v2 == 0) { + nfs_read_kstat(nfs2_ksp_client, /* version = */ 2, "client", + nfs2_procedures_names, nfs2_procedures_names_num); + nfs_read_kstat(nfs2_ksp_server, /* version = */ 2, "server", + nfs2_procedures_names, nfs2_procedures_names_num); + } + if (ignore_v3 == 0) { + nfs_read_kstat(nfs3_ksp_client, /* version = */ 3, "client", + nfs3_procedures_names, nfs3_procedures_names_num); + nfs_read_kstat(nfs3_ksp_server, /* version = */ 3, "server", + nfs3_procedures_names, nfs3_procedures_names_num); + } + if (ignore_v2 == 0) { + nfs_read_kstat(nfs4_ksp_client, /* version = */ 4, "client", + nfs4_procedures_names, nfs4_procedures_names_num); + nfs_read_kstat(nfs4_ksp_server, /* version = */ 4, "server", + nfs4_procedures_names, nfs4_procedures_names_num); + } return 0; } #endif /* HAVE_LIBKSTAT */ void module_register(void) { + plugin_register_config("nfs", nfs_config, config_keys, config_keys_num); plugin_register_init("nfs", nfs_init); plugin_register_read("nfs", nfs_read); } /* void module_register */