Skip to content


 Zabbix
 Grafana
 Prometheus
 Threejs and TypeScript
 SocketIO and TypeScript
 Blender Topological Earth
 Sweet Home 3D
 Design Patterns Python
 Design Patterns TypeScript
   
 Course Coupon Codes
Three.js and TypeScript
Kindle Edition
$9.99 $14.99 Paperback 
$29.99 $34.99




Design Patterns in TypeScript
Kindle Edition
$9.99 $14.99 Paperback
$19.99 $24.99




Design Patterns in Python
Kindle Edition
$9.99 $14.99 Paperback
$19.99 $24.99




Install an SNMP Agent and Configure Telegraf SNMP Input

Video Lecture

Install an SNMP Agent and Configure Telegraf SNMP Input Install an SNMP Agent and Configure Telegraf SNMP Input Install an SNMP Agent and Configure Telegraf SNMP Input

Description

SNMP stands for Simple Network Management Protocol.

We can configure Telegraf to read SNMP, save it into InfluxDB and view it in Grafana.

Common devices that support SNMP are routers, switches, printers, servers, workstations and other devices found on IP networks.

Not every network device supports SNMP, or has it enabled, and there is a good chance you don't have an SNMP enabled device available that you can use in this section.

So, I will show you how to install SNMP on an Ubuntu 20.04 server.

I will install it locally on the same server running InfluxDB.

sudo apt install snmp snmpd snmp-mibs-downloader

It is normally running after install.

sudo service snmpd status

Individual commands to either start, stop or restart are,

sudo service snmpd start
sudo service snmpd stop
sudo service snmpd restart

Do a test query

snmpwalk -v 2c -c public 127.0.0.1 .

The response should show results with OID numbers like in this example output

iso.3.6.1.2.1.1.1.0 = STRING: "Linux grafana 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64"
iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.8072.3.2.10
iso.3.6.1.2.1.1.3.0 = Timeticks: (443) 0:00:04.43
iso.3.6.1.2.1.1.4.0 = STRING: "Me <me@example.org>"
iso.3.6.1.2.1.1.5.0 = STRING: "grafana"
iso.3.6.1.2.1.1.6.0 = STRING: "Sitting on the Dock of the Bay"
iso.3.6.1.2.1.1.7.0 = INTEGER: 72
iso.3.6.1.2.1.1.8.0 = Timeticks: (11) 0:00:00.11
iso.3.6.1.2.1.1.9.1.2.1 = OID: iso.3.6.1.6.3.11.3.1.1
iso.3.6.1.2.1.1.9.1.2.2 = OID: iso.3.6.1.6.3.15.2.1.1
iso.3.6.1.2.1.1.9.1.2.3 = OID: iso.3.6.1.6.3.10.3.1.1
...
etc

Now to enable MIB descriptions instead of OIDs.

Edit the snmp.conf file

sudo nano /etc/snmp/snmp.conf

comment out the line mibs as below, using a #

#mibs

Save, and retry a query.

snmpwalk -v 2c -c public 127.0.0.1 .

It should now show the MIBs descriptions in the results like in this example output.

SNMPv2-MIB::sysDescr.0 = STRING: Linux grafana 4.15.0-72-generic #81-Ubuntu SMP Tue Nov 26 12:20:02 UTC 2019 x86_64
SNMPv2-MIB::sysObjectID.0 = OID: NET-SNMP-MIB::netSnmpAgentOIDs.10
DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (3015) 0:00:30.15
SNMPv2-MIB::sysContact.0 = STRING: Me <me@example.org>
SNMPv2-MIB::sysName.0 = STRING: grafana
SNMPv2-MIB::sysLocation.0 = STRING: Sitting on the Dock of the Bay
SNMPv2-MIB::sysServices.0 = INTEGER: 72
SNMPv2-MIB::sysORLastChange.0 = Timeticks: (11) 0:00:00.11
SNMPv2-MIB::sysORID.1 = OID: SNMP-MPD-MIB::snmpMPDCompliance
SNMPv2-MIB::sysORID.2 = OID: SNMP-USER-BASED-SM-MIB::usmMIBCompliance
SNMPv2-MIB::sysORID.3 = OID: SNMP-FRAMEWORK-MIB::snmpFrameworkMIBCompliance
...
etc

Now to configure Telegraf to read SNMP

sudo nano /etc/telegraf/telegraf.conf

Add this script below to the telegraf.conf file.

[[inputs.snmp]]
  agents = ["udp://127.0.0.1:161"]

  [[inputs.snmp.field]]
    oid = "RFC1213-MIB::sysUpTime.0"
    name = "uptime"

  [[inputs.snmp.field]]
    oid = "RFC1213-MIB::sysName.0"
    name = "source"
    is_tag = true

  [[inputs.snmp.table]]
    oid = "IF-MIB::ifTable"
    name = "interface"
    inherit_tags = ["source"]

    [[inputs.snmp.table.field]]
      oid = "IF-MIB::ifDescr"
      name = "ifDescr"
      is_tag = true

Save the above configuration addition, restart Telegraf and check status.

sudo service telegraf restart
sudo service telegraf status

⚠️ NOTE : By default SNMPD restricts how much information it returns. So currently we won't get any IF-MIB:: data from a SNMP query.

Go back into snmpd.conf and edit the view section to return more data.

sudo nano /etc/snmp/snmpd.conf

Change lines

...
view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1
...

to

...
view   systemonly  included   .1.3.6.1.2.1
#view   systemonly  included   .1.3.6.1.2.1.25.1
...

This will now return all data with the OID prefixes .1.3.6.1.2.1 which also includes interface information.

After a few moments, the snmp.table information should be queryable in InfluxDB and in Grafana through the interface measurement.

Sample Queries

Some sample queries to try against the InfluxDB data source in the Grafana explore tab.

from(bucket: "telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "interface")
  |> yield(name: "mean")
from(bucket: "telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "snmp")
  |> filter(fn: (r) => r["_field"] == "uptime")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")