12 void (*statfn[])(int) =
25 static int fd = -1, fdb = -1;
26 int i, last = -1, curr = -1;
29 fd = open("/proc/acpi/battery/BAT0/info", OREAD);
30 fdb = open("/proc/acpi/battery/BAT0/state", OREAD);
33 if(fd == -1 || fdb == -1)
37 for(i=0; i<nline; i++){
41 if(strcmp(tok[0], "last") == 0 && strcmp(tok[1], "full") == 0)
45 for(i = 0; i < nline; i++) {
49 if(strcmp(tok[0], "remaining") == 0 && strcmp(tok[1], "capacity:") == 0)
53 if(curr != -1 && last != -1)
54 Bprint(&bout, "battery =%d 100\n", (int)(((float)curr/(float)last)*100.0));
64 fd = open("/proc/loadavg", OREAD);
71 Bprint(&bout, "load =%d 1000\n", (int)(atof(tok[0])*1000));
83 fd = open("/proc/meminfo", OREAD);
89 for(i=0; i<nline; i++){
95 if(strcmp(tok[0], "Mem:") == 0)
96 Bprint(&bout, "mem =%lld %lld\n", used/1024, tot/1024);
97 else if(strcmp(tok[0], "Swap:") == 0)
98 Bprint(&bout, "swap =%lld %lld\n", used/1024, tot/1024);
99 else if(strcmp(tok[0], "MemTotal:") == 0)
100 mtot = atoll(tok[1]); /* kb */
101 else if(strcmp(tok[0], "MemFree:") == 0){
102 mfree = atoll(tok[1]);
105 Bprint(&bout, "mem =%lld %lld\n", mtot-mfree, mtot);
114 vlong totb, totp, tote, totin, totou, totinb, totoub, b, p, e, in, ou, inb, oub;
119 fd = open("/proc/net/dev", OREAD);
132 for(i=0; i<nline; i++){
133 if((q = strchr(line[i], ':')) != nil)
138 if(strncmp(tok[0], "eth", 3) != 0)
146 e = atoll(tok[3])+atoll(tok[11]);
156 Bprint(&bout, "etherb %lld %d\n", totb, n*1000000);
157 Bprint(&bout, "ether %lld %d\n", totp, n*1000);
158 Bprint(&bout, "ethererr %lld %d\n", tote, n*1000);
159 Bprint(&bout, "etherin %lld %d\n", totin, n*1000);
160 Bprint(&bout, "etherout %lld %d\n", totou, n*1000);
161 Bprint(&bout, "etherinb %lld %d\n", totinb, n*1000);
162 Bprint(&bout, "etheroutb %lld %d\n", totoub, n*1000);
172 fd = open("/proc/stat", OREAD);
177 for(i=0; i<nline; i++){
181 if(strcmp(tok[0], "cpu") == 0 && ntok >= 5){
182 Bprint(&bout, "user %lld 100\n", atoll(tok[1]));
183 Bprint(&bout, "sys %lld 100\n", atoll(tok[3]));
184 Bprint(&bout, "cpu %lld 100\n", atoll(tok[1])+atoll(tok[3]));
185 Bprint(&bout, "idle %lld\n", atoll(tok[4]));
188 if(strcmp(tok[0], "page") == 0 && ntok >= 3){
189 Bprint(&bout, "pagein %lld 500\n", atoll(tok[1]));
190 Bprint(&bout, "pageout %lld 500\n", atoll(tok[2]));
191 Bprint(&bout, "page %lld 1000\n", atoll(tok[1])+atoll(tok[2]));
193 if(strcmp(tok[0], "swap") == 0 && ntok >= 3){
194 Bprint(&bout, "swapin %lld 500\n", atoll(tok[1]));
195 Bprint(&bout, "swapout %lld 500\n", atoll(tok[2]));
196 Bprint(&bout, "swap %lld 1000\n", atoll(tok[1])+atoll(tok[2]));
199 if(strcmp(tok[0], "intr") == 0)
200 Bprint(&bout, "interrupt %lld 1000\n", atoll(tok[1]));
201 if(strcmp(tok[0], "ctxt") == 0)
202 Bprint(&bout, "context %lld 1000\n", atoll(tok[1]));
203 if(strcmp(tok[0], "processes") == 0)
204 Bprint(&bout, "fork %lld 1000\n", atoll(tok[1]));