diff options
-rw-r--r-- | usr.bin/systat/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/systat/cmdtab.c | 7 | ||||
-rw-r--r-- | usr.bin/systat/extern.h | 8 | ||||
-rw-r--r-- | usr.bin/systat/sensors.c | 198 | ||||
-rw-r--r-- | usr.bin/systat/systat.1 | 7 |
5 files changed, 218 insertions, 6 deletions
diff --git a/usr.bin/systat/Makefile b/usr.bin/systat/Makefile index ada225f1cf4..e509b9b8410 100644 --- a/usr.bin/systat/Makefile +++ b/usr.bin/systat/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.16 2004/11/16 09:52:33 markus Exp $ +# $OpenBSD: Makefile,v 1.17 2007/02/23 22:02:58 deanna Exp $ PROG= systat @@ -6,7 +6,7 @@ PROG= systat CPPFLAGS+=-I${.CURDIR}/../../usr.bin/vmstat SRCS= cmds.c cmdtab.c disks.c dkstats.c fetch.c if.c iostat.c keyboard.c \ - main.c mbufs.c netcmds.c netstat.c pigs.c swap.c vmstat.c + main.c mbufs.c netcmds.c netstat.c pigs.c sensors.c swap.c vmstat.c DPADD= ${LIBCURSES} ${LIBM} ${LIBKVM} LDADD= -lcurses -lm -lkvm BINGRP= kmem diff --git a/usr.bin/systat/cmdtab.c b/usr.bin/systat/cmdtab.c index 0f77e0214ef..29fc3db1170 100644 --- a/usr.bin/systat/cmdtab.c +++ b/usr.bin/systat/cmdtab.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmdtab.c,v 1.7 2004/11/16 09:52:33 markus Exp $ */ +/* $OpenBSD: cmdtab.c,v 1.8 2007/02/23 22:02:58 deanna Exp $ */ /* $NetBSD: cmdtab.c,v 1.2 1995/01/20 08:51:51 jtc Exp $ */ /*- @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)cmdtab.c 8.1 (Berkeley) 6/6/93"; #endif -static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.7 2004/11/16 09:52:33 markus Exp $"; +static char rcsid[] = "$OpenBSD: cmdtab.c,v 1.8 2007/02/23 22:02:58 deanna Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -65,6 +65,9 @@ struct cmdtab cmdtab[] = { { "ifstat", showifstat, fetchifstat, labelifstat, initifstat, openifstat, closeifstat, cmdifstat, CF_LOADAV }, + { "sensors", showsensors, fetchsensors, labelsensors, + initsensors, opensensors, closesensors, 0, + CF_LOADAV }, { 0 } }; struct cmdtab *curcmd = &cmdtab[0]; diff --git a/usr.bin/systat/extern.h b/usr.bin/systat/extern.h index 68c0a2c4ca5..dfab8ae9a60 100644 --- a/usr.bin/systat/extern.h +++ b/usr.bin/systat/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.15 2006/03/31 04:10:59 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.16 2007/02/23 22:02:58 deanna Exp $ */ /* $NetBSD: extern.h,v 1.3 1996/05/10 23:16:34 thorpej Exp $ */ /*- @@ -67,6 +67,7 @@ void closekre(WINDOW *); void closembufs(WINDOW *); void closenetstat(WINDOW *); void closepigs(WINDOW *); +void closesensors(WINDOW *); void closeswap(WINDOW *); int cmdifstat(char *, char *); int cmdiostat(char *, char *); @@ -88,6 +89,7 @@ void fetchkre(void); void fetchmbufs(void); void fetchnetstat(void); void fetchpigs(void); +void fetchsensors(void); void fetchswap(void); int initifstat(void); int initiostat(void); @@ -95,6 +97,7 @@ int initkre(void); int initmbufs(void); int initnetstat(void); int initpigs(void); +int initsensors(void); int initswap(void); void keyboard(void); int kvm_ckread(void *, void *, size_t); @@ -105,6 +108,7 @@ void labelmbufs(void); void labelnetstat(void); void labelpigs(void); void labels(void); +void labelsensors(void); void labelswap(void); void load(void); int netcmd(char *, char *); @@ -115,6 +119,7 @@ WINDOW *openkre(void); WINDOW *openmbufs(void); WINDOW *opennetstat(void); WINDOW *openpigs(void); +WINDOW *opensensors(void); WINDOW *openswap(void); int prefix(char *, char *); void sigwinch(int); @@ -124,6 +129,7 @@ void showkre(void); void showmbufs(void); void shownetstat(void); void showpigs(void); +void showsensors(void); void showswap(void); void status(void); void gethz(void); diff --git a/usr.bin/systat/sensors.c b/usr.bin/systat/sensors.c new file mode 100644 index 00000000000..f46df0aa3af --- /dev/null +++ b/usr.bin/systat/sensors.c @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2007 Deanna Phillips <deanna@openbsd.org> + * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include <sys/param.h> +#include <sys/sysctl.h> +#include <sys/sensors.h> + +#include <err.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> + +#include "systat.h" +#include "extern.h" + +struct sensor sensor; +struct sensordev sensordev; +int row, sensor_cnt; +void printline(void); + +WINDOW * +opensensors(void) +{ + return (subwin(stdscr, LINES-5-1, 0, 5, 0)); +} + +void +closesensors(WINDOW *w) +{ + if (w == NULL) + return; + wclear(w); + wrefresh(w); + delwin(w); +} + +void +labelsensors(void) +{ + wmove(wnd, 0, 0); + wclrtobot(wnd); + mvwaddstr(wnd, 1, 0, "Device"); + mvwaddstr(wnd, 1, 34, "Value"); + mvwaddstr(wnd, 1, 45, "Status"); + mvwaddstr(wnd, 1, 58, "Description"); +} + +void +fetchsensors(void) +{ + enum sensor_type type; + size_t slen, sdlen; + int mib[5], dev, numt; + + mib[0] = CTL_HW; + mib[1] = HW_SENSORS; + slen = sizeof(struct sensor); + sdlen = sizeof(struct sensordev); + + row = 2; + sensor_cnt = 0; + for (dev = 0; dev < MAXSENSORDEVICES; dev++) { + mib[2] = dev; + if (sysctl(mib, 3, &sensordev, &sdlen, NULL, 0) == -1) { + if (errno != ENOENT) + warn("sysctl"); + continue; + } + for (type = 0; type < SENSOR_MAX_TYPES; type++) { + mib[3] = type; + for (numt = 0; numt < sensordev.maxnumt[type]; numt++) { + mib[4] = numt; + if (sysctl(mib, 5, &sensor, &slen, NULL, 0) + == -1) { + if (errno != ENOENT) + warn("sysctl"); + continue; + } + if (sensor.flags & SENSOR_FINVALID) + continue; + sensor_cnt++; + if (sensor_cnt > 0) + printline(); + } + } + } +} + +const char *drvstat[] = { + NULL, "empty", "ready", "powerup", "online", "idle", "active", + "rebuild", "powerdown", "fail", "pfail" +}; + +void +showsensors(void) +{ + row = 2; + if (sensor_cnt == 0) + mvwaddstr(wnd, row, 0, "No sensors found."); +} + +int +initsensors(void) +{ + fetchsensors(); +} + +void +printline(void) +{ + wmove(wnd, row, 0); + wclrtoeol(wnd); + mvwprintw(wnd, row, 0, "%s.%s%d", sensordev.xname, + sensor_type_s[sensor.type], sensor.numt); + switch(sensor.type) { + case SENSOR_TEMP: + mvwprintw(wnd, row, 24, "%10.2f degC", + (sensor.value - 273150000) / 1000000.0); + break; + case SENSOR_FANRPM: + mvwprintw(wnd, row, 24, "%11lld RPM", sensor.value); + break; + case SENSOR_VOLTS_DC: + mvwprintw(wnd, row, 24, "%10.2f V DC", + sensor.value / 1000000.0); + break; + case SENSOR_AMPS: + mvwprintw(wnd, row, 24, "%10.2f A", sensor.value / 1000000.0); + break; + case SENSOR_INDICATOR: + mvwprintw(wnd, row, 24, "%15s", sensor.value? "On" : "Off"); + break; + case SENSOR_INTEGER: + mvwprintw(wnd, row, 24, "%11lld raw", sensor.value); + break; + case SENSOR_PERCENT: + mvwprintw(wnd, row, 24, "%14.2f%%", sensor.value / 1000.0); + break; + case SENSOR_LUX: + mvwprintw(wnd, row, 24, "%15.2f lx", sensor.value / 1000000.0); + break; + case SENSOR_DRIVE: + if (0 < sensor.value && sensor.value < + sizeof(drvstat)/sizeof(drvstat[0])) { + mvwprintw(wnd, row, 24, "%15s", drvstat[sensor.value]); + break; + } + case SENSOR_TIMEDELTA: + mvwprintw(wnd, row, 24, "%10.6f secs", + sensor.value / 1000000000.0); + break; + case SENSOR_WATTHOUR: + mvwprintw(wnd, row, 24, "%12.2f Wh", sensor.value / 1000000.0); + break; + case SENSOR_AMPHOUR: + mvwprintw(wnd, row, 24, "%10.2f Ah", sensor.value / 1000000.0); + break; + /* FALLTHROUGH */ + default: + mvwprintw(wnd, row, 24, "%10lld", sensor.value); + } + if ((sensor.desc != NULL) && strlen(sensor.desc) < 1) + mvwprintw(wnd, row, 58, "(%s%d)", + sensor_type_s[sensor.type], sensor.numt); + else + mvwprintw(wnd, row, 58, "(%s)", sensor.desc); + switch (sensor.status) { + case SENSOR_S_UNKNOWN: + mvwaddstr(wnd, row++, 45, "unknown"); + break; + case SENSOR_S_WARN: + mvwaddstr(wnd, row++, 45, "WARNING"); + break; + case SENSOR_S_CRIT: + mvwaddstr(wnd, row++, 45, "CRITICAL"); + break; + /* FALLTHROUGH */ + default: + mvwaddstr(wnd, row++, 45, "OK"); + break; + } + +} diff --git a/usr.bin/systat/systat.1 b/usr.bin/systat/systat.1 index 66214732117..a497f3ad2be 100644 --- a/usr.bin/systat/systat.1 +++ b/usr.bin/systat/systat.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: systat.1,v 1.47 2006/10/15 01:45:10 millert Exp $ +.\" $OpenBSD: systat.1,v 1.48 2007/02/23 22:02:58 deanna Exp $ .\" $NetBSD: systat.1,v 1.6 1996/05/10 23:16:39 thorpej Exp $ .\" .\" Copyright (c) 1985, 1990, 1993 @@ -199,6 +199,10 @@ Areas known to the kernel but not in use are shown as not available. .It Ic mbufs Display, in the lower window, the number of mbufs allocated for particular uses, i.e., data, socket structures, etc. +.It Ic sensors +Display the current values of available hardware sensors, +in a format similar to that of +.Xr sysctl 8 . .It Ic vmstat Take over the entire display and show a (rather crowded) compendium of statistics related to virtual memory usage, process scheduling, @@ -499,6 +503,7 @@ port names .Xr iostat 8 , .Xr pstat 8 , .Xr renice 8 , +.Xr sysctl 8 , .Xr vmstat 8 .Sh HISTORY The |