Monitor your old Linux devices
Remote Commands
Rather than having remote Linux servers send data to a central monitoring node, the central node can periodically poll the remote servers for data.
SSH can be used to run remote commands; however, SSH needs you to enter a password. Although this is fine for manual testing, for automated polling it is a problem. Two solutions to this problem are:
ssh-keygen
, which generates an SSH key pair that is stored in a user directory, enabling the standard SSH client to run without you having to enter a password.sshpass
, which is an SSH client that includes the username/password as a command-line option.
The ssh-keygen
approach is recommended for most applications because it does not expose passwords. For testing, I use the sshpass
method, and in the Node-RED project that follows, I use the ssh-keygen
approach. The sshpass
command is included in many standard distributions. To install it, enter:
sudo apt-get install sshpass
Listing 3 shows how to get CPU (line 1) and hard drive (line 13) temperatures.
Listing 3
CPU and Hard Drive Temps
01 $ sshpass -p mypassword ssh username@192.168.0.116 sensors 02 dell_smm-virtual-0 03 Adapter: Virtual device 04 Processor Fan: 3044 RPM 05 CPU: +31.0°C 06 Ambient: +33.0°C 07 SODIMM: +33.0°C 08 09 acpitz-virtual-0 10 Adapter: Virtual device 11 temp1: +51.5°C (crit = +107.0°C) 12 13 $ sshpass -p mypassword ssh username@192.168.0.116 hddtemp /dev/sda 14 /dev/sda: HTS548040M9AT00: 39°C
As you saw earlier, grep
and awk
calls can be used to show just the required values for the CPU:
$ sshpass -p mypassword ssh username@192.168.0.116 sensors | grep temp1 | awk '{print $2}' +30.5°C
and for the hard drive:
$ sshpass -p mypassword ssh username@192.168.0.116 hddtemp /dev/sda | awk '{print $3}' 39°C
At this point, a mechanism is available to get key monitoring values from remote Linux nodes. The next step is to pass these values to a Node-RED dashboard.
Node-RED Dashboard
Node-RED [4] is a web-based visual programming environment with a wide variety of nodes that can be wired together to create logic. On the Raspberry Pi platform, Node-RED is pre-installed in Raspbian images. To install Node-RED on other systems see the Get Started docs [5].
For this project I installed two nodes: bigssh, an SSH node that saves and uses ssh-keygen
credentials, and bigtimer, a timer node that schedules data polling. These components can be installed either manually or with the Manage palette menu option (Figure 2).
A basic test circuit to poll a Linux server manually and return a temperature would use an Inject, a bigssh, and a Debug node (Figure 3). The Inject node is used to pulse the logic.
By double-clicking on the bigssh node, an Edit configuration window opens. In the myssh field, you enter the username, host, and ssh-keygen
password. The bigssh node passes its first output (commandLine) to a Debug node. The Debug node sends message and payload information to the Debug tab. If the Debug node does not show the expected SSH command result, then the bigssh third output (minError) shows the error output.
After I was able to get all my SSH commands working successfully in the test logic, I changed the logic to use a bigtimer node for scheduling and some dashboard nodes for display (Figure 4). The bigtimer node has a good selection of scheduling and timing functions. Of the three Big Timer outputs, the middle output pin generates a pulse every minute.
You have the choice of a number of dashboard presentations. For a simple first pass, I used gauge and chart nodes. Double-click on each of these dashboard nodes to edit properties like labels and scales.
After the logic is complete, click the Deploy button on the right side of the menubar to run your updated project. The Node-RED web dashboard is at http://<your-node-red-ip>:1880/ui/ (Figure 5).
Final Comment
In this article, I only looked at three command-line utilities; however, many others commands could use this technique.
Infos
- iostat: http://man7.org/linux/man-pages/man1/iostat.1.html
- lm-sensors: https://github.com/lm-sensors/lm-sensors
- hddtemp: https://linux.die.net/man/8/hddtemp
- Node-RED documentation: https://flows.nodered.org/
- Getting started with Node-RED: https://nodered.org/#get-started
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.
-
Fedora 40 Beta Released Soon
With the official release of Fedora 40 coming in April, it's almost time to download the beta and see what's new.
-
New Pentesting Distribution to Compete with Kali Linux
SnoopGod is now available for your testing needs
-
Juno Computers Launches Another Linux Laptop
If you're looking for a powerhouse laptop that runs Ubuntu, the Juno Computers Neptune 17 v6 should be on your radar.
-
ZorinOS 17.1 Released, Includes Improved Windows App Support
If you need or desire to run Windows applications on Linux, there's one distribution intent on making that easier for you and its new release further improves that feature.
-
Linux Market Share Surpasses 4% for the First Time
Look out Windows and macOS, Linux is on the rise and has even topped ChromeOS to become the fourth most widely used OS around the globe.
-
KDE’s Plasma 6 Officially Available
KDE’s Plasma 6.0 "Megarelease" has happened, and it's brimming with new features, polish, and performance.
-
Latest Version of Tails Unleashed
Tails 6.0 is based on Debian 12 and includes GNOME 43.
-
KDE Announces New Slimbook V with Plenty of Power and KDE’s Plasma 6
If you're a fan of KDE Plasma, you'll be thrilled to hear they've announced a new Slimbook with an AMD CPU and the latest version of KDE Plasma desktop.
-
Monthly Sponsorship Includes Early Access to elementary OS 8
If you want to get a glimpse of what's in the pipeline for elementary OS 8, just set up a monthly sponsorship to help fund its continued existence.