Hi, I’d like to make a /healthz
route for my Meteor app. It returns 200 if the app is healthy and 500 if there is an error.
Simple to do in Iron Router with server side routes:
// Liveness test
Router.route('/healthz', { where: 'server' })
.get( function() {
this.response.statusCode = 200;
this.response.end('ok');
});
How can I check if the database connection is up w/o writing/reading from the database.?
This would run every few seconds to see if the app should be restarted, so I’d prefer not to r/w the database.
Detecting a previous error would be fine. Ideas? Thanks!
sashko
2
Hi @Sashko, thanks.
Is the driver configured to automatically reconnect?
If it does, then restarting the container may be worse than waiting for it to reconnect.
Re: rawDatabase, this page shows error and reconnect events that could be listened to. Here is someone who used db.stats().ok.
In Meteor w/ Iron Router that might look something like (I haven’t tried this):
// Liveness test
Router.route('/healthz', { where: 'server' })
.get( function() {
if (myCollection.rawDatabase().stats().ok) {
this.response.statusCode = 200;
this.response.end('ok');
} else {
this.response.statusCode = 500;
this.response.end('db connection not ok');
}
});
sashko
4
Yes, it definitely should be doing that. I doubt restarting the container is the right solution in the case of a database disconnect.
1 Like