X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fload.c;h=019f952c07066e7c753dbd193cc40d58ccab11d6;hb=f763c933f11eeb07d4a159fc711190434439eef4;hp=d082816aee1a2598d8167819ba21f203c57e132a;hpb=f9ee71b22e47eec32ceedd8d85afc99949a084a6;p=collectd.git diff --git a/src/load.c b/src/load.c index d082816a..019f952c 100644 --- a/src/load.c +++ b/src/load.c @@ -1,6 +1,6 @@ /** * collectd - src/load.c - * Copyright (C) 2005 Florian octo Forster + * Copyright (C) 2005,2006 Florian octo Forster * * 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 @@ -20,13 +20,17 @@ * Florian octo Forster **/ -#include "load.h" +#include "collectd.h" +#include "common.h" +#include "plugin.h" -#if COLLECT_LOAD #define MODULE_NAME "load" -#include "plugin.h" -#include "common.h" +#if defined(HAVE_GETLOADAVG) || defined(KERNEL_LINUX) || defined(HAVE_LIBSTATGRAB) +# define LOAD_HAVE_READ 1 +#else +# define LOAD_HAVE_READ 0 +#endif #ifdef HAVE_SYS_LOADAVG_H #include @@ -44,25 +48,26 @@ static char *load_file = "load.rrd"; static char *ds_def[] = { - "DS:shortterm:GAUGE:25:0:100", - "DS:midterm:GAUGE:25:0:100", - "DS:longterm:GAUGE:25:0:100", + "DS:shortterm:GAUGE:"COLLECTD_HEARTBEAT":0:100", + "DS:midterm:GAUGE:"COLLECTD_HEARTBEAT":0:100", + "DS:longterm:GAUGE:"COLLECTD_HEARTBEAT":0:100", NULL }; static int ds_num = 3; -void load_init (void) +static void load_init (void) { return; } -void load_write (char *host, char *inst, char *val) +static void load_write (char *host, char *inst, char *val) { rrd_update_file (host, load_file, val, ds_def, ds_num); } +#if LOAD_HAVE_READ #define BUFSIZE 256 -void load_submit (double snum, double mnum, double lnum) +static void load_submit (double snum, double mnum, double lnum) { char buf[BUFSIZE]; @@ -74,7 +79,7 @@ void load_submit (double snum, double mnum, double lnum) } #undef BUFSIZE -void load_read (void) +static void load_read (void) { #if defined(HAVE_GETLOADAVG) double load[3]; @@ -102,6 +107,7 @@ void load_read (void) if (fgets (buffer, 16, loadavg) == NULL) { syslog (LOG_WARNING, "load: fgets: %s", strerror (errno)); + fclose (loadavg); return; } @@ -134,6 +140,9 @@ void load_read (void) load_submit (snum, mnum, lnum); #endif /* HAVE_LIBSTATGRAB */ } +#else +# define load_read NULL +#endif /* LOAD_HAVE_READ */ void module_register (void) { @@ -141,4 +150,3 @@ void module_register (void) } #undef MODULE_NAME -#endif /* COLLECT_LOAD */