10 #define STATFILE "/proc/stat"
12 int cpu_parser(char *data)
16 FILE *file = fopen(STATFILE, "r");
17 int user, nice, sys, idle, wait, irq, softirq;
20 fprintf(stderr, "Failed to open file %s\n", STATFILE);
24 if (!fgets(buf, 1024, file)) {
25 fprintf(stderr, "Failed to read file %s\n", STATFILE);
30 user = dec_to_int(str, &str);
31 nice = dec_to_int(str, &str);
32 sys = dec_to_int(str, &str);
33 idle = dec_to_int(str, &str);
34 wait = dec_to_int(str, &str);
35 irq = dec_to_int(str, &str);
36 softirq = dec_to_int(str, &str);
38 sprintf(data, "%d:%d:%d:%d:%d:%d:%d",
39 user, nice, sys, idle, wait, irq, softirq);
45 #define MEMFILE "/proc/meminfo"
47 int mem_parser(char *data)
49 char buf[1024], word[1024];
50 int free = 0, buffered = 0, cache = 0, active = 0, inactive = 0,
51 swapfree = 0, anon = 0, slab = 0, tables = 0;
52 FILE *file = fopen(MEMFILE, "r");
55 fprintf(stderr, "Failed to open file %s\n", MEMFILE);
59 while (fgets(buf, 1024, file)) {
60 get_word(buf, 0, word, 1024);
62 if (!strcmp(word, "MemFree:")) {
63 free = dec_to_int(buf, 0);
64 } else if (!strcmp(word, "Buffers:")) {
65 buffered = dec_to_int(buf, 0);
66 } else if (!strcmp(word, "Cached:")) {
67 cache = dec_to_int(buf, 0);
68 } else if (!strcmp(word, "Active:")) {
69 active = dec_to_int(buf, 0);
70 } else if (!strcmp(word, "Inactive:")) {
71 inactive = dec_to_int(buf, 0);
72 } else if (!strcmp(word, "SwapFree:")) {
73 swapfree = dec_to_int(buf, 0);
74 } else if (!strcmp(word, "AnonPages:")) {
75 anon = dec_to_int(buf, 0);
76 } else if (!strcmp(word, "Slab:")) {
77 slab = dec_to_int(buf, 0);
78 } else if (!strcmp(word, "PageTables:")) {
79 tables = dec_to_int(buf, 0);
84 sprintf(data, "%f:%f:%f:%f:%f:%f:%f:%f:%f",
98 int cpu_mem_parser(char *data)
100 char cpu[1024], mem[1024];
104 sprintf(data, "%s:%s", cpu, mem);
109 int digitemp_parser(char *data)
111 const char digitemp_cmd[] = "/usr/bin/digitemp";
112 char *const digitemp_args[] = { "", "-o2", "-a", "-q", 0 };
113 FILE *readf, *writef;
115 char buf[1024], *bptr = buf;
118 pid = run_piped_stream(digitemp_cmd, digitemp_args, &readf, &writef);
120 fprintf(stderr, "Failed to parse digitemp");
121 sprintf(data, "U:U");
125 fgets(buf, 1024, readf);
128 get_word(bptr, &bptr, t1, 16);
130 get_word(bptr, &bptr, t2, 16);
132 get_word(bptr, &bptr, t3, 16);
135 t1 = dec_to_float(bptr, &bptr);
136 t2 = dec_to_float(bptr, &bptr);
137 t3 = dec_to_float(bptr, &bptr);
142 while (fgets(buf, 1024, readf));
143 harvest_zombies(pid);
144 sprintf(data, "%.2f:%.2f", t3, t2);
148 int digitemp_parser_mod(char *data)
153 ret = digitemp_parser(buf);
154 sprintf(data, "U:%s", buf);