perl plugin: Exported plugin_log() to Perl.
[collectd.git] / src / nfs.c
index f585b97..40e4110 100644 (file)
--- a/src/nfs.c
+++ b/src/nfs.c
@@ -23,9 +23,6 @@
 #include "collectd.h"
 #include "common.h"
 #include "plugin.h"
-#include "utils_debug.h"
-
-#define MODULE_NAME "nfs"
 
 /* #if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) */
 #if KERNEL_LINUX
@@ -89,6 +86,7 @@ static data_set_t procedure_ds =
        "nfs_procedure", 1, procedure_dsrc
 };
 
+#if NFS_HAVE_READ
 static const char *nfs2_procedures_names[] =
 {
        "null",
@@ -194,7 +192,6 @@ static int nfs_init (void)
 #endif
 
 #define BUFSIZE 1024
-#if NFS_HAVE_READ
 static void nfs_procedures_submit (const char *plugin_instance,
                unsigned long long *val, const char **names, int len)
 {
@@ -205,7 +202,7 @@ static void nfs_procedures_submit (const char *plugin_instance,
        vl.values = values;
        vl.values_len = 1;
        vl.time = time (NULL);
-       strcpy (vl.host, hostname);
+       strcpy (vl.host, hostname_g);
        strcpy (vl.plugin, "nfs");
        strncpy (vl.plugin_instance, plugin_instance,
                        sizeof (vl.plugin_instance));
@@ -215,13 +212,12 @@ static void nfs_procedures_submit (const char *plugin_instance,
                values[0].counter = val[i];
                strncpy (vl.type_instance, names[i],
                                sizeof (vl.type_instance));
-               DBG ("%s-%s/nfs_procedure-%s = %llu",
+               DEBUG ("%s-%s/nfs_procedure-%s = %llu",
                                vl.plugin, vl.plugin_instance,
                                vl.type_instance, val[i]);
                plugin_dispatch_values ("nfs_procedure", &vl);
        }
 } /* void nfs_procedures_submit */
-#endif /* NFS_HAVE_READ */
 
 #if KERNEL_LINUX
 static void nfs_read_stats_file (FILE *fh, char *inst)
@@ -252,7 +248,7 @@ static void nfs_read_stats_file (FILE *fh, char *inst)
 
                        if ((numfields - 2) != nfs2_procedures_names_num)
                        {
-                               syslog (LOG_WARNING, "nfs plugin: Wrong "
+                               WARNING ("nfs plugin: Wrong "
                                                "number of fields (= %i) "
                                                "for NFSv2 statistics.",
                                                numfields - 2);
@@ -266,9 +262,10 @@ static void nfs_read_stats_file (FILE *fh, char *inst)
                        values = (unsigned long long *) malloc (nfs2_procedures_names_num * sizeof (unsigned long long));
                        if (values == NULL)
                        {
-                               syslog (LOG_ERR, "nfs plugin: malloc "
+                               char errbuf[1024];
+                               ERROR ("nfs plugin: malloc "
                                                "failed: %s",
-                                               strerror (errno));
+                                               sstrerror (errno, errbuf, sizeof (errbuf)));
                                continue;
                        }
 
@@ -288,7 +285,7 @@ static void nfs_read_stats_file (FILE *fh, char *inst)
 
                        if ((numfields - 2) != nfs3_procedures_names_num)
                        {
-                               syslog (LOG_WARNING, "nfs plugin: Wrong "
+                               WARNING ("nfs plugin: Wrong "
                                                "number of fields (= %i) "
                                                "for NFSv3 statistics.",
                                                numfields - 2);
@@ -302,9 +299,10 @@ static void nfs_read_stats_file (FILE *fh, char *inst)
                        values = (unsigned long long *) malloc (nfs3_procedures_names_num * sizeof (unsigned long long));
                        if (values == NULL)
                        {
-                               syslog (LOG_ERR, "nfs plugin: malloc "
+                               char errbuf[1024];
+                               ERROR ("nfs plugin: malloc "
                                                "failed: %s",
-                                               strerror (errno));
+                                               sstrerror (errno, errbuf, sizeof (errbuf)));
                                continue;
                        }
 
@@ -350,7 +348,6 @@ static void nfs2_read_kstat (kstat_t *ksp, char *inst)
 }
 #endif
 
-#if NFS_HAVE_READ
 static int nfs_read (void)
 {
 #if KERNEL_LINUX
@@ -381,13 +378,13 @@ static int nfs_read (void)
 }
 #endif /* NFS_HAVE_READ */
 
-void module_register (void)
+void module_register (modreg_e load)
 {
-       plugin_register_data_set (&procedure_ds);
+       if (load & MR_DATASETS)
+               plugin_register_data_set (&procedure_ds);
 
 #if NFS_HAVE_READ
-       plugin_register_read ("nfs", nfs_read);
+       if (load & MR_READ)
+               plugin_register_read ("nfs", nfs_read);
 #endif
-}
-
-#undef MODULE_NAME
+} /* void module_register */