Redis Monitoring Server

Published on:
Tags: redis, release

It’s been quite some time since my last post – but as I decided recently to refresh the sites template I thought I would celebrate with a new post on a recent release I made.

Redis Monitoring Server is a small python server which monitors and logs one or more redis instances, the server can then be queried in a number of ways to retrieve the commands run on the observed instances

The requirement came from the need to perform automated, external tests on a number of different applications, all of which are written in different languages. When testing the applications it is required to assert the commands being run on the server. This necessitated the stand alone server, for the queryable interface to the server I chose to use the excellent ØMQ, this enables anyone to communicate with the server rapidly without the need for redundent boilerplate (or me writing specific)

See below for a couple of examples of querying the monitoring server:

Python Example
1
2
3
4
5
6
7
import zmq
context = zmq.Context()

socket = context.socket(zmq.REQ)
socket.connect("tcp://localhost:5559")
socket.send('last')
response = socket.recv()
Lua Example
1
2
3
4
5
6
7
require "zmq"
local context = zmq.init(1)

local socket = context:socket(zmq.REQ)
socket:connect("tcp://localhost:5559")
socket:send('last')
local response = socket:recv()

Even in PHP!

Php Example
1
2
3
4
5
6
$context = new ZMQContext();

$socket = new ZMQSocket($context, ZMQ::SOCKET_REQ);
$socket->connect("tcp://localhost:5559");
$socket->send("last");
$response = $socket->recv();

I’ve included a very basic python interface wrapper for the tool, mainly as means of an example, which i’m currently using in a number of different projects

It can be used in the following way:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from monitor import RedisMonitor

rm = RedisMonitor(redis_ports=[6997,6998])

# do a test
rm.get_last_command()   # returns the last command run accross all instances
rm.get_last_command_by_instance(6997)   # returns the last command run on instance @ port 6997
rm.get_all_commands()   # returns all commands run to date
rm.get_command_counts() # returns a dict of port => number of commands recorded

rm.reset()  # reset the current lists..

# more tests...

rm.shutdown()

For more information on the tool checkout the GitHub Page

/Matt