Monday, January 28, 2013

A Log4Net Ducksboard Appender

A Log4Net Ducksboard Appender:
Ducksboard, is absolutely the most fun I’ve had on a web api in a long time.. “Monitor your metrics with Ducksboard, a real time visualization of your key performance indicators..”  Basically, you make dashboards with it.  It’s got built in pugins for tons of other apps (basecamp, github, twitter, pingdom etc. etc.) and a really nicely done restful api where you can manage your dashboards.

I’m just playing at this point, but I’m thinking that I’d like to use it to create some customer dashboards to show real-time metrics that are applicable to our apps.  One thing I was thinking was an uptime dashboard that could show the health of our services and devices, sort of like this.
Screen Shot 2013-01-26 at 6.29.28 PM
One way I can easily post to this board whenever there is an error in any of our apps is to create a Ducksboard Appender for log4net.  I used a nice little .net wrapper for Ducksboard and made the following appender :




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

using Ducksboard;
using Ducksboard.Objects;
using log4net.Appender;
using log4net.Core;
namespace PSI.Logging.DucksboardLog4NetLogger
{
public class DucksboardAppender : AppenderSkeleton
{
private static DucksboardClient _ducksboardClient;
public string ApiKey { get; set; }
public string WidgetId { get; set; }
protected override void Append(LoggingEvent loggingEvent)
{
if (_ducksboardClient == null)
_ducksboardClient = new DucksboardClient(ApiKey);
var timeline = new Timeline
{
Value =
{
Image = GetImage(loggingEvent.Level),
Content = loggingEvent.RenderedMessage,
Title = loggingEvent.Level.ToString()
}
};
_ducksboardClient.Update(WidgetId, timeline);
}
private static string GetImage(Level level)
{
if (level >= Level.Error)
return
"https://app.ducksboard.com/static/img/timeline/red.gif";
return level == Level.Warn ?
"https://app.ducksboard.com/static/img/timeline/orange.gif" :
"https://app.ducksboard.com/static/img/timeline/green.gif";
}
}
}



Configure it like this :




1
2
3
4
5
6
7
8
9
10
11
12
13

<log4net>
<appender name="DucksboardAppender" type="DucksboardLog4NetLogger.DucksboardAppender">
<apiKey value="oPmjHv4N3J6RVPGoz2SKiEhX3f3jH4nBH4myykj7xTGYarwbkz" />
<widgetId value="109846" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date | %-5level | %message~%newline" />
</layout>
</appender>
<logger name="PSI.ServiceBus">
<level value="ALL" />
<appender-ref ref="DucksboardAppender" />
</logger>
</log4net>



I’m hoping to contribute to the Ducksboard api for .NET and add the dashboard API, which allows you to create dashboards in code.  A new installation of one of our services could create a new monitoring dashboard, add all of the relevant graph and informational displays, then start updating it.
Disclaimer : I recently asked Ducksboard to become “Friends” of CodeBetter.Com so you’ll see them linked at the bottom of the site, but this post is unrelated.


DIGITAL JUICE

No comments:

Post a Comment

Thank's!