create probe.[ch]

This commit is contained in:
Olaf Rempel 2007-04-01 14:30:05 +02:00
parent 8210d25ec4
commit f16b9a8169
18 changed files with 35 additions and 60 deletions

View File

@ -8,7 +8,7 @@ WITH_CURL = yes
# ############################
SAMMLER_SRC := sammler.c configfile.c event.c helper.c logging.c network.c plugins.c
SAMMLER_SRC := sammler.c configfile.c event.c helper.c logging.c network.c plugins.c probe.c
PLUGIN_SRC := p_ctstat.c p_load.c p_memory.c p_mount.c p_netdev.c p_random.c
PLUGIN_SRC += p_rtstat.c p_stat.c p_uptime.c p_vmstat.c
CFLAGS := -O2 -Wall -fno-stack-protector

View File

@ -4,6 +4,7 @@
#include "plugins.h"
int net_init(void);
void net_close(void);
int net_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data);
void net_submit_flush(void);

View File

@ -28,6 +28,7 @@
#include "helper.h"
#include "list.h"
#include "plugins.h"
#include "probe.h"
#define BUFSIZE 8192

View File

@ -23,6 +23,7 @@
#include "helper.h"
#include "plugins.h"
#include "probe.h"
struct sammler_plugin plugin;

View File

@ -22,6 +22,7 @@
#include "helper.h"
#include "plugins.h"
#include "probe.h"
struct sammler_plugin plugin;

View File

@ -22,6 +22,7 @@
#include <string.h>
#include "plugins.h"
#include "probe.h"
#define DS_MEMORY 1
#define DS_SWAP 2

View File

@ -24,6 +24,7 @@
#include <string.h>
#include "plugins.h"
#include "probe.h"
struct sammler_plugin plugin;

View File

@ -25,6 +25,7 @@
#include "helper.h"
#include "list.h"
#include "plugins.h"
#include "probe.h"
#include "p_mysql_helper.h"

View File

@ -23,6 +23,7 @@
#include "helper.h"
#include "plugins.h"
#include "probe.h"
struct sammler_plugin plugin;

View File

@ -22,6 +22,7 @@
#include "helper.h"
#include "plugins.h"
#include "probe.h"
struct sammler_plugin plugin;

View File

@ -23,6 +23,7 @@
#include "helper.h"
#include "plugins.h"
#include "probe.h"
#define DS_STAT 1
#define DS_GC 2

View File

@ -23,6 +23,7 @@
#include "helper.h"
#include "plugins.h"
#include "probe.h"
#define DS_CPU 1
#define DS_PROC 2

View File

@ -22,6 +22,7 @@
#include "helper.h"
#include "plugins.h"
#include "probe.h"
struct sammler_plugin plugin;

View File

@ -22,6 +22,7 @@
#include <string.h>
#include "plugins.h"
#include "probe.h"
struct sammler_plugin plugin;

View File

@ -22,27 +22,17 @@
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <time.h>
#include <limits.h>
#include "list.h"
#include "plugins.h"
#include "configfile.h"
#include "event.h"
#include "logging.h"
#include "network.h"
#include "rrdtool.h"
#define BUFSIZE 512
#define SUBMIT_NET_ONLY 0x01
#include "plugins.h"
static LIST_HEAD(plugin_list);
static int submit_flags;
static char *scratchpad;
static int plugin_init_cb(const char *filename, void *privdata)
@ -118,11 +108,15 @@ static int plugins_probe(void *privdata)
int plugin_init(void)
{
int bufsize = 0;
config_get_strings("global", "plugin", plugin_init_cb, &bufsize);
int cnt = config_get_strings("global", "plugin", plugin_init_cb, &bufsize);
if (cnt == 0) {
log_print(LOG_ERROR, "plugin_init(): no working plugins");
return -1;
}
scratchpad = malloc(bufsize);
if (scratchpad == NULL) {
log_print(LOG_ERROR, "plugin_init: out of memory");
log_print(LOG_ERROR, "plugin_init(): out of memory");
return -1;
}
@ -130,10 +124,6 @@ int plugin_init(void)
list_for_each_entry(plugin, &plugin_list, list)
plugin->buffer = scratchpad;
const char *fwd_only = config_get_string("global", "forward_only", NULL);
if (fwd_only == NULL || strncmp(fwd_only, "true", 4))
submit_flags |= SUBMIT_NET_ONLY;
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
@ -151,35 +141,3 @@ struct sammler_plugin * plugin_lookup(const char *name)
}
return NULL;
}
int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... )
{
static const char *hostname = NULL;
if (hostname == NULL)
hostname = config_get_string("global", "hostname", "localhost");
char *buffer = malloc(BUFSIZE);
if (buffer == NULL) {
log_print(LOG_ERROR, "probe_submit: out of memory");
return -1;
}
va_list az;
va_start(az, fmt);
int len = vsnprintf(buffer, BUFSIZE, fmt, az);
va_end(az);
if (len < 0 || len >= BUFSIZE) {
log_print(LOG_ERROR, "probe_submit: %s arguments too long", plugin->name);
free(buffer);
return -1;
}
net_submit(hostname, plugin->name, filename, ds_id, buffer);
if (!(submit_flags & SUBMIT_NET_ONLY))
rrd_submit(hostname, plugin->name, filename, ds_id, buffer);
free(buffer);
return 0;
}

View File

@ -25,9 +25,6 @@ struct sammler_plugin {
};
int plugin_init(void);
struct sammler_plugin * plugin_lookup(const char *name);
int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... );
#endif /* _PLUGINS_H_ */

View File

@ -74,7 +74,7 @@ static int do_rrd(int (*rrd_func)(int, char **), char *cmd)
int retval = rrd_func(argc, argv);
if (retval == -1) {
errno = 0;
log_print(LOG_ERROR, "rrd_func failed: %s", rrd_get_error());
log_print(LOG_ERROR, "rrd_func failed: %s: %s", argv[1], rrd_get_error());
}
free(cmd);

View File

@ -32,6 +32,7 @@
#include "logging.h"
#include "network.h"
#include "plugins.h"
#include "probe.h"
#define DEFAULT_CONFIG "sammler.conf"
#define DEFAULT_LOGFILE "sammler.log"
@ -71,7 +72,7 @@ int main(int argc, char *argv[])
break;
case '?': /* error */
exit(-1);
exit(1);
break;
default: /* unknown / all options parsed */
@ -81,14 +82,14 @@ int main(int argc, char *argv[])
/* parse config file */
if (config_parse(config))
exit(-1);
exit(1);
/* check logfile */
const char *logfile = config_get_string("global", "logfile", DEFAULT_LOGFILE);
if (logfile != NULL && debug == 0) {
/* start logging */
if (log_init(logfile))
exit(-1);
exit(1);
/* zum daemon mutieren */
daemon(-1, 0);
@ -97,10 +98,16 @@ int main(int argc, char *argv[])
const char *hostname = config_get_string("global", "hostname", "localhost");
log_print(LOG_EVERYTIME, "sammler (pid:%d) started on host '%s'", getpid(), hostname);
if (net_init())
exit(-1);
if (probe_init())
exit(1);
plugin_init();
if (net_init())
exit(1);
if (plugin_init()) {
net_close();
exit(1);
}
event_loop();
return 0;