-
-
Save fliphess/2cc9a9b3b00f04e2976fd135b0a96e1f to your computer and use it in GitHub Desktop.
Single page website to show statistics on a redis server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$redis_server = '127.0.0.1'; | |
$redis_port = 6379; | |
$banned_keys = [ | |
'rdb_changes_since_last_save', | |
'rdb_bgsave_in_progress', | |
'rdb_last_save_time', | |
'rdb_last_bgsave_status', | |
'rdb_last_bgsave_time_sec', | |
'rdb_current_bgsave_time_sec', | |
'aof_last_rewrite_time_sec', | |
'aof_rewrite_in_progress', | |
'aof_rewrite_scheduled', | |
'aof_last_rewrite_time_sec', | |
'aof_current_rewrite_time_sec', | |
'aof_last_bgrewrite_status', | |
'aof_last_write_status', | |
'repl_backlog_active', | |
'repl_backlog_size', | |
'repl_backlog_first_byte_offset', | |
'repl_backlog_histlen', | |
]; | |
$fp = fsockopen($redis_server, $redis_port, $errno, $errstr, 30); | |
$data = array(); | |
if (!$fp) { | |
die($errstr); | |
} else { | |
fwrite($fp, "INFO\r\nQUIT\r\n"); | |
while (!feof($fp)) { | |
$info = split(':', trim(fgets($fp))); | |
if (isset($info[1]) and !in_array($info[0], $banned_keys)) $data[str_replace('_', ' ', $info[0])] = $info[1]; | |
} | |
fclose($fp); | |
} | |
?> | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>Redis statistics</title> | |
<link rel="shortcut icon" type="image/png" href="https://downtek.com/favicon.ico"/> | |
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> | |
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" rel="stylesheet"> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> | |
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js "></script> | |
<style type="text/css"> | |
body { font-family: arial,sans-serif; color: #111; } | |
div.box { background-color: #F8F8F8; width: 250px; height: 150px; | |
text-align: center; padding: 20px; margin: 10px; float: left; font-size: 1vw; } | |
div.key { font-weight: bold; padding: 10px; font-size: 1.4vw; word-wrap: break-word; } | |
div.detail { padding: 20px; text-align: center; } | |
div.detail span { width: 90px; padding: 2px; display: inline-block; } | |
div.detail span.title { text-align: right; } | |
</style> | |
</head> | |
<body> | |
<nav class="navbar navbar-default"> | |
<div class="container-fluid responsive"> | |
<ul class="nav navbar-text"><b>Redis Statistics</b></ul> | |
<ul class="nav navbar-text"><?php printf("Server: %s", $redis_server); ?></ul> | |
<ul class="nav navbar-text"><?php printf("Port: %s", $redis_port); ?></ul> | |
</div> | |
</nav> | |
<?php foreach ($data as $key => $value) { printf("<div class='box'>\n<div>%s</div><div class='key'>%s</div></div>", $key, $value); } ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment