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 #if __FreeBSD_version < 600000
15 #include <machine/apm_bios.h>
17 #include <sys/ioctl.h>
32 void (*statfn[])(int) =
46 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 struct ifaddrs *ifap, *ifa;
88 ulong out, in, outb, inb, err;
93 if (getifaddrs(&ifap) != 0)
96 out = in = outb = inb = err = 0;
97 #define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
98 for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
99 if (ifa->ifa_addr->sa_family != AF_LINK)
101 out += IFA_STAT(opackets);
102 in += IFA_STAT(ipackets);
103 outb += IFA_STAT(obytes);
104 inb += IFA_STAT(ibytes);
105 err += IFA_STAT(oerrors) + IFA_STAT(ierrors);
109 Bprint(&bout, "etherin %lud 1000\n", in);
110 Bprint(&bout, "etherout %lud 1000\n", out);
111 Bprint(&bout, "etherinb %lud 1000000\n", inb);
112 Bprint(&bout, "etheroutb %lud 1000000\n", outb);
113 Bprint(&bout, "ethererr %lud 1000\n", err);
114 Bprint(&bout, "ether %lud 1000\n", in+out);
115 Bprint(&bout, "etherb %lud 1000000\n", inb+outb);
118 #if __FreeBSD_version >= 500000
127 rv = sysctlbyname("hw.acpi.battery.life", &val, &len, nil, 0);
130 Bprint(&bout, "battery =%d 100\n", val);
141 #if __FreeBSD_version < 600000
150 fd = open("/dev/apm", OREAD);
157 if(ioctl(fd, APMIO_GETINFO, &ai) < 0)
160 if(ai.ai_batt_life <= 100)
161 Bprint(&bout, "battery =%d 100\n", ai.ai_batt_life);
172 rsys(char *name, char *buf, int len)
177 if(sysctlbyname(name, buf, &l, nil, 0) < 0)
190 if(sysctlbyname(name, &u, &l, nil, 0) < 0)
201 pgsize = isys("vm.stats.vm.v_page_size");
206 Bprint(&bout, "mem =%lld %lld\n",
207 isys("vm.stats.vm.v_active_count")*pgsize,
208 isys("vm.stats.vm.v_page_count")*pgsize);
209 Bprint(&bout, "context %lld 1000\n", isys("vm.stats.sys.v_swtch"));
210 Bprint(&bout, "syscall %lld 1000\n", isys("vm.stats.sys.v_syscall"));
211 Bprint(&bout, "intr %lld 1000\n", isys("vm.stats.sys.v_intr")+isys("vm.stats.sys.v_trap"));
212 Bprint(&bout, "fault %lld 1000\n", isys("vm.stats.vm.v_vm_faults"));
213 Bprint(&bout, "fork %lld 1000\n", isys("vm.stats.vm.v_forks")
214 +isys("vm.stats.vm.v_rforks")
215 +isys("vm.stats.vm.v_vforks"));
229 if(rsys("kern.clockrate", (char*)u.x, sizeof u.x) < sizeof u.ci)
232 stathz = u.ci.stathz;
236 if((n=rsys("kern.cp_time", (char*)u.x, sizeof u.x)) < 5*sizeof(ulong))
239 Bprint(&bout, "user %lud %d\n", u.x[CP_USER]+u.x[CP_NICE], stathz);
240 Bprint(&bout, "sys %lud %d\n", u.x[CP_SYS], stathz);
241 Bprint(&bout, "cpu %lud %d\n", u.x[CP_USER]+u.x[CP_NICE]+u.x[CP_SYS], stathz);
242 Bprint(&bout, "idle %lud %d\n", u.x[CP_IDLE], stathz);
253 if(getloadavg(l, 3) < 0)
255 Bprint(&bout, "load =%d 1000\n", (int)(l[0]*1000.0));
261 static struct kvm_swap s;
262 static ulong pgin, pgout;
267 pgsize = getpagesize();
276 i = isys("vm.stats.vm.v_swappgsin");
277 o = isys("vm.stats.vm.v_swappgsout");
278 if(i != pgin || o != pgout){
281 kvm_getswapinfo(kvm, &s, 1, 0);
285 Bprint(&bout, "swap =%lld %lld\n", s.ksw_used*(vlong)pgsize, s.ksw_total*(vlong)pgsize);