#define STATFILE "/proc/stat"
-static int cpu_parser(char *data, const char **p)
+static int cpu_parser(char *data, const char **p, void **state)
{
char buf[1024];
char *str = buf;
#define MEMFILE "/proc/meminfo"
-static int mem_parser(char *data, const char **p)
+static int mem_parser(char *data, const char **p, void **state)
{
char buf[1024], word[1024];
int free = 0, buffered = 0, cache = 0, active = 0, inactive = 0,
return 0;
}
-int cpu_mem_parser(char *data, const char **p)
+int cpu_mem_parser(char *data, const char **p, void **state)
{
+ int ret;
char cpu[RRD_DATA_MAX_LEN], mem[RRD_DATA_MAX_LEN];
- cpu_parser(cpu, p);
- mem_parser(mem, p);
- snprintf(data, RRD_DATA_MAX_LEN, "%s:%s", cpu, mem);
-
- return 0;
-}
-
-static int digitemp_parser(char *data, const char **p)
-{
- const char digitemp_cmd[] = "/usr/bin/digitemp";
- char *const digitemp_args[] = { "", "-o2", "-a", "-q", 0 };
- FILE *readf;
- int pid, ret;
- float t1 = 0, t2 = 0, t3 = 0;
- char buf[1024];
-
- pid = run_piped_stream(digitemp_cmd, digitemp_args, 0, &readf, 0);
- if (pid < 0) {
- pr_err("Failed to parse digitemp\n");
- sprintf(data, "U:U");
- return -1;
- }
-
- ret = fscanf(readf, "%f %f %f", &t1, &t2, &t3);
-
- if (ret != 3) {
- pr_err("Failed to parse digitemp output: %m\n");
- sprintf(data, "U:U");
- return 1;
- }
+ cpu_parser(cpu, p, state);
+ mem_parser(mem, p, state);
+ ret = snprintf(data, RRD_DATA_MAX_LEN, "%s:%s", cpu, mem);
- t2 += 2.16;
- t3 += -0.44;
+ /* No actual data overflow, snprintf just couldn't fit all data in the buffer */
+ if (ret >= RRD_DATA_MAX_LEN)
+ pr_err("Buffer overlfow\n");
- /* Read whatever the process might be still printing out */
- while (fgets(buf, 1024, readf));
-
- clear_zombie(pid);
- snprintf(data, RRD_DATA_MAX_LEN, "%.2f:%.2f", t3, t2);
return 0;
}
-static int digitemp_parser_mod(char *data, const char **p)
-{
- char buf[1024];
- int ret;
-
- ret = digitemp_parser(buf, p);
- snprintf(data, RRD_DATA_MAX_LEN, "U:%s", buf);
-
- return ret;
-}
-
/* Run a command and feed the output from stdout directly to rrdtool */
-static int script_parser(char *rrd_data, const char **parser_data)
+static int script_parser(char *rrd_data, const char **parser_data, void **state)
{
FILE *readf;
int pid, ret;
stat->rx_bytes, stat->rx_packets,
stat->tx_bytes, stat->tx_packets);
+ fclose(netdev);
return 0;
}
+ fclose(netdev);
pr_err("Interface %s not found\n", iface);
return -ENODEV;
}
-int netstats_parser(char *rrd_data, const char **parser_data)
+int netstats_parser(char *rrd_data, const char **parser_data, void **state)
{
struct iface_stats stat;
const char **iface_name = parser_data;
.name = "cpu_mem",
.parse = cpu_mem_parser,
},
- {
- .name = "digitemp",
- .parse = digitemp_parser,
- },
- {
- .name = "digitemp_mod",
- .parse = digitemp_parser_mod,
- },
{
.name = "script",
.parse = script_parser,