Setting up Telegraf

Telegraf1 is an agent that is capable of collecting various metrics and exporting them to various storage backends.

Setup

Telegraf is lots of options. Start with something small and simple, then iterate on adding something else to the config. Makes it easier to troubleshoot.

[global_tags]
[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = ""
  omit_hostname = false
[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]
  database = "telegraf"
  skip_database_creation = false
[[inputs.snmp]]
   agents = ["udp://192.168.0.1:161"]
   interval = "60s"
   timeout = "10s"
   version = 1
   community = "public"
   retries = 3
  [[inputs.snmp.field]]
    name = "hostname"
    oid = "RFC1213-MIB::sysName.0"
    is_tag = true
  [[inputs.snmp.field]]
    name = "uptime"
    oid = ".1.3.6.1.2.1.1.3.0"
  [[inputs.snmp.table]]
    name = "interface"
    inherit_tags = [ "hostname" ]
    oid = "IF-MIB::ifTable"
  [[inputs.snmp.table.field]]
    name = "ifDescr"
    oid = "IF-MIB::ifDescr"
    is_tag = true
  [[inputs.snmp.table]]
    name = "interface"
    inherit_tags = [ "hostname" ]
    oid = "IF-MIB::ifXTable"
  [[inputs.snmp.table.field]]
    name = "ifDescr"
    oid = "IF-MIB::ifDescr"
    is_tag = true
  [[inputs.snmp.table]]
    name = "interface"
    inherit_tags = [ "hostname" ]
    oid = "EtherLike-MIB::dot3StatsTable"
  [[inputs.snmp.table.field]]
    name = "ifDescr"
    oid = "IF-MIB::ifDescr"
    is_tag = true

Here is the config I started with. It collects a small number of things from a single device. In this case, a Juniper SRX100. Things I changed from the defaults:

  • URL for influxdb
  • Database name
  • SNMP agents
  • SNMP community
  • The sub-sections for SNMP (I hard-coded the OID because it wasn’t working with the MIB name)

You can test your telegraf config by doing

$ telegraf --test --config /path/to/telegraf.conf
...
$

There should be plenty of output that is collected from the SNMP device configured, and no errors.

Viewing the data we collected

root@monitoring:~ # influx
Connected to http://localhost:8086 version 1.8.0
InfluxDB shell version: 1.8.0
> use telegraf
Using database telegraf
> show measurements
name: measurements
name
----
interface
> select * from interface limit 2
name: interface
time                agent_host dot3StatsAlignmentErrors dot3StatsCarrierSenseErrors dot3StatsDeferredTransmissions dot3StatsDuplexStatus dot3StatsEtherChipSet dot3StatsExcessiveCollisions dot3StatsFCSErrors dot3StatsFrameTooLongs dot3StatsIndex dot3StatsInternalMacReceiveErrors dot3StatsInternalMacTransmitErrors dot3StatsLateCollisions dot3StatsMultipleCollisionFrames dot3StatsSQETestErrors dot3StatsSingleCollisionFrames dot3StatsSymbolErrors host       hostname       ifAdminStatus ifAlias ifConnectorPresent ifCounterDiscontinuityTime ifDescr     ifHCInBroadcastPkts ifHCInMulticastPkts ifHCInOctets ifHCInUcastPkts ifHCOutBroadcastPkts ifHCOutMulticastPkts ifHCOutOctets ifHCOutUcastPkts ifHighSpeed ifInBroadcastPkts ifInDiscards ifInErrors ifInMulticastPkts ifInNUcastPkts ifInOctets ifInUcastPkts ifInUnknownProtos ifIndex ifLastChange ifLinkUpDownTrapEnable ifMtu ifName ifOperStatus ifOutBroadcastPkts ifOutDiscards ifOutErrors ifOutMulticastPkts ifOutNUcastPkts ifOutOctets ifOutQLen ifOutUcastPkts ifPhysAddress     ifPromiscuousMode ifSpecific ifSpeed ifType
----                ---------- ------------------------ --------------------------- ------------------------------ --------------------- --------------------- ---------------------------- ------------------ ---------------------- -------------- --------------------------------- ---------------------------------- ----------------------- -------------------------------- ---------------------- ------------------------------ --------------------- ----       --------       ------------- ------- ------------------ -------------------------- -------     ------------------- ------------------- ------------ --------------- -------------------- -------------------- ------------- ---------------- ----------- ----------------- ------------ ---------- ----------------- -------------- ---------- ------------- ----------------- ------- ------------ ---------------------- ----- ------ ------------ ------------------ ------------- ----------- ------------------ --------------- ----------- --------- -------------- -------------     ----------------- ---------- ------- ------
1595976547000000000 192.168.2.1                                                                                                                                                                                                                                                                                                                                                                                                                                 monitoring srx100.lab 1                                                                   ge-0/0/10.0                                                                                                                                                                             0            0                            0              0          0             0                 506     3693                                1514         7                               0             0                              0               0           0         0              54:e0:32:2f:86:8d                   .0.0       0       53
1595976547000000000 192.168.2.1                                                                                                                                                                                                                                                                                                                                                                                                                                 monitoring srx100.lab 1                                                                   ge-0/0/11                                                                                                                                                                               0            0                            0              0          0             0                 507     3369                                1514         2                               0             0                              0               0           0         0              54:e0:32:2f:86:8e                   .0.0       0       6
>
root@monitoring:~ #

Looks like we’re successfully storing data in InfluxDB2.

Conclusion

Next up, setting up visualizations.

Footnotes and References


  1. Telegraf Documentation ↩︎

  2. InfluxDB Documentation ↩︎