Browse Source

include / plugins directory

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

+ 0
- 1
.gitignore View File

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

+ 9
- 31
Makefile View File

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

configfile.h → include/configfile.h View File


event.h → include/event.h View File


helper.h → include/helper.h View File


list.h → include/list.h View File


logging.h → include/logging.h View File


network.h → include/network.h View File


plugins.h → include/plugins.h View File


+ 9
- 0
include/probe.h 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_ */

rrdtool.h → include/rrdtool.h View File


+ 3
- 0
plugins/.gitignore View File

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

+ 26
- 0
plugins/Makefile 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)

p_apache.c → plugins/apache.c View File


p_ctstat.c → plugins/ctstat.c View File


p_load.c → plugins/load.c View File


p_memory.c → plugins/memory.c View File


p_mount.c → plugins/mount.c View File


p_mysql.c → plugins/mysql.c View File

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

p_mysql_helper.c → plugins/mysql_helper.c View File

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

p_mysql_helper.h → plugins/mysql_helper.h View File

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

p_netdev.c → plugins/netdev.c View File


p_random.c → plugins/random.c View File


p_rtstat.c → plugins/rtstat.c View File


p_stat.c → plugins/stat.c View File


p_uptime.c → plugins/uptime.c View File


p_vmstat.c → plugins/vmstat.c View File


+ 56
- 0
probe.c 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;
}

+ 13
- 13
sammler.conf View File

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