Only first SNMP instance in telegraf.conf outputs to InfluxDB

I’m trying to get SNMP data from two devices (a router and a NAS), where it’s not feasible to install Telegraf locally.
To do this - using the ‘new’ SNMP plugin - I’ve defined two [[inputs.snmp]] sections in my telegraf.conf file.

Everything looks good during telegraf -test, but it seems that only the first section’s fields are being sent to InfluxDB. The fields from the second section are listed fine during test, but then don’t arrive in InfluxDB when I run Telegraf properly.

The required fields from each device overlap a bit, but not completely, so I can’t just specify both devices in the same agents array.

@GainfulShrimp Hello!

Can you post your telegraf configuration file?

Thanks @jackzampolin.

Here’s my config file, with comments stripped out:

[global_tags]

[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "5s"
  precision = "s"
  debug = false
  quiet = false
  logfile = ""
  hostname = ""
  omit_hostname = false

[[outputs.influxdb]]
  urls = ["http://localhost:8086"] # required
  database = "telegraf" # required
  retention_policy = ""
  write_consistency = "any"
  timeout = "5s"

[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false

[[inputs.disk]]
  mount_points = ["/"]
  ignore_fs = ["tmpfs", "devtmpfs"]

[[inputs.mem]]

[[inputs.system]]

[[inputs.net]]

[[inputs.snmp]]
  agents = [ "192.168.2.1:161", "192.168.2.50:161" ]
  timeout = "5s"
  retries = 3
  version = 2
  community = "somelongstring"
  max_repetitions = 10

  name = "system"
  [[inputs.snmp.field]]
    name = "hostname"
    oid = "SNMPv2-SMI::mib-2.1.5.0"
    is_tag = true
  [[inputs.snmp.field]]
    name = "uptime"
    oid = "1.3.6.1.2.1.1.3.0" 
  [[inputs.snmp.field]]
    name = "cpuIdle"
    oid = "SNMPv2-SMI::enterprises.2021.11.11.0"
  [[inputs.snmp.field]]
    name = "memRealTotal"
    oid = "SNMPv2-SMI::enterprises.2021.4.5.0"
  [[inputs.snmp.field]]
    name = "memRealAvail"
    oid = "SNMPv2-SMI::enterprises.2021.4.6.0"
  [[inputs.snmp.field]]
    name = "memRealBuffers"
    oid = "SNMPv2-SMI::enterprises.2021.4.14.0"
  [[inputs.snmp.field]]
    name = "memRealCached"
    oid = "SNMPv2-SMI::enterprises.2021.4.15.0"

  [[inputs.snmp.table]]
    ## measurement name
    name = "if_counters"
    inherit_tags = [ "hostname" ]
    [[inputs.snmp.table.field]]
      name = "bytes_recv"
      oid = ".1.3.6.1.2.1.31.1.1.1.6"
    [[inputs.snmp.table.field]]
      name = "bytes_sent"
      oid = ".1.3.6.1.2.1.31.1.1.1.10"
    [[inputs.snmp.table.field]]
      name = "interface"
      oid = ".1.3.6.1.2.1.31.1.1.1.1"
      is_tag = true

[[inputs.snmp]]
  agents = [ "192.168.2.50:161" ]
  timeout = "5s"
  retries = 3
  version = 2
  community = "somelongstring"
  max_repetitions = 10

  ## measurement name
  name = "nas"
  [[inputs.snmp.field]]
    name = "hostname"
    oid = "SNMPv2-SMI::mib-2.1.5.0"
    is_tag = true

  [[inputs.snmp.field]]
    name = "model"
	oid = "SYNOLOGY-SYSTEM-MIB::modelName.0"
	is_tag = true

  # DSM update available or not
  # Available(1), Unavailable(2), Connecting(3), Disconnected(4), Others(5)
  [[inputs.snmp.field]]
    name = "upgradeAvailable"
	oid = "SYNOLOGY-SYSTEM-MIB::upgradeAvailable.0"

  # system partition status
  # Normal(1), Failed(2)
  [[inputs.snmp.field]]
    name = "systemStatus"
	oid = "SYNOLOGY-SYSTEM-MIB::systemStatus.0"
	
  [[inputs.snmp.field]]
    name = "temperature"
	oid = "SYNOLOGY-SYSTEM-MIB::temperature.0"

  # power supply health
  # Normal(1), Failed(2)	
  [[inputs.snmp.field]]
    name = "powerStatus"
	oid = "SYNOLOGY-SYSTEM-MIB::powerStatus.0"

  # Normal(1), Failed(2)	
  [[inputs.snmp.field]]
    name = "systemFanStatus"
	oid = "SYNOLOGY-SYSTEM-MIB::systemFanStatus.0"
	
  # Normal(1), Failed(2)
  [[inputs.snmp.field]]
    name = "CPUFanStatus"
	oid = "SYNOLOGY-SYSTEM-MIB::cpuFanStatus.0"

  [[inputs.snmp.field]]
    name = "storageAllocUnits"
	oid = "SNMPv2-SMI::mib-2.25.2.3.1.4.51"

  [[inputs.snmp.field]]
    name = "storageTotalUnits"
	oid = "SNMPv2-SMI::mib-2.25.2.3.1.5.51"
	
  [[inputs.snmp.field]]
    name = "storageUsedUnits"
	oid = "SNMPv2-SMI::mib-2.25.2.3.1.6.51"

  [[inputs.snmp.field]]
    name = "upsModel"
    oid = "SYNOLOGY-UPS-MIB::upsDeviceModel.0"

  [[inputs.snmp.field]]
    name = "upsStatus"
    oid = "SYNOLOGY-UPS-MIB::upsInfoStatus.0"

  [[inputs.snmp.field]]
    name = "upsLoad"
    oid = "SYNOLOGY-UPS-MIB::upsInfoLoadValue.0"

  [[inputs.snmp.field]]
    name = "upsBatteryCharge"
    oid = "SYNOLOGY-UPS-MIB::upsBatteryChargeValue.0"

  [[inputs.snmp.field]]
    name = "upsBatteryChargeLow"
    oid = "SYNOLOGY-UPS-MIB::upsBatteryChargeLow.0"

  [[inputs.snmp.field]]
    name = "upsBatteryChargeWarning"
    oid = "SYNOLOGY-UPS-MIB::upsBatteryChargeWarning.0"

  [[inputs.snmp.field]]
    name = "upsBatteryVoltage"
    oid = "SYNOLOGY-UPS-MIB::upsBatteryVoltageValue.0"

  [[inputs.snmp.field]]
    name = "upsBatteryRuntime"
    oid = "SYNOLOGY-UPS-MIB::upsBatteryRuntimeValue.0"

  [[inputs.snmp.field]]
    name = "upsInputVoltage"
    oid = "SYNOLOGY-UPS-MIB::upsInputVoltageValue.0"

  [[inputs.snmp.table]]
    ## measurement name
    name = "nasdisk"
    inherit_tags = [ "hostname" ]
    [[inputs.snmp.table.field]]
      name = "diskID"
      oid = "SYNOLOGY-DISK-MIB::diskID"
	  is_tag = true
    # Normal(1), Initialized(2), NotInitialized(3), SystemPartitionFailed(4), Crashed(5)
    [[inputs.snmp.table.field]]
      name = "diskStatus"
      oid = "SYNOLOGY-DISK-MIB::diskStatus"
    [[inputs.snmp.table.field]]
      name = "diskTemperature"
      oid = "SYNOLOGY-DISK-MIB::diskTemperature"

When I run telegraf -test, I see output from both [[inputs.snmp]] sections, including the ‘nas’ and ‘nasdisk’ measurements:

* Plugin: inputs.snmp, Collection 1
> system,hostname=ubnt,agent_host=192.168.2.1,host=pi5 memRealBuffers=61752i,memRealCached=219692i,uptime=99305537i,cpuIdle=98i,memRealTotal=495516i,memRealAvail=123392i 1490941678000000000
> if_counters,interface=vtun0,hostname=ubnt,agent_host=192.168.2.1,host=pi5 bytes_recv=0i,bytes_sent=295815i 1490941678000000000
> if_counters,agent_host=192.168.2.1,host=pi5,interface=lo,hostname=ubnt bytes_recv=92489973i,bytes_sent=92489973i 1490941678000000000
> if_counters,interface=eth0,hostname=ubnt,agent_host=192.168.2.1,host=pi5 bytes_recv=341163025675i,bytes_sent=117878656500i 1490941678000000000
> if_counters,interface=eth1,hostname=ubnt,agent_host=192.168.2.1,host=pi5 bytes_recv=118953159597i,bytes_sent=340292290149i 1490941678000000000
> if_counters,agent_host=192.168.2.1,host=pi5,interface=eth2,hostname=ubnt bytes_recv=0i,bytes_sent=0i 1490941678000000000
> if_counters,interface=imq0,hostname=ubnt,agent_host=192.168.2.1,host=pi5 bytes_sent=51168i,bytes_recv=0i 1490941678000000000
> if_counters,interface=vtun1,hostname=ubnt,agent_host=192.168.2.1,host=pi5 bytes_recv=0i,bytes_sent=295815i 1490941678000000000
> system,agent_host=192.168.2.50,host=pi5,hostname=DiskStation memRealAvail=110624i,memRealBuffers=492468i,memRealCached=1711156i,uptime=59640877i,cpuIdle=76i,memRealTotal=3076176i 1490941678000000000
> if_counters,interface=lo,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 bytes_recv=174576972i,bytes_sent=174576972i 1490941678000000000
> if_counters,interface=sit0,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 bytes_recv=0i,bytes_sent=0i 1490941678000000000
> if_counters,host=pi5,interface=eth0,hostname=DiskStation,agent_host=192.168.2.50 bytes_recv=10826852661i,bytes_sent=19349381237i 1490941678000000000
> if_counters,interface=eth1,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 bytes_recv=57037850462i,bytes_sent=81635759627i 1490941678000000000
> if_counters,interface=bond0,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 bytes_recv=67864703123i,bytes_sent=100985140864i 1490941678000000000
> if_counters,host=pi5,interface=tun0,hostname=DiskStation,agent_host=192.168.2.50 bytes_recv=14409822922i,bytes_sent=7026390977i 1490941678000000000
* Plugin: inputs.snmp, Collection 1
> nas,hostname=DiskStation,model=DS1812+,agent_host=192.168.2.50,host=pi5 systemStatus=1i,systemFanStatus=1i,storageTotalUnits=1079848968i,upsStatus="OL",upsBatteryRuntime=3595i,CPUFanStatus=1i,storageAllocUnits=16384i,storageUsedUnits=904886348i,powerStatus=1i,upsModel="Back-UPS RS 900G",upgradeAvailable=2i,temperature=38i 1490941679000000000
> nasdisk,diskID=Disk\ 8,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 diskStatus=1i,diskTemperature=31i 1490941680000000000
> nasdisk,agent_host=192.168.2.50,host=pi5,diskID=Disk\ 1,hostname=DiskStation diskStatus=1i,diskTemperature=34i 1490941680000000000
> nasdisk,diskID=Disk\ 2,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 diskStatus=1i,diskTemperature=33i 1490941680000000000
> nasdisk,host=pi5,diskID=Disk\ 3,hostname=DiskStation,agent_host=192.168.2.50 diskStatus=1i,diskTemperature=32i 1490941680000000000
> nasdisk,hostname=DiskStation,agent_host=192.168.2.50,host=pi5,diskID=Disk\ 4 diskStatus=1i,diskTemperature=32i 1490941680000000000
> nasdisk,diskID=Disk\ 5,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 diskStatus=1i,diskTemperature=32i 1490941680000000000
> nasdisk,agent_host=192.168.2.50,host=pi5,diskID=Disk\ 6,hostname=DiskStation diskStatus=1i,diskTemperature=32i 1490941680000000000
> nasdisk,diskID=Disk\ 7,hostname=DiskStation,agent_host=192.168.2.50,host=pi5 diskStatus=1i,diskTemperature=32i 1490941680000000000

… but when I run the Telegraf service for real, the ‘nas’ and ‘nasdisk’ measurements are not logged:

pi@pi5:~ $ influx
Connected to http://localhost:8086 version 1.2.1
InfluxDB shell version: 1.2.1
> use telegraf
Using database telegraf
> show measurements
name: measurements
name
----
cpu
disk
if_counters
mem
net
system

Please note: while trying to get this working, I tried another config where both SNMP agents had their own [[inputs.snmp]] sections, with some fields repeated in each, rather than the above pattern of a ‘common’ section for both router and NAS, then some NAS-specific fields in another section.
I got the same result: i.e. both sections’ output shown during telegraf -test, yet only measurements from the first section appeared subsequently in InfluxDB.

Thanks for any tips you can provide to solve this! :slight_smile:

Very pleased to say that I managed to work out what was wrong here on my own in the end… so thought I’d post the solution here in case it helps anyone else.

When I worked out that Telegraf was logging to /var/log/syslog on my system, I tailed the last few hundred lines and found errors like these:

Mar 31 12:23:30 pi5 telegraf[22294]: 2017-03-31T12:23:30Z E! ERROR in input [inputs.snmp]: initializing table nasdisk: initializing field diskID: translating: exit status 2: MIB search path: /etc/telegraf/.snmp/mibs:/usr/share/snmp/mibs:/usr/share/snmp/mibs/iana:/usr/share/snmp/mibs/ietf:/usr/share/mibs/site:/usr/share/snmp/mibs:/usr/share/mibs/iana:/usr/share/mibs/ietf:/usr/share/mibs/netsnmp

I think the reason telegraf -test worked, was that the Synology MIBs were installed in ~/.snmp/mibs - so when running telegraf as my user, the MIB/OID translation worked fine.
When running as a service, my user’s home folder wasn’t searched, so the MIBs weren’t found and the translation failed.

I thus created the path /etc/telegraf/.snmp/mibs and copied the Synology MIB files into it.

I’m now seeing happier results in the logs, and can see the (previously missing) ‘nas’ and ‘nasdisk’ measurements listed in InfluxDB as expected:

> show measurements
name: measurements
name
----
cpu
disk
if_counters
mem
nas
nasdisk
net
system

1 Like

@GainfulShrimp Glad you were able to get it working! Thank your for posting your solution. Sorry I wasn’t more help.

1 Like