Add Multiple SNMP Agents to Telegraf Config
Video Lecture
Description
I can add many more SNMP agents to the Telegraf config.
In order for Telegraf to connect to external SNMP agents, those other SNMP agents will need to be configured to allow my Telegraf agent to connect remotely.
On my servers, that I'd like monitor using SNMP, I install SNMPD using
sudo apt install snmpd
I then configure snmpd.conf.
sudo nano /etc/snmp/snmpd.conf
I change below,
...
agentAddress 127.0.0.1,[::1]
...
to allow remote connections,
...
agentAddress udp:161
...
and I change below
...
view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1
...
to return more data,
...
view systemonly included .1.3.6.1.2.1
#view systemonly included .1.3.6.1.2.1.25.1
...
If your server is on the internet, and you don't have a firewall in place, then the SNMPD service can be connected to remotely by anybody on the internet.
You can use iptables
to restrict UDP connections on port 161 to the localhost and any external servers domain or ip that needs access to it.
iptables -A INPUT -p udp -s [domain name or ip] --dport 161 -j ACCEPT
iptables -A INPUT -p udp -s localhost --dport 161 -j ACCEPT
iptables -A INPUT -p udp --dport 161 -j DROP
iptables -L
Restart the SNMPD service
sudo service snmpd restart
I then go back to my InfluxDB server, and test that I can query the new SNMPD on the other server using SNMPWALK.
snmpwalk -v 2c -c public [domain name or ip] .
I then reconfigure the Telegraf conf to add the information for my external SNMP agent.
I add the IP address to the existing agents
property array in the [[inputs.snmp]]
section.
I can repeat the above process for other servers or devices that I want to monitor using SNMP.
After I've added all my SNMP agent configs to the telegraf.conf
, I then restart the Telegraf service. The information will then become available in InfluxDB and then Grafana through the InfluxDB data source configuration.
sudo service telegraf restart
The complete SNMP inputs configuration for my 3 servers is below for your reference.
[[inputs.snmp]]
agents = [
"udp://127.0.0.1:161",
"udp://10.133.0.4:161",
"udp://10.133.0.3: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
And this is the Flux query that shows uptime
for all my 3 SNMPD services.
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")
Useful Links
Grafana 10 and Ubuntu 22.04 Notes
There are no considerable differences to be aware of as shown and discussed in the video.