Subversion repository monitoring with Monitis

In previous articles, we’ve shown how to use Monitis for monitoring various properties of computers systems, such as system load, the sizes of various files, and file system free space. One of the great features of Monitis is that it is extensible, and can be used to monitor and record information about virtually anything that can be measured. In this article, we’ll take a look at using Monitis to monitor something less common: code and contributors in a Subversion (SVN) repository.

We begin by creating a simple example library for interacting with the SVN command line tools. This is where we take advantage of Monitis’ extensibility by making an SVN repository something we can measure. Using an interface to the command line tools is the simplest method for implementing the protocols needed to gather communicate with an SVN repository. Input is passed to the command line program via command line arguments, and results are obtained by parsing the output. A future version could improve on this by implementing the interaction with the SVN repository directly.

Let’s take a look at the implementation of the interface in more detail. The code for the interaction interface is in, available in the Monitis Exchange GitHub repository at Go take a look, and follow along with the discussion.

The implementation of the library provides three key pieces of functionality. First, the class RepoCommand provides an abstraction for running command line tools, so that subclasses can be instantiated without the need to individually deal with the details of running processes, redirecting output, etc. Second, SvnCommand is just such a subclass of RepoCommand. It uses the internal _cmd method to interact with the ‘svn’ command line tool. Using ‘svn’, SvnCommand offers several higher level methods.

  • list_files: list of files in a specified repository location, along with their type
  • log: list of log entries for a specified repository location, optionally filtering on a given list of authors/commiters
  • _log: internal method not intended to be invoked from outside instances of the class. It implements technical details of the log method, including the regular expression which parses the output of the ‘svn’ command line tool. It is this regular expression that allows for the extraction of log features such as revision, author, date, and number of lines of each commit in the log.

Since classes that use SvnCommand may make multiple calls to log for a given repository, a simple caching mechanism is employed to avoid multiple calls over the network for the same data. In a future version, this could be improved by abstracting the log results into another class to support multiple queries per log result.

The third component of is the class SvnRepository. It uses an instance of SvnCommand to provide a high level abstraction that other programs can use to get information from Subversion repositories. The methods available in the current version are:

  • files: names of the files in a specified repository, optionally excluding directories
  • authors: authors who have committed to the specified repository
  • log: the repository log, including the optional filter on committers as described in SvnCommand

With the example library in place, let’s take a look at an example monitor that uses the library. The monitor code can be found in, available in the Monitis Exchange GitHub repository at This version of interacts with the Monitis API by using the library in the same directory. The API is discussed in previous articles and won’t be covered further here.

The monitor example in provides three kinds of monitors, which correspond to the information available from respositories using the library. At this point, these should be familiar:

  • files: number of files currently tracked in the repository
  • commits: number of commits that have been performed on the repository
  • authors: number of authors that have committed code to the repository

Connecting to the Monitis API requires the use of your Monitis API Key and Secret Key. To retrieve these keys for your account, log in to the Monitis portal at and select “Tools–>API–>API key”. The monitor can take these keys as arguments or as environment variables. For simplicity on the command line, providing these values in the environment works best.

$ export MONITIS_APIKEY=<Monitis API key>
$ export MONITIS_SECRET=<Monitis Secret key>

Next, we need to create the monitor in the Monitis portal. We’ll use the script covered in previous articles.

$ ./ -m svnMonitor -n "SVN Monitor" \
-r "svnfiles:Files:files:4;commits:Commits:commits:4;authors:Authors:authors:4"

With the environment variables in place and the monitor created in the Monitis portal, we can now proceed to invoke the monitor. For the purposes of this articles, we’ll use a file system based Subversion repository, but the behavior is the same with HTTP repository URLs.

$ svnadmin create /path/to/svnrepo
$ export REPO=/path/to/svnrepo

In another directory, import a new, empty project.

$ mkdir project
$ svn import project file:///$REPO/project -m 'initial import'

In a third directory, do the check out. The monitor will use the repository we created in the first step, but the checkout is the directory we’ll interact with when adding and modifying files.

$ svn co file:///$REPO/project project

Now, we can run the monitor against the repository. The following command will run with the file system based repository we created, and run queries for files, commits, and authors, and send the result to our monitor. By default, it finds an appropriate monitor based on the svnMonitor tag, but an alternate monitor can be specified by monitor ID.

$ ./ -u file:///$REPO/project -q files -q commits -q authors
Sending result: svnfiles:1;commits:1;authors:1

This submits the initial data point for the empty repository. We can then see that data point in the table of results.

Let’s generate some more data points, and then take a look at some graphs of the data.

First, add a directory.

Next, add a file.

And, add a line to the file.

After continuing this process with a number of additional files and edits, we can see our progress in the graphs.

After more time and more commits to the repository, it becomes easy to see trends in the activity of the repository and its committers.

That’s it! By using the extensibility and flexibility of the Monitis API, and a little bit of code to get metrics from an SVN repository, we are able to monitor the state and progress of a project. Now, try it out for yourself. Download the code from the Monitis Exchange GitHub repository, and run the script against a SVN repository of your own.