sensething
is a CLI tool for discovering, reading, and logging Linux system
sensor data. Its goals are as follows:
- Make as many hardware sensors as possible visible from within a single tool,
- Provide a human-friendly way of querying specific sensors,
- Produce output in formats that are easy to parse (for humans and computers).
- Rationale: why use SenseThing instead of lm-sensors?
- How SenseThing works
- Tutorial
- Installation
- Discovering your system's sensors
- A simple way to read sensor data
- Logging sensor data continuously
- Monitoring sensor data remotely
SenseThing shows all the same data as lm-sensors, plus some additional things:
- SenseThing can report CPU and GPU clock frequency data, which is not reported by lm-sensors.
- SenseThing supports Nvidia GPUs, and can report many of the same metrics reported by nvidia-smi.
SenseThing fits some use cases that aren't covered by lm-sensors. Here are a couple examples:
- Periodically logging sensor data to a CSV file during benchmark testing.
- Monitoring remote servers through a simple web UI.
SenseThing works by traversing Linux's sysfs. It is aware of the interfaces exposed by the hwmon, drm, and cpufreq kernel modules. Nvidia sensor data is acquired via nvidia-smi.
For apt-based Linux distros, SenseThing can be installed using one of the deb files available in the GitHub Releases.
On other distros, unfortunately you'll have to install SenseThing manually. Run the following commands to check out this repo and install:
git clone git@github.com:ryukoposting/sensething.git
cd sensething
bundle install
rake install
sensething --version
First, you'll want to grab a list of the available sensors on your system:
# these are synonyms, use whichever one you prefer
sensething ls
sensething list-sensors
The ls
(a.k.a. "list-sensors") command prints a list of sensors. Here's
a truncated example from my 10th gen ThinkPad X1:
acpitz/temperature_1 Temperature Sensor (hwmon1/temp1)
BAT0/voltage_0 Voltage Sensor (hwmon2/in0)
nvme/Composite Temperature Sensor (hwmon3/temp1)
**snip**
thinkpad/fan_1 Fan (hwmon6/fan1)
thinkpad/pwm_1 PWM (hwmon6/pwm1)
thinkpad/CPU Temperature Sensor (hwmon6/temp1)
thinkpad/fan_2 Fan (hwmon6/fan2)
thinkpad/GPU Temperature Sensor (hwmon6/temp2)
thinkpad/temperature_3 Temperature Sensor (hwmon6/temp3)
thinkpad/temperature_4 Temperature Sensor (hwmon6/temp4)
**snip**
coretemp/Package id 0 Temperature Sensor (hwmon7/temp1)
coretemp/Core 0 Temperature Sensor (hwmon7/temp2)
coretemp/Core 4 Temperature Sensor (hwmon7/temp3)
coretemp/Core 8 Temperature Sensor (hwmon7/temp4)
coretemp/Core 12 Temperature Sensor (hwmon7/temp5)
coretemp/Core 16 Temperature Sensor (hwmon7/temp6)
**snip**
cpu0/frequency CPU Frequency (cpufreq/policy0)
cpu1/frequency CPU Frequency (cpufreq/policy1)
cpu2/frequency CPU Frequency (cpufreq/policy2)
cpu3/frequency CPU Frequency (cpufreq/policy3)
cpu4/frequency CPU Frequency (cpufreq/policy4)
**snip**
card0/frequency Graphics Frequency (drm/card0)
Skimming through that list, you'll see myriad temperature sensors, a couple fans, a PWM output, battery voltage, and CPU/GPU clock frequencies.
Some of the sensors have pretty self-evident names, like BAT0/voltage_0
and coretemp/Core 0
. SenseThing always tries to give descriptive,
human-friendly names to all sensors it discovers.
Let's grab a value from one of those sensors:
# 'r' is a synonym for 'read'
sensething r -s BAT0/voltage_0
sensething read -s BAT0/voltage_0
To read a sensor, use the r
(a.k.a. "read") command to fetch sensor values
in a human-friendly format. Here's what I got when I ran that command:
BAT0/voltage_0 16490.0 mV
SenseThing happily prints the sensor's name, followed by its value, with its units. Let's try adding some more sensors to our query:
sensething r -s BAT0/voltage_0 -s thinkpad/CPU -s card0/frequency
You can add as many sensors as you want, and SenseThing will dutifully print out their values for you:
BAT0/voltage_0 16487.0 mV
thinkpad/CPU 47.0 °C
card0/frequency 300.0 MHz
Let's say you're running some benchmarks, and you want to keep an eye on CPU
and GPU temperatures during the test. SenseThing's l
(a.k.a. "log")
command is made for that purpose:
# 'l' is a synonym for 'log'
sensething l -s thinkpad/CPU -s thinkpad/GPU
sensething log -s thinkpad/CPU -s thinkpad/GPU
SenseThing will start printing out a CSV file containing the measurements. Every 5 seconds, a new line of data will be printed.
thinkpad/CPU,thinkpad/GPU
43.0,43.0
43.0,42.0
43.0,45.0
To include units of measurement in the header row, add the -u
(a.k.a
"--units") flag:
sensething l -u -s thinkpad/CPU -s thinkpad/GPU
The sample output above would look like this when the -u
flag is added:
thinkpad/CPU [°C],thinkpad/GPU [°C]
43.0,43.0
43.0,42.0
43.0,45.0
To make SenseThing record data every 2 seconds instead of 5, use the -i
(a.k.a. "--interval") flag:
sensething l -i 2
-i
accepts decimal numbers like 4.2
or 0.5
, as well.
Nvidia users: Please note that, while you can still set a faster interval, data from nvidia-smi won't actually change faster than once per second.
Depending on your use case, it may also be useful to include timestamps
with your data. The -t
flag (a.k.a. "--timestamp") facilitates this:
sensething l -t # same thing as "-t seconds"
sensething l -t seconds
sensething l -t millis
With -t seconds
and -t millis
, SenseThing's timestamps will show the
time elapsed since the program started. This is usually the most useful
form when recording data during benchmarking.
When an absolute wall-clock time is desired, timestamps can also be formatted in standard ISO 8601 standard forms:
sensething l -t iso8601 # yyyy-mm-ddThh:mm:ss+ZZZZ
sensething l -t iso8601-millis # yyyy-mm-ddThh:mm:ss.sss+ZZZZ
SenseThing's logging feature defaults to CSV. However, it also supports
JSON output, thanks to the -f
(a.k.a. "--format") flag:
sensething l -f json
sensething l -f csv # this is the default
If you want to monitor a system's sensors remotely, you could simply
pipe sensething l -f json ...
into netcat, but this approach has its fair
share of flaws. SenseThing's s
command (a.k.a "serve") exposes an HTTP
server that provides more refined access to the system's sensors.
# These are synonyms, use whichever one you prefer
sensething s
sensething serve
Run sensething s
, open your browser, and navigate to localhost:4567
. You'll
see a page that looks something like this:
Pretty? Not really. Informative? Absolutely!
Adding Accept: text/json
to your request will cause SenseThing to respond
with JSON instead of HTML.
The server's configuration can be altered using the -a
and -p
options,
which set the server's address and port respectively. For example,
sensething s -a 0.0.0.0 -p 80