kdb+ Server Monitor
Friday, September 16th, 2005It’s a common requirement to have server monitoring in an enterprise system. Most companies already have their own favourite tools for monitoring system resources (memory, cpu, disk, etc) and they are likely to have log file scanners and also process monitors too. So what’s the best way to monitor kdb+?
A standard process monitor can check that the kdb+ instance is present, and the log file scanners can check for error messages in the kdb+ log file.
This is fine, but supposing that you dont have those tools in place, or they are too much hassle to configure. You could have a monitoring process that checks that the server’s port is listening, and by leaving the connection open you can detect when the server process goes down, or the system becomes unreachable via the network. It’s probably best to do this in q itself, but if you don’t have an enterprise license to run it anywhere you can get by with Java, as the following code shows
import java.net.Socket;
import java.io.IOException;
public class Monitor {
public static void main(String []args) {
try{new Socket(args[0],Integer.parseInt(args[1])).getInputStream().read();}
catch( IOException e) {System.err.println(\”Server down/disconnected\”);}
}
}
Some people will look at the code and shake their heads. Others will look at it and accept that it does nothing more than is needed. Too many “programmers” these days over engineer a solution and clutter their code with drivel.
The above script could be used in combination with a log file monitor or extended to send an email or trigger a pager when a kdb+ process is no longer running.