simple plugins: use fscanf
This commit is contained in:
parent
eb17f95748
commit
e476640b74
@ -20,7 +20,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "helper.h"
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "plugins.h"
|
#include "plugins.h"
|
||||||
#include "probe.h"
|
#include "probe.h"
|
||||||
@ -40,28 +39,21 @@ static const char * get_ds(int ds_id)
|
|||||||
|
|
||||||
static int probe(void)
|
static int probe(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp = fopen("/proc/loadavg", "r");
|
||||||
char buffer[32];
|
|
||||||
char *val[3];
|
|
||||||
|
|
||||||
fp = fopen("/proc/loadavg", "r");
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
log_print(LOG_WARN, "plugin load");
|
log_print(LOG_WARN, "plugin load: fopen()");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
|
double load1, load5, load15;
|
||||||
log_print(LOG_WARN, "plugin load");
|
if (fscanf(fp, "%lf %lf %lf", &load1, &load5, &load15) != 3) {
|
||||||
|
log_print(LOG_WARN, "plugin load: fscanf()");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (strsplit(buffer, " \t\n", val, 3) != 3)
|
probe_submit(&plugin, "load.rrd", 0, "%.02lf:%.02lf:%.02lf", load1, load5, load15);
|
||||||
return -1;
|
|
||||||
|
|
||||||
probe_submit(&plugin, "load.rrd", 0, "%s:%s:%s", val[0], val[1], val[2]);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "helper.h"
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "plugins.h"
|
#include "plugins.h"
|
||||||
#include "probe.h"
|
#include "probe.h"
|
||||||
@ -38,28 +37,21 @@ static const char * get_ds(int ds_id)
|
|||||||
|
|
||||||
static int probe(void)
|
static int probe(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp = fopen("/proc/sys/kernel/random/entropy_avail", "r");
|
||||||
char buffer[32];
|
|
||||||
char *val[1];
|
|
||||||
|
|
||||||
fp = fopen("/proc/sys/kernel/random/entropy_avail", "r");
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
log_print(LOG_WARN, "plugin random");
|
log_print(LOG_WARN, "plugin random: fopen()");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
|
int entropy;
|
||||||
log_print(LOG_WARN, "plugin random");
|
if (fscanf(fp, "%d", &entropy) != 1) {
|
||||||
|
log_print(LOG_WARN, "plugin random: fopen()");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (strsplit(buffer, " \t\n", val, 1) != 1)
|
probe_submit(&plugin, "random.rrd", 0, "%d", entropy);
|
||||||
return -1;
|
|
||||||
|
|
||||||
probe_submit(&plugin, "random.rrd", 0, "%s", val[0]);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "helper.h"
|
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "plugins.h"
|
#include "plugins.h"
|
||||||
#include "probe.h"
|
#include "probe.h"
|
||||||
@ -39,28 +38,21 @@ static const char * get_ds(int ds_id)
|
|||||||
|
|
||||||
static int probe(void)
|
static int probe(void)
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp = fopen("/proc/uptime", "r");
|
||||||
char buffer[32];
|
|
||||||
char *val[2];
|
|
||||||
|
|
||||||
fp = fopen("/proc/uptime", "r");
|
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
log_print(LOG_WARN, "plugin uptime");
|
log_print(LOG_WARN, "plugin uptime: fopen()");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fgets(buffer, sizeof(buffer), fp) == NULL) {
|
double uptime, idletime;
|
||||||
log_print(LOG_WARN, "plugin uptime");
|
if (fscanf(fp, "%lf %lf\n", &uptime, &idletime) != 2) {
|
||||||
|
log_print(LOG_WARN, "plugin uptime: fscanf()");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
if (strsplit(buffer, " \t\n", val, 2) != 2)
|
probe_submit(&plugin, "uptime.rrd", 0, "%.02lf:%.02lf", uptime, idletime);
|
||||||
return -1;
|
|
||||||
|
|
||||||
probe_submit(&plugin, "uptime.rrd", 0, "%s:%s", val[0], val[1]);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user