X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fload.c;h=b7372a1091f9e35e7ffc597570129dc3cb636c2a;hb=de0fdb208de123fe753c5fcf03533833777a5b4a;hp=aaba3a5f2c650bcf54928000498ba47ec9b18565;hpb=838af4cdc6c8674ed3e14a95fea172118c707a85;p=collectd.git diff --git a/src/load.c b/src/load.c index aaba3a5f..b7372a10 100644 --- a/src/load.c +++ b/src/load.c @@ -1,6 +1,6 @@ /** * collectd - src/load.c - * Copyright (C) 2005,2006 Florian octo Forster + * Copyright (C) 2005-2008 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 @@ -23,18 +23,14 @@ #include "common.h" #include "plugin.h" -#define MODULE_NAME "load" - -#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 #endif +#if HAVE_STATGRAB_H +# include +#endif + #ifdef HAVE_GETLOADAVG #if !defined(LOADAVG_1MIN) || !defined(LOADAVG_5MIN) || !defined(LOADAVG_15MIN) #define LOADAVG_1MIN 0 @@ -43,19 +39,6 @@ #endif #endif /* defined(HAVE_GETLOADAVG) */ -static data_source_t dsrc[3] = -{ - {"shortterm", DS_TYPE_GAUGE, 0.0, 100.0}, - {"midterm", DS_TYPE_GAUGE, 0.0, 100.0}, - {"longterm", DS_TYPE_GAUGE, 0.0, 100.0} -}; - -static data_set_t ds = -{ - "load", 3, dsrc -}; - -#if LOAD_HAVE_READ static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum) { value_t values[3]; @@ -67,11 +50,11 @@ static void load_submit (gauge_t snum, gauge_t mnum, gauge_t lnum) vl.values = values; vl.values_len = STATIC_ARRAY_SIZE (values); - vl.time = time (NULL); - strcpy (vl.host, hostname_g); - strcpy (vl.plugin, "load"); + sstrncpy (vl.host, hostname_g, sizeof (vl.host)); + sstrncpy (vl.plugin, "load", sizeof (vl.plugin)); + sstrncpy (vl.type, "load", sizeof (vl.type)); - plugin_dispatch_values ("load", &vl); + plugin_dispatch_values (&vl); } static int load_read (void) @@ -82,7 +65,11 @@ static int load_read (void) if (getloadavg (load, 3) == 3) load_submit (load[LOADAVG_1MIN], load[LOADAVG_5MIN], load[LOADAVG_15MIN]); else - WARNING ("load: getloadavg failed: %s", strerror (errno)); + { + char errbuf[1024]; + WARNING ("load: getloadavg failed: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } /* #endif HAVE_GETLOADAVG */ #elif defined(KERNEL_LINUX) @@ -95,24 +82,32 @@ static int load_read (void) if ((loadavg = fopen ("/proc/loadavg", "r")) == NULL) { - WARNING ("load: fopen: %s", strerror (errno)); - return; + char errbuf[1024]; + WARNING ("load: fopen: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + return (-1); } if (fgets (buffer, 16, loadavg) == NULL) { - WARNING ("load: fgets: %s", strerror (errno)); + char errbuf[1024]; + WARNING ("load: fgets: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); fclose (loadavg); - return; + return (-1); } if (fclose (loadavg)) - WARNING ("load: fclose: %s", strerror (errno)); + { + char errbuf[1024]; + WARNING ("load: fclose: %s", + sstrerror (errno, errbuf, sizeof (errbuf))); + } numfields = strsplit (buffer, fields, 8); if (numfields < 3) - return; + return (-1); snum = atof (fields[0]); mnum = atof (fields[1]); @@ -121,7 +116,7 @@ static int load_read (void) load_submit (snum, mnum, lnum); /* #endif KERNEL_LINUX */ -#elif defined(HAVE_LIBSTATGRAB) +#elif HAVE_LIBSTATGRAB gauge_t snum, mnum, lnum; sg_load_stats *ls; @@ -133,18 +128,16 @@ static int load_read (void) lnum = ls->min15; load_submit (snum, mnum, lnum); -#endif /* HAVE_LIBSTATGRAB */ +/* #endif HAVE_LIBSTATGRAB */ + +#else +# error "No applicable input method." +#endif return (0); } -#endif /* LOAD_HAVE_READ */ void module_register (void) { - plugin_register_data_set (&ds); -#if LOAD_HAVE_READ plugin_register_read ("load", load_read); -#endif -} - -#undef MODULE_NAME +} /* void module_register */