include / plugins directory

This commit is contained in:
Olaf Rempel 2007-04-01 14:56:14 +02:00
parent f16b9a8169
commit b71a7cfe04
29 changed files with 121 additions and 50 deletions

1
.gitignore vendored
View File

@ -1,5 +1,4 @@
*.o *.o
*.so
*.d *.d
sammler sammler
sammler.log sammler.log

View File

@ -1,17 +1,13 @@
# Toplevel Makefile # Toplevel Makefile
WITH_RRD=yes
WITH_RRD = yes PLUGINS := ctstat load memory mount netdev random rtstat stat uptime vmstat
PLUGINS += apache mysql
WITH_MYSQL = yes
WITH_CURL = yes
# ############################ # ############################
SAMMLER_SRC := sammler.c configfile.c event.c helper.c logging.c network.c plugins.c probe.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 CFLAGS := -O2 -Wall -fno-stack-protector -Iinclude
PLUGIN_SRC += p_rtstat.c p_stat.c p_uptime.c p_vmstat.c
CFLAGS := -O2 -Wall -fno-stack-protector
LDFLAGS := -ldl -rdynamic LDFLAGS := -ldl -rdynamic
# ############################ # ############################
@ -22,17 +18,10 @@ ifeq ("$(WITH_RRD)", "yes")
LDFLAGS += -lrrd LDFLAGS += -lrrd
endif endif
ifeq ("$(WITH_MYSQL)", "yes")
PLUGIN_SRC += p_mysql.c
endif
ifeq ("$(WITH_CURL)", "yes")
PLUGIN_SRC += p_apache.c
endif
# ############################ # ############################
all: sammler $(PLUGIN_SRC:%.c=%.so) all: sammler
make -C plugins PLUGINS="$(PLUGINS)"
sammler: $(SAMMLER_SRC:%.c=%.o) sammler: $(SAMMLER_SRC:%.c=%.o)
$(CC) $(LDFLAGS) $^ -o $@ $(CC) $(LDFLAGS) $^ -o $@
@ -43,19 +32,8 @@ sammler: $(SAMMLER_SRC:%.c=%.o)
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) -o $@ -c $< $(CC) $(CFLAGS) -o $@ -c $<
%_sh.o: %.c
$(CC) $(CFLAGS) -fPIC -o $@ -c $<
p_apache.so: p_apache_sh.o
$(LD) -shared -lcurl -o $@ $^
p_mysql.so: p_mysql_sh.o p_mysql_helper_sh.o
$(LD) -shared -lmysqlclient -o $@ $^
%.so: %_sh.o
$(LD) -shared -o $@ $<
clean: clean:
rm -rf *.d *.o *.so sammler rm -rf *.d *.o sammler
make -C plugins clean
-include $(SAMMLER_SRC:.c=.d) $(PLUGIN_SRC:.c=.d) -include $(SAMMLER_SRC:%.c=%.d)

9
include/probe.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef _PROBE_H_
#define _PROBE_H_
#include "plugins.h"
int probe_init(void);
int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... );
#endif /* _PROBE_H_ */

3
plugins/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.o
*.so
*.d

26
plugins/Makefile Normal file
View File

@ -0,0 +1,26 @@
CFLAGS := -O2 -Wall -fno-stack-protector -I../include
LDFLAGS := -ldl -rdynamic
# ############################
all: $(PLUGINS:%=%.so)
%.d: %.c
$(CC) $(CFLAGS) -MM -c $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -fPIC -o $@ -c $<
apache.so: apache.o
$(LD) -shared -lcurl -o $@ $^
mysql.so: mysql.o mysql_helper.o
$(LD) -shared -lmysqlclient -o $@ $^
%.so: %.o
$(LD) -shared -o $@ $<
clean:
rm -rf *.d *.o *.so
-include $(PLUGINS:%=%.d)

View File

@ -27,7 +27,7 @@
#include "plugins.h" #include "plugins.h"
#include "probe.h" #include "probe.h"
#include "p_mysql_helper.h" #include "mysql_helper.h"
#define DS_TRAFFIC 1 #define DS_TRAFFIC 1
#define DS_COMMANDS 2 #define DS_COMMANDS 2

View File

@ -5,7 +5,7 @@
#include <mysql/mysql.h> #include <mysql/mysql.h>
#include "logging.h" #include "logging.h"
#include "p_mysql_helper.h" #include "mysql_helper.h"
void * init_connection(const char *host, const char *user, const char *pass) void * init_connection(const char *host, const char *user, const char *pass)
{ {

View File

@ -1,5 +1,5 @@
#ifndef _P_MYSQL_HELPER_H_ #ifndef _MYSQL_HELPER_H_
#define _P_MYSQL_HELPER_H_ #define _MYSQL_HELPER_H_
#include <stdint.h> #include <stdint.h>
@ -32,4 +32,4 @@ int close_connection(void *mysql);
int get_stats(void *mysql, struct mysql_stats *stats); int get_stats(void *mysql, struct mysql_stats *stats);
#endif /* _P_MYSQL_HELPER_H_ */ #endif /* _MYSQL_HELPER_H_ */

56
probe.c Normal file
View File

@ -0,0 +1,56 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "configfile.h"
#include "logging.h"
#include "network.h"
#include "rrdtool.h"
#define BUFSIZE 512
#define SUBMIT_NET_ONLY 0x01
static int submit_flags;
int probe_init(void)
{
const char *fwd_only = config_get_string("global", "forward_only", "false");
if (fwd_only == NULL || strncmp(fwd_only, "true", 4))
submit_flags |= SUBMIT_NET_ONLY;
return 0;
}
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

@ -9,19 +9,19 @@ logfile sammler.log
rrd_dir rrd rrd_dir rrd
plugin_dir . plugin_dir plugins
plugin p_stat.so plugin stat.so
plugin p_load.so plugin load.so
plugin p_memory.so plugin memory.so
plugin p_vmstat.so plugin vmstat.so
plugin p_uptime.so plugin uptime.so
plugin p_netdev.so plugin netdev.so
plugin p_mount.so plugin mount.so
plugin p_ctstat.so plugin ctstat.so
plugin p_rtstat.so plugin rtstat.so
plugin p_random.so plugin random.so
plugin p_mysql.so plugin mysql.so
plugin p_apache.so plugin apache.so
# 1h(10s), 12h(1min), 48h(2min), 14d(15min), 4w(60min), 2y(12h) # 1h(10s), 12h(1min), 48h(2min), 14d(15min), 4w(60min), 2y(12h)
rra RRA:MIN:0.1:1:360 RRA:AVERAGE:0.1:1:360 RRA:MAX:0.1:1:360 rra RRA:MIN:0.1:1:360 RRA:AVERAGE:0.1:1:360 RRA:MAX:0.1:1:360