const stuff

This commit is contained in:
Olaf Rempel 2007-03-31 22:31:07 +02:00
parent 042b7ce9a0
commit 253a79584e
20 changed files with 60 additions and 58 deletions

View File

@ -24,7 +24,7 @@ static int fwd_sock;
static char *tx_buf, *rx_buf; static char *tx_buf, *rx_buf;
static int tx_pos; static int tx_pos;
int net_submit(const char *hostname, char *plugin, char *filename, int ds_id, char *data) int net_submit(const char *hostname, const char *plugin, const char *filename, int ds_id, const char *data)
{ {
int size = snprintf(tx_buf + tx_pos, BUFSIZE - tx_pos, "%s:%s:%s:%d %s\n", int size = snprintf(tx_buf + tx_pos, BUFSIZE - tx_pos, "%s:%s:%s:%d %s\n",
hostname, plugin, filename, ds_id, data); hostname, plugin, filename, ds_id, data);
@ -39,7 +39,7 @@ int net_submit(const char *hostname, char *plugin, char *filename, int ds_id, ch
return 0; return 0;
} }
int net_submit_flush() int net_submit_flush(void)
{ {
if (tx_pos != 0) if (tx_pos != 0)
sendto(fwd_sock, tx_buf, tx_pos, 0, (struct sockaddr *)&fwd_sa, sizeof(fwd_sa)); sendto(fwd_sock, tx_buf, tx_pos, 0, (struct sockaddr *)&fwd_sa, sizeof(fwd_sa));
@ -76,7 +76,7 @@ int net_receive(int socket)
return 0; return 0;
} }
static int net_config_get_saddr(char *section, char *option, struct sockaddr_in *sa) static int net_config_get_saddr(const char *section, const char *option, struct sockaddr_in *sa)
{ {
char *part[2]; char *part[2];
@ -94,7 +94,7 @@ static int net_config_get_saddr(char *section, char *option, struct sockaddr_in
return 0; return 0;
} }
int net_init_cli() int net_init_cli(void)
{ {
int ret = net_config_get_saddr("global", "forward", &fwd_sa); int ret = net_config_get_saddr("global", "forward", &fwd_sa);
if (ret < 0) if (ret < 0)
@ -118,7 +118,7 @@ int net_init_cli()
return 0; return 0;
} }
int net_init_srv() int net_init_srv(void)
{ {
struct sockaddr_in sa_srv; struct sockaddr_in sa_srv;

View File

@ -3,11 +3,11 @@
#include "plugins.h" #include "plugins.h"
int net_init_srv(); int net_init_srv(void);
int net_init_cli(); int net_init_cli(void);
int net_receive(int sock); int net_receive(int sock);
int net_submit(const char *hostname, char *plugin, char *filename, int ds_id, char *data); int net_submit(const char *hostname, const char *plugin, const char *filename, int ds_id, const char *data);
int net_submit_flush(); int net_submit_flush();
#endif /* _NETWORK_H_ */ #endif /* _NETWORK_H_ */

View File

@ -39,7 +39,7 @@ struct server_entry {
static LIST_HEAD(server_list); static LIST_HEAD(server_list);
static char *ds_def = { static const char *ds_def = {
"DS:total_accesses:COUNTER:90:0:U " "DS:total_accesses:COUNTER:90:0:U "
"DS:total_kbytes:COUNTER:90:0:U " "DS:total_kbytes:COUNTER:90:0:U "
"DS:busy_workers:GAUGE:90:0:U " "DS:busy_workers:GAUGE:90:0:U "
@ -58,7 +58,7 @@ struct sammler_plugin plugin;
static char *rx_buf; static char *rx_buf;
static int rx_pos; static int rx_pos;
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -28,7 +28,7 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def = { static const char *ds_def = {
"DS:entries:GAUGE:15:0:U " "DS:entries:GAUGE:15:0:U "
"DS:searched:DERIVE:15:0:U " "DS:searched:DERIVE:15:0:U "
"DS:found:DERIVE:15:0:U " "DS:found:DERIVE:15:0:U "
@ -47,7 +47,7 @@ static char *ds_def = {
"DS:expect_delete:DERIVE:15:0:U " "DS:expect_delete:DERIVE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -25,13 +25,13 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def = { static const char *ds_def = {
"DS:1min:GAUGE:15:0:U " "DS:1min:GAUGE:15:0:U "
"DS:5min:GAUGE:15:0:U " "DS:5min:GAUGE:15:0:U "
"DS:15min:GAUGE:15:0:U " "DS:15min:GAUGE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -30,19 +30,19 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *mem_ds_def = { static const char *mem_ds_def = {
"DS:total:GAUGE:15:0:U " "DS:total:GAUGE:15:0:U "
"DS:free:GAUGE:15:0:U " "DS:free:GAUGE:15:0:U "
"DS:buffers:GAUGE:15:0:U " "DS:buffers:GAUGE:15:0:U "
"DS:cached:GAUGE:15:0:U " "DS:cached:GAUGE:15:0:U "
}; };
static char *swap_ds_def = { static const char *swap_ds_def = {
"DS:total:GAUGE:15:0:U " "DS:total:GAUGE:15:0:U "
"DS:free:GAUGE:15:0:U " "DS:free:GAUGE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
switch (ds_id) { switch (ds_id) {
case DS_MEMORY: case DS_MEMORY:

View File

@ -27,12 +27,12 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def = { static const char *ds_def = {
"DS:block_total:GAUGE:15:0:U " "DS:block_total:GAUGE:15:0:U "
"DS:block_free:GAUGE:15:0:U " "DS:block_free:GAUGE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -41,12 +41,12 @@ struct server_entry {
static LIST_HEAD(server_list); static LIST_HEAD(server_list);
static char *traffic_ds_def = { static const char *traffic_ds_def = {
"DS:bytes_received:COUNTER:90:0:U " "DS:bytes_received:COUNTER:90:0:U "
"DS:bytes_sent:COUNTER:90:0:U " "DS:bytes_sent:COUNTER:90:0:U "
}; };
static char *commands_ds_def = { static const char *commands_ds_def = {
"DS:com_delete:COUNTER:90:0:U " "DS:com_delete:COUNTER:90:0:U "
"DS:com_insert:COUNTER:90:0:U " "DS:com_insert:COUNTER:90:0:U "
"DS:com_select:COUNTER:90:0:U " "DS:com_select:COUNTER:90:0:U "
@ -55,7 +55,7 @@ static char *commands_ds_def = {
"DS:questions:COUNTER:90:0:U " "DS:questions:COUNTER:90:0:U "
}; };
static char *qcache_ds_def = { static const char *qcache_ds_def = {
"DS:qc_free_blocks:GAUGE:90:0:U " "DS:qc_free_blocks:GAUGE:90:0:U "
"DS:qc_free_memory:GAUGE:90:0:U " "DS:qc_free_memory:GAUGE:90:0:U "
"DS:qc_hits:COUNTER:90:0:U " "DS:qc_hits:COUNTER:90:0:U "
@ -66,14 +66,14 @@ static char *qcache_ds_def = {
"DS:qc_total_blocks:GAUGE:90:0:U " "DS:qc_total_blocks:GAUGE:90:0:U "
}; };
static char *threads_ds_def = { static const char *threads_ds_def = {
"DS:threads_cached:GAUGE:90:0:U " "DS:threads_cached:GAUGE:90:0:U "
"DS:threads_connected:GAUGE:90:0:U " "DS:threads_connected:GAUGE:90:0:U "
"DS:threads_created:COUNTER:90:0:U " "DS:threads_created:COUNTER:90:0:U "
"DS:threads_running:GAUGE:90:0:U " "DS:threads_running:GAUGE:90:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
switch (ds_id) { switch (ds_id) {
case DS_TRAFFIC: case DS_TRAFFIC:

View File

@ -7,7 +7,7 @@
#include "logging.h" #include "logging.h"
#include "p_mysql_helper.h" #include "p_mysql_helper.h"
void * init_connection(char *host, char *user, char *pass) void * init_connection(const char *host, const char *user, const char *pass)
{ {
MYSQL *con = NULL; MYSQL *con = NULL;

View File

@ -26,7 +26,7 @@ struct mysql_stats {
uint64_t threads_running; uint64_t threads_running;
}; };
void * init_connection(char *host, char *user, char *pass); void * init_connection(const char *host, const char *user, const char *pass);
int ping_connection(void *mysql); int ping_connection(void *mysql);
int close_connection(void *mysql); int close_connection(void *mysql);

View File

@ -28,14 +28,14 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def = { static const char *ds_def = {
"DS:byte_in:COUNTER:15:0:U " "DS:byte_in:COUNTER:15:0:U "
"DS:byte_out:COUNTER:15:0:U " "DS:byte_out:COUNTER:15:0:U "
"DS:pkt_in:COUNTER:15:0:U " "DS:pkt_in:COUNTER:15:0:U "
"DS:pkt_out:COUNTER:15:0:U " "DS:pkt_out:COUNTER:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -25,11 +25,11 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def = { static const char *ds_def = {
"DS:entropy:GAUGE:15:0:U " "DS:entropy:GAUGE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -31,7 +31,7 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def_stat = { static const char *ds_def_stat = {
"DS:in_hit:DERIVE:15:0:U " "DS:in_hit:DERIVE:15:0:U "
"DS:in_slow_tot:DERIVE:15:0:U " "DS:in_slow_tot:DERIVE:15:0:U "
"DS:in_slow_mc:DERIVE:15:0:U " "DS:in_slow_mc:DERIVE:15:0:U "
@ -46,7 +46,7 @@ static char *ds_def_stat = {
"DS:out_hlist_search:DERIVE:15:0:U " "DS:out_hlist_search:DERIVE:15:0:U "
}; };
static char *ds_def_gc = { static const char *ds_def_gc = {
"DS:entries:GAUGE:15:0:U " "DS:entries:GAUGE:15:0:U "
"DS:gc_total:DERIVE:15:0:U " "DS:gc_total:DERIVE:15:0:U "
"DS:gc_ignored:DERIVE:15:0:U " "DS:gc_ignored:DERIVE:15:0:U "
@ -54,7 +54,7 @@ static char *ds_def_gc = {
"DS:gc_dst_overflow:DERIVE:15:0:U " "DS:gc_dst_overflow:DERIVE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
switch (ds_id) { switch (ds_id) {
case DS_STAT: case DS_STAT:

View File

@ -31,7 +31,7 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *cpu_ds_def = { static const char *cpu_ds_def = {
"DS:user:COUNTER:15:0:U " "DS:user:COUNTER:15:0:U "
"DS:nice:COUNTER:15:0:U " "DS:nice:COUNTER:15:0:U "
"DS:system:COUNTER:15:0:U " "DS:system:COUNTER:15:0:U "
@ -42,13 +42,13 @@ static char *cpu_ds_def = {
"DS:steal:COUNTER:15:0:U " "DS:steal:COUNTER:15:0:U "
}; };
static char *proc_ds_def = { static const char *proc_ds_def = {
"DS:intr:COUNTER:15:0:U " "DS:intr:COUNTER:15:0:U "
"DS:ctxt:COUNTER:15:0:U " "DS:ctxt:COUNTER:15:0:U "
"DS:fork:COUNTER:15:0:U " "DS:fork:COUNTER:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
switch (ds_id) { switch (ds_id) {
case DS_CPU: case DS_CPU:
@ -104,10 +104,10 @@ static int probe(void)
else if (numfields == 5) else if (numfields == 5)
val[5] = val[6] = val[7] = val[8] = "0"; val[5] = val[6] = val[7] = val[8] = "0";
else if (numfields == 8) else if (numfields == 8)
val[8] = "0"; val[8] = "0";
probe_submit(&plugin, filename, DS_CPU, probe_submit(&plugin, filename, DS_CPU,
"%s:%s:%s:%s:%s:%s:%s:%s", "%s:%s:%s:%s:%s:%s:%s:%s",
val[1], val[2], val[3], val[4], val[1], val[2], val[3], val[4],

View File

@ -25,12 +25,12 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def = { static const char *ds_def = {
"DS:uptime:GAUGE:15:0:U " "DS:uptime:GAUGE:15:0:U "
"DS:idletime:GAUGE:15:0:U " "DS:idletime:GAUGE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -27,7 +27,7 @@
struct sammler_plugin plugin; struct sammler_plugin plugin;
static char *ds_def = { static const char *ds_def = {
"DS:pgalloc_high:DERIVE:15:0:U " "DS:pgalloc_high:DERIVE:15:0:U "
"DS:pgalloc_normal:DERIVE:15:0:U " "DS:pgalloc_normal:DERIVE:15:0:U "
"DS:pgalloc_dma:DERIVE:15:0:U " "DS:pgalloc_dma:DERIVE:15:0:U "
@ -35,7 +35,7 @@ static char *ds_def = {
"DS:pgfault:DERIVE:15:0:U " "DS:pgfault:DERIVE:15:0:U "
}; };
static char * get_ds(int ds_id) static const char * get_ds(int ds_id)
{ {
return ds_def; return ds_def;
} }

View File

@ -24,6 +24,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#include <limits.h>
#include "list.h" #include "list.h"
@ -51,14 +52,14 @@ static int plugin_init_cb(const char *filename, void *privdata)
if (plugin_dir == NULL) if (plugin_dir == NULL)
plugin_dir = config_get_string("global", "plugin_dir", "."); plugin_dir = config_get_string("global", "plugin_dir", ".");
buffer = malloc(BUFSIZE); buffer = malloc(PATH_MAX);
if (buffer == NULL) { if (buffer == NULL) {
log_print(LOG_ERROR, "plugin_load: out of memory"); log_print(LOG_ERROR, "plugin_load: out of memory");
return -1; return -1;
} }
len = snprintf(buffer, BUFSIZE, "%s/%s", plugin_dir, filename); len = snprintf(buffer, PATH_MAX, "%s/%s", plugin_dir, filename);
if (len < 0 || len >= BUFSIZE) { if (len < 0 || len >= PATH_MAX) {
log_print(LOG_ERROR, "plugin_load: file name too long: %s/%s", plugin_dir, filename); log_print(LOG_ERROR, "plugin_load: file name too long: %s/%s", plugin_dir, filename);
free(buffer); free(buffer);
return -1; return -1;
@ -117,7 +118,7 @@ void plugins_probe(void)
net_submit_flush(); net_submit_flush();
} }
struct sammler_plugin * plugin_lookup(char *name) struct sammler_plugin * plugin_lookup(const char *name)
{ {
struct sammler_plugin *plugin; struct sammler_plugin *plugin;
list_for_each_entry(plugin, &plugin_list, list) { list_for_each_entry(plugin, &plugin_list, list) {
@ -128,7 +129,7 @@ struct sammler_plugin * plugin_lookup(char *name)
return NULL; return NULL;
} }
int probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ) int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... )
{ {
static const char *hostname = NULL; static const char *hostname = NULL;

View File

@ -9,21 +9,21 @@
struct sammler_plugin { struct sammler_plugin {
struct list_head list; struct list_head list;
char *name; const char *name;
unsigned int interval; unsigned int interval;
unsigned long lastprobe; unsigned long lastprobe;
int (*init) (void); int (*init) (void);
int (*fini) (void); int (*fini) (void);
int (*probe) (void); int (*probe) (void);
char * (*get_ds) (int ds_id); const char * (*get_ds) (int ds_id);
}; };
void plugin_init(int flags); void plugin_init(int flags);
void plugins_probe(void); void plugins_probe(void);
struct sammler_plugin * plugin_lookup(char *name); struct sammler_plugin * plugin_lookup(const char *name);
int probe_submit(struct sammler_plugin *plugin, char *filename, int ds_id, const char *fmt, ... ); int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... );
#endif /* _PLUGINS_H_ */ #endif /* _PLUGINS_H_ */

View File

@ -73,7 +73,7 @@ static int append_rra_config(char *buffer, int size, int *pos)
return config_get_strings("global", "rra", append_rra_config_cb, &data); return config_get_strings("global", "rra", append_rra_config_cb, &data);
} }
static int do_rrd(int mode, char *cmd) static int do_rrd(int mode, const char *cmd)
{ {
int argc; int argc;
char *argv[ARGCMAX]; char *argv[ARGCMAX];
@ -103,11 +103,12 @@ static int do_rrd(int mode, char *cmd)
return 0; return 0;
} }
static int rrd_create_file(char *filename, char *plugin_name, int ds_id) static int rrd_create_file(const char *filename, const char *plugin_name, int ds_id)
{ {
struct sammler_plugin *plugin; struct sammler_plugin *plugin;
int pos, step, retval; int pos, step, retval;
char *ds_def, *buffer; const char *ds_def;
char *buffer;
plugin = plugin_lookup(plugin_name); plugin = plugin_lookup(plugin_name);
if (plugin == NULL) { if (plugin == NULL) {
@ -147,7 +148,7 @@ static int rrd_create_file(char *filename, char *plugin_name, int ds_id)
return retval; return retval;
} }
static int rrd_update_file(char *filename, char *values) static int rrd_update_file(const char *filename, const char *values)
{ {
int pos, retval; int pos, retval;
char *buffer; char *buffer;
@ -171,7 +172,7 @@ static int rrd_update_file(char *filename, char *values)
return retval; return retval;
} }
static int check_create_dir(char *dir) static int check_create_dir(const char *dir)
{ {
struct stat statbuf; struct stat statbuf;
if (stat(dir, &statbuf) == -1) { if (stat(dir, &statbuf) == -1) {
@ -228,7 +229,7 @@ static int create_parent_dirs(char *filename)
return 0; return 0;
} }
int rrd_submit(const char *hostname, char *plugin, char *filename, int ds_id, char *data) int rrd_submit(const char *hostname, const char *plugin, const char *filename, int ds_id, const char *data)
{ {
struct stat statbuf; struct stat statbuf;
static const char *rrd_dir = NULL; static const char *rrd_dir = NULL;

View File

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