REL-0.9 Fix Redis/Memcached overview

This commit is contained in:
cytopia 2017-05-07 18:49:38 +02:00
parent 0afeefd964
commit 2d7e51027b
No known key found for this signature in database
GPG Key ID: 6D56EDB8695128A2
15 changed files with 235 additions and 59 deletions

View File

@ -0,0 +1,45 @@
<?php require '../config.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php require '../include/head.php'; ?>
</head>
<body>
<?php require '../include/navbar.php'; ?>
<div class="container">
<h1>Memcached Keys</h1>
<br/>
<br/>
<div class="row">
<div class="col-md-12">
<table class="table table-striped ">
<thead class="thead-inverse ">
<tr>
<th>Key</th>
<th>Value</th>
</th>
</thead>
<tbody>
<?php foreach (loadClass('Memcd')->getKeys() as $data): ?>
<tr>
<td><?php print_r($data['key']);?></td>
<td><?php print_r($data['value']);?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div><!-- /.container -->
<?php require '../include/footer.php'; ?>
</body>
</html>

View File

@ -1,5 +1,5 @@
<?php require '../config.php'; ?>
<?php $Postgres = loadClass('Postgres'); ?>
<?php $Postgres = loadClass('Pgsql'); ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -1,8 +1,4 @@
<?php require '../config.php'; ?>
<?php if (loadClass('Docker')->getEnv('COMPOSE_OPTIONAL') != 1) {
header('Location: /index.php');
exit(0);
} ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -0,0 +1,47 @@
<?php require '../config.php'; ?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php require '../include/head.php'; ?>
</head>
<body>
<?php require '../include/navbar.php'; ?>
<div class="container">
<h1>Memcached Info</h1>
<br/>
<br/>
<div class="row">
<div class="col-md-12">
<?php foreach (loadClass('Memcd')->getInfo() as $srv => $data): ?>
<h2><?php echo $srv; ?></h2>
<table class="table table-striped">
<thead class="thead-inverse">
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $key => $val): ?>
<tr>
<td><?php echo $key;?></td>
<td class="break-word"><code><?php echo $val;?></code></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endforeach; ?>
</div>
</div>
</div><!-- /.container -->
<?php require '../include/footer.php'; ?>
</body>
</html>

View File

@ -1,5 +1,4 @@
<?php require '../config.php'; ?>
<?php $Docker = loadClass('Docker'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -33,7 +32,7 @@
</tr>
</thead>
<tbody>
<?php foreach ($Docker->MySQL_config() as $key => $val): ?>
<?php foreach (loadClass('Mysql')->getConfig() as $key => $val): ?>
<tr>
<td><?php echo $key;?></td>
<td class="break-word"><code><?php echo $val;?></code></td>

View File

@ -1,5 +1,4 @@
<?php require '../config.php'; ?>
<?php $Docker = loadClass('Docker'); ?>
<!DOCTYPE html>
<html lang="en">
<head>
@ -26,7 +25,7 @@
</tr>
</thead>
<tbody>
<?php foreach ($Docker->Postgres_config() as $key => $val): ?>
<?php foreach (loadClass('Pgsql')->getConfig() as $key => $val): ?>
<tr>
<td><?php echo $key;?></td>
<td class="break-word"><code><?php echo $val;?></code></td>

View File

@ -1,9 +1,4 @@
<?php require '../config.php'; ?>
<?php $Docker = loadClass('Docker'); ?>
<?php if ($Docker->getEnv('COMPOSE_OPTIONAL') != 1 ) {
header('Location: /index.php');
exit(0);
} ?>
<!DOCTYPE html>
<html lang="en">
<head>

View File

@ -238,7 +238,7 @@ $opcache = OpCacheService::init($options);
<title>OPcache statistics on <?php echo $opcache->getData('version', 'host'); ?></title>
<script src="/vendor/react/react.min.js"></script>
<script src="/vendor/react/react-dom.min.js"></script>
<script src="/vendor/jquery/jquery-2.2.3.min.js"></script>
<script src="/vendor/jquery/jquery-3.1.1.slim.min.js"></script>
<style type="text/css">
body { font-family:sans-serif; font-size:90%; padding: 0; margin: 0 }
nav { padding-top: 20px; }

View File

@ -115,15 +115,44 @@ class Memcd extends _Base implements _iBase
*/
public function __construct($host)
{
$memcd = new \Memcached();
$memcd->resetServerList();
$memcd = new \Memcached('_devilbox');
$list = $memcd->getServerList();
if (!$memcd->addServer($host, 11211)) {
if (empty($list)) {
//$memcd->setOption(\Memcached::OPT_RECV_TIMEOUT, 1000);
//$memcd->setOption(\Memcached::OPT_SEND_TIMEOUT, 1000);
$memcd->setOption(\Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$memcd->setOption(\Memcached::OPT_BINARY_PROTOCOL, false);
//$memcd->setOption(\Memcached::OPT_SERVER_FAILURE_LIMIT, 50);
//$memcd->setOption(\Memcached::OPT_CONNECT_TIMEOUT, 500);
//$memcd->setOption(\Memcached::OPT_RETRY_TIMEOUT, 300);
//$memcd->setOption(\Memcached::OPT_REMOVE_FAILED_SERVERS, true);
$memcd->addServer($host, 11211);
}
$err = false;
$stats = $memcd->getStats();
if (!isset($stats[$host.':11211'])) {
$memcd->quit();
$err = 'Failed to connect to Memcached host on '.$host;
}
if (!isset($stats[$host.':11211']['pid'])) {
$memcd->quit();
$err = 'Failed to connect to Memcached host on '.$host;
}
if ($stats[$host.':11211']['pid'] < 1) {
$memcd->quit();
$err = 'Failed to connect to Memcached host on '.$host;
}
if ($err === false) {
$memcd->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')');
$this->_memcached = $memcd;
} else {
$this->_connect_error = 'Failed to connect to Memcached host on '.$host;
$this->_connect_errno = 1;
//loadClass('Logger')->error($this->_connect_error);
} else {
$this->_memcached = $memcd;
}
}
@ -143,23 +172,27 @@ class Memcd extends _Base implements _iBase
*
*********************************************************************************/
/* public function getInfo()
{
if ($this->_memcached) {
return $this->_memcached->info('all');
} else {
return array();
}
}
public function getKeys()
{
$store = array();
if ($this->_memcached) {
return $this->_memcached->keys('*');
} else {
return array();
if (!($keys = $this->_memcached->getAllKeys())) {
$keys = array();
}
$this->_memcached->getDelayed($keys);
$store = $this->_memcached->fetchAll();
}
}*/
return $store;
}
public function getInfo()
{
$stats = $this->_memcached->getStats();
return $stats;
}
/*********************************************************************************
*

View File

@ -252,7 +252,7 @@ class Mysql extends _Base implements _iBase
$data[$key] = $val;
};
return $this->select('SHOW VARIABLES;');
return $this->select('SHOW VARIABLES;', $callback);
} else { // Get single config

View File

@ -196,7 +196,7 @@ class Pgsql extends _Base implements _iBase
// Get schemas for each database
foreach ($databases as $name => &$database) {
$PSQL = new Postgres('postgres', loadClass('Docker')->getEnv('PGSQL_ROOT_PASSWORD'), $GLOBALS['PGSQL_HOST_ADDR'], $name);
$PSQL = new Pgsql('postgres', loadClass('Docker')->getEnv('PGSQL_ROOT_PASSWORD'), $GLOBALS['PGSQL_HOST_NAME'], $name);
$sql = "SELECT n.nspname AS schemas FROM pg_catalog.pg_namespace AS n WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema';";
$callback = function ($row, &$data) {
@ -219,7 +219,7 @@ class Pgsql extends _Base implements _iBase
*/
public function getSchemaSize($database, $schema)
{
$PSQL = new Postgres('postgres', loadClass('Docker')->getEnv('PGSQL_ROOT_PASSWORD'), $GLOBALS['PGSQL_HOST_ADDR'], $database);
$PSQL = new Pgsql('postgres', loadClass('Docker')->getEnv('PGSQL_ROOT_PASSWORD'), $GLOBALS['PGSQL_HOST_ADDR'], $database);
$callback = function ($row, &$data) {
$data = $row['size'];
@ -248,7 +248,7 @@ class Pgsql extends _Base implements _iBase
*/
public function getTableCount($database, $schema)
{
$PSQL = new Postgres('postgres', loadClass('Docker')->getEnv('PGSQL_ROOT_PASSWORD'), $GLOBALS['PGSQL_HOST_ADDR'], $database);
$PSQL = new Pgsql('postgres', loadClass('Docker')->getEnv('PGSQL_ROOT_PASSWORD'), $GLOBALS['PGSQL_HOST_ADDR'], $database);
$callback = function ($row, &$data) {
$data = $row['count'];
};
@ -268,6 +268,42 @@ class Pgsql extends _Base implements _iBase
}
/**
* Read out PostgreSQL Server configuration by variable
*
* @param string|null $key Config key name
* @return string|mixed[]
*/
public function getConfig($key = null)
{
// Get all configs as array
if ($key === null) {
$callback = function ($row, &$data) {
$key = $row['name'];
$val = $row['setting'];
$data[$key] = $val;
};
$sql = 'SELECT name, setting FROM pg_settings;';
$configs = $this->select($sql, $callback);
return $configs ? $configs : array();
} else { // Get single config
$callback = function ($row, &$data) use ($key) {
$data = isset($row['setting']) ? $row['setting'] : false;
};
$sql = "SELECT name, setting FROM pg_settings WHERE name = '".$key."';";
$val = $this->select($sql, $callback);
return is_array($val) ? '' : $val;
}
}
/*********************************************************************************
*
* Interface required functions

View File

@ -105,6 +105,7 @@ class Redis extends _Base implements _iBase
$this->setConnectErrno(1);
//loadClass('Logger')->error($this->_connect_error);
} else {
$redis->set('devilbox-version', $GLOBALS['DEVILBOX_VERSION'].' ('.$GLOBALS['DEVILBOX_DATE'].')');
$this->_redis = $redis;
}
error_reporting(-1);
@ -139,11 +140,14 @@ class Redis extends _Base implements _iBase
public function getKeys()
{
$store = array();
if ($this->_redis) {
return $this->_redis->keys('*');
} else {
return array();
$keys = $this->_redis->keys('*');
foreach ($keys as $key) {
$store[$key] = $this->_redis->get($key);
}
}
return $store;
}

View File

@ -22,34 +22,40 @@
<a class="nav-link" href="<?php echo $file == $current ? '#' : '/'.$file;?>"><?php echo $name;?><?php echo $file == $current ? ' <span class="sr-only">(current)</span>' : '';?></a>
</li>
<?php $file = 'db_mysql.php'; $name = 'MySQL DB';?>
<li class="nav-item <?php echo $file == $current ? 'active' : '';?>">
<a class="nav-link" href="<?php echo $file == $current ? '#' : '/'.$file;?>"><?php echo $name;?><?php echo $file == $current ? ' <span class="sr-only">(current)</span>' : '';?></a>
</li>
<?php $file = 'db_postgres.php'; $name = 'PostgreSQL DB';?>
<li class="nav-item <?php echo $file == $current ? 'active' : '';?>">
<a class="nav-link" href="<?php echo $file == $current ? '#' : '/'.$file;?>"><?php echo $name;?><?php echo $file == $current ? ' <span class="sr-only">(current)</span>' : '';?></a>
</li>
<?php $file = 'db_redis.php'; $name = 'Redis DB';?>
<li class="nav-item <?php echo $file == $current ? 'active' : '';?>">
<a class="nav-link" href="<?php echo $file == $current ? '#' : '/'.$file;?>"><?php echo $name;?><?php echo $file == $current ? ' <span class="sr-only">(current)</span>' : '';?></a>
</li>
<?php $file = 'mail.php'; $name = 'Emails';?>
<li class="nav-item <?php echo $file == $current ? 'active' : '';?>">
<a class="nav-link" href="<?php echo $file == $current ? '#' : '/'.$file;?>"><?php echo $name;?><?php echo $file == $current ? ' <span class="sr-only">(current)</span>' : '';?></a>
</li>
<?php
// ---- Datbases ---- //
$script = $_SERVER['SCRIPT_NAME'];
$files = array(
'db_mysql.php' => 'MySQL DB',
'db_postgres.php' => 'PgSQL DB',
'db_redis.php' => 'Redis DB',
'db_memcd.php' => 'Memcached DB'
);
$active = (in_array($script, array_keys($files))) ? 'active' : '';
?>
<li class="nav-item dropdown <?php echo $active;?>">
<a class="nav-link dropdown-toggle" href="#" id="supportedContentDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Databases</a>
<div class="dropdown-menu" aria-labelledby="supportedContentDropdown">
<?php foreach ($files as $href => $name): ?>
<a class="dropdown-item" href="/<?php echo $href;?>"><?php echo $name;?></a>
<?php endforeach; ?>
</div>
</li>
<?php
// ---- Info ---- //
$script = $_SERVER['SCRIPT_NAME'];
$files = array(
'phpinfo.php' => 'PHP info',
'mysqlinfo.php' => 'MySQL info',
'postgresinfo.php' => 'PostgreSQL info',
'redisinfo.php' => 'Redis info'
'info_php.php' => 'PHP Info',
'info_mysql.php' => 'MySQL Info',
'info_pgsql.php' => 'PgSQL Info',
'info_redis.php' => 'Redis Info',
'info_memcd.php' => 'Memcached Info'
);
$active = (in_array($script, array_keys($files))) ? 'active' : '';
?>
@ -62,6 +68,7 @@
</div>
</li>
<?php
// ---- Tools ---- //
if (strpos(loadClass('Php')->getVersion(), '5.4') !== false) {

View File

@ -152,7 +152,22 @@ REDIS_SERVER=3.2
### (only for docker-compose.optional.yml)
### $ docker-compose -f docker-compose.optional.yml up
###
MEMCACHED_SERVER=latest
MEMCACHED_SERVER=1.4.21
#MEMCACHED_SERVER=1.4.22
#MEMCACHED_SERVER=1.4.23
#MEMCACHED_SERVER=1.4.24
#MEMCACHED_SERVER=1.4.25
#MEMCACHED_SERVER=1.4.26
#MEMCACHED_SERVER=1.4.27
#MEMCACHED_SERVER=1.4.28
#MEMCACHED_SERVER=1.4.29
#MEMCACHED_SERVER=1.4.30
#MEMCACHED_SERVER=1.4.31
#MEMCACHED_SERVER=1.4.32
#MEMCACHED_SERVER=1.4.33
#MEMCACHED_SERVER=1.4.34
#MEMCACHED_SERVER=1.4.35
#MEMCACHED_SERVER=latest