Browse Source

include / plugins directory

master
Olaf Rempel 15 years ago
parent
commit
b71a7cfe04
  1. 1
      .gitignore
  2. 40
      Makefile
  3. 0
      include/configfile.h
  4. 0
      include/event.h
  5. 0
      include/helper.h
  6. 0
      include/list.h
  7. 0
      include/logging.h
  8. 0
      include/network.h
  9. 0
      include/plugins.h
  10. 9
      include/probe.h
  11. 0
      include/rrdtool.h
  12. 3
      plugins/.gitignore
  13. 26
      plugins/Makefile
  14. 0
      plugins/apache.c
  15. 0
      plugins/ctstat.c
  16. 0
      plugins/load.c
  17. 0
      plugins/memory.c
  18. 0
      plugins/mount.c
  19. 2
      plugins/mysql.c
  20. 2
      plugins/mysql_helper.c
  21. 6
      plugins/mysql_helper.h
  22. 0
      plugins/netdev.c
  23. 0
      plugins/random.c
  24. 0
      plugins/rtstat.c
  25. 0
      plugins/stat.c
  26. 0
      plugins/uptime.c
  27. 0
      plugins/vmstat.c
  28. 56
      probe.c
  29. 26
      sammler.conf

1
.gitignore vendored

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

40
Makefile

@ -1,17 +1,13 @@
# Toplevel Makefile
WITH_RRD=yes
WITH_RRD = yes
WITH_MYSQL = yes
WITH_CURL = yes
PLUGINS := ctstat load memory mount netdev random rtstat stat uptime vmstat
PLUGINS += apache mysql
# ############################
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
CFLAGS := -O2 -Wall -fno-stack-protector -Iinclude
LDFLAGS := -ldl -rdynamic
# ############################
@ -22,17 +18,10 @@ ifeq ("$(WITH_RRD)", "yes")
LDFLAGS += -lrrd
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)
$(CC) $(LDFLAGS) $^ -o $@
@ -43,19 +32,8 @@ sammler: $(SAMMLER_SRC:%.c=%.o)
%.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:
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)

0
configfile.h → include/configfile.h

0
event.h → include/event.h

0
helper.h → include/helper.h

0
list.h → include/list.h

0
logging.h → include/logging.h

0
network.h → include/network.h

0
plugins.h → include/plugins.h

9
include/probe.h

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

0
rrdtool.h → include/rrdtool.h

3
plugins/.gitignore vendored

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

26
plugins/Makefile

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

0
p_apache.c → plugins/apache.c

0
p_ctstat.c → plugins/ctstat.c

0
p_load.c → plugins/load.c

0
p_memory.c → plugins/memory.c

0
p_mount.c → plugins/mount.c

2
p_mysql.c → plugins/mysql.c

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

2
p_mysql_helper.c → plugins/mysql_helper.c

@ -5,7 +5,7 @@
#include <mysql/mysql.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)
{

6
p_mysql_helper.h → plugins/mysql_helper.h

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

0
p_netdev.c → plugins/netdev.c

0
p_random.c → plugins/random.c

0
p_rtstat.c → plugins/rtstat.c

0
p_stat.c → plugins/stat.c

0
p_uptime.c → plugins/uptime.c

0
p_vmstat.c → plugins/vmstat.c

56
probe.c

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

26
sammler.conf

@ -9,19 +9,19 @@ logfile sammler.log
rrd_dir rrd
plugin_dir .
plugin p_stat.so
plugin p_load.so
plugin p_memory.so
plugin p_vmstat.so
plugin p_uptime.so
plugin p_netdev.so
plugin p_mount.so
plugin p_ctstat.so
plugin p_rtstat.so
plugin p_random.so
plugin p_mysql.so
plugin p_apache.so
plugin_dir plugins
plugin stat.so
plugin load.so
plugin memory.so
plugin vmstat.so
plugin uptime.so
plugin netdev.so
plugin mount.so
plugin ctstat.so
plugin rtstat.so
plugin random.so
plugin mysql.so
plugin apache.so
# 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

Loading…
Cancel
Save