Page 1 of 1

Using WMI - Check if my SQL Instance is up

Posted: Thu Jan 26, 2017 3:25 pm
by brdr
Hi Support Team,

We use XI 5.2.2. We are completely agentless with regards to our Nagios checks.

We have SQL Servers typically running many SQL DB instances running on each. I want to detect if an instance goes down.

This WMI query below works well returning PERF related data for each instance. We don't usually use this perf data from this class.

wmic -Uusr%pwd //DBSERVER "SELECT * FROM Win32_PerfRawData_MSSQLSERVER_SQLSERVERDatabases"

However, there is no field in this class that tells me the state of the instance.

Do you have a method using WMI remotely to check if a particular instance is running, or not?

Thanks,
brdr

Re: Using WMI - Check if my SQL Instance is up

Posted: Thu Jan 26, 2017 5:18 pm
by avandemore
What wmic are you referring to? Can you show us the full service and command definition? It seems you might be more interested in using:

Code: Select all

# /usr/local/nagios/libexec/check_nt -h
However you are using a really old version of XI if possible I would upgrade to 5.4.1 prior to solving this issue.

Re: Using WMI - Check if my SQL Instance is up

Posted: Fri Jan 27, 2017 6:40 am
by brdr
wmic is a WMI client program that runs on Linux (and other OSs). wmic is the basis for all WMI checks in Nagios on Linux into window servers inan agentless environment.

Our version is not really old. And, upgrading is not going to help with my question (solving my problem). :)

Re: Using WMI - Check if my SQL Instance is up

Posted: Fri Jan 27, 2017 1:32 pm
by rkennedy
Is there a specific process that runs for the instance? Might be able to check this out through WMI. Otherwise, we can look to see if there is a counter which specifies possibly a 0 or 1 if it's up. Can you run typeperf.exe -q > C:\perfcounters.txt on the Windows machine, and attach perfcounters.txt to this post? (you may need to save to a different folder pending permissions)

Re: Using WMI - Check if my SQL Instance is up

Posted: Wed Feb 01, 2017 3:32 pm
by brdr
output from command.

Re: Using WMI - Check if my SQL Instance is up

Posted: Wed Feb 01, 2017 5:03 pm
by tgriep
If you are interested in looking to see if a process or a service is running on the Windows system, here are a few examples you can look at and tailor for your needs.
This one checks for a process running, supply the name of the .exe file

Code: Select all

/usr/local/nagios/libexex/check_wmi_plus.pl -H xxx.xxx.xxx.xxx -u username -p password -m checkprocess -s Commandline -a 'csrss.exe'
This one checks for is a service is running, supply the name of the service name swich you can get from services.msc.

Code: Select all

/usr/local/nagios/libexex/check_wmi_plus.pl -H xxx.xxx.xxx.xxx -u username -p password -m checkservice -a 'MSSQLSERVICE'
If you have any questions, post them here.
BTW, you can run the Windows WMI wizard for setting up the system for what you are looking for.

Re: Using WMI - Check if my SQL Instance is up

Posted: Thu Feb 02, 2017 12:09 pm
by SteveBeauchemin
Have you thought of using a plugin to test MSSQL instances?

If agentless is important... look at the check_mssql_health plugin.

Code: Select all

./check_mssql_health --help
Copyright (c) 2009 Gerhard Lausser


  Check various parameters of MSSQL databases

  Usage:
    check_mssql_health [-v] [-t <timeout>] --hostname=<db server hostname>
        --username=<username> --password=<password> [--port <port>]
        --mode=<mode>
    check_mssql_health [-v] [-t <timeout>] --server=<db server>
        --username=<username> --password=<password>
        --mode=<mode>
    check_mssql_health [-h | --help]
    check_mssql_health [-V | --version]

  Options:
    --hostname
       the database server
    --port
       the database server's port
    --server
       the name of a predefined connection
    --currentdb
       the name of a database which is used as the current database
       for the connection. (don't use this parameter unless you
       know what you're doing)
    --username
       the mssql user
    --password
       the mssql user's password
    --warning
       the warning range
    --critical
       the critical range
    --mode
       the mode of the plugin. select one of the following keywords:
       connection-time                  (Time to connect to the server)
       cpu-busy                         (Cpu busy in percent)
       io-busy                          (IO busy in percent)
       full-scans                       (Full table scans per second)
       connected-users                  (Number of currently connected users)
       transactions                     (Transactions per second (per database))
       batch-requests                   (Batch requests per second)
       latches-waits                    (Number of latch requests that could not be granted immediately)
       latches-wait-time                (Average time for a latch to wait before the request is met)
       locks-waits                      (The number of locks per second that had to wait)
       locks-timeouts                   (The number of locks per second that timed out)
       locks-deadlocks                  (The number of deadlocks per second)
       sql-recompilations               (Re-Compilations per second)
       sql-initcompilations             (Initial compilations per second)
       total-server-memory              (The amount of memory that SQL Server has allocated to it)
       mem-pool-data-buffer-hit-ratio   (Data Buffer Cache Hit Ratio)
       lazy-writes                      (Lazy writes per second)
       page-life-expectancy             (Seconds a page is kept in memory before being flushed)
       free-list-stalls                 (Requests per second that had to wait for a free page)
       checkpoint-pages                 (Dirty pages flushed to disk per second. (usually by a checkpoint))
       database-online                  (Check if a database is online and accepting connections)
       database-free                    (Free space in database)
       database-backup-age              (Elapsed time (in hours) since a database was last backed up)
       database-logbackup-age           (Elapsed time (in hours) since a database transaction log was last backed up)
       database-file-auto-growths       (The number of File Auto Grow events (either data or log) in the last <n> minutes (use --lookback))
       database-logfile-auto-growths    (The number of Log File Auto Grow events in the last <n> minutes (use --lookback))
       database-datafile-auto-growths   (The number of Data File Auto Grow events in the last <n> minutes (use --lookback))
       database-file-auto-shrinks       (The number of File Auto Shrink events (either data or log) in the last <n> minutes (use --lookback))
       database-logfile-auto-shrinks    (The number of Log File Auto Shrink events in the last <n> minutes (use --lookback))
       database-datafile-auto-shrinks   (The number of Data File Auto Shrink events in the last <n> minutes (use --lookback))
       database-file-dbcc-shrinks       (The number of DBCC File Shrink events (either data or log) in the last <n> minutes (use --lookback))
       failed-jobs                      (The jobs which did not exit successful in the last <n> minutes (use --lookback))
       jobs-enabled                     (The jobs which are not enabled (scheduled))
       sql                              (any sql command returning a single number)
       sql-runtime                      (the time an sql command needs to run)
       list-databases                   (convenience function which lists all databases)
       list-datafiles                   (convenience function which lists all datafiles)
       list-locks                       (convenience function which lists all locks)

    --name
       the name of the database etc depending on the mode.
    --name2
       if name is a sql statement, this statement would appear in
       the output and the performance data. This can be ugly, so
       name2 can be used to appear instead.
    --regexp
       if this parameter is used, name will be interpreted as a
       regular expression.
    --units
       one of %, KB, MB, GB. This is used for a better output of mode=sql
       and for specifying thresholds for mode=tablespace-free
    --offlineok
       if mode database-free finds a database which is currently offline,
       a WARNING is issued. If you don't want this and if offline databases
       are perfectly ok for you, then add --offlineok. You will get OK instead.
    --commit
       turns on autocommit for the dbd::sybase module

  Database-related modes check all databases in one run by default.
  If only a single database should be checked, use the --name parameter.
  The same applies to datafile-related modes.
  If an additional --regexp is added, --name's argument will be interpreted
  as a regular expression.
  The parameter --mitigation lets you classify the severity of an offline
  tablespace.

  In mode sql you can url-encode the statement so you will not have to mess
  around with special characters in your Nagios service definitions.
  Instead of
  --name="select count(*) from master..sysprocesses"
  you can say
  --name=select%20count%28%2A%29%20from%20master%2E%2Esysprocesses
  For your convenience you can call check_mssql_health with the --encode
  option and it will encode the standard input.

  You can find the full documentation for this plugin at
  http://labs.consol.de/nagios/check_mssql_health or


Send email to [email protected] if you have questions
regarding use of this software.
Please include version information with all correspondence (when possible,
use output from the --version option of the plugin itself).
WMI has it's place. Not here I think. Just my opinion.

Steve B

Re: Using WMI - Check if my SQL Instance is up

Posted: Thu Feb 02, 2017 12:34 pm
by dwhitfield
@brdr, were either of the last two responses useful for you?

If you do try the check_mssql_health plugin and experience issues, it's probably best to open a new thread so people aren't confused.

Re: Using WMI - Check if my SQL Instance is up

Posted: Fri Feb 03, 2017 9:58 am
by brdr
I agree WMI has its place. I hadn't looked at check_mssql_health plugin. Though, I was hoping I could make the call for database (at the instance level) status (up/down) without using db user creds as we have couple hundred instances. Thx.

I will continue to research.

Plz close thread. Thx.

Re: Using WMI - Check if my SQL Instance is up

Posted: Fri Feb 03, 2017 10:19 am
by rkennedy
Will close this one up! Feel free to make a new thread if you have questions in the future.