/usr/bin/horde-memcache-stats is in php-horde 5.2.9+debian0-1build1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #!/usr/bin/php
<?php
/**
* This script outputs statistics on the current memcache pool.
*
* Copyright 2007-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL-2). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @license http://www.horde.org/licenses/lgpl LGPL-2
* @package Horde
*/
$baseFile = __DIR__ . '/../lib/Application.php';
if (file_exists($baseFile)) {
require_once $baseFile;
} else {
require_once 'PEAR/Config.php';
require_once PEAR_Config::singleton()
->get('horde_dir', null, 'pear.horde.org') . '/lib/Application.php';
}
Horde_Registry::appInit('horde', array(
'authentication' => 'none',
'cli' => true
));
$hashtable = $injector->getInstance('Horde_HashTable');
if (!($hashtable instanceof Horde_HashTable_Memcache)) {
$cli->fatal('Memcache HashTable driver not enabled.');
}
$parser = new Horde_Argv_Parser();
$parser->addOption('-a', '--all', array(
'action' => 'store_true',
'dest' => 'all',
'help' => 'Show all servers'
));
$parser->addOption('--flush', array(
'action' => 'store_true',
'dest' => 'flush',
'help' => 'Flush all data'
));
$parser->addOptions('-l', '--lookup', array(
'dest' => 'lookup',
'help' => 'Key to lookup'
));
$parser->addOptions('-r', '--raw', array(
'action' => 'store_true',
'dest' => 'raw',
'help' => 'Display raw data'
));
$parser->addOptions('-s', '--summary', array(
'action' => 'store_true',
'dest' => 'summary',
'help' => 'Display summary'
));
list($values,) = $parser->parseArgs();
if ($values->flush) {
if ($cli->prompt($cli->red('Are you sure you want to flush all data?'), array('y' => 'Yes', 'n' => 'No'), 'n') == 'y') {
$hashtable->clear();
$cli->writeln($cli->green('Done.'));
}
exit;
}
if ($values->lookup) {
$data = $hashtable->get($values->lookup);
$cli->writeln(empty($data) ? '[Key not found.]' : print_r($data, true));
exit;
}
$stats = $hashtable->stats();
if ($values->raw) {
$cli->writeln(print_r($stats, true));
} elseif (!$values->summary) {
$values->all = true;
}
if ($values->all || $values->summary) {
if ($values->summary) {
$total = array();
$total_keys = array('bytes', 'limit_maxbytes', 'curr_items', 'total_items', 'get_hits', 'get_misses', 'curr_connections', 'bytes_read', 'bytes_written');
foreach ($total_keys as $key) {
$total[$key] = 0;
}
}
$i = count($stats);
$s_count = 0;
foreach ($stats as $key => $val) {
if ($val === false) {
$cli->message('Could not connect to server: ' . $key, 'cli.warning');
continue;
}
++$s_count;
if ($values->summary) {
foreach ($total_keys as $k) {
$total[$k] += $val[$k];
}
}
if ($values->all) {
$cli->writeln($cli->green('Server: ' . $key . ' (Version: ' . $val['version'] . ' - ' . $val['threads'] . ' thread(s))'));
_outputInfo($val, $cli);
if (--$i || $values->summary) {
$cli->writeln();
}
}
}
if ($values->summary) {
$cli->writeln($cli->green('Memcache pool (' . $s_count . ' active server(s))'));
if ($s_count) {
_outputInfo($total, $cli);
}
}
}
function _outputInfo($val, $cli)
{
$cli->writeln($cli->indent('Size: ' . sprintf("%0.2f", $val['bytes'] / 1048576) . ' MB (Max: ' . sprintf("%0.2f", ($val['limit_maxbytes']) / 1048576) . ' MB - ' . ((!empty($val['limit_maxbytes']) ? round(($val['bytes'] / $val['limit_maxbytes']) * 100, 1) : 'N/A')) . '% used)'));
$cli->writeln($cli->indent('Items: ' . $val['curr_items'] . ' (Total: ' . $val['total_items'] . ')'));
$cli->writeln($cli->indent('Cache Ratio: ' . $val['get_hits'] . ' hits, ' . $val['get_misses'] . ' misses'));
$cli->writeln($cli->indent('Connections: ' . $val['curr_connections']));
$cli->writeln($cli->indent('Traffic: ' . sprintf("%0.2f", $val['bytes_read'] / 1048576) . ' MB in, ' . sprintf("%0.2f", $val['bytes_written'] / 1048576) . ' MB out'));
}
|