5 #include <sys/protosw.h>
6 #include <sys/socket.h>
7 #include <sys/sysctl.h>
9 #include <sys/dkstat.h>
11 #include <net/if_var.h>
12 #include <net/if_dl.h>
13 #include <net/if_types.h>
14 #include <machine/apm_bios.h>
15 #include <sys/ioctl.h>
21 /* XXX: #if __FreeBSD_version */
31 void (*statfn[])(int) =
45 static struct nlist nl[] = {
54 char buf[_POSIX2_LINE_MAX];
58 kvm = kvm_openfiles(nil, nil, nil, OREAD, buf);
61 if(kvm_nlist(kvm, nl) < 0 || nl[0].n_type == 0){
75 kread(ulong addr, char *buf, int size)
77 if(kvm_read(kvm, addr, buf, size) != size){
87 ulong out, in, outb, inb, err;
88 static ulong ifnetaddr;
91 struct ifnethead ifnethead;
98 ifnetaddr = nl[0].n_value;
103 if(kread(ifnetaddr, (char*)&ifnethead, sizeof ifnethead) < 0)
106 out = in = outb = inb = err = 0;
107 addr = (ulong)TAILQ_FIRST(&ifnethead);
109 #if __FreeBSD_version < 500000
110 if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0
111 || kread((ulong)ifnet.if_name, name, 16) < 0)
114 if(kread(addr, (char*)&ifnet, sizeof ifnet) < 0
115 || kread((ulong)ifnet.if_dname, name, 16) < 0)
119 addr = (ulong)TAILQ_NEXT(&ifnet, if_link);
120 out += ifnet.if_opackets;
121 in += ifnet.if_ipackets;
122 outb += ifnet.if_obytes;
123 inb += ifnet.if_ibytes;
124 err += ifnet.if_oerrors+ifnet.if_ierrors;
126 Bprint(&bout, "etherin %lud 1000\n", in);
127 Bprint(&bout, "etherout %lud 1000\n", out);
128 Bprint(&bout, "etherinb %lud 1000000\n", inb);
129 Bprint(&bout, "etheroutb %lud 1000000\n", outb);
130 Bprint(&bout, "ethererr %lud 1000\n", err);
131 Bprint(&bout, "ether %lud 1000\n", in+out);
132 Bprint(&bout, "etherb %lud 1000000\n", inb+outb);
135 #if __FreeBSD_version >= 500000
143 rv = sysctlbyname("hw.acpi.battery.life", &val, &len, nil, 0);
146 Bprint(&bout, "battery =%d 100\n", val);
165 fd = open("/dev/apm", OREAD);
172 if(ioctl(fd, APMIO_GETINFO, &ai) < 0)
175 if(ai.ai_batt_life <= 100)
176 Bprint(&bout, "battery =%d 100\n", ai.ai_batt_life);
180 rsys(char *name, char *buf, int len)
185 if(sysctlbyname(name, buf, &l, nil, 0) < 0)
198 if(sysctlbyname(name, &u, &l, nil, 0) < 0)
209 pgsize = isys("vm.stats.vm.v_page_size");
214 Bprint(&bout, "mem =%lld %lld\n",
215 isys("vm.stats.vm.v_active_count")*pgsize,
216 isys("vm.stats.vm.v_page_count")*pgsize);
217 Bprint(&bout, "context %lld 1000\n", isys("vm.stats.sys.v_swtch"));
218 Bprint(&bout, "syscall %lld 1000\n", isys("vm.stats.sys.v_syscall"));
219 Bprint(&bout, "intr %lld 1000\n", isys("vm.stats.sys.v_intr")+isys("vm.stats.sys.v_trap"));
220 Bprint(&bout, "fault %lld 1000\n", isys("vm.stats.vm.v_vm_faults"));
221 Bprint(&bout, "fork %lld 1000\n", isys("vm.stats.vm.v_forks")
222 +isys("vm.stats.vm.v_rforks")
223 +isys("vm.stats.vm.v_vforks"));
231 struct clockinfo *ci;
235 if(rsys("kern.clockrate", (char*)&x, sizeof x) < sizeof ci)
238 ci = (struct clockinfo*)x;
244 if((n=rsys("kern.cp_time", (char*)x, sizeof x)) < 5*sizeof(ulong))
247 Bprint(&bout, "user %lud %d\n", x[CP_USER]+x[CP_NICE], stathz);
248 Bprint(&bout, "sys %lud %d\n", x[CP_SYS], stathz);
249 Bprint(&bout, "cpu %lud %d\n", x[CP_USER]+x[CP_NICE]+x[CP_SYS], stathz);
250 Bprint(&bout, "idle %lud %d\n", x[CP_IDLE], stathz);
261 if(getloadavg(l, 3) < 0)
263 Bprint(&bout, "load =%d 1000\n", (int)(l[0]*1000.0));
269 static struct kvm_swap s;
270 static ulong pgin, pgout;
275 pgsize = getpagesize();
284 i = isys("vm.stats.vm.v_swappgsin");
285 o = isys("vm.stats.vm.v_swappgsout");
286 if(i != pgin || o != pgout){
289 kvm_getswapinfo(kvm, &s, 1, 0);
293 Bprint(&bout, "swap =%lld %lld\n", s.ksw_used*(vlong)pgsize, s.ksw_total*(vlong)pgsize);