TOPIC: STAT
Keeping a graphical eye on CPU temperature and power consumption on the Linux command line
20th March 2025Following my main workstation upgrade in January, some extra monitoring has been needed. This follows on from the experience with building its predecessor more than three years ago.
Being able to do this in a terminal session keeps things lightweight, and I have done that with text displays like what you see below using a combination of sensors
and nvidia-smi
in the following command:
watch -n 2 "sensors | grep -i 'k10'; sensors | grep -i 'tdie'; sensors | grep -i 'tctl'; echo "" | tee /dev/fd/2; nvidia-smi"
Everything is done within a watch
command that refreshes the display every two seconds. Then, the panels are built up by a succession of commands separated with semicolons, one for each portion of the display. The grep
command is used to pick out the desired output of the sensors
command that is piped to it; doing that twice gets us two lines. The next command, echo "" | tee /dev/fd/2
, adds an extra line by sending a space to STDERR output before the output of nvidia-smi
is displayed. The result can be seen in the screenshot below.
However, I also came across a more graphical way to do things using commands like turbostat
or sensors
along with AWK programming and ttyplot
. Using the temperature output from the above and converting that needs the following:
while true; do sensors | grep -i 'tctl' | awk '{ printf("%.2f\n", $2); fflush(); }'; sleep 2; done | ttyplot -s 100 -t "CPU Temperature (Tctl)" -u "°C"
This is done in an infinite while
loop to keep things refreshing; the watch
command does not work for piping output from the sensors
command to both the awk
and ttyplot
commands in sequence and on a repeating, periodic basis. The awk
command takes the second field from the input text, formats it to two places of decimals and prints it before flushing the output buffer afterwards. The ttyplot
command then plots those numbers on the plot seen below in the screenshot with a y-axis scaled to a maximum of 100 (-s
), units of °C
(-u
) and a title of CPU Temperature (Tctl)
(-t
).
A similar thing can be done for the CPU wattage, which is how I learned of the graphical display possibilities in the first place. The command follows:
sudo turbostat --Summary --quiet --show PkgWatt --interval 1 | sudo awk '{ printf("%.2f\n", $1); fflush(); }' | sudo ttyplot -s 200 -t "Turbostat - CPU Power (watts)" -u "watts"
Handily, the turbostat
can be made to update every so often (every second in the command above), avoiding the need for any infinite while
loop. Since only a summary is needed for the wattage, all other output can be suppressed, though everything needs to work using superuser privileges, unlike the sensors
command earlier. Then, awk
is used like before to process the wattage for plotting; the first field is what is being picked out here. After that, ttyplot
displays the plot seen in the screenshot below with appropriate title, units and scaling. All works with output from one command acting as input to another using pipes.
All of this offers a lightweight way to keep an eye on system load, with the top
command showing the impact of different processes if required. While there are graphical tools for some things, command line possibilities cannot be overlooked either.
Saving yourself a reboot: remounting any overlooked volumes in Linux
14th September 2024Recently, I got things a little out of order when starting up my main Linux system after an absence. Usually, I start up my NAS first so that the volumes get mounted when I start my Linux machine. However, it happened that I near enough started them together. Thus, my workstation completed it startup without having the NAS volumes mounted. A reboot would have sorted this, but there was another way: issuing the command that you see below:
sudo mount -a
This looked in my /etc/fstab
file and mounted anything that was missing as long as the noauto
option was not set. Because this was executed after the NAS had completed its own boot process, it volumes were not mounted on my system and fully available for what I needed to do next. If I had wanted to see what had been mounted, then I needed to issue the following command instead:
sudo mount -av
In addition to the a
switch that triggers the mounting of missing volumes, there is now a v
(for verbose) one for telling you what has happened. Needless to say, all this happens only if your /etc/fstab
file is set up properly. If you are adding a new volume, and I was not, it does no harm to mount it manually before updating the configuration file. That should catch any errors first.