3

I want to monitor if my sqlserver is up from a distant machine.

I currently send a simple "select @@version" query with sqlcmd and then validate if that query returned the expected part of text :

sqlcmd -S np:\\<servername>\pipe\sql\query -i version.sql | findstr /I "expected string"

then I proceed to validate conditions based on this event.

Is there a better way to monitor db up events and db down events ?

Thanks

asked May 3, 2016 at 15:17

1 Answer 1

1

The best way (aside from buying a proper product) is to do it with PowerShell, with Invoke-SqlCmd, because it will give you more flexibility to check the response and do something with it.

I probably wouldn't confirm version because it's meaningless and will change when you upgrade or patch; I would confirm @@Servername matches what I expect in case the IP has somehow become mixed.

As for alternatives they're not really "better" but you can expand it as far as you want to:

  • You can check the Event Log for failed connection attempts. Just because you can connect doesn't mean the critical application which uses an AD account which just expired when it wasn't meant to, can connect. This is actually pretty useful. If you're not tracking failed logins then you absolutely should start, whether it's the event log, an audit, extended event, or standard trace.

  • Are all the databases online / sync'd? Just because you can connect to master doesn't mean one of the disks hasn't disconnected and caused the database to go into suspect mode.

  • You can use WMI/CIM to determine whether the service is running. Is your Agent running? It better be because otherwise your backups and other processes are probably going to stop. You're probably going to want to use WMI/CIM to check that.

  • Technically you can write a WMI handler which gets injected onto the server which can trigger an email notification when the SQL service stops/starts unexpectedly. But this is tricky and I wouldn't bother.

  • You could query performance counters to pull back logins/sec to see whether it has dropped radically from the norm. But it would be so tricky to identify outliers it's probably not worth the effort. On the other hand if it increases to> 1000 per second (4 million per hour, thanks to a broken Oracle software reading from SQL!) it can indicate a problem, so maybe you do want to catch it.

answered May 3, 2016 at 15:43
1
  • Thanks for your input, what is a good application to do such work appart from the multi-thousand dollar redgate aplications ? Commented May 3, 2016 at 18:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.