From 52369dbed12986398a77c7ed74d965a76647893f Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Fri, 8 Feb 2013 17:36:32 +0100 Subject: [PATCH] mnc: initial add --- tools/munin-node-c/Makefile | 14 +++++++++ tools/munin-node-c/README | 28 ++++++++++++++++++ tools/munin-node-c/main.c | 58 +++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+) create mode 100644 tools/munin-node-c/Makefile create mode 100644 tools/munin-node-c/README create mode 100644 tools/munin-node-c/main.c diff --git a/tools/munin-node-c/Makefile b/tools/munin-node-c/Makefile new file mode 100644 index 00000000..bec42767 --- /dev/null +++ b/tools/munin-node-c/Makefile @@ -0,0 +1,14 @@ +CC=gcc +CFLAGS=-W -Wall -pedantic -Wextra -g -O2 +OBJS=main.o +LINKS= + +%.o: %.c + ${CC} ${CFLAGS} -c $< -o $@ +all: munin-node-c + +munin-node-c: ${OBJS} + ${CC} ${CFLAGS} $^ -o $@ +clean: + rm -f munin-node-c ${OBJS} ${LINKS} +.PHONY: all clean diff --git a/tools/munin-node-c/README b/tools/munin-node-c/README new file mode 100644 index 00000000..67c1544f --- /dev/null +++ b/tools/munin-node-c/README @@ -0,0 +1,28 @@ +This is a rewrite of munin node in C. + +Pro: +---- + +The purpose is multiple: + + * reducing resource usage for embedded plateforms, specially when paired + with the C rewrite of the core plugins. + + * no need for Perl + + * Everything runs from inetd. + +Cons: +----- + + * You lose flexibility + + It is compiled code, so you have to create binaries. Even one for each + architecture. + + * Not all the features are implemented + + - root uid is not supported. All plugins are run with a single user, usually nobody. + - no socket is opened. Everything runs from inetd. + +GPLv2 - (C) 2013 Steve SCHNEPP diff --git a/tools/munin-node-c/main.c b/tools/munin-node-c/main.c new file mode 100644 index 00000000..e173ee59 --- /dev/null +++ b/tools/munin-node-c/main.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include + + +char VERSION[] = "1.0.0"; + +int verbose; + +char* host = ""; +char* plugin_dir = "plugins"; +char* spoolfetch_dir = ""; + +int main(int argc, char *argv[]) { + + int optch; + extern int opterr; + int optarg_len; + + char format[] = "vd:h:s:"; + + opterr = 1; + + while ((optch = getopt(argc, argv, format)) != -1) + switch (optch) { + case 'v': + verbose ++; + break; + case 'd': + optarg_len = strlen(optarg); + plugin_dir = (char *) malloc(optarg_len + 1); + strcpy(plugin_dir, optarg); + break; + case 'h': + optarg_len = strlen(optarg); + host = (char *) malloc(optarg_len + 1); + strcpy(host, optarg); + break; + case 's': + optarg_len = strlen(optarg); + spoolfetch_dir = (char *) malloc(optarg_len + 1); + strcpy(spoolfetch_dir, optarg); + break; + } + + /* get default hostname if not precised */ + if (! strlen(host)) { + host = (char *) malloc(HOST_NAME_MAX + 1); + gethostname(host, HOST_NAME_MAX); + } + + printf("verbose: %d, host: %s, plugin_dir: %s, spoolfetch_dir: %s\n", verbose, host, plugin_dir, spoolfetch_dir); + + + return 0; +}