Skip to content

Commit

Permalink
Replace Redis Stats GUI with the newer Valkey Stats GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
abias committed Oct 29, 2024
1 parent ce3a25d commit 00d2e77
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 90 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ moodle-tool_redis
Changes
-------

### Unreleased

* 2024-10-29 - Replace Redis Stats GUI with the newer Valkey Stats GUI

### v4.1-r5

* 2024-08-21 - Replace deprecated print_error() with moodle_exception.
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ Motivation for this plugin

For performance reasons, Moodle should always be run with a Caching backend. Redis is such a caching backend which Moodle can connect to. Unfortunately, Redis is kind of a black box and doesn't provide a management interface by default.

Luckily, there are some free Redis management GUIs out there with Redis Stats by Helmut K. C. Tessarek (https://github.com/tessus/redis-stats) being a really nice and compact one. As a Moodle server administrator, you can just throw Redis Stats somewhere onto your Moodle server and get a Redis management GUI instantly. However, this approach requires that you protect Redis Stats from unauthorized access manually in your webserver and comes with the downside that Redis Stats is located outside Moodle.
Luckily, there are some free Redis management GUIs out there with Valkey Stats by Helmut K. C. Tessarek (https://github.com/tessus/valkey-stats) being a really nice and compact one. As a Moodle server administrator, you can just throw Valkey Stats somewhere onto your Moodle server and get a Redis management GUI instantly. However, this approach requires that you protect Valkey Stats from unauthorized access manually in your webserver and comes with the downside that Valkey Stats is located outside Moodle.

For these reasons, we have packaged Redis Stats as a very simple Moodle admin tool providing it within Moodle site adminstration for Moodle administrators only.
For these reasons, we have packaged Valkey Stats as a very simple Moodle admin tool providing it within Moodle site adminstration for Moodle administrators only.


Installation
Expand Down Expand Up @@ -171,5 +171,5 @@ It was contributed to the Moodle an Hochschulen e.V. plugin catalogue in 2022.
Credits
-------

This Moodle plugin is only a simple wrapper for the Redis Stats management GUI by Helmut K. C. Tessarek.
Helmut owns all copyrights for Redis Stats and maintains this tool on https://github.com/tessus/redis-stats.
This Moodle plugin is only a simple wrapper for the Valkey Stats management GUI by Helmut K. C. Tessarek.
Helmut owns all copyrights for Valkey Stats and maintains this tool on https://github.com/tessus/valkey-stats.
2 changes: 1 addition & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ General
Upstream changes
----------------

* This plugin relies on the thiry-party Redis Stats management GUI tool which is located within the plugin directory. Every now and then, it should be checked if there is a new version which could be updated in the plugin.
* This plugin relies on the thiry-party Valkey Stats management GUI tool which is located within the plugin directory. Every now and then, it should be checked if there is a new version which could be updated in the plugin.


Automated tests
Expand Down
8 changes: 4 additions & 4 deletions flushdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
/**
* Admin tool "Redis management" - Redis Stats Flush DB stub.
*
* The Redis Stats code which we have placed into lib/redis-stats/redis-stats.php.inc
* The Valkey Stats code which we have placed into lib/valkey-stats/valkey-stats.php.inc
* is calling a file called flushdb.php to flush the Redis DB.
* With this file, we provide a stub at the location where the Redis Stats code expect it to be and include the original file.
* With this file, we provide a stub at the location where the Valkey Stats code expect it to be and include the original file.
*
* @package tool_redis
* @copyright 2020 Alexander Bias, Ulm University <[email protected]>
Expand All @@ -36,5 +36,5 @@
// Make sure that only admins flush the DB.
require_capability('moodle/site:config', context_system::instance());

// Include Redis Stats Flush DB.
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/redis/lib/redis-stats/flushdb.php.inc');
// Include Valkey Stats Flush DB.
require_once($CFG->dirroot.'/'.$CFG->admin.'/tool/redis/lib/valkey-stats/flushdb.php.inc');
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
ob_start();

// Include Redis Stats.
require_once(__DIR__ . '/lib/redis-stats/redis-stats.php.inc');
require_once(__DIR__ . '/lib/valkey-stats/valkey-stats.php.inc');

// Get buffered content and finish buffering.
$output = ob_get_contents();
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions lib/redis-stats/config.php → lib/valkey-stats/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
/**
* Admin tool "Redis management" - Redis Stats configuration file
*
* The Redis Stats code which we have placed into lib/redis-stats/redis-stats.php.inc
* The Valkey Stats code which we have placed into lib/valkey-stats/valkey-stats.php.inc
* is looking for a file called config.php and includes this file.
* In this file, we can set the configuration of Redis Stats.
* In this file, we can set the configuration of Valkey Stats.
*
* @package tool_redis
* @copyright 2020 Alexander Bias, Ulm University <[email protected]>
Expand All @@ -28,7 +28,7 @@

defined('MOODLE_INTERNAL') || die();

// Get the Redis server(s) configuration from the MUC configuration and provide it in a way as Redis Stats expects it.
// Get the Redis server(s) configuration from the MUC configuration and provide it in a way as Valkey Stats expects it.
//
// Servers are defined as an array
// [ Name, IP/Socket, Port, Password ]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

/* KIZ MODIFICATION START
REASON: Redis Stats must not use any custom session handling. */
/* MAH MODIFICATION START
REASON: Valkey Stats must not use any custom session handling. */
require(__DIR__ . '/../../../../../config.php');
if (!isset($_GET['id']) || isset($_GET['id']) && $_GET['id'] != sesskey())
{
die("Invalid request.");
}
/* KIZ MODIFICATION END */
/* MAH MODIFICATION END */
/* ORIGINAL START
session_start();
Expand Down Expand Up @@ -66,7 +66,18 @@ if (isset($command[$serverName]['AUTH']) && !is_null($command[$serverName]['AUTH
$AUTH = $command[$serverName]['AUTH'];
}

// Talk to Redis server
// Functions
function debug($var, $pre = true)
{
if (DEBUG)
{
if ($pre) echo "<pre>".PHP_EOL;
var_dump($var);
if ($pre) echo "</pre>".PHP_EOL;
}
}

// Talk to server
$error = null;

$fp = @fsockopen($servers[$server][1], $servers[$server][2], $errno, $errstr, 30);
Expand All @@ -79,8 +90,9 @@ if (!$fp)
}
else
{
$redisCommand = '';
$ASYNC = '';
$vkCommand = '';
$ASYNC = '';
$numCmds = 0;

isset($servers[$server][3]) ? $pwdEntry = $servers[$server][3] : $pwdEntry = null;
if (!is_null($pwdEntry) && !empty($pwdEntry))
Expand All @@ -97,48 +109,45 @@ else
{
$credentials = $pwdEntry;
}
$redisCommand = "$AUTH $credentials\r\n";
$vkCommand = "$AUTH $credentials\r\n";
$numCmds++;
}
if ($async) // we want async flush
{
$ASYNC = ' ASYNC';
}
if ($db != -1) // one specific database
{
$redisCommand .= "SELECT $db\r\n$FLUSHDB$ASYNC\r\nQUIT\r\n";
$vkCommand .= "SELECT $db\r\n$FLUSHDB$ASYNC\r\nQUIT\r\n";
$numCmds += 3;
}
else // entire instance
{
$redisCommand .= "$FLUSHALL$ASYNC\r\nQUIT\r\n";
$vkCommand .= "$FLUSHALL$ASYNC\r\nQUIT\r\n";
$numCmds += 2;
}

fwrite($fp, $redisCommand);
fwrite($fp, $vkCommand);
while (!feof($fp))
{
$info[] = trim(fgets($fp));
}
fclose($fp);
}

if (array_unique($info) === array('+OK'))
{
/* KIZ MODIFICATION START
REASON: Redis Stats must not use any custom session handling. */
/* ORIGINAL START
$_SESSION['id'] = '';
ORIGINAL END */
echo "Success";
}
else
for ($i = 0; $i < $numCmds; $i++)
{
if (DEBUG === true)
{
var_dump($redisCommand);
var_dump($info);
}
foreach ($info as $v)
if ($info[$i] != '+OK')
{
if ($v != '+OK')
die($v);
debug($vkCommand);
debug($info);
die($info[$i]);
}
}

/* MAH MODIFICATION START
REASON: Valkey Stats must not use any custom session handling. */
/* ORIGINAL START
$_SESSION['id'] = '';
ORIGINAL END */
echo "Success";
Loading

0 comments on commit 00d2e77

Please sign in to comment.