You are on page 1of 7

MSSQL

Monitoring a Windows SQL server is an aspect that many Nagios administrators will need to do.  One of the better 
plugins for this is check_mssql_health.  This plugin provides health related checks that are useful in understanding the 
status of a SQL server.  

Installation

Nagios Exchange lists the plugin here:
http://exchange.nagios.org/directory/Plugins/Databases/SQLServer/check_mssql_health/details

The website for download is here:
http://labs.consol.de/nagios/check_mssql_health/

Download the script into a directory, untar it, download and install the prerequisites and then compile the plugin.  Be 
sure to install the perl­DBD­Sybase as this is important to how it functions.

cd /usr/local/src

Install the rpmforge repository.
wget http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge­release­
0.3.6­1.el5.rf.i386.rpm

rpm ­Uhv  rpmforge­release­0.3.6­1.el5.rf.i386.rpm

wget http://labs.consol.de/wp­content/uploads/2011/01/check_mssql_health­
1.5.8.2.tar.gz 
  tar zxvf check_mssql_health­1.5.8.2.tar.gz 
cd cd check_mssql_health­1.5.8.2 

yum install ­y perl­DBD­Sybase 

  ./configure 
­­­cut­­­
configure: creating ./config.status 
config.status: creating Makefile 
config.status: creating plugins­scripts/Makefile 
config.status: creating plugins­scripts/subst 
config.status: creating t/Makefile 
                       ­­with­perl: /usr/bin/perl 
             ­­with­statefiles­dir: /var/tmp/check_mssql_health 
                ­­with­nagios­user: nagios 
               ­­with­nagios­group: nagios 
              ­­with­mymodules­dir: /usr/local/nagios/libexec 
          ­­with­mymodules­dyn­dir: /usr/local/nagios/libexec

make
make install

Options
There are a number of options you should pay attention to in building commands.

­­hostname <hostname> The database server 
­­username <username> The database user 
­­password <password> The database password
­­port <port> The port, where the server listens (Default: 1433) 
­­server <server> An alternative to hostname+port. <server> will be looked up in the file freetds.conf. 
­­mode <modus> With the mode­parameter you tell the plugin what you want it to do. 
­­name <objectname> Several checks can be limited to a single object (e.g. a specific database). 
­­name2 <string> If you use –mode=sql, the SQL­statement will be shown in the plugin output and the performance 
data (which looks ugly). The parameter name2 can be used to provide a used­defined string. 
­­warning <range> Values outside this range result in a WARNING. 
­­critical <range> Values outside this range result in a CRITICAL. 
­­environment <variable>=<wert> It is possible to set environment variables at runtime 
­­method <connectmethode> which connection method it should use.
­­units <%|KB|MB|GB> This parameter adds units to the performance, when using mod
­­dbthresholds With this parameter thresholds are read from the database table check_mssql_health_thresholds 

Mode is a very important parameter.

    ­­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­free                  (Free space in database) 
       database­backup­age            (Elapsed time (in hours) since a database was last backupped) 
       sql                            (any sql command returning a single number) 
       list­databases                 (convenience function which lists all databases) 
       list­datafiles                 (convenience function which lists all datafiles) 
       list­locks                     (convenience function which lists all locks) 

Keyword   Meaning   Range of result 


connection­time  Measures how long it takes to login  0..n seconds (1, 5) 
connected­users  Number of connected users  0..n (50, 80) 
cpu­busy  CPU Busy Time  0%..100% (80, 90) 
io­busy  IO Busy Time  0%..100% (80, 90) 
full­scans  Number of Full Table Scans per second  0..n (100, 500) 
transactions  Number of Transactions per second  0..n (10000, 50000) 
batch­requests  Number of Batch Requests per second  0..n (100, 200) 
latches­waits  Number of Latch­Requests per second, which could not be fulfilled  0..n (10, 50) 
latches­wait­time  Average time a Latch­Request had to wait until it was granted  0..n ms (1, 5) 
locks­waits  Number of Lock­Requests per second, which could not be satisfied.  0..n (100, 500) 
locks­timeouts  Number of Lock­Requests per second, which resulted in a timeout.  0..n (1, 5) 
locks­deadlocks  Number of Deadlocks per second  0..n (1, 5) 
sql­recompilations  Number of Re­Compilations per second  0..n (1, 10) 
sql­initcompilations  Number of Initial Compilations per second  0..n (100, 200) 
total­server­memory  The main memory reserved for the SQL Server  0..n (nearly1G, 1G) 
mem­pool­data­buffer­hit­ratio  Data Buffer Cache Hit Ratio  0%..100% (90, 80:) 
lazy­writes  Number of Lazy Writes per second  0..n (20, 40) 
page­life­expectancy  Average time a page stays in main memory  0..n (300:, 180:) 
free­list­stalls  Number of Free List Stalls per second  0..n (4, 10) 
checkpoint­pages  Number of Flushed Dirty Pages per second  0..n () 
database­free  Free space in a database  0%..100% (5%, 2%) 
database­backup­age  Elapsed time since a database was last backupped. 0..n 
sql  Result of a user­defined SQL statement, which returns a numerical value. The statement is passed to the 
plugin as an argument to the –sql parameter. A label for the performancedata can be defined with the –name2 
parameter. A unit can be appended by using –units. If the SQL statement contains special characters, it is 
recommended to encode it first by calling check_mssql_health with the –encode parameter and sending the statement 
to STDIN.  0..n 
list­databases  Returns a list of all databases   
list­locks  Returns a list of all locks   

Examples from the Command Line
It is a good idea to check from the command line before you enter those settings into service definitions.  Here are a 
few examples.  Note in these examples the hostname is an IP Address, you will need DNS resolution for a hostname. 
The user and password are listed in order to gain access to the database.  Be sure you limit this user as this is plain text 
over the wire.

 ./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode cpu­busy 
OK ­ CPU busy 0.22% | cpu_busy=0.22;80;90 

./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode io­busy 
OK ­ IO busy 0.00% | io_busy=0.00;80;90 

  ./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode transactions 
OK ­ tempdb has 0.0000 transactions / sec, msdb has 0.0000 transactions / sec, 
model has 0.0000 transactions / sec, master has 0.0000 transactions / sec, _Total 
has 0.0000 transactions / sec, ReportServerTempDB has 0.0000 transactions / sec, 
ReportServer has 0.0000 transactions / sec | 
tempdb_transactions_per_sec=0.0000;10000;50000 
msdb_transactions_per_sec=0.0000;10000;50000 
model_transactions_per_sec=0.0000;10000;50000 
master_transactions_per_sec=0.0000;10000;50000 
_Total_transactions_per_sec=0.0000;10000;50000 
ReportServerTempDB_transactions_per_sec=0.0000;10000;50000 
ReportServer_transactions_per_sec=0.0000;10000;50000 
 
./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode list­databases 
ReportServer 
ReportServerTempDB 
master 
model 
msdb 
tempdb 
OK ­ have fun 

  ./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode list­datafiles 
master 
mastlog 
tempdev 
templog 
MSDBData 
MSDBLog 
master 
mastlog 
modeldev 
modellog 
tempdev 
templog 
master 
mastlog 
modeldev 
modellog 
tempdev 
templog 
master 
mastlog 
MSDBData 
MSDBLog 
ReportServer 
ReportServerTempDB 
ReportServerTempDB_log 
ReportServer_log 
master 
mastlog 
modeldev 
modellog 
tempdev 
templog 
MSDBData 
MSDBLog 
ReportServer 
ReportServer_log 
master 
mastlog 
modeldev 
modellog 
tempdev 
templog 
OK ­ have fun, have fun, have fun, have fun, have fun, have fun 

 
 ./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode list­locks  
AllocUnit 
Application 
Database 
Extent 
File 
HoBT 
Key 
Metadata 
Object 
Page 
RID 
_Total 
OK ­ have fun 

./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode connected­users 
OK ­ 3 connected users | connected_users=3;50;80 

 ./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode batch­requests 
OK ­ 0.00 batch requests / sec | batch_requests_per_sec=0.00;100;200 

 ./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode batch­requests ­name master 
OK ­ 0.00 batch requests / sec | batch_requests_per_sec=0.00;100;200 

  ./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode page­life­expectancy 
OK ­ page life expectancy is 4521 seconds | page_life_expectancy=4521;300:;180: 

./check_mssql_health ­­hostname 184.106.77.67 ­­username nagios ­­password 
linux ­­mode database­backup­age ­­name model 
CRITICAL ­ model was never backupped | 'model_bck_age'=0;48;72 'model_bck_time'=0 

Command Definition 
This example of a command definition lists the hostname, user and password for the server.  This makes it much easier 
when the service definitions are set up but it also will require multiple definitions if you have multiple servers. 
 define command{ 
        command_name            check_mssql _health
        command_line            $USER1$/check_mssql_health ­­hostname 
184.106.77.67 ­­username nagios ­­password linux ­­mode $ARG1$ 

Service Definitions
In this example the host definition is listed with service definitions which may be the case if you are only checking one 
server.  These all use the port 1433 so one check is designed to monitor the port itself with a tcp check.

define host{ 
       use                             windows­server 
       host_name                       win2008 
       alias                           Windows Server 
       address                         184.106.77.67 

define service{ 
        use                      generic­service 
        host_name                win2008 
        service_description      SQL Connectivity 1433 
        check_command            check_tcp!1433 

define service{ 
        use                             generic­service 
        host_name                       win2008 
        service_description             SQL io­busy 
        check_command                   check_mssql _health!io­busy 

define service{ 
        use                             generic­service 
        host_name                       win2008 
        service_description             SQL Backup of model 
        check_command                   check_mssql _health!database­backup­age 
­­name model 

define service{ 
        use                             generic­service 
        host_name                       win2008 
        service_description             SQL Page Life 
        check_command                   check_mssql _health!page­life­expectancy 

define service{ 
        use                             generic­service 
        host_name                       win2008 
        service_description             SQL Locks 
        check_command                   check_mssql _health!list­locks 

define service{ 
        use                             generic­service 
        host_name                       win2008 
        service_description             SQL Datafiles 
        check_command                   check_mssql _health!list­datafiles 

define service{ 
        use                             generic­service 
        host_name                       win2008 
        service_description             SQL Databases 
        check_command                   check_mssql _health!list­databases 

define service{ 
        use                             generic­service 
        host_name                       win2008 
        service_description             SQL Connected Users 
        check_command                   check_mssql _health!connected­users 

It is best practice to test from the command line first. Be sure the Windows server firewall is open on port 1433 for the 
Nagios server only as the username and password are plain text.

You might also like