Browse Source

create probe.[ch]

master
Olaf Rempel 15 years ago
parent
commit
f16b9a8169
  1. 2
      Makefile
  2. 1
      network.h
  3. 1
      p_apache.c
  4. 1
      p_ctstat.c
  5. 1
      p_load.c
  6. 1
      p_memory.c
  7. 1
      p_mount.c
  8. 1
      p_mysql.c
  9. 1
      p_netdev.c
  10. 1
      p_random.c
  11. 1
      p_rtstat.c
  12. 1
      p_stat.c
  13. 1
      p_uptime.c
  14. 1
      p_vmstat.c
  15. 56
      plugins.c
  16. 3
      plugins.h
  17. 2
      rrdtool.c
  18. 17
      sammler.c

2
Makefile

@ -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

1
network.h

@ -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);

1
p_apache.c

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

1
p_ctstat.c

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

1
p_load.c

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

1
p_memory.c

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

1
p_mount.c

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

1
p_mysql.c

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

1
p_netdev.c

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

1
p_random.c

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

1
p_rtstat.c

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

1
p_stat.c

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

1
p_uptime.c

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

1
p_vmstat.c

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

56
plugins.c

@ -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;
}

3
plugins.h

@ -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_ */

2
rrdtool.c

@ -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);

17
sammler.c

@ -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 (probe_init())
exit(1);
if (net_init())
exit(-1);
exit(1);
plugin_init();
if (plugin_init()) {
net_close();
exit(1);
}
event_loop();
return 0;

Loading…
Cancel
Save