diff --git a/src/traffic.c b/src/traffic.c
index 5a276a825dec02a7faa3d2a56cc823add5cb73f5..7c852f819dc32cc071b2d56982b28daa45502d19 100644 (file)
--- a/src/traffic.c
+++ b/src/traffic.c
* Florian octo Forster <octo at verplant.org>
**/
-#include "traffic.h"
+#include "collectd.h"
+#include "common.h"
+#include "plugin.h"
-#if COLLECT_TRAFFIC
#define MODULE_NAME "traffic"
-#include "plugin.h"
-#include "common.h"
+#if defined(KERNEL_LINUX) || defined(HAVE_LIBKSTAT) || defined(HAVE_LIBSTATGRAB)
+# define TRAFFIC_HAVE_READ 1
+#else
+# define TRAFFIC_HAVE_READ 0
+#endif
-#ifdef HAVE_LIBKSTAT
-#define MAX_NUMIF 256
-extern kstat_ctl_t *kc;
-static kstat_t *ksp[MAX_NUMIF];
-static int numif = 0;
-#endif /* HAVE_LIBKSTAT */
+#define BUFSIZE 512
static char *traffic_filename_template = "traffic-%s.rrd";
};
static int ds_num = 2;
-void traffic_init (void)
+#ifdef HAVE_LIBKSTAT
+#define MAX_NUMIF 256
+extern kstat_ctl_t *kc;
+static kstat_t *ksp[MAX_NUMIF];
+static int numif = 0;
+#endif /* HAVE_LIBKSTAT */
+
+static void traffic_init (void)
{
#ifdef HAVE_LIBKSTAT
kstat_t *ksp_chain;
#endif /* HAVE_LIBKSTAT */
}
-void traffic_write (char *host, char *inst, char *val)
+static void traffic_write (char *host, char *inst, char *val)
{
- char file[512];
+ char file[BUFSIZE];
int status;
- status = snprintf (file, 512, traffic_filename_template, inst);
+ status = snprintf (file, BUFSIZE, traffic_filename_template, inst);
if (status < 1)
return;
- else if (status >= 512)
+ else if (status >= BUFSIZE)
return;
rrd_update_file (host, file, val, ds_def, ds_num);
}
-#define BUFSIZE 512
-void traffic_submit (char *device,
+#if TRAFFIC_HAVE_READ
+static void traffic_submit (char *device,
unsigned long long incoming,
unsigned long long outgoing)
{
plugin_submit (MODULE_NAME, device, buf);
}
-#undef BUFSIZE
-void traffic_read (void)
+static void traffic_read (void)
{
#ifdef KERNEL_LINUX
FILE *fh;
traffic_submit (ios[i].interface_name, ios[i].rx, ios[i].tx);
#endif /* HAVE_LIBSTATGRAB */
}
+#else
+#define traffic_read NULL
+#endif /* TRAFFIC_HAVE_READ */
void module_register (void)
{
plugin_register (MODULE_NAME, traffic_init, traffic_read, traffic_write);
}
+#undef BUFSIZE
#undef MODULE_NAME
-#endif /* COLLECT_TRAFFIC */