Browse Source

do plugin_lookup() only when needed

master
Olaf Rempel 15 years ago
parent
commit
3d0063c419
  1. 12
      network.c
  2. 2
      network.h
  3. 4
      plugins.c
  4. 14
      rrdtool.c
  5. 2
      rrdtool.h

12
network.c

@ -30,13 +30,13 @@ static LIST_HEAD(fwd_list);
static char *tx_buf, *rx_buf;
static int tx_pos;
int net_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data)
int net_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data)
{
if (list_empty(&fwd_list))
return 0;
int size = snprintf(tx_buf + tx_pos, BUFSIZE - tx_pos, "%s:%s:%s:%d %s\n",
hostname, plugin->name, filename, ds_id, data);
hostname, pluginname, filename, ds_id, data);
if (size < 0 || size >= BUFSIZE - tx_pos) {
log_print(LOG_ERROR, "net_submit(): arguments too long");
@ -83,13 +83,7 @@ static int net_receive(int socket, void *privdata)
continue;
}
struct sammler_plugin *plugin = plugin_lookup(part[1]);
if (plugin == NULL) {
log_print(LOG_ERROR, "net_receive(): plugin not found (%s)", part[1]);
continue;
}
rrd_submit(part[0], plugin, part[2], atoi(part[3]), data[1]);
rrd_submit(part[0], part[1], part[2], atoi(part[3]), data[1]);
rx_pos = (delim - rx_buf) +1;
}

2
network.h

@ -5,7 +5,7 @@
int net_init(void);
int net_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data);
int net_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data);
void net_submit_flush(void);
#endif /* _NETWORK_H_ */

4
plugins.c

@ -175,10 +175,10 @@ int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id,
return -1;
}
net_submit(hostname, plugin, filename, ds_id, buffer);
net_submit(hostname, plugin->name, filename, ds_id, buffer);
if (!(submit_flags & SUBMIT_NET_ONLY))
rrd_submit(hostname, plugin, filename, ds_id, buffer);
rrd_submit(hostname, plugin->name, filename, ds_id, buffer);
free(buffer);
return 0;

14
rrdtool.c

@ -81,8 +81,14 @@ static int do_rrd(int (*rrd_func)(int, char **), char *cmd)
return retval;
}
static int rrd_create_file(const char *filename, struct sammler_plugin *plugin, int ds_id)
static int rrd_create_file(const char *filename, const char *pluginname, int ds_id)
{
struct sammler_plugin *plugin = plugin_lookup(pluginname);
if (plugin == NULL) {
log_print(LOG_ERROR, "rrd_create_file: plugin not found (%s)", pluginname);
return -1;
}
const char *ds_def = plugin->get_ds(ds_id);
if (ds_def == NULL) {
log_print(LOG_ERROR, "No vaild DS found (%s:%d)", plugin->name, ds_id);
@ -91,7 +97,7 @@ static int rrd_create_file(const char *filename, struct sammler_plugin *plugin,
char *buffer = malloc(ARGVSIZE);
if (buffer == NULL) {
log_print(LOG_ERROR, "append_ds_config: out of memory");
log_print(LOG_ERROR, "rrd_create_file: out of memory");
return -1;
}
@ -193,7 +199,7 @@ static int create_parent_dirs(char *filename)
return 0;
}
int rrd_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data)
int rrd_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data)
{
static const char *rrd_dir = NULL;
if (rrd_dir == NULL)
@ -222,7 +228,7 @@ int rrd_submit(const char *hostname, struct sammler_plugin *plugin, const char *
return -1;
}
if (rrd_create_file(fullfile, plugin, ds_id) == -1) {
if (rrd_create_file(fullfile, pluginname, ds_id) == -1) {
free(fullfile);
return -1;
}

2
rrdtool.h

@ -2,7 +2,7 @@
#define _RRDTOOL_H_
#ifdef WITH_RRD
int rrd_submit(const char *hostname, struct sammler_plugin *plugin, const char *filename, int ds_id, const char *data);
int rrd_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data);
#else
#define rrd_submit(hostname, plugin, filename, ds_id, data)
#endif

Loading…
Cancel
Save