Thursday, December 29, 2011

More monitoring goodies

The ekg library now supports user-defined counters. User-defined counters can be used to track custom program state (e.g. the number of requests served by a server.)

Adding a new counter to a program is easy. Here's a small example program:

main = do
    handle <- forkServer "localhost" 8000
    counter <- getCounter "iterations" handle
    let loop = do
            inc counter

The counter will show up in a new section of the web interface, together with a number of built-in counters (e.g. garbage collector and memory usage counters):

All user-defined counters are also available via the REST API.

I've expanded the REST API to allow you to retrieve single counters, with the caveat that single counters can only be retrieved using the "text/plain" MIME type, as the JSON specification doesn't allow simple values (e.g. integers) to occur at the top-level.

Tuesday, December 27, 2011

Remotely monitor any Haskell application

I am delighted to announce the first release of ekg, a new library for remote monitoring of processes over HTTP.

The library gives you insight into what your application is doing right now. It lets you see

  • how much memory your application is using,
  • how much time is spent on GC, and
  • what the current memory allocation rate is.

Live monitoring is sometimes the only way to get insight into issues that only show up when an application is deployed in production. By exporting the stats over HTTP, the library lets you monitor applications running on remote machines by simply pointing your web browser at the machine you're interested in. (N.B. You need to make sure that unauthorized users can't do the same.)

Adding monitoring to your application is simple. Just launch the monitoring server as soon as your application starts

import System.Remote.Monitoring

main = do
     forkServer "localhost" 8000

and then visit http://localhost:8000/ in your web browser.

The web interface currently includes

  • a summary table that shows the latest stats,
  • a number of graphs that show how the stats change over time,
  • a control for setting the desired sampling rate, and
  • a toggle for pausing the UI (e.g. to take a closer look at the graphs).

The summary table looks like this:

The graphs are updated continously, using the specified sampling rate, and show you the value of each stat over the last 60 seconds. Here's an example showing the productivity (i.e. percentage of time spent running the mutator) of an application:

(A low producivity is a strong signal that the something is wrong; perhaps your memory allocation rate is too high).

The monitoring server also lets you to retrieve the stats as JSON. Simply send the server an HTTP GET request with the Accept header set to "application/json":

curl -H "Accept: application/json" http://localhost:8000/

You can use the JSON API to e.g. write applications that monitor other applications.

If you'd like to contribute, you can get the source tree from GitHub:

git clone

Note that the library requires GHC 7.4, which should be released any day now.