InfluxDB 2 not showing snmp plugin from telegraf

I setup snmp on telegraf 1.26.3 and it writing to the bucket fine according to the logs. However, i can’t see the SNMP plugin on my bucket on influxdb2. Does anybody know how to fix this?

nobody to help, really?

hello @bar81,
Can you please share your telegraf config?
What do you mean by you can’t see the plugin on your bucket?
The data from the plugin?
Or you don’t see it on the config?
Thanks

Thanks for being interested in this situation.
So, i have telegraf.conf file configured with the SNMP configs below:

[[inputs.snmp]]
agents = [ “udp://1.2.3.4:161” ]
timeout = “5s”
interval = “30s”
version = 2
community = “mycommunity”
retries = 3

And specific configs on the directory: /etc/telegraf/telegraf.d/switch.conf

[[inputs.snmp.field]]
name = “hostname”
#oid = “SNMPv2-MIB::sysName”
oid = “.1.3.6.1.2.1.1.5”
#is_tag = false

[[inputs.snmp.table]]
name = “ifXTable”
#oid = “IF-MIB::ifHCInOctets”
oid = “.1.3.6.1.2.1.31.1.1”

[[inputs.snmp.table.field]]
name = “interfaceStatistics”
#oid = “IF-MIB::ifHCInOctets”
oid = “.1.3.6.1.2.1.31.1.1.1.6”

See the 0utput below:

root@userver2:/home/test# telegraf --config /etc/telegraf/telegraf.conf --config-directory /etc/telegraf/telegraf.d/netgearSw.conf --debug
2023-06-13T22:50:35Z I! Loading config: /etc/telegraf/telegraf.conf
2023-06-13T22:50:35Z I! Loading config: /etc/telegraf/telegraf.d/netgearSw.conf
2023-06-13T22:50:35Z I! Starting Telegraf 1.26.3
2023-06-13T22:50:35Z I! Available plugins: 235 inputs, 9 aggregators, 27 processors, 22 parsers, 57 outputs, 2 secret-stores
2023-06-13T22:50:35Z I! Loaded inputs: cpu disk diskio file kernel mem processes snmp (2x) swap system
2023-06-13T22:50:35Z I! Loaded aggregators:
2023-06-13T22:50:35Z I! Loaded processors:
2023-06-13T22:50:35Z I! Loaded secretstores:
2023-06-13T22:50:35Z I! Loaded outputs: influxdb_v2
2023-06-13T22:50:35Z I! Tags enabled: host=userver2
2023-06-13T22:50:35Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:“userver2”, Flush Interval:10s
2023-06-13T22:50:35Z D! [agent] Initializing plugins
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “-m” “all” “.1.3.6.1.2.1.31.1.1”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “IF-MIB::ifXTable.1”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptable” “-Ch” “-Cl” “-c” “public” “127.0.0.1” “IF-MIB::ifXTable”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifName”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifInMulticastPkts”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifInBroadcastPkts”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifOutMulticastPkts”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifOutBroadcastPkts”
2023-06-13T22:50:35Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCInOctets”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCInUcastPkts”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCInMulticastPkts”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCInBroadcastPkts”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCOutOctets”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCOutUcastPkts”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCOutMulticastPkts”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHCOutBroadcastPkts”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifLinkUpDownTrapEnable”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifHighSpeed”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifPromiscuousMode”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifConnectorPresent”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifAlias”
2023-06-13T22:50:36Z D! [inputs.snmp] executing “snmptranslate” “-Td” “-Ob” “IF-MIB::ifCounterDiscontinuityTime”
2023-06-13T22:50:36Z D! [agent] Connecting outputs
2023-06-13T22:50:36Z D! [agent] Attempting connection to [outputs.influxdb_v2]
2023-06-13T22:50:36Z D! [agent] Successfully connected to outputs.influxdb_v2
2023-06-13T22:50:36Z D! [agent] Starting service inputs
2023-06-13T22:50:46Z D! [outputs.influxdb_v2] Wrote batch of 20 metrics in 19.877025ms
2023-06-13T22:50:46Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2023-06-13T22:50:56Z D! [outputs.influxdb_v2] Wrote batch of 22 metrics in 9.153223ms
2023-06-13T22:50:56Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2023-06-13T22:51:06Z D! [outputs.influxdb_v2] Wrote batch of 22 metrics in 18.508926ms
2023-06-13T22:51:06Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
^C2023-06-13T22:51:06Z D! [agent] Stopping service inputs
2023-06-13T22:51:06Z D! [agent] Input channel closed
2023-06-13T22:51:06Z I! [agent] Hang on, flushing any cached metrics before shutdown
2023-06-13T22:51:06Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics
2023-06-13T22:51:06Z I! [agent] Stopping running outputs
2023-06-13T22:51:06Z D! [agent] Stopped Successfully

As you can see telegraf is loading snmp plugin. But when i go to influxdb it didnt show SNMP.

While splitting the config up like that seems to be technically valid TOML, there’s no real benefit to it, and it’s possible that it’s confusing telegraf’s parser by having other configuration for other plugins interleaved between the two parts.

I’d suggest moving the [[inputs.snmp]] section out of telegraf.conf and put it at top of switch.conf, especially if you intend to collect SNMP data from multiple devices with a single telegraf instance (each agent would get a separate config file that starts with [[inputs.snmp]]).

if i do that i got the error below.
[telegraf] Error running agent: no inputs found, did you provide a valid config file?

Telegraf doesn’t read files on “/etc/telegraf/telegraf.d”. It only read the plugin if i move the configs
to /etc/telegraf/telegraf.conf, even though the “–config-directory” is there. Any idea?

In your original comment, you use the following command:

# telegraf --config /etc/telegraf/telegraf.conf --config-directory /etc/telegraf/telegraf.d/netgearSw.conf --debug

Which is actually telling telegraf to load /etc/telegraf.d/netgearSw.conf/*.conf (no idea how that even worked in the first place). The correct command line would be:

# telegraf --config /etc/telegraf/telegraf.conf --config-directory /etc/telegraf/telegraf.d --debug

I’m a telegraf beginner. I’m following the best practice according to this document Telegraf Best Practices: Config Recommendations and Performance Monitoring | InfluxData". I agree having different files, it gives you more flexibility.

As a beginner i’m having a lot issues. I did a test having three files on telegraf.d directory, input.conf, output.conf, and switch.conf. I can start telegraf manually, but if i use systemd to start it as a service it complains about telegraf.conf not being a valid file.

$ sudo telegraf -config /etc/telegraf/telegraf.conf --debug
2023-06-17T15:36:37Z I! Loading config: /etc/telegraf/telegraf.conf
2023-06-17T15:36:37Z E! [telegraf] Error running agent: no outputs found, did you provide a valid config file?"

The file telegraf.conf is empty and i moved all configs to telegraf.d folder. Why systemd complain about this? Even thoug the path to the directory is there.
ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OPTS

That sounds like an ownership/permissions issue on the configuration files, which is being masked when you run it manually with elevated privileges via sudo.

Check your unit file to see which user systemd is configured to run telegraf, and then make sure the relevant configuration files/directory ownership and permissions permit that user to access them.

That was the problem. The service was setup for the user “telegraf”. I changed it to root user and it worked. I changed the permission but I didn’t work out using user telegraf. How can I make the user telegraf to work, I don’t wanna root user for that.

Yes, telegraf should be run as a non-privileged user these days.

I just checked my installation on EL8, systemd runs as the telegraf user, file owner is root:root on all relevant files/dirs, with the following permissions:

drwxr-xr-x. on /etc/telegraf/ and /etc/telegraf.d/
-rw-r--r--. on /etc/telegraf/telegraf.conf and /etc/telegraf/telegraf.d/*.conf

@tjamesking thank you very much, after i changed the permissions i was able to start the service using telegraf as user.