Add snmp polling capability for Memcached #3949

Merged
merged 5 commits into from Aug 5, 2016

Projects

None yet

3 participants

@florianbeer
Contributor

This is a sort of proof of concept of snmp's extend feature. It is here to show, that no check_mk is needed to run local scripts on remote servers, it's all available within snmp.
The apache, nginx and mysql scripts in /opt/librenms/includes/polling/application already have snmp polling included, I just ported it to the memcache poller script.

The slightly daunting nested code beginning on line 30 is just a transformation to get memcached's strange status output into the required php array. It is basically a map/reduce for all of the available values using native php functions.

To activate memcache over snmp take the following steps:

  • Deploy the memcache status script (https://github.com/librenms/librenms-agent/blob/master/agent-local/memcached) on your remote server for example in /usr/local/bin
  • On your remote server edit the snmp daemon config (most probably in /etc/snmp/snmpd.conf) and add the following line at the bottom extend memcached /usr/local/memcached
  • Restart snmpd
  • On your LibreNMS webfrontend, find the device you just deployed the script to, click on edit and activate "Memcached" on the "Applications" tab.
@murrant murrant and 1 other commented on an outdated diff Aug 4, 2016
includes/polling/applications/memcached.inc.php
@@ -1,6 +1,53 @@
<?php
-$data = $agent_data['app']['memcached'][$app['app_instance']];
+if (!empty($agent_data['app']['memcached'])) {
+ $data = $agent_data['app']['memcached'][$app['app_instance']];
+} else {
+ $options = '-O qv';
+ $oid = 'nsExtendOutputFull.9.109.101.109.99.97.99.104.101.100';
+ $res = explode(';' , snmp_get($device, $oid, $options));
@murrant
murrant Aug 4, 2016 edited Contributor

Wouldn't it be easier to remove the first line, and then call unserialize() on the remainder of the string?

$result = snmp_get($device, $oid, $options);
$data = unserialize(str_replace("<<<app-memcached>>>\n", '', $result));
@florianbeer
florianbeer Aug 4, 2016 edited Contributor

Had I known, that this is the textual representation of a serialized PHP object, then yes that would have been drastically easier. Thanks for pointing it out. I guess I'll never stop learning.

@murrant
Contributor
murrant commented Aug 4, 2016

Make sure you update the documentation as well: doc/Extensions/Applications.md

@murrant murrant commented on an outdated diff Aug 4, 2016
includes/polling/applications/memcached.inc.php
@@ -1,6 +1,53 @@
<?php
-$data = $agent_data['app']['memcached'][$app['app_instance']];
+if (!empty($agent_data['app']['memcached'])) {
+ $data = $agent_data['app']['memcached'][$app['app_instance']];
+} else {
+ $options = '-O qv';
+ $oid = 'nsExtendOutputFull.9.109.101.109.99.97.99.104.101.100';
@murrant
murrant Aug 4, 2016 Contributor

Use the full number .1.3.6.1.4.1.8072.1.3.2.3.1.2.9.109.101.109.99.97.99.104.101.100 or specify the NET-SNMP-EXTEND-MIB mib.

@murrant murrant added the Blocker label Aug 4, 2016
@murrant murrant commented on an outdated diff Aug 4, 2016
includes/polling/applications/memcached.inc.php
@@ -1,6 +1,13 @@
<?php
-$data = $agent_data['app']['memcached'][$app['app_instance']];
+if (!empty($agent_data['app']['memcached'])) {
+ $data = $agent_data['app']['memcached'][$app['app_instance']];
+} else {
+ $options = '-O qv';
+ $oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.9.109.101.109.99.97.99.104.101.100';
+ $result = snmp_get($device, $oid, $options);
+ $data = reset(unserialize(str_replace("<<<app-memcached>>>\n", '', $result)));
@murrant
murrant Aug 4, 2016 Contributor

Scrutinizer bug, reset() expects a reference.
So you might as well set it to a variable and then use [0]

@murrant
Contributor
murrant commented Aug 5, 2016

Looks good, just need to you to fix the merge conflicts likely the Contributer file.

florianbeer added some commits Aug 3, 2016
@florianbeer florianbeer Add snmp polling capability for memcache 6e3b01e
@florianbeer florianbeer I agree to the conditions of the Contributor Agreement
contained in doc/General/Contributing.md.
a77027d
@florianbeer florianbeer Use unserialize() and full OID number b3a5f3b
@florianbeer florianbeer Resolve merge conflicts 69166e3
@florianbeer florianbeer Fix array return value
Scrutinizer bug, reset() expects a reference.
12f441b
@murrant murrant merged commit 08a2005 into librenms:master Aug 5, 2016

2 checks passed

Auto-Deploy Build finished.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@murrant murrant added Enhancement and removed Blocker labels Aug 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment