find-sensor-mibs: Tool for finding MIB structure of sensors on OpenBSD
Description
OpenBSD has a great framework called
sysctl
that can be used for querying system information and modifying various system
settings.
One handy application of sysctl is querying sensor data. Most modern
machines have plenty of them, and the sysctl framework provides a
single method to query this information.
From the command line, one only has to use
sysctl(8)
to get the information. From C, OpenBSD provides
sysctl(3).
To obtain this information using sysctl(3), one has to know the
Message Interface Buffer, or MIB, for the sensor in question.
A MIB is nothing more than an array of integers. To find these arrays
for each sensor, I wrote find-sensor-mibs.
The following program displays all sensors on the system it is running on
along with their current readings and, most importantly, their MIB
structure.
Example
On my laptop (a Lenovo T61 running OpenBSD 4.3-release) I have the following
output from 'sysctl hw.sensors'
ryan@barwise# sysctl hw.sensors
hw.sensors.cpu0.temp0=35.00 degC
hw.sensors.cpu1.temp0=35.00 degC
hw.sensors.acpitz0.temp0=47.05 degC (zone temperature)
hw.sensors.acpitz1.temp0=42.05 degC (zone temperature)
hw.sensors.acpibat0.volt0=14.40 VDC (voltage)
hw.sensors.acpibat0.volt1=16.58 VDC (current voltage)
hw.sensors.acpibat0.watthour0=37.22 Wh (last full capacity)
hw.sensors.acpibat0.watthour1=1.86 Wh (warning capacity)
hw.sensors.acpibat0.watthour2=0.20 Wh (low capacity)
hw.sensors.acpibat0.watthour3=37.22 Wh (remaining capacity), OK
hw.sensors.acpibat0.raw0=0 (battery full), OK
hw.sensors.acpibat0.raw1=0 (rate)
hw.sensors.acpiac0.indicator0=On (power supply)
When running the find-sensor-mibs program, I get the following
ryan@barwise# ./find-sensor-mibs
For reading sensor data via sysctl(3), the MIB structure for each
sensor on this system is the following:
mib[] = { CTL_HW, HW_SENSORS, x, y, z }
where x, y, and z are as follows:
x y z sensor name (from sysctl) and raw value
--- --- --- ---------------------------------------
0 0 0 hw.sensors.cpu0.temp0 = 309150000
1 0 0 hw.sensors.cpu1.temp0 = 309150000
2 0 0 hw.sensors.acpitz0.temp0 = 320200000
3 0 0 hw.sensors.acpitz1.temp0 = 315200000
4 2 0 hw.sensors.acpibat0.volt0 = 14400000
4 2 1 hw.sensors.acpibat0.volt1 = 16584000
4 7 0 hw.sensors.acpibat0.watthour0 = 37220000
4 7 1 hw.sensors.acpibat0.watthour1 = 1861000
4 7 2 hw.sensors.acpibat0.watthour2 = 200000
4 7 3 hw.sensors.acpibat0.watthour3 = 37220000
4 10 0 hw.sensors.acpibat0.raw0 = 0
4 10 1 hw.sensors.acpibat0.raw1 = 0
5 2 0 hw.sensors.acpibat1.volt0 = 0
5 2 1 hw.sensors.acpibat1.volt1 = 0
5 7 0 hw.sensors.acpibat1.watthour0 = 0
5 7 1 hw.sensors.acpibat1.watthour1 = 0
5 7 2 hw.sensors.acpibat1.watthour2 = 0
5 7 3 hw.sensors.acpibat1.watthour3 = 0
5 10 0 hw.sensors.acpibat1.raw0 = 0
5 10 1 hw.sensors.acpibat1.raw1 = 0
6 9 0 hw.sensors.acpiac0.indicator0 = 1
As you can see, sensor MIBs are 5-element integer arrays, where the first 2
elements are CTL_HW and HW_SENSORS, respectively (these are
defined constants). The remaining 3 components of each MIB are displayed for
each sensor.
Documentation
- Installation
-
Download the source zip below and then simply
- tar xvzf find-sensor-mibs.tar.gz
- cd find-sensor-mibs
- make
- Usage
-
After doing the above, you should simply be able to
'./find-sensor-mibs' and see a list of all sensors and their
associated MIB structures.
Download
Here:
find-sensor-mibs.tar.gz.
Notes
This could easily be extended to display the MIB structure for any sysctl.
Each first and second level sysctl object, however, has its own structure,
so some work would have to be done. None-the-less,
The code for the program (all 58 lines) should be more than enough to help out
anyone who is curious how to find MIB structures of other sysctl
properties.
Copyright (c) 2008 Ryan Flannery <ryan.flannery@gmail.com>