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
            loop
    loop

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.

4 comments:

  1. It looks good, but could you set a header row in a darker color and place a heading text like "Counter Name" and "Value"?

    ReplyDelete
  2. I've added a header now, it'll be in the next release.

    ReplyDelete
  3. Awesome! Just a minor comment: Maybe other people are simply better than me at reading long, unbroken numbers (that's 1.8TB allocated, isn't it?), but for human consumption I always find comma-separated numbers to be much easier.

    Sadly this is functionality that seems to not usually make it into most language's standard libraries. In Haskell's case I tend to use something simple like the function below.


    import Data.List
    import Data.List.Split (chunk)

    commaint :: (Show a, Integral a) => a -> String
    commaint n | n < 0 = "-" ++ commaint (-n)
    commaint n =
    reverse $ concat $
    intersperse "," $
    chunk 3 $ reverse (show n)

    ReplyDelete
  4. Ryan, I just released v0.3 which addresses this usability issue (and a few others.)

    ReplyDelete