Tuesday, 4 November 2008

Hello, Nagios\n

Nagios is a generic monitoring tool, and I want to use it to monitor my own application. It has a lot of built-in and offical plugins. However, it is always good to try a Hello, World-type example.

Firstly, my very interesting application. It follows the Nagios Plugin guidelines: return a value in {0, 1, 2, 3} and a status message of less than 4k to standard out. And it gives you some random sysadmin-action:

(np.c, compiles into an executable np)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char* argv[]) {
srand(time(NULL));

int r = rand() % 10;

int status = -1;
char* message = NULL;

switch(r){
case 0:
case 1:
case 2:
case 3:
status = 0;
message = "Everything is alright :-)";
break;
case 4:
case 5:
case 6:
status = 1;
message = "You have been warned.";
break;
case 7:
case 8:
status = 2;
message = "She is gonna blow!";
break;
case 9:
status = 3;
message = "Oh shit...";
break;
}

printf("%s\n", message);

return status;
}


Nagios is easy to install with this quickstart guide. You just need to configure it:

1) In $NAGIOS_HOME/etc/nagios.cfg, add a line cfg_file=$NAGIOS_HOME/etc/objects/np.cfg

2) In $NAGIOS_HOME/etc/nagios.cfg, set interval_length to a suitably low number, e.g. 5 seconds, so you can see changes quickly

3) In $NAGIOS_HOME/etc/objects/np.cfg, make it look something like this:

define hostgroup {
hostgroup_name app_hosts
alias Application Hosts
}

define host {
use generic-host
host_name app_host
alias Application Host
address localhost
hostgroups app_hosts
max_check_attempts 10
}

define service {
use local-service
host_name app_host
service_description My Application
check_command monitor_np
normal_check_interval 1
retry_check_interval 1
}

define command {
command_name monitor_np
command_line $APPLICATION_HOME/bin/np
}

The configuration is quite fidgety. Lots of required attributes, no sensible defaults. Luckily you can reuse example configuration that comes with Nagios. And there is a handy pre-flight-check feature, you just run /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg and it will give you errors and warnings against your configuration files, with line numbers.

Anyway, by now Bob is your uncle and you can restart nagios to pick up changes. Then point your browser to http://localhost/nagios and watch the action!

Monday, 3 November 2008

Any Fool Can Sysadmin

I have Windows XP on my laptop, but I needed a Linux environment for client work. The last time I played around with dual booting was in 2000 when I had just bought my self-builder home computer. I installed Windows 2000 then RedHat 6, but the whole thing failed (I suspect my then very new motherboard didn't have drivers, or something) and I had to wipe everything (using my home sysadmin skills: if anything goes wrong, wipe and reinstall!).

So, it is fair to say I am a non-sysadmin, and maybe that's why I am sometimes accused of being a girly drinker. But with VMware I am suddenly sucessful and confident - in fact I am so confident I might just run as root - it is a vm after all, what could go wrong?

I found this guide extremely helpful. VMware Player is free and easy, the guide helps to hook things up, Ubuntu is quite user friendly. Why was I so scared of sysadmining for so long?

Well, these are early days, and I might just revert to my old self if I get a problem with Linux - wipe and reinstall. But since it is a vm, that is actually a painless solution...

Actually I forget; I first tried installing Damn Small Linux using a VMware Appliance, since it was only a 50MB download. However, I didn't manage to get the network working. And my colleagues and I didn't have a clue how to fix it. So I ended up with Ubuntu. Morale of the story though, sysadmining is no fun if you can't easily wipe and reinstall.


Friday, 3 October 2008

Software Apprentice

Kerry is always talking about Dreyfus and nursing competencies.

That got me thinking: is there a book you can give to a software developer that he can follow and use to improve himself through the five levels?

Well, I haven't read it yet but Elizabeth Keogh recommended me Apprenticeship Patterns: Guidance For The Aspiring Software Craftsman. I shall put it on my list right after finishing the DDD book and several volumes on how to raise babies.

More on this topic: http://dannorth.net/2008/06/learning-to-lean - loved the Bruce Lee quote at the bottom.

Wednesday, 1 October 2008

Annoying Eclipse Configuration

I needed to get Eclipse to use a JDK instead of a JRE so I could play around with Maven.

Easy peasy? Well, no, not exactly...

"Just specify a -vm option in your eclipse.ini, and Bob is your uncle", they stated. Hah!
  • I put the option in with a blank line seperator. Doesn't work.
  • I delete the blank line after reading a blog entry. Doesn't work.
  • Hmm, it keeps defaulting to my JRE, maybe I will uninstall that so I can "debug". Que slow Windows uninstallation...
  • Now I get error messages. Maybe it is the space in Program Files? I'll put a %20 in there. Doesn't work.
  • I discover option values go onto a new line (how obscure). Combinatorials ensue. Still doesn't work.
Turns out it won't work if you don't -vm option before the -vmargs option. Why??? Worse, it will just silently die/ ignore/ not warn you. Perhaps they should work on their error messages?

But i'm not ashamed to have wasted half an hour. Others have wasted time on this stuff too.

Isn't there a standard or convention for text-based config files, and couldn't someone get Eclipse to use it?

Tuesday, 30 September 2008

Unit Testing With Threads

I saw this and started thinking back on a calculus course at university.

Wouldn't we expect a theorem like this to be true:

"for all codebases C and features F, there exists a set of refactorings R and unit test U, such that U(F) is safe under R(C)"

In other words, can we not manipulate any piece of untestable thread code into a testable one, given enough refactorings and inversion of control levers (and effort!)? Seems reasonable to me.

In a situation with 2 threads and one interaction, it is easy to imagine the combinatorial complexity of test cases. It of course explodes when the numbers go up - but perhaps we could argue that for any number of threads and interactions, we can reduce the complexity of our tests by looking at each in isolation...

If my theorem holds, you can of course turn it around and use it to knock people over their heads when they screw up thread testing - hmm, how productive that would be :-)

Interesting thought, anyway.

Thursday, 25 September 2008

Surprisingly Good Error Messages!

I was stunned recently by finding a piece of software that does something reasonably complicated, but still manages to give good error messages.

Just look at this beauty from Spring IOC:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'magiceightball' defined in file [C:\...\random\magiceightball.test.xml]: Cannot resolve reference to bean 'randomsource' while setting constructor argument; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [foo.Foo] for bean with name 'randomsource' defined in file [C:\...\random\magiceightball.test.xml]; nested exception is java.lang.ClassNotFoundException: foo.Foo at [...]

That is actually perfectly readable! Alright, I am a nerd, and I have some experience with debugging Java code, but I bet a 9-year-old child could deduce that they forgot to implement a RandomSource called Foo.

I was stunned when I saw it, perhaps because it is so rare to get useful error messages from clever frameworks. As soon as reflection enters the picture, people just give up it seems. Look at this example as a contrast:

com.google.inject.CreationException: Guice configuration errors: 1) Error at foo.BarTestModule$TestBar.(BarTest.java:18): Could not find a suitable constructor in foo.BarTestModule$TestBar. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor. 1 error[s] at com.google.inject.BinderImpl.createInjector(BinderImpl.java:277)
[blah blah]

Hmm, that's funny, I distinctly remember creating a zero-argument constructor in TestBar??? It turns out, Guice does not support injection of inner classes. And it only took me an hour to figure that out... So is this error message helpful, or rather harmful?

Hibernate is equally bad and will give you a lot of grief if you do not tread carefully. And these are popular, high-profile pieces of software, not random open-source amateur junk off of SourceForge. So how come Spring IOC got it right and these guys got it so wrong?

Monday, 22 September 2008

T-shirt Size Estimation

We have all been through painfil estimation sessions. What makes them painful is formality.

The Living Room Architect talks about a Story Matrix, as a way of facilitating a smoother flow for estimating a bunch of stories. Good idea.

One problem still persists though, is the formality of it, with the whole points debate: do we use Fibonacci, linear, exponential, what? What do the numbers mean? And the apprehention on the part of us developers to be specific with stories they have only just begun to think about.

Someone today introduced me to T-shirt Sized Estimation - you basically cluster your stories into S, M and L. Sizes cover plain "lines of code", complexity and risk. But it has an implied light touch which seems to solve some problems I think, it seemed to go quickly and easily, and we did get a result out of it.
  • No numbers, so nothing to get too hung up about
  • Only 3 categories, so we don't have to discuss things for very long - it is implied that this isn't the final clustering
  • We still got to communicate about the stories, so Agile Tick Mark right there
  • And we got a rough set of estimates
Now, that isn't of course the final word in the estimation process, and we all know that, so no point in getting defensive. We will need numbers at some point. But it got us perhaps half way. We did talk about our understanding of the stories, and we did get a picture of how hard the project might be.

But most importantly, we didn't get hung up on details - instead we split the process into 2 (or more) phases. A bit like when you look at algorithms, you know that when you need to traverse a graph and do something complicated, you can either write the mother of all recursive functions, or you can split up into separate stages (search and modify stages for example). In the end, we all know that O(n) + O(n) = O(n) - i.e. the amount of effort will be the same, but it will be easier to manage the two things separately.

We will certainly need another card session, and we will need some numbers at some point, but for now we have fleshed out some things, in a very short time and noone has run off crying. And that has to be considered progress.

Monday, 15 September 2008

Schema Spy

While reverse-engineering a customer's database, my pair-mate introduced me to Schema Spy. It looks quite good: lightweight cross-db reporting and visualization, runs from the command line and gives you an HTML folder structure.


Thursday, 11 September 2008

Top 10 Books On Software

A friend of mine blogged about books. His question was: "What are, in your opinion, the top 10 books that every software engineer/developer should read?". Well, here are a few to get you started:
  • Gamma et al.: "Design Patterns". An absolute classic. After reading it I immediately went into pattern fever (as everyone does?). Interestingly, the patterns themselves aren't that useful for the stuff I do day to day, but the idea is powerful. And of course, this book started the whole Patterns Movement...
  • Møller & Schwartzbach: "An Introduction to XML and Web Technologies". I am slightly biased, having taken an XML course from the authors. But, this book really puts things in perspective, it is thorough and clear, and offers opinion. The web is full of simple examples, re-hashes, cheaply written stuff without depth. So this was a great and welcome read.
  • Larman: "Applying UML and Patterns". This one really hit the spot. I was idling somewhat, lacking direction, and this one gave me a spark of inspiration. The way it formulates those simple, old-fashioned OO values, it takes you back to first principles and reminds you why it is we do what we do. It is easy to get lost in new technology, tools, methodology and process - but what we really need is to remember those few, simple things: model your domain, separate concerns, an Bob is your uncle!

All The Cool Kids Have A Blog

All the cool kids have a blog, so I think I should have one too. That is about as much reasoning as I can muster right now.

I am always impressed with blogger's boldness, the way they reveal their hand to the world and take sides. I wonder if I will be as brave? I like to ask questions. Do questions belong in a blog? Or does it only work if you have that blogger-swagger?

Anyway, we shall see what comes of it!