1
|
1 |
#define _DEFAULT_SOURCE |
|
2 |
#include <stdio.h> |
|
3 |
#include <stdlib.h> |
|
4 |
#include <unistd.h> |
|
5 |
#include <string.h> |
|
6 |
#include <errno.h> |
|
7 |
|
|
8 |
#include "config.h" |
|
9 |
|
|
10 |
int |
|
11 |
main(void) |
|
12 |
{ |
|
13 |
while (1) { |
|
14 |
double avgs[3]; |
|
15 |
|
|
16 |
if (getloadavg(avgs, 3) < 0) { |
|
17 |
perror("getloadavg"); |
|
18 |
exit(1); |
|
19 |
} |
3
|
20 |
#ifdef PANGO_MARKUP |
|
21 |
char *cols[3]; |
1
|
22 |
for ( int i = 0; i < 3; i++ ) { |
|
23 |
if ( avgs[i] <= GREEN ) |
|
24 |
cols[i] = "color='green'"; |
|
25 |
else if ( avgs[i] <= ORANGE ) |
|
26 |
cols[i] = "color='orange'"; |
|
27 |
else |
|
28 |
cols[i] = "color='red'"; |
|
29 |
} |
|
30 |
|
|
31 |
printf("<span %s>%.2f</span> <span %s>%.2f</span> <span %s>%.2f</span>\n", |
|
32 |
cols[0], avgs[0], cols[1], avgs[1], cols[2], avgs[2]); |
3
|
33 |
#else |
|
34 |
printf("%.2f %.2f %.2f\n", avgs[0], avgs[1], avgs[2]); |
|
35 |
#endif |
1
|
36 |
fflush(stdout); |
|
37 |
sleep(UPDATE_PERIOD); |
|
38 |
} |
|
39 |
} |