11 #define STATFILE "/proc/stat"
13 int cpu_parser(char *data, void *p)
17 FILE *file = fopen(STATFILE, "r");
18 long long user, nice, sys, idle, wait, irq, softirq;
21 pr_err("Failed to open file %s\n", STATFILE);
25 if (!fgets(buf, 1024, file)) {
26 pr_err("Failed to read file %s\n", STATFILE);
31 user = dec_to_longlong(str, &str);
32 nice = dec_to_longlong(str, &str);
33 sys = dec_to_longlong(str, &str);
34 idle = dec_to_longlong(str, &str);
35 wait = dec_to_longlong(str, &str);
36 irq = dec_to_longlong(str, &str);
37 softirq = dec_to_longlong(str, &str);
39 snprintf(data, RRD_DATA_MAX_LEN, "%lld:%lld:%lld:%lld:%lld:%lld:%lld",
40 user, nice, sys, idle, wait, irq, softirq);
46 #define MEMFILE "/proc/meminfo"
48 int mem_parser(char *data, void *p)
50 char buf[1024], word[1024];
51 int free = 0, buffered = 0, cache = 0, active = 0, inactive = 0,
52 swapfree = 0, anon = 0, slab = 0, tables = 0, swaptotal = 0;
53 FILE *file = fopen(MEMFILE, "r");
56 pr_err("Failed to open file %s\n", MEMFILE);
60 while (fgets(buf, 1024, file)) {
61 get_word(buf, 0, word, 1024);
63 if (!strcmp(word, "MemFree:")) {
64 free = dec_to_int(buf, 0);
65 } else if (!strcmp(word, "Buffers:")) {
66 buffered = dec_to_int(buf, 0);
67 } else if (!strcmp(word, "Cached:")) {
68 cache = dec_to_int(buf, 0);
69 } else if (!strcmp(word, "Active:")) {
70 active = dec_to_int(buf, 0);
71 } else if (!strcmp(word, "Inactive:")) {
72 inactive = dec_to_int(buf, 0);
73 } else if (!strcmp(word, "SwapFree:")) {
74 swapfree = dec_to_int(buf, 0);
75 } else if (!strcmp(word, "AnonPages:")) {
76 anon = dec_to_int(buf, 0);
77 } else if (!strcmp(word, "Slab:")) {
78 slab = dec_to_int(buf, 0);
79 } else if (!strcmp(word, "PageTables:")) {
80 tables = dec_to_int(buf, 0);
81 } else if (!strcmp(word, "SwapTotal:")) {
82 swaptotal = dec_to_int(buf, 0);
87 snprintf(data, RRD_DATA_MAX_LEN, "%f:%f:%f:%f:%f:%f:%f:%f:%f:%f",
97 (swaptotal - swapfree) / 1024.0);
102 int cpu_mem_parser(char *data, void *p)
104 char cpu[1024], mem[1024];
108 snprintf(data, RRD_DATA_MAX_LEN, "%s:%s", cpu, mem);
113 int digitemp_parser(char *data, void *p)
115 const char digitemp_cmd[] = "/usr/bin/digitemp";
116 char *const digitemp_args[] = { "", "-o2", "-a", "-q", 0 };
119 float t1 = 0, t2 = 0, t3 = 0;
122 pid = run_piped_stream(digitemp_cmd, digitemp_args, 0, &readf, 0);
124 pr_err("Failed to parse digitemp\n");
125 sprintf(data, "U:U");
129 ret = fscanf(readf, "%f %f %f", &t1, &t2, &t3);
133 pr_err("Failed to parse digitemp output: %s\n",
135 sprintf(data, "U:U");
142 /* Read whatever the process might be still printing out */
143 while (fgets(buf, 1024, readf));
145 harvest_zombies(pid);
146 snprintf(data, RRD_DATA_MAX_LEN, "%.2f:%.2f", t3, t2);
150 int digitemp_parser_mod(char *data, void *p)
155 ret = digitemp_parser(buf, p);
156 snprintf(data, RRD_DATA_MAX_LEN, "U:%s", buf);
161 /* Run a command and feed the output from stdout directly to rrdtool */
162 int script_parser(char *rrd_data, void *parser_data)
165 char **cmd = parser_data;
168 pid = run_piped_stream(cmd[0], &cmd[1], NULL, &readf, NULL);
169 ret = fread(rrd_data, RRD_DATA_MAX_LEN, 1, readf);
171 pr_info("Read :%s\n", rrd_data);
174 harvest_zombies(pid);