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:

  1. 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.
  2. 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@ 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
09 acpitz-virtual-0
10 Adapter: Virtual device
11 temp1:        +51.5°C  (crit = +107.0°C)
13 $ sshpass -p mypassword ssh username@ 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@ sensors | grep temp1 | awk '{print $2}'

and for the hard drive:

$ sshpass -p mypassword ssh username@ hddtemp /dev/sda | awk '{print $3}'

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).

Figure 2: Installing nodes from the Manage palette menu.

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.

Figure 3: Basic polling test circuit with Inject, Big SSH, and Debug nodes (left to right).

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.

Figure 4: Monitoring data sent to Node-RED dashboards.

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).

Figure 5: Node-RED dashboard showing data from old Linux servers.

Final Comment

In this article, I only looked at three command-line utilities; however, many others commands could use this technique.

The Author

You can investigate more neat projects by Pete Metcalfe and his daughters at

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95