|
|
|
@ -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, |
|
|
|
|
}; |
|
|
|
|