From 6e3b01e20457565295fd45b80be31643d86b1a39 Mon Sep 17 00:00:00 2001 From: Florian Beer Date: Thu, 4 Aug 2016 01:04:36 +0200 Subject: [PATCH 1/5] Add snmp polling capability for memcache --- .../polling/applications/memcached.inc.php | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/includes/polling/applications/memcached.inc.php b/includes/polling/applications/memcached.inc.php index d68013a698..9e1bf3ff64 100644 --- a/includes/polling/applications/memcached.inc.php +++ b/includes/polling/applications/memcached.inc.php @@ -1,6 +1,53 @@ Date: Thu, 4 Aug 2016 01:32:47 +0200 Subject: [PATCH 2/5] I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. --- AUTHORS.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index 4cb6240c8f..3ccf67d0bc 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -106,14 +106,15 @@ LibreNMS contributors: - Marc Runkel (mrunkel) - Josh Driver (keeperofdakeys) - Felix Eckhofer (tribut) -- Vikram Adukia (justmedude) +- Vikram Adukia (justmedude) - Tijmen de Mes (tijmenNL) - Benjamin Busche (optic00) - Brandon Boudrias (brandune) -- Andy Noyland (Zappatron) +- Andy Noyland (Zappatron) - Cercel Valentin (crcro) - Ahmed Sajid (ahmedsajid) - Karsten Schmidt (guggemand) +- Florian Beer (florianbeer) [1]: http://observium.org/ "Observium web site" Observium was written by: From b3a5f3b61ca4d8963711e28266fefa6fd84c5d1e Mon Sep 17 00:00:00 2001 From: Florian Beer Date: Thu, 4 Aug 2016 10:44:25 +0200 Subject: [PATCH 3/5] Use unserialize() and full OID number --- .../polling/applications/memcached.inc.php | 46 ++----------------- 1 file changed, 3 insertions(+), 43 deletions(-) diff --git a/includes/polling/applications/memcached.inc.php b/includes/polling/applications/memcached.inc.php index 9e1bf3ff64..6016a973fe 100644 --- a/includes/polling/applications/memcached.inc.php +++ b/includes/polling/applications/memcached.inc.php @@ -4,49 +4,9 @@ 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)); - $values = [ - 'uptime', - 'threads', - 'rusage_user_microseconds', - 'rusage_system_microseconds', - 'curr_items', - 'total_items', - 'limit_maxbytes', - 'curr_connections', - 'total_connections', - 'connection_structures', - 'bytes', - 'cmd_get', - 'cmd_set', - 'get_hits', - 'get_misses', - 'evictions', - 'bytes_read', - 'bytes_written', - ]; - - $data = array_map(function ($key) use ($res) { - return substr($res[$key+1], 2); - }, - array_combine( - $values, - array_values( - array_flip( - array_filter( - $res, - function ($item) use ($values) { - foreach ($values as $value) { - if (strpos($item, $value)) { - return true; - } - } - } - ) - ) - ) - )); + $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("<<>>\n", '', $result))); } $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-memcached-'.$app['app_id'].'.rrd'; From 69166e37a91f3d5c302b1192aaf7b173d1b1e7db Mon Sep 17 00:00:00 2001 From: Florian Beer Date: Fri, 5 Aug 2016 20:51:22 +0200 Subject: [PATCH 4/5] Resolve merge conflicts --- doc/Extensions/Applications.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/doc/Extensions/Applications.md b/doc/Extensions/Applications.md index a54ea7f1c7..4c0539d86b 100644 --- a/doc/Extensions/Applications.md +++ b/doc/Extensions/Applications.md @@ -12,6 +12,8 @@ Different applications support a variety of ways collect data: by direct connect 6. [TinyDNS/djbdns](#tinydns-aka-djbdns) - Agent 7. [OS Updates](#os-updates) - extend SNMP 8. [DHCP Stats](#dhcp-stats) - extend SNMP +9. [Memcached](#memcached) - extend SNMP + * [Agent Setup](#agent-setup) @@ -156,6 +158,15 @@ extend dhcpstats /opt/dhcp-status.sh 4. Restart snmpd on your host 5. On the device page in Librenms, edit your host and check the `DHCP Stats` under the Applications tab. +### Memcached +1. Copy the [memcached script](https://github.com/librenms/librenms-agent/blob/master/agent-local/memcached) to `/usr/local/bin` (or any other suitable location) on your remote server. +2. Make the script executable: `chmod +x /usr/local/memcached` +3. Edit your snmpd.conf file (usually `/etc/snmp/snmpd.conf`) and add: +``` +extend memcached /usr/local/bin/memcached +``` +4. Restart snmpd on your host +5. On the device page in Librenms, edit your host and check `Memcached` under the Applications tab. Agent Setup ----------- From 12f441b2bc1d9775e94c498340ef5d63a1f0b86f Mon Sep 17 00:00:00 2001 From: Florian Beer Date: Thu, 4 Aug 2016 23:45:48 +0200 Subject: [PATCH 5/5] Fix array return value Scrutinizer bug, reset() expects a reference. --- includes/polling/applications/memcached.inc.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/polling/applications/memcached.inc.php b/includes/polling/applications/memcached.inc.php index 6016a973fe..7cbb04f4a2 100644 --- a/includes/polling/applications/memcached.inc.php +++ b/includes/polling/applications/memcached.inc.php @@ -6,7 +6,8 @@ if (!empty($agent_data['app']['memcached'])) { $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("<<>>\n", '', $result))); + $result = unserialize(str_replace("<<>>\n", '', $result)); + $data = $result[0]; } $rrd_filename = $config['rrd_dir'].'/'.$device['hostname'].'/app-memcached-'.$app['app_id'].'.rrd';