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 https://github.com/tibbe/ekg.git

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

3 comments:

  1. I am delighted, too. We are two now!

    ReplyDelete
  2. Any possibility of getting this to run on GHC 7.0? It's going to be a long time before 7.4 is available in a released distribution.

    AfC

    ReplyDelete
  3. Andrew,

    Unfortunately not, the GHC.Stats API, which I use, was introduced in GHC 7.4.

    ReplyDelete