Test if database is online

This question has probably already been answered somewhere, but I’m having trouble finding the answer.

I want to be able to test if a given database server is online.

Using databaseManager.getServerNames() I’m able to generate a list of all the databases that were enabled at startup. But how, without doing some kind of actual query on the database, can I determine if the database is online?

Or perhaps I should ask is there an inexpensive querry I could perform that would tell me if a given database is online?

Ideally, this should work for both traditional databases such as mysql and postgresql as well as others such as MongoDB and FileMaker.

My guess would be to use the maintenance plugin (see isValid() for JSServer), I never used this but it seems to me a check for an active server. Or you could run a simple query on the server (i.e. select 1 from table).
The last option would recieve a time-out if the server is offline, so you would have to wait until that time-out expires and I think that is depending on the db settings.