SNMP monitoring with Grafana and telegraf on FreeBSD

This monitoring solution has three components, a database, collector and visualisor.

Database – influxdb

As the package description suggests influxdb is the perfect piece of software for storing SNMP data, and unlike the classic RRDtool it does not lose fidelity as the age of the data increases. Installing and start the service is easy:

# pkg search influxdb
influxdb-1.7.9                 Open-source distributed time series database
# pkg install influxdb-1.7.9
# sysrc influxd_enable=YES
# service influxd start 

Create a service user for the collector:

# influx
Connected to http://localhost:8086 version 1.7.9
InfluxDB shell version: 1.7.9
> CREATE USER "telegraf_squid" WITH PASSWORD 'some_pa55' WITH ALL PRIVILEGES
> exit
# service influxd restart

Collector – Telegraf

Telegraf will be used to take the values of the out SNMP OIDs and stores them in the influxdb.

# pkg search telegraf
telegraf-1.12.5                Time-series data collection
# pkg install telegraf-1.12.5

Configure telegraf to use the local influxdb instance as an ouput and also specify the Squid SNMP OIDs of interest as inputs.

# /usr/local/etc/telegraf.conf
[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]
  database = "telegraf"
  user = "telegraf_squid"
  password = "some_pa55"

[[inputs.snmp]]
  agents = [ "127.0.0.1:3401" ]
  timeout = "5s"
  retries = 3
  version = 2
  community = "squid_proxy"
  name = squid

 [[inputs.snmp.field]]
    name = "uptime"
    oid = "1.3.6.1.4.1.3495.1.1.3.0"

 [[inputs.snmp.field]]
    name = "cacheVersionId"
    oid = "1.3.6.1.4.1.3495.1.2.3.0"

 [[inputs.snmp.field]]
    name = "cacheMemMaxSize"
    oid = "1.3.6.1.4.1.3495.1.2.5.1.0"

 [[inputs.snmp.field]]
    name = "cacheSwapMaxSize"
    oid = "1.3.6.1.4.1.3495.1.2.5.2.0"

 [[inputs.snmp.field]]
    name = "cacheMemUsage"
    oid = "1.3.6.1.4.1.3495.1.3.1.3.0"

 [[inputs.snmp.field]]
    name = "cacheCpuUsage"
    oid = "1.3.6.1.4.1.3495.1.3.1.5.0"

 [[inputs.snmp.field]]
    name = "cacheNumObjCount"
    oid = "1.3.6.1.4.1.3495.1.3.1.7.0"

 [[inputs.snmp.field]]
    name = "cacheProtoClientHttpRequests"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.1.0"

 [[inputs.snmp.field]]
    name = "cacheCurrentSwapSize"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.14.0"

 [[inputs.snmp.field]]
    name = "cacheHttpHits"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.2.0"

 [[inputs.snmp.field]]
    name = "cacheHttpErrors"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.3.0"

 [[inputs.snmp.field]]
    name = "cacheHttpInKb"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.4.0"

 [[inputs.snmp.field]]
    name = "cacheHttpOutKb"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.5.0"

 [[inputs.snmp.field]]
    name = "cacheServerInKb"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.12.0"

 [[inputs.snmp.field]]
    name = "cacheServerOutKb"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.13.0"

 [[inputs.snmp.field]]
    name = "cacheClients"
    oid = "1.3.6.1.4.1.3495.1.3.2.1.15.0"
# sysrc telegraf_enable="YES"
# service telegraf start

Squid Config

Configure the local Squid instance for SNMP. Only SNMP v2c is supported so change the community string to something other than ‘public’. An ACL is also used to only allow SNMP queries from localhost.

# /usr/local/etc/squid/squid.conf
acl snmp_net src 127.0.0.1
acl snmp_r snmp_community squid_proxy
snmp_port 3401
snmp_access allow snmp_r snmp_net
snmp_access deny all

Visualiser – Grafana

The final piece to this puzzle is Grafana which will give us the ability to create a multitude of dashboards based on the data held within the influxdb. First install the package and configure the service.

# pkg search grafana
grafana6-6.5.2                 Dashboard and graph editor for multiple data stores
# pkg install grafana6-6.5.2
# sysrc grafana_enable=YES
# service grafana start

Next log onto webGUI, using the default credentials: admin / admin . Once logged in go ahead and configure the infuxdb instance as the datastore.

Setting up influxDB datasource

Once the davestore has been tested working and saved, graphs can then be created. The names which we gave to the Squid OIDs in the telgraf config file will appear as fields which can be queried and graphed.

Creating graphs by querying influxdb

In a very short space of time a multitude of graphs can be added to your dashboard.

Grafana Squid dashboard

If you don’t fancy digging through the various graphing options and creating your own, Grafana has an excellent ecosystem of user submitted dashboard: https://grafana.com/grafana/dashboards

This does still require you to configure influxdb/ telegraf to collect necessary SNMP OIDs but does safe some of the legwork.

Squid Dashboard by molu8bits

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: