diff --git a/Makefile b/Makefile index ab7c353..6f44913 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ # Toplevel Makefile -SAMMLER_SRC := sammler.c config.c logging.c rrdtool.c plugins.c +SAMMLER_SRC := sammler.c configfile.c logging.c network.c rrdtool.c plugins.c PLUGIN_SRC := $(wildcard p_*.c) CFLAGS := -O2 -Wall LDFLAGS := -ldl -lrrd -rdynamic diff --git a/config.c b/configfile.c similarity index 99% rename from config.c rename to configfile.c index f36fed6..72aa088 100644 --- a/config.c +++ b/configfile.c @@ -24,7 +24,7 @@ #include "list.h" -#include "config.h" +#include "configfile.h" #include "logging.h" static LIST_HEAD(config_list); diff --git a/config.h b/configfile.h similarity index 100% rename from config.h rename to configfile.h diff --git a/network.c b/network.c new file mode 100644 index 0000000..416ac83 --- /dev/null +++ b/network.c @@ -0,0 +1,53 @@ +#include +#include +#include + +#include "configfile.h" +#include "logging.h" + +#define MAX_SIZE 8192 + +static char *pktbuf = NULL; +static int pos = 0; + +static char *hostname = NULL; + +void net_submit(char *plugin, int version, char *filename, int ds_id, char *data) +{ + int len = 0; + + if (pktbuf == NULL) { + pktbuf = malloc(MAX_SIZE); + pos = 0; + } + + if (hostname == NULL) + hostname = config_get_string("global", "hostname", "localhost"); + + if (pos == 0) { + len = snprintf(pktbuf, MAX_SIZE - pos, "%s\n", hostname); + if (len < 0 || len >= MAX_SIZE - pos) + return; + + pos += len; + } + + len = snprintf(pktbuf + pos, MAX_SIZE - pos, "%s:%d:%s:%d %s\n", + plugin, version, filename, ds_id, data); + + if (len < 0 || len >= MAX_SIZE - pos) + return; + + pos += len; + return; +} + +void net_commit() +{ + if (pos == 0) + return; + + log_print(LOG_ERROR, "%s", pktbuf); + + pos = 0; +} diff --git a/network.h b/network.h new file mode 100644 index 0000000..eeee136 --- /dev/null +++ b/network.h @@ -0,0 +1,7 @@ +#ifndef _NETWORK_H_ +#define _NETWORK_H_ + +void net_submit(char *plugin, int version, char *filename, int ds_id, char *data); +void net_commit(); + +#endif /* _NETWORK_H_ */ diff --git a/plugins.c b/plugins.c index dae1a4e..42a7342 100644 --- a/plugins.c +++ b/plugins.c @@ -27,8 +27,9 @@ #include "list.h" #include "plugins.h" -#include "config.h" +#include "configfile.h" #include "logging.h" +#include "network.h" #include "rrdtool.h" #define BUFSIZE 1024 @@ -104,6 +105,8 @@ void plugins_probe(void) list_for_each_entry(plugin, &plugin_list, list) plugin->probe(); + + net_commit(); } char ** plugins_get_ds(char *name, int version, int ds_id) @@ -143,8 +146,8 @@ void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, cons return; } - rrd_submit(plugin->name, plugin->version, filename, ds_id, buffer); -// net_submit(plugin->name, plugin->version, filename, ds_id, buffer); +// rrd_submit(plugin->name, plugin->version, filename, ds_id, buffer); + net_submit(plugin->name, plugin->version, filename, ds_id, buffer); free(buffer); } diff --git a/rrdtool.c b/rrdtool.c index 716ffb6..87bfed0 100644 --- a/rrdtool.c +++ b/rrdtool.c @@ -29,7 +29,7 @@ #include "list.h" #include "logging.h" -#include "config.h" +#include "configfile.h" #include "plugins.h" #define DEFAULT_STEP 10 diff --git a/sammler.c b/sammler.c index 9dccb87..26b28b9 100644 --- a/sammler.c +++ b/sammler.c @@ -24,7 +24,7 @@ #include #include -#include "config.h" +#include "configfile.h" #include "logging.h" #include "plugins.h" @@ -89,7 +89,8 @@ int main(int argc, char *argv[]) daemon(-1, 0); } - log_print(LOG_EVERYTIME, "sammler started"); + char *hostname = config_get_string("global", "hostname", "localhost"); + log_print(LOG_EVERYTIME, "sammler (pid:%d) started on host '%s'", getpid(), hostname); plugin_load_all(); diff --git a/sammler.conf b/sammler.conf index 855c22a..a5e7ec8 100644 --- a/sammler.conf +++ b/sammler.conf @@ -1,8 +1,12 @@ [global] +hostname localhost + logfile sammler.log -plugin_dir . +step 10 +rrd_dir /var/lib/rrd +plugin_dir . plugin p_stat.so plugin p_load.so plugin p_memory.so @@ -14,10 +18,6 @@ plugin p_mount.so #plugin p_rtstat.so plugin p_random.so -rrd_dir /var/lib/rrd - -step 10 - # 1h(10s), 48h(1min), 7d(5min), 4w(30min) rra RRA:MIN:0.1:1:360 rra RRA:MIN:0.1:6:2880 @@ -32,4 +32,4 @@ rra RRA:AVERAGE:0.1:180:1344 rra RRA:MAX:0.1:1:360 rra RRA:MAX:0.1:6:2880 rra RRA:MAX:0.1:30:2016 -rra RRA:MAX:0.1:180:13446 +rra RRA:MAX:0.1:180:1344