Network monitoring and GPIO control with SNMP
Pins and Nodes
![© Lead Image © Julia Borisenko, 123RF.com © Lead Image © Julia Borisenko, 123RF.com](/var/linux_magazin/storage/images/issues/2018/216/pi-network-monitoring/123rf_44462998_vintage-pens-and-needles_juliaborisenko_resized.png/735336-1-eng-US/123rf_44462998_Vintage-pens-and-needles_JuliaBorisenko_resized.png_medium.png)
© Lead Image © Julia Borisenko, 123RF.com
Monitor disk space and network and CPU loads with SNMP, view and control Rasp Pi GPIO pins remotely with custom SNMP objects, and create web dashboards with Node-RED.
Some of the great full-featured networking packages like Nagios [1] and MRTG [2] can be loaded on a Raspberry Pi. If, however, you are looking for something a bit smaller in scale, a Simple Network Management Protocol (SNMP) installation and Node-RED is a great place to start. Node-RED [3] is a visual programming environment that lets you create applications by dragging and dropping blocks (nodes) on the screen and directing the logic flow by connecting the nodes together.
In this article, I look at some basic SNMP monitoring that will allow you to integrate a Raspberry Pi into a larger network (Figure 1).
![](/var/linux_magazin/storage/images/issues/2018/216/pi-network-monitoring/figure-1/735339-1-eng-US/Figure-1_large.png)
SNMP
SNMP is the standard for communicating with and monitoring network devices. Common device information is grouped into management information bases (MIBs). Data items are object identifiers (OIDs), referenced by either their MIB name or their OID numeric name. For example, the SNMP device could be queried by its MIB name (e.g., SNMPv2-MIB::sysName.0) or its OID number (e.g., .1.3.6.1.2.1.1.5.0).
Install the SNMP monitor and server on your Rasp Pi with:
sudo apt-get update sudo apt-get install snmp snmpd snmp-mibs-downloader
To show meaningful MIB names, modify the SNMP config file by opening it in the Nano editor
sudo nano /etc/snmp/snmp.conf
and commenting out the first (#mibs
) line. The SNMP server agent has many configuration options. For testing (not recommended in a real system), begin by opening the configuration file and uncommenting the agentAddress
line, so all interfaces are open:
sudo nano /etc/snmp/snmpd.conf ** # Listen for connections on all interfaces (both IPv4 *and* IPv6) agentAddress udp:161,udp6:[::1]:161
In the ACCESS CONTROL section, add a line to give read/write access to the public and comment out all other access control definitions:
# ACCESS CONTROL # # Set read/write access to public anywhere # rwcommunity public
After saving the changes you've made to snmpd.conf
, the service needs to be restarted:
sudo service snmpd restart
A number of useful SNMP command-line programs are available (Table 1). The basic syntax for these commands is:
Table 1
SNMP CLI Programs
Program | Function |
---|---|
snmpget |
Gets an SNMP message for a specific OID. |
snmpset |
Sets an SNMP OID (OID needs to be writable). |
snmpwalk |
Gets multiple OID values in an MIB tree. |
command -c <community> -v <version> <node> <OID>
To begin, test SNMP on the Rasp Pi to see if it is working by running the snmpwalk
command, starting at the top of the tree (.1.3
); it should return a long list of all the available SNMP OIDs (Listing 1).
Listing 1
Testing SNMP
Node-RED
Node-RED has been preinstalled on Raspbian Jesse since the November 2015 version. For this networking example, you will need to load the Node-RED SNMP module, dashboard, and timer library by entering:
sudo apt-get update sudo apt-get install npm cd $HOME/.node-red npm install node-red-node-snmp npm install node-red-dashboard npm install node-red-contrib-bigtimer
At a terminal window, you can start Node-RED with:
node-red-start &
Node-RED has a web configuration interface that is accessed at http://localhost:1880 or http://<pi_ip_address>:1880.
A good first Node-RED application is to make a web dashboard that shows ping (node-to-node) delay times. The dashboards are defined in the right panel of Node-RED (Figure 2). Dashboard items are put into groups, and groups are put into tabs. Each tab will be shown as a separate page on your smartphone.
The logic is created by dragging and dropping ping
and chart
nodes onto the flow sheet (Figure 3) and then wiring the ping outputs to the chart inputs. Next, double-click the ping
node and enter the IP address of the node to ping and the scan rate (Figure 4). Similarly, double-click the chart
node and enter the dashboard group, size, label, and chart time (Figure 5).
After the configuration is done, click the Deploy button on the Node-RED menubar. The Node-RED dashboard user interface is accessed at http:<IPaddress>:1880/ui (e.g., http://192.168.1.102:1880/ui). Figure 6 shows the final dashboard. Chart data values are shown by clicking on the chart line.
Node-RED SNMP Example
The ping
node is quite simple, returning just the ping value. The snmp
node is more complex, returning multiple pieces of information. To use snmp
nodes in a Node-RED application, you need some support nodes to parse and pass the payload messages. Sending SNMP data to a chart dashboard (Figure 7) uses the following nodes:
Big Timer
– Triggers the polling of data.snmp
– Gets SNMP and OID information.split
– Splits the message into addressable variables.change
– Puts the OID value into the message payload.chart
– Shows the payload.
The Big Timer
node has many useful options. For a simple one-minute monitoring circuit, the middle Big Timer
output pin is connected as an input to the snmp
node. The snmp
node needs a host, community, and numeric OID configuration (Figure 8). The split
node should be set up to split on a comma (,
).
The powerful change
node can adjust and move information within the msg
and payload
items. For this application, you need to move payload.value
to payload
(Figure 9). Like the ping example, the chart
node is configured as a line chart with the required labels and ranges.
Many other SNMP objects can be monitored. Table 2 shows some of the more commonly monitored objects, and the dashboard in Figure 10 shows the typical output of monitoring CPU load, total RAM free, and free disk space.
Table 2
Useful SNMP Objects to Monitor
Object | OID |
---|---|
One-minute CPU load |
.1.3.6.1.4.1.2021.10.1.3.1 |
Five-minute CPU load |
.1.3.6.1.4.1.2021.10.1.3.2 |
15-minute CPU load |
.1.3.6.1.4.1.2021.10.1.3.3 |
Idle CPU time (%) |
.1.3.6.1.4.1.2021.11.11.0 |
Total RAM in machine |
.1.3.6.1.4.1.2021.4.5.0 |
Total RAM used |
.1.3.6.1.4.1.2021.4.6.0 |
Total RAM free |
.1.3.6.1.4.1.2021.4.11.0 |
Total disk/partition size (KB) |
.1.3.6.1.4.1.2021.9.1.6.1 |
Available space on disk |
.1.3.6.1.4.1.2021.9.1.7.1 |
Used space on disk |
.1.3.6.1.4.1.2021.9.1.8.1 |
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.