global plugin scratchpad memory
This commit is contained in:
parent
253a79584e
commit
b94e64cd45
2
Makefile
2
Makefile
@ -58,4 +58,4 @@ p_mysql.so: p_mysql_sh.o p_mysql_helper_sh.o
|
||||
clean:
|
||||
rm -rf *.d *.o *.so sammler
|
||||
|
||||
#-include $(SAMMLER_SRC:.c=.d) $(PLUGIN_SRC:.c=.d)
|
||||
-include $(SAMMLER_SRC:.c=.d) $(PLUGIN_SRC:.c=.d)
|
||||
|
@ -31,6 +31,8 @@
|
||||
|
||||
#define BUFSIZE 8192
|
||||
|
||||
struct sammler_plugin plugin;
|
||||
|
||||
struct server_entry {
|
||||
struct list_head list;
|
||||
CURL *handle;
|
||||
@ -53,8 +55,6 @@ struct stats {
|
||||
uint64_t idle_workers;
|
||||
};
|
||||
|
||||
struct sammler_plugin plugin;
|
||||
|
||||
static char *rx_buf;
|
||||
static int rx_pos;
|
||||
|
||||
|
29
p_ctstat.c
29
p_ctstat.c
@ -24,8 +24,6 @@
|
||||
#include "helper.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
struct sammler_plugin plugin;
|
||||
|
||||
static const char *ds_def = {
|
||||
@ -52,8 +50,6 @@ static const char * get_ds(int ds_id)
|
||||
return ds_def;
|
||||
}
|
||||
|
||||
static char *buffer;
|
||||
|
||||
static int probe(void)
|
||||
{
|
||||
FILE *fp;
|
||||
@ -67,11 +63,11 @@ static int probe(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, BUFSIZE, fp) != NULL) {
|
||||
if (!strncmp(buffer, "entries", 7))
|
||||
while (fgets(plugin.buffer, plugin.bufsize, fp) != NULL) {
|
||||
if (!strncmp(plugin.buffer, "entries", 7))
|
||||
continue;
|
||||
|
||||
if (strsplit(buffer, " \t\n", val, 16) != 16)
|
||||
if (strsplit(plugin.buffer, " \t\n", val, 16) != 16)
|
||||
continue;
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
@ -94,27 +90,10 @@ static int probe(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
buffer = malloc(BUFSIZE);
|
||||
if (buffer == NULL) {
|
||||
log_print(LOG_WARN, "plugin ctstat: out of memory");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fini(void)
|
||||
{
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sammler_plugin plugin = {
|
||||
.name = "ctstat",
|
||||
.interval = 10,
|
||||
.init = &init,
|
||||
.fini = &fini,
|
||||
.bufsize = 1024,
|
||||
.probe = &probe,
|
||||
.get_ds = &get_ds,
|
||||
};
|
||||
|
49
p_memory.c
49
p_memory.c
@ -23,8 +23,6 @@
|
||||
|
||||
#include "plugins.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
#define DS_MEMORY 1
|
||||
#define DS_SWAP 2
|
||||
|
||||
@ -65,8 +63,6 @@ struct meminfo_ {
|
||||
unsigned long long swapfree;
|
||||
};
|
||||
|
||||
static char *buffer;
|
||||
|
||||
static int probe(void)
|
||||
{
|
||||
FILE *fp;
|
||||
@ -80,24 +76,24 @@ static int probe(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, BUFSIZE, fp) != NULL) {
|
||||
if (!strncmp(buffer, "MemTotal:", 9))
|
||||
meminfo.memtotal = atoll(buffer + 10);
|
||||
while (fgets(plugin.buffer, plugin.bufsize, fp) != NULL) {
|
||||
if (!strncmp(plugin.buffer, "MemTotal:", 9))
|
||||
meminfo.memtotal = atoll(plugin.buffer + 10);
|
||||
|
||||
else if (!strncmp(buffer, "MemFree:", 8))
|
||||
meminfo.memfree = atoll(buffer + 9);
|
||||
else if (!strncmp(plugin.buffer, "MemFree:", 8))
|
||||
meminfo.memfree = atoll(plugin.buffer + 9);
|
||||
|
||||
else if (!strncmp(buffer, "Buffers:", 8))
|
||||
meminfo.buffers = atoll(buffer + 9);
|
||||
else if (!strncmp(plugin.buffer, "Buffers:", 8))
|
||||
meminfo.buffers = atoll(plugin.buffer + 9);
|
||||
|
||||
else if (!strncmp(buffer, "Cached:", 7))
|
||||
meminfo.cached = atoll(buffer + 8);
|
||||
else if (!strncmp(plugin.buffer, "Cached:", 7))
|
||||
meminfo.cached = atoll(plugin.buffer + 8);
|
||||
|
||||
else if (!strncmp(buffer, "SwapTotal:", 10))
|
||||
meminfo.swaptotal = atoll(buffer + 11);
|
||||
else if (!strncmp(plugin.buffer, "SwapTotal:", 10))
|
||||
meminfo.swaptotal = atoll(plugin.buffer + 11);
|
||||
|
||||
else if (!strncmp(buffer, "SwapFree:", 9))
|
||||
meminfo.swapfree = atoll(buffer + 10);
|
||||
else if (!strncmp(plugin.buffer, "SwapFree:", 9))
|
||||
meminfo.swapfree = atoll(plugin.buffer + 10);
|
||||
}
|
||||
|
||||
probe_submit(&plugin, "memory.rrd", DS_MEMORY, "%llu:%llu:%llu:%llu",
|
||||
@ -111,27 +107,10 @@ static int probe(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
buffer = malloc(BUFSIZE);
|
||||
if (buffer == NULL) {
|
||||
log_print(LOG_WARN, "plugin memory: out of memory");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fini(void)
|
||||
{
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sammler_plugin plugin = {
|
||||
.name = "memory",
|
||||
.interval = 10,
|
||||
.init = &init,
|
||||
.fini = &fini,
|
||||
.bufsize = 1024,
|
||||
.probe = &probe,
|
||||
.get_ds = &get_ds,
|
||||
};
|
||||
|
@ -33,6 +33,8 @@
|
||||
#define DS_QCACHE 3
|
||||
#define DS_THREADS 4
|
||||
|
||||
struct sammler_plugin plugin;
|
||||
|
||||
struct server_entry {
|
||||
struct list_head list;
|
||||
void *mysql;
|
||||
@ -93,8 +95,6 @@ static const char * get_ds(int ds_id)
|
||||
}
|
||||
}
|
||||
|
||||
struct sammler_plugin plugin;
|
||||
|
||||
static int probe(void)
|
||||
{
|
||||
struct mysql_stats stats;
|
||||
|
29
p_netdev.c
29
p_netdev.c
@ -24,8 +24,6 @@
|
||||
#include "helper.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
struct sammler_plugin plugin;
|
||||
|
||||
static const char *ds_def = {
|
||||
@ -40,8 +38,6 @@ static const char * get_ds(int ds_id)
|
||||
return ds_def;
|
||||
}
|
||||
|
||||
static char *buffer;
|
||||
|
||||
static int probe(void)
|
||||
{
|
||||
FILE *fp;
|
||||
@ -55,14 +51,14 @@ static int probe(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, BUFSIZE, fp) != NULL) {
|
||||
while (fgets(plugin.buffer, plugin.bufsize, fp) != NULL) {
|
||||
|
||||
if (!(stats = strchr(buffer, ':')))
|
||||
if (!(stats = strchr(plugin.buffer, ':')))
|
||||
continue;
|
||||
|
||||
*stats++ = '\0';
|
||||
|
||||
device = buffer;
|
||||
device = plugin.buffer;
|
||||
while (*device == ' ')
|
||||
device++;
|
||||
|
||||
@ -83,27 +79,10 @@ static int probe(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
buffer = malloc(BUFSIZE);
|
||||
if (buffer == NULL) {
|
||||
log_print(LOG_WARN, "plugin netdev: out of memory");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fini(void)
|
||||
{
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sammler_plugin plugin = {
|
||||
.name = "netdev",
|
||||
.interval = 10,
|
||||
.init = &init,
|
||||
.fini = &fini,
|
||||
.bufsize = 1024,
|
||||
.probe = &probe,
|
||||
.get_ds = &get_ds,
|
||||
};
|
||||
|
29
p_rtstat.c
29
p_rtstat.c
@ -24,8 +24,6 @@
|
||||
#include "helper.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
#define DS_STAT 1
|
||||
#define DS_GC 2
|
||||
|
||||
@ -68,8 +66,6 @@ static const char * get_ds(int ds_id)
|
||||
}
|
||||
}
|
||||
|
||||
static char *buffer;
|
||||
|
||||
static int probe(void)
|
||||
{
|
||||
FILE *fp;
|
||||
@ -83,11 +79,11 @@ static int probe(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, BUFSIZE, fp) != NULL) {
|
||||
if (!strncmp(buffer, "entries", 7))
|
||||
while (fgets(plugin.buffer, plugin.bufsize, fp) != NULL) {
|
||||
if (!strncmp(plugin.buffer, "entries", 7))
|
||||
continue;
|
||||
|
||||
if (strsplit(buffer, " \t\n", val, 17) != 17)
|
||||
if (strsplit(plugin.buffer, " \t\n", val, 17) != 17)
|
||||
continue;
|
||||
|
||||
for (i = 0; i < 17; i++)
|
||||
@ -117,27 +113,10 @@ static int probe(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
buffer = malloc(BUFSIZE);
|
||||
if (buffer == NULL) {
|
||||
log_print(LOG_WARN, "plugin rtstat: out of memory");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fini(void)
|
||||
{
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sammler_plugin plugin = {
|
||||
.name = "rtstat",
|
||||
.interval = 10,
|
||||
.init = &init,
|
||||
.fini = &fini,
|
||||
.bufsize = 1024,
|
||||
.probe = &probe,
|
||||
.get_ds = &get_ds,
|
||||
};
|
||||
|
45
p_stat.c
45
p_stat.c
@ -24,8 +24,6 @@
|
||||
#include "helper.h"
|
||||
#include "plugins.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
#define DS_CPU 1
|
||||
#define DS_PROC 2
|
||||
|
||||
@ -68,8 +66,6 @@ struct proc_ {
|
||||
unsigned long long fork;
|
||||
};
|
||||
|
||||
static char *buffer;
|
||||
|
||||
static int probe(void)
|
||||
{
|
||||
FILE *fp;
|
||||
@ -83,13 +79,13 @@ static int probe(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, BUFSIZE, fp) != NULL) {
|
||||
if (!strncmp(buffer, "cpu", 3)) {
|
||||
while (fgets(plugin.buffer, plugin.bufsize, fp) != NULL) {
|
||||
if (!strncmp(plugin.buffer, "cpu", 3)) {
|
||||
char *val[9], filename[16];
|
||||
int numfields, len, cpu;
|
||||
|
||||
if ((buffer[3] >= '0') && (buffer[3] <= '9')) {
|
||||
cpu = atoi(buffer +3);
|
||||
if ((plugin.buffer[3] >= '0') && (plugin.buffer[3] <= '9')) {
|
||||
cpu = atoi(plugin.buffer +3);
|
||||
len = snprintf(filename, sizeof(filename), "cpu-%d.rrd", cpu);
|
||||
if (len < 0 || len >= sizeof(filename))
|
||||
continue;
|
||||
@ -98,7 +94,7 @@ static int probe(void)
|
||||
strncpy(filename, "cpu.rrd", sizeof(filename));
|
||||
}
|
||||
|
||||
numfields = strsplit(buffer, " \t\n", val, 9);
|
||||
numfields = strsplit(plugin.buffer, " \t\n", val, 9);
|
||||
if (numfields < 5)
|
||||
continue;
|
||||
|
||||
@ -113,14 +109,14 @@ static int probe(void)
|
||||
val[1], val[2], val[3], val[4],
|
||||
val[5], val[6], val[7], val[8]);
|
||||
|
||||
} else if (!strncmp(buffer, "intr", 4)) {
|
||||
proc.intr = atoll(buffer + 5);
|
||||
} else if (!strncmp(plugin.buffer, "intr", 4)) {
|
||||
proc.intr = atoll(plugin.buffer + 5);
|
||||
|
||||
} else if (!strncmp(buffer, "ctxt", 4)) {
|
||||
proc.ctxt = atoll(buffer + 5);
|
||||
} else if (!strncmp(plugin.buffer, "ctxt", 4)) {
|
||||
proc.ctxt = atoll(plugin.buffer + 5);
|
||||
|
||||
} else if (!strncmp(buffer, "processes", 9)) {
|
||||
proc.fork = atoll(buffer + 10);
|
||||
} else if (!strncmp(plugin.buffer, "processes", 9)) {
|
||||
proc.fork = atoll(plugin.buffer + 10);
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,27 +127,10 @@ static int probe(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
buffer = malloc(BUFSIZE);
|
||||
if (buffer == NULL) {
|
||||
log_print(LOG_WARN, "plugin stat: out of memory");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fini(void)
|
||||
{
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sammler_plugin plugin = {
|
||||
.name = "stat",
|
||||
.interval = 10,
|
||||
.init = &init,
|
||||
.fini = &fini,
|
||||
.bufsize = 1024,
|
||||
.probe = &probe,
|
||||
.get_ds = &get_ds,
|
||||
};
|
||||
|
45
p_vmstat.c
45
p_vmstat.c
@ -23,8 +23,6 @@
|
||||
|
||||
#include "plugins.h"
|
||||
|
||||
#define BUFSIZE 1024
|
||||
|
||||
struct sammler_plugin plugin;
|
||||
|
||||
static const char *ds_def = {
|
||||
@ -48,8 +46,6 @@ struct vmstat_ {
|
||||
unsigned long long pgfault;
|
||||
};
|
||||
|
||||
static char *buffer;
|
||||
|
||||
static int probe(void)
|
||||
{
|
||||
FILE *fp;
|
||||
@ -63,21 +59,21 @@ static int probe(void)
|
||||
return -1;
|
||||
}
|
||||
|
||||
while (fgets(buffer, BUFSIZE, fp) != NULL) {
|
||||
if (!strncmp(buffer, "pgalloc_high", 12))
|
||||
vmstat.pgalloc_high = atoll(buffer + 13);
|
||||
while (fgets(plugin.buffer, plugin.bufsize, fp) != NULL) {
|
||||
if (!strncmp(plugin.buffer, "pgalloc_high", 12))
|
||||
vmstat.pgalloc_high = atoll(plugin.buffer + 13);
|
||||
|
||||
else if (!strncmp(buffer, "pgalloc_normal", 14))
|
||||
vmstat.pgalloc_normal = atoll(buffer + 15);
|
||||
else if (!strncmp(plugin.buffer, "pgalloc_normal", 14))
|
||||
vmstat.pgalloc_normal = atoll(plugin.buffer + 15);
|
||||
|
||||
else if (!strncmp(buffer, "pgalloc_dma", 11))
|
||||
vmstat.pgalloc_dma = atoll(buffer + 12);
|
||||
else if (!strncmp(plugin.buffer, "pgalloc_dma", 11))
|
||||
vmstat.pgalloc_dma = atoll(plugin.buffer + 12);
|
||||
|
||||
else if (!strncmp(buffer, "pgfree", 6))
|
||||
vmstat.pgfree = atoll(buffer + 7);
|
||||
else if (!strncmp(plugin.buffer, "pgfree", 6))
|
||||
vmstat.pgfree = atoll(plugin.buffer + 7);
|
||||
|
||||
else if (!strncmp(buffer, "pgfault", 7))
|
||||
vmstat.pgfault = atoll(buffer + 8);
|
||||
else if (!strncmp(plugin.buffer, "pgfault", 7))
|
||||
vmstat.pgfault = atoll(plugin.buffer + 8);
|
||||
}
|
||||
|
||||
probe_submit(&plugin, "vmstat.rrd", 0, "%llu:%llu:%llu:%llu:%llu",
|
||||
@ -88,27 +84,10 @@ static int probe(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int init(void)
|
||||
{
|
||||
buffer = malloc(BUFSIZE);
|
||||
if (buffer == NULL) {
|
||||
log_print(LOG_WARN, "plugin vmstat: out of memory");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fini(void)
|
||||
{
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sammler_plugin plugin = {
|
||||
.name = "vmstat",
|
||||
.interval = 10,
|
||||
.init = &init,
|
||||
.fini = &fini,
|
||||
.bufsize = 1024,
|
||||
.probe = &probe,
|
||||
.get_ds = &get_ds,
|
||||
};
|
||||
|
28
plugins.c
28
plugins.c
@ -40,8 +40,11 @@ static LIST_HEAD(plugin_list);
|
||||
|
||||
static int plugin_flags;
|
||||
|
||||
static char *scratchpad;
|
||||
|
||||
static int plugin_init_cb(const char *filename, void *privdata)
|
||||
{
|
||||
int *bufsize = (int *)privdata;
|
||||
struct sammler_plugin *plugin = NULL;
|
||||
static const char *plugin_dir;
|
||||
|
||||
@ -90,22 +93,39 @@ static int plugin_init_cb(const char *filename, void *privdata)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (plugin->bufsize > *bufsize)
|
||||
*bufsize = plugin->bufsize;
|
||||
|
||||
list_add_tail(&plugin->list, &plugin_list);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void plugin_init(int flags)
|
||||
int plugin_init(int flags)
|
||||
{
|
||||
config_get_strings("global", "plugin", plugin_init_cb, NULL);
|
||||
struct sammler_plugin *plugin;
|
||||
int bufsize = 0;
|
||||
|
||||
config_get_strings("global", "plugin", plugin_init_cb, &bufsize);
|
||||
plugin_flags = flags;
|
||||
|
||||
scratchpad = malloc(bufsize);
|
||||
if (scratchpad == NULL) {
|
||||
log_print(LOG_ERROR, "plugin_init: out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
list_for_each_entry(plugin, &plugin_list, list)
|
||||
plugin->buffer = scratchpad;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void plugins_probe(void)
|
||||
{
|
||||
struct sammler_plugin *plugin;
|
||||
unsigned long now;
|
||||
time_t now;
|
||||
|
||||
now = time(NULL);
|
||||
time(&now);
|
||||
|
||||
list_for_each_entry(plugin, &plugin_list, list) {
|
||||
if (plugin->lastprobe + plugin->interval <= now) {
|
||||
|
13
plugins.h
13
plugins.h
@ -1,6 +1,8 @@
|
||||
#ifndef _PLUGINS_H_
|
||||
#define _PLUGINS_H_
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "list.h"
|
||||
#include "logging.h"
|
||||
|
||||
@ -10,15 +12,22 @@
|
||||
struct sammler_plugin {
|
||||
struct list_head list;
|
||||
const char *name;
|
||||
|
||||
/* timing */
|
||||
unsigned int interval;
|
||||
unsigned long lastprobe;
|
||||
time_t lastprobe;
|
||||
|
||||
/* scratchpad memory */
|
||||
int bufsize;
|
||||
char *buffer;
|
||||
|
||||
int (*init) (void);
|
||||
int (*fini) (void);
|
||||
int (*probe) (void);
|
||||
const char * (*get_ds) (int ds_id);
|
||||
};
|
||||
|
||||
void plugin_init(int flags);
|
||||
int plugin_init(int flags);
|
||||
|
||||
void plugins_probe(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user