network stuff

This commit is contained in:
Olaf Rempel 2006-08-03 19:49:07 +02:00
parent a7101d33a9
commit f437881d52
9 changed files with 78 additions and 14 deletions

View File

@ -1,6 +1,6 @@
# Toplevel Makefile # Toplevel Makefile
SAMMLER_SRC := sammler.c config.c logging.c rrdtool.c plugins.c SAMMLER_SRC := sammler.c configfile.c logging.c network.c rrdtool.c plugins.c
PLUGIN_SRC := $(wildcard p_*.c) PLUGIN_SRC := $(wildcard p_*.c)
CFLAGS := -O2 -Wall CFLAGS := -O2 -Wall
LDFLAGS := -ldl -lrrd -rdynamic LDFLAGS := -ldl -lrrd -rdynamic

View File

@ -24,7 +24,7 @@
#include "list.h" #include "list.h"
#include "config.h" #include "configfile.h"
#include "logging.h" #include "logging.h"
static LIST_HEAD(config_list); static LIST_HEAD(config_list);

53
network.c Normal file
View File

@ -0,0 +1,53 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "configfile.h"
#include "logging.h"
#define MAX_SIZE 8192
static char *pktbuf = NULL;
static int pos = 0;
static char *hostname = NULL;
void net_submit(char *plugin, int version, char *filename, int ds_id, char *data)
{
int len = 0;
if (pktbuf == NULL) {
pktbuf = malloc(MAX_SIZE);
pos = 0;
}
if (hostname == NULL)
hostname = config_get_string("global", "hostname", "localhost");
if (pos == 0) {
len = snprintf(pktbuf, MAX_SIZE - pos, "%s\n", hostname);
if (len < 0 || len >= MAX_SIZE - pos)
return;
pos += len;
}
len = snprintf(pktbuf + pos, MAX_SIZE - pos, "%s:%d:%s:%d %s\n",
plugin, version, filename, ds_id, data);
if (len < 0 || len >= MAX_SIZE - pos)
return;
pos += len;
return;
}
void net_commit()
{
if (pos == 0)
return;
log_print(LOG_ERROR, "%s", pktbuf);
pos = 0;
}

7
network.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _NETWORK_H_
#define _NETWORK_H_
void net_submit(char *plugin, int version, char *filename, int ds_id, char *data);
void net_commit();
#endif /* _NETWORK_H_ */

View File

@ -27,8 +27,9 @@
#include "list.h" #include "list.h"
#include "plugins.h" #include "plugins.h"
#include "config.h" #include "configfile.h"
#include "logging.h" #include "logging.h"
#include "network.h"
#include "rrdtool.h" #include "rrdtool.h"
#define BUFSIZE 1024 #define BUFSIZE 1024
@ -104,6 +105,8 @@ void plugins_probe(void)
list_for_each_entry(plugin, &plugin_list, list) list_for_each_entry(plugin, &plugin_list, list)
plugin->probe(); plugin->probe();
net_commit();
} }
char ** plugins_get_ds(char *name, int version, int ds_id) char ** plugins_get_ds(char *name, int version, int ds_id)
@ -143,8 +146,8 @@ void probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, cons
return; return;
} }
rrd_submit(plugin->name, plugin->version, filename, ds_id, buffer); // rrd_submit(plugin->name, plugin->version, filename, ds_id, buffer);
// net_submit(plugin->name, plugin->version, filename, ds_id, buffer); net_submit(plugin->name, plugin->version, filename, ds_id, buffer);
free(buffer); free(buffer);
} }

View File

@ -29,7 +29,7 @@
#include "list.h" #include "list.h"
#include "logging.h" #include "logging.h"
#include "config.h" #include "configfile.h"
#include "plugins.h" #include "plugins.h"
#define DEFAULT_STEP 10 #define DEFAULT_STEP 10

View File

@ -24,7 +24,7 @@
#include <getopt.h> #include <getopt.h>
#include <sys/stat.h> #include <sys/stat.h>
#include "config.h" #include "configfile.h"
#include "logging.h" #include "logging.h"
#include "plugins.h" #include "plugins.h"
@ -89,7 +89,8 @@ int main(int argc, char *argv[])
daemon(-1, 0); daemon(-1, 0);
} }
log_print(LOG_EVERYTIME, "sammler started"); char *hostname = config_get_string("global", "hostname", "localhost");
log_print(LOG_EVERYTIME, "sammler (pid:%d) started on host '%s'", getpid(), hostname);
plugin_load_all(); plugin_load_all();

View File

@ -1,8 +1,12 @@
[global] [global]
hostname localhost
logfile sammler.log logfile sammler.log
plugin_dir . step 10
rrd_dir /var/lib/rrd
plugin_dir .
plugin p_stat.so plugin p_stat.so
plugin p_load.so plugin p_load.so
plugin p_memory.so plugin p_memory.so
@ -14,10 +18,6 @@ plugin p_mount.so
#plugin p_rtstat.so #plugin p_rtstat.so
plugin p_random.so plugin p_random.so
rrd_dir /var/lib/rrd
step 10
# 1h(10s), 48h(1min), 7d(5min), 4w(30min) # 1h(10s), 48h(1min), 7d(5min), 4w(30min)
rra RRA:MIN:0.1:1:360 rra RRA:MIN:0.1:1:360
rra RRA:MIN:0.1:6:2880 rra RRA:MIN:0.1:6:2880
@ -32,4 +32,4 @@ rra RRA:AVERAGE:0.1:180:1344
rra RRA:MAX:0.1:1:360 rra RRA:MAX:0.1:1:360
rra RRA:MAX:0.1:6:2880 rra RRA:MAX:0.1:6:2880
rra RRA:MAX:0.1:30:2016 rra RRA:MAX:0.1:30:2016
rra RRA:MAX:0.1:180:13446 rra RRA:MAX:0.1:180:1344