X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fload.c;h=491a985e432c1752a504f9f953808741c93ad76a;hb=86090b3d409634d016da7bbb0cbe43ed5a851d30;hp=2c02d8be0d7890933c35b9d6ebc3d18c889d8f5b;hpb=73681054cbff428d352d8ed707d24fab1bf67b24;p=collectd.git diff --git a/src/load.c b/src/load.c index 2c02d8be..491a985e 100644 --- a/src/load.c +++ b/src/load.c @@ -1,11 +1,10 @@ /** * 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 - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. + * Free Software Foundation; only version 2 of the License is applicable. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of @@ -44,42 +43,40 @@ #endif #endif /* defined(HAVE_GETLOADAVG) */ -static char *load_file = "load.rrd"; - -static char *ds_def[] = +static data_source_t dsrc[3] = { - "DS:shortterm:GAUGE:25:0:100", - "DS:midterm:GAUGE:25:0:100", - "DS:longterm:GAUGE:25:0:100", - NULL + {"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 int ds_num = 3; -void load_init (void) +static data_set_t ds = { - return; -} + "load", 3, dsrc +}; -void load_write (char *host, char *inst, char *val) +#if LOAD_HAVE_READ +static void load_submit (double snum, double mnum, double lnum) { - rrd_update_file (host, load_file, val, ds_def, ds_num); + value_t values[3]; + value_list_t vl = VALUE_LIST_INIT; + + values[0].gauge = snum; + values[1].gauge = mnum; + values[2].gauge = lnum; + + vl.values = values; + vl.values_len = 3; + vl.time = time (NULL); + strcpy (vl.host, hostname); + strcpy (vl.plugin, "load"); + strcpy (vl.plugin_instance, ""); + strcpy (vl.type_instance, ""); + + plugin_dispatch_values ("load", &vl); } -#define BUFSIZE 256 -void load_submit (double snum, double mnum, double lnum) -{ - char buf[BUFSIZE]; - - if (snprintf (buf, BUFSIZE, "%u:%.2f:%.2f:%.2f", (unsigned int) curtime, - snum, mnum, lnum) >= BUFSIZE) - return; - - plugin_submit (MODULE_NAME, "-", buf); -} -#undef BUFSIZE - -#if LOAD_HAVE_READ -void load_read (void) +static int load_read (void) { #if defined(HAVE_GETLOADAVG) double load[3]; @@ -107,6 +104,7 @@ void load_read (void) if (fgets (buffer, 16, loadavg) == NULL) { syslog (LOG_WARNING, "load: fgets: %s", strerror (errno)); + fclose (loadavg); return; } @@ -138,18 +136,17 @@ void load_read (void) load_submit (snum, mnum, lnum); #endif /* HAVE_LIBSTATGRAB */ + + return (0); } #endif /* LOAD_HAVE_READ */ void module_register (void) { - plugin_register (MODULE_NAME, load_init, + plugin_register_data_set (&ds); #if LOAD_HAVE_READ - load_read, -#else - NULL, + plugin_register_read ("load", load_read); #endif - load_write); } #undef MODULE_NAME