Escolar Documentos
Profissional Documentos
Cultura Documentos
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 perlDBDSybase 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/rpmforgerelease
0.3.61.el5.rf.i386.rpm
rpm Uhv rpmforgerelease0.3.61.el5.rf.i386.rpm
wget http://labs.consol.de/wpcontent/uploads/2011/01/check_mssql_health
1.5.8.2.tar.gz
tar zxvf check_mssql_health1.5.8.2.tar.gz
cd cd check_mssql_health1.5.8.2
yum install y perlDBDSybase
./configure
cut
configure: creating ./config.status
config.status: creating Makefile
config.status: creating pluginsscripts/Makefile
config.status: creating pluginsscripts/subst
config.status: creating t/Makefile
withperl: /usr/bin/perl
withstatefilesdir: /var/tmp/check_mssql_health
withnagiosuser: nagios
withnagiosgroup: nagios
withmymodulesdir: /usr/local/nagios/libexec
withmymodulesdyndir: /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 modeparameter 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 SQLstatement will be shown in the plugin output and the performance
data (which looks ugly). The parameter name2 can be used to provide a useddefined 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:
connectiontime (Time to connect to the server)
cpubusy (Cpu busy in percent)
iobusy (IO busy in percent)
fullscans (Full table scans per second)
connectedusers (Number of currently connected users)
transactions (Transactions per second (per database))
batchrequests (Batch requests per second)
latcheswaits (Number of latch requests that could not be granted immediately)
latcheswaittime (Average time for a latch to wait before the request is met)
lockswaits (The number of locks per second that had to wait)
lockstimeouts (The number of locks per second that timed out)
locksdeadlocks (The number of deadlocks per second)
sqlrecompilations (ReCompilations per second)
sqlinitcompilations (Initial compilations per second)
totalservermemory (The amount of memory that SQL Server has allocated to it)
mempooldatabufferhitratio (Data Buffer Cache Hit Ratio)
lazywrites (Lazy writes per second)
pagelifeexpectancy (Seconds a page is kept in memory before being flushed)
freeliststalls (Requests per second that had to wait for a free page)
checkpointpages (Dirty pages flushed to disk per second. (usually by a checkpoint))
databasefree (Free space in database)
databasebackupage (Elapsed time (in hours) since a database was last backupped)
sql (any sql command returning a single number)
listdatabases (convenience function which lists all databases)
listdatafiles (convenience function which lists all datafiles)
listlocks (convenience function which lists 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 cpubusy
OK CPU busy 0.22% | cpu_busy=0.22;80;90
./check_mssql_health hostname 184.106.77.67 username nagios password
linux mode iobusy
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 listdatabases
ReportServer
ReportServerTempDB
master
model
msdb
tempdb
OK have fun
./check_mssql_health hostname 184.106.77.67 username nagios password
linux mode listdatafiles
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 listlocks
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 connectedusers
OK 3 connected users | connected_users=3;50;80
./check_mssql_health hostname 184.106.77.67 username nagios password
linux mode batchrequests
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 batchrequests 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 pagelifeexpectancy
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 databasebackupage 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 windowsserver
host_name win2008
alias Windows Server
address 184.106.77.67
}
define service{
use genericservice
host_name win2008
service_description SQL Connectivity 1433
check_command check_tcp!1433
}
define service{
use genericservice
host_name win2008
service_description SQL iobusy
check_command check_mssql _health!iobusy
}
define service{
use genericservice
host_name win2008
service_description SQL Backup of model
check_command check_mssql _health!databasebackupage
name model
}
define service{
use genericservice
host_name win2008
service_description SQL Page Life
check_command check_mssql _health!pagelifeexpectancy
}
define service{
use genericservice
host_name win2008
service_description SQL Locks
check_command check_mssql _health!listlocks
}
define service{
use genericservice
host_name win2008
service_description SQL Datafiles
check_command check_mssql _health!listdatafiles
}
define service{
use genericservice
host_name win2008
service_description SQL Databases
check_command check_mssql _health!listdatabases
}
define service{
use genericservice
host_name win2008
service_description SQL Connected Users
check_command check_mssql _health!connectedusers
}
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.