equal
deleted
inserted
replaced
|
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 char *cols[3]; |
|
16 |
|
17 if (getloadavg(avgs, 3) < 0) { |
|
18 perror("getloadavg"); |
|
19 exit(1); |
|
20 } |
|
21 for ( int i = 0; i < 3; i++ ) { |
|
22 if ( avgs[i] <= GREEN ) |
|
23 cols[i] = "color='green'"; |
|
24 else if ( avgs[i] <= ORANGE ) |
|
25 cols[i] = "color='orange'"; |
|
26 else |
|
27 cols[i] = "color='red'"; |
|
28 } |
|
29 |
|
30 printf("<span %s>%.2f</span> <span %s>%.2f</span> <span %s>%.2f</span>\n", |
|
31 cols[0], avgs[0], cols[1], avgs[1], cols[2], avgs[2]); |
|
32 fflush(stdout); |
|
33 sleep(UPDATE_PERIOD); |
|
34 } |
|
35 } |