SNMP + Telegraf + InfluxDB

First, install telegraf from github with the branch to fix-snmp-not-in-mib branch, that solves the issue #1833

git clone -b fix-snmp-not-in-mib --single-branch https://github.com/phemmer/telegraf.git

After, I searched all MIB about an specific interface through bash language:

IFACE="enp3s0"
ID=`snmpwalk -v2c -c public localhost | grep "ifName.*STRING: $IFACE" | sed 's/\./ /g' | tail -n1 | awk '{print $2}'`
snmpwalk -v2c -c public localhost | grep "^IF-MIB::if.*\.$ID"

It outputs a lots MIBs, but most relevants are:

IF-MIB::ifName.2 = STRING: enp3s0
IF-MIB::ifDescr.2 = STRING: Realtek Semiconductor Co., Ltd. RTL8111/8168/8411 PCI Express
IF-MIB::ifType.2 = INTEGER: ethernetCsmacd(6)
IF-MIB::ifMtu.2 = INTEGER: 1500
IF-MIB::ifSpeed.2 = Gauge32: 10000000

IF-MIB::ifHighSpeed.2 = Gauge32: 10
IF-MIB::ifPromiscuousMode.2 = INTEGER: false(2)
IF-MIB::ifConnectorPresent.2 = INTEGER: true(1)

IF-MIB::ifPhysAddress.2 = STRING: AB:57:40:85:bc:35
IF-MIB::ifAdminStatus.2 = INTEGER: up(1)
IF-MIB::ifOperStatus.2 = INTEGER: up(1)
IF-MIB::ifLastChange.2 = Timeticks: (1879004) 5:13:10.04

IF-MIB::ifInOctets.2 = Counter32: 997055099
IF-MIB::ifInUcastPkts.2 = Counter32: 807196
IF-MIB::ifInNUcastPkts.2 = Counter32: 625
IF-MIB::ifInDiscards.2 = Counter32: 0
IF-MIB::ifInErrors.2 = Counter32: 0
IF-MIB::ifInUnknownProtos.2 = Counter32: 0

IF-MIB::ifOutOctets.2 = Counter32: 57885767
IF-MIB::ifOutUcastPkts.2 = Counter32: 519963
IF-MIB::ifOutNUcastPkts.2 = Counter32: 0
IF-MIB::ifOutDiscards.2 = Counter32: 0
IF-MIB::ifOutErrors.2 = Counter32: 0
IF-MIB::ifOutQLen.2 = Gauge32: 0

IF-MIB::ifHCInOctets.2 = Counter64: 997055099
IF-MIB::ifHCInUcastPkts.2 = Counter64: 807196
IF-MIB::ifHCInMulticastPkts.2 = Counter64: 625
IF-MIB::ifHCInBroadcastPkts.2 = Counter64: 0

IF-MIB::ifHCOutOctets.2 = Counter64: 57885767
IF-MIB::ifHCOutUcastPkts.2 = Counter64: 519963
IF-MIB::ifHCOutMulticastPkts.2 = Counter64: 0
IF-MIB::ifHCOutBroadcastPkts.2 = Counter64: 0

Now, you need to create your telegraf configuration file with the information that you need in input pugins, like:

###############################################################################
#                            INPUT PLUGINS                                    #
###############################################################################
[[inputs.snmp]]
  interval= "5s"
  agents = [ "127.0.0.1:161" ]
  version = 2
  community = "public"
  timeout= 2.0

  name = "system"
  [[inputs.snmp.field]]
    name="sysUpTime"
    oid="DISMAN-EVENT-MIB::sysUpTimeInstance"
  [[inputs.snmp.field]]
    name="OperStatus"
    oid="IF-MIB::ifOperStatus.2"
  [[inputs.snmp.field]]
    name="InOctets"
    oid="IF-MIB::ifInOctets.2"
  [[inputs.snmp.field]]
    name="InUcastPkts"
    oid="IF-MIB::ifInUcastPkts.2"
  [[inputs.snmp.field]]
    name="OutOctets"
    oid="IF-MIB::ifOutOctets.2"
    [[inputs.snmp.field]]
    name="OutUcastPkts"
    oid="IF-MIB::ifOutUcastPkts.2"
    is_tag = true
    conversion = "float"

Run your filter with the following sentence:

telegraf -config telegraf_snmp.conf --test


Now, you can see the data through InfluxDB



Enjoy it!

Comments

Popular posts from this blog

How to fix Android when developer options are not available for this user

from: can't read /var/mail/ in Python scripts

Fix "Set scan parameters failed: Input/output error" on Ubuntu 16.04