-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.c
More file actions
50 lines (45 loc) · 796 Bytes
/
Copy pathplot.c
File metadata and controls
50 lines (45 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
// write out loadavg to a file;
main(int argc, char *argv[]) {
char buf[180];
char *ind;
FILE *f;
char *x, *y, *z, *q;
double d;
FILE *log;
chdir("/home/vsrinivas/bin");
log = fopen("plot.log", "a");
for (;;) {
bzero(buf, 180);
f = popen("uptime", "r");
fgets(buf, 180, f);
pclose(f);
ind = rindex(buf, ':');
// load average: 9.73, 9.97, 9.51
ind++;
ind++;
x = ind;
y = index(x, ',');
*y = 0;
y++;
y++;
z = index(y, ',');
*z = 0;
z++;
z++;
q = index(z, '\n');
*q = 0;
d = atof(x); // 1s avg
bzero(buf, 180);
f = popen("date +%s", "r");
fgets(buf, 180, f);
pclose(f);
x = index(buf, '\n');
*x = 0;
fprintf(log, "%s, %f\n", buf, d);
sleep(10);
}
}