One of our long time customers, Appfolio, who makes great SaaS property management software, asked how they could use LogicMonitor to monitor the size of some files across their fleet of Linux servers. A simple request, but not as simple as one might hope. Why not? LogicMonitor usually uses SNMP to monitor Linux servers, as that way there is no need for extra software to be installed on any server. (It should be noted that some people deploy LogicMonitor collectors as agents, deploying one per server. In this case, you could use a script based datasource to simply run ‘ls’ on arbitrary files – but that’s for a different blog entry.) While SNMP has many defined OIDs (a fancy way of saying questions that can be asked and answered), there is no defined OID for “how big is arbitrary file X?” Which means that by default, there is no way to remotely query a system, using SNMP, to determine a file size.
Luckily, the Net-SNMP daemon used on virtually all Linux distributions can be extended to provide this (and many other kinds) of functionality. For example, to monitor the size of the /var/spool/rsyslog file, simply add a line such as:
extend lm-rsyslog-size /usr/bin/du /var/spool/rsyslog
to snmpd.conf, and restart snmpd. This tells the SNMP daemon to run the specified commands when certain OIDs are queried, and return the results. This will create some new OID entries under the tree .188.8.131.52.4.1.8072.1.3.2, with big long dotted decimal indexes that make it hard to know what the object is – especially if you have multiple extend commands in snmpd.conf. However, with a walk of .184.108.40.206.4.1.8072.1.3.2.2.1.2, you can see the commands that have been added as snmp extensions:
snmpwalk servername .220.127.116.11.4.1.8072.1.3.2.2.1.2 Walking OID .18.104.22.168.4.1.8072.1.3.2.2.1.2 version=v2c, timeout=3 seconds: 22.214.171.124.126.96.36.199.188.8.131.52.97.100.121 => /usr/sbin/rabbitmqctl 184.108.40.206.220.127.116.11.18.104.22.168.22.214.171.124 => /usr/bin/du
So the index for the du command we added is 126.96.36.199.188.8.131.52.184.108.40.206.220.127.116.11 – which, the astute among you will notice, happens to be the octet string representation of “lm-rsyslog-size” (although with one prior character.) So now we can query either the table .18.104.22.168.4.1.8072.1.3.2.3.1.1 (nsExtendOutput1Line), which gives the first line of the output of the command when run, or .22.214.171.124.4.1.8072.1.3.2.3.1.2, which gives the full (multi-line) output, using the index we figured out above. In this case, the output of ‘du’ against a single file is a single line, so the OIDs are equivalent. e.g.
>>!snmpget servername .126.96.36.199.4.1.8072.1.3.2.188.8.131.52.184.108.40.206.220.127.116.11.18.104.22.168.105.122.101
Getting OIDs from host=servername, version=v2c, timeout=3 seconds: .22.214.171.124.4.1.8072.1.3.2.126.96.36.199.108.109. 188.8.131.52.184.108.40.206.220.127.116.11.101 => 1025360 /var/spool/rsyslog
Getting the data into LogicMonitor
Ok, we have extended snmpd so we can get the data we want via SNMP. (And if we are clever, we’ve pushed this out to all our systems via our IT automation tool: puppet, chef, Ansible, or what-have-you.) How do we monitor and alert on this? We create a datasource. From Settings…Datasources, click New Datasource. Set the General Information section:
Set the Active Discovery Section as below:
“Wait”, I hear you ask. “Why are we using Active Discovery when this snmp extension is only reporting the size of a single file?” Well – we can’t assume every Linux server will respond to this OID, which you just created. So, we test for it’s presence in ActiveDiscovery. If it responds, we’ll monitor it. If not, we won’t create the instance. (Note that the index we add in the discovery OID is one number shorter than the index we found above, as Active Discovery always does an SNMP walk, not a get, so it wants to find at least one entry in the walked result.)
Now we just need to add a single Normal Datapoint to the datasource:
Because the output of the command is both the size of the file and the file path, we use a regular expression capture group to extract the digits at the start. Save, and we are done. You can also add a graph to track the file size over time, etc, or add additional thresholds for error and critical states, etc. All the usual LogicMonitor goodness.
Want to see more? Follow us here:
Or, e-mail us @ [email protected]
Steve is the founder of LogicMonitor.
Subscribe to our LogicBlog to stay updated on the latest developments from LogicMonitor and get notified about blog posts from our world-class team of IT experts and engineers, as well as our leadership team with in-depth knowledge and decades of collective experience in delivering a product IT professionals love.