no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | monitors:bbsql-server [2010/09/14 19:11] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== monitor script for Microsoft SQL server 2000 and up ====== | ||
+ | |||
+ | ^ Author | [[ bart.gillis@cegeka.be| Bart Gillis]] | | ||
+ | ^ Compatibility | Xymon 4.2 | | ||
+ | ^ Requirements | BBWin 0.12 | | ||
+ | ^ Download | None | | ||
+ | ^ Last Update | 2010-03-25| | ||
+ | |||
+ | ===== Description ===== | ||
+ | This is a port of the bbsql-server script that was written 03/2002 by Jason Benassi (jbenassi at futurecasting.com) | ||
+ | Used for monitoring MS SQL Server | ||
+ | * Blocking Locks -> This test will look at a 20 minute window for database jobs | ||
+ | * Statistics on " | ||
+ | * Statistics on the Size and usage of the transaction logs | ||
+ | |||
+ | ===== Installation ===== | ||
+ | === Client side === | ||
+ | * Install BBWin 0.12 on the MSSQL server | ||
+ | * Place this script anywhere on your SQL-Server 7, 2000, 2005 or 2008 server. | ||
+ | * Configure the BBWin client to execute this script as an external script. | ||
+ | * Alternatively you can configure BBWin in central mode and schedule this script in the Windows " | ||
+ | === Server side === | ||
+ | (none) | ||
+ | ==== bbsql-server.vbs ==== | ||
+ | <hidden onHidden=" | ||
+ | <code vb> | ||
+ | ' Script for Xymon (Big Brother) Monitoring Tool | ||
+ | ' Modified 02/2010 By Bart Gillis | ||
+ | ' email: Bart.Gillis@cegeka.be | ||
+ | ' This is a port of the bbsql-server script that was written 03/2002 by Jason Benassi | ||
+ | ' | ||
+ | ' Used for monitoring SQL Server Blocking Locks | ||
+ | ' And database jobs | ||
+ | ' This test will look at a 20 minute window for database jobs | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | ' Modification History: | ||
+ | ' bbsql-server-v2.0 | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | ' bbsql-server-v3.0 | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | ' bbsql-server-v3.0.1 | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | Dim version, ws, extPath, testName, testString, gbFailed, outputfilename, | ||
+ | |||
+ | ' | ||
+ | |||
+ | testName = " | ||
+ | version = " | ||
+ | |||
+ | ' | ||
+ | outputfilename = replace(testName," | ||
+ | tempfilename = outputfilename & " | ||
+ | Const adStateClosed = 0 | ||
+ | |||
+ | Set ws = WScript.CreateObject(" | ||
+ | ProcessorCheck | ||
+ | if Proc = " | ||
+ | ' | ||
+ | | ||
+ | WScript.Echo Proc | ||
+ | else | ||
+ | ' | ||
+ | | ||
+ | WScript.Echo Proc | ||
+ | end if | ||
+ | gbFailed = false | ||
+ | CheckJobStats extPath | ||
+ | CheckLocks | ||
+ | CheckBackup | ||
+ | CheckTransactionlog | ||
+ | WriteFile extPath | ||
+ | |||
+ | Sub WriteFile (strFilePath) | ||
+ | Set fso = CreateObject(" | ||
+ | If gbFailed = False Then | ||
+ | | ||
+ | Else | ||
+ | | ||
+ | End If | ||
+ | Set f = fso.OpenTextFile(strFilePath & " | ||
+ | f.Write testString | ||
+ | f.Close | ||
+ | Set fso = Nothing | ||
+ | End Sub | ||
+ | |||
+ | Sub CheckLocks | ||
+ | Dim cn, rs, sqlStr, strResult, htmlcolorcode | ||
+ | Set cn = CreateObject (" | ||
+ | cn.Open " | ||
+ | Set rs = CreateObject (" | ||
+ | htmlcolorcode="## | ||
+ | | ||
+ | sqlStr = _ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "FROM master.dbo.syslockinfo l1, " & _ | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "WHERE l1.rsc_type = v.number " & _ | ||
+ | "AND v.type = ' | ||
+ | "AND l1.req_status = x.number " & _ | ||
+ | "AND x.type = ' | ||
+ | "AND l1.req_mode + 1 = u.number " & _ | ||
+ | "AND u.type = ' | ||
+ | "AND l1.rsc_type <>2 /* NOT a DB lock */ " & _ | ||
+ | "AND l1.rsc_dbid = l2.rsc_dbid " & _ | ||
+ | "AND l1.rsc_bin = l2.rsc_bin " & _ | ||
+ | "AND l1.rsc_objid = l2.rsc_objid " & _ | ||
+ | "AND l1.rsc_indid = l2.rsc_indid " & _ | ||
+ | "AND l1.req_spid <> l2.req_spid " & _ | ||
+ | "AND l1.req_status <> l2.req_status " & _ | ||
+ | "ORDER BY substring (l1.rsc_text, | ||
+ | rs.Open sqlStr, cn , 3 ,3 | ||
+ | |||
+ | If Not rs.EOF Then | ||
+ | | ||
+ | Do While Not rs.EOF | ||
+ | htmlcolorcode="# | ||
+ | gbFailed = True | ||
+ | strResult = strResult & " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | wscript.echo " | ||
+ | rs.MoveNext | ||
+ | Loop | ||
+ | Else | ||
+ | strResult = strResult & vbcrlf & " | ||
+ | | ||
+ | End If | ||
+ | testString = testString & "< | ||
+ | testString = testString & strResult | ||
+ | |||
+ | Set rs = Nothing | ||
+ | Set cn = Nothing | ||
+ | | ||
+ | End Sub | ||
+ | |||
+ | Sub CheckJobStats (strFilePath) | ||
+ | Dim cn, rs, cmd, sqlStr, fso, f, htmlStr1, htmlStr2, rColor, strStatus, tmpStr, bFailed, htmlcolorcode | ||
+ | Set cn = CreateObject(" | ||
+ | cn.Open " | ||
+ | |||
+ | sqlStr = " | ||
+ | "FOR " & _ | ||
+ | " | ||
+ | "OPEN all_jobs_cursor " & _ | ||
+ | " | ||
+ | "FETCH NEXT FROM all_jobs_cursor " & _ | ||
+ | "INTO @current_id " & _ | ||
+ | "WHILE @@FETCH_STATUS = 0 " & _ | ||
+ | "BEGIN " & _ | ||
+ | " | ||
+ | "WHERE s.job_id = v.job_id and s.job_id = @current_id " & _ | ||
+ | "and cast(cast(run_date as varchar)+' | ||
+ | "ORDER BY instance_id " & _ | ||
+ | "FETCH NEXT FROM all_jobs_cursor " & _ | ||
+ | "INTO @current_id " & _ | ||
+ | "END " & _ | ||
+ | "CLOSE all_jobs_cursor " & _ | ||
+ | " | ||
+ | Set rs = cn.Execute(sqlStr) | ||
+ | |||
+ | bFailed = False | ||
+ | strStatus = " | ||
+ | htmlcolorcode= "# | ||
+ | |||
+ | Set fso = CreateObject(" | ||
+ | Do Until rs Is Nothing | ||
+ | if NOT rs.State = adStateClosed then | ||
+ | Set f = fso.OpenTextFile(strFilePath & " | ||
+ | rCnt = 1 | ||
+ | If Not rs.EOF Then | ||
+ | Do While Not rs.EOF | ||
+ | bFailed = False | ||
+ | If rs.Fields(" | ||
+ | strStatus = " | ||
+ | End If | ||
+ | |||
+ | If rs.Fields(" | ||
+ | bFailed = True | ||
+ | rColor = "& | ||
+ | htmlcolorcode = "# | ||
+ | Else | ||
+ | bFailed = False | ||
+ | rColor = "& | ||
+ | htmlcolorcode = "# | ||
+ | End If | ||
+ | |||
+ | If Not rCnt > 1 Then | ||
+ | f.Write " | ||
+ | End If | ||
+ | msg = replace(rs.Fields(" | ||
+ | str = " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | f.Write str | ||
+ | wscript.echo str | ||
+ | |||
+ | rCnt = rCnt + 1 | ||
+ | rs.MoveNext | ||
+ | Loop | ||
+ | f.Write vbcrlf & vbcrlf | ||
+ | End If | ||
+ | If bFailed = True Then | ||
+ | gbFailed = True | ||
+ | End If | ||
+ | f.Close | ||
+ | rCnt = 1 | ||
+ | End If | ||
+ | Set rs = rs.NextRecordSet | ||
+ | | ||
+ | Loop | ||
+ | if fso.FileExists(strFilePath & " | ||
+ | Set f = fso.OpenTextFile(strFilePath & " | ||
+ | If Not f.AtEndOfLine Then | ||
+ | | ||
+ | Else | ||
+ | | ||
+ | End If | ||
+ | | ||
+ | | ||
+ | else | ||
+ | | ||
+ | end if | ||
+ | |||
+ | tmpStr = "< | ||
+ | |||
+ | testString = testString & tmpStr & vbcrlf & vbcrlf | ||
+ | |||
+ | Set fso = Nothing | ||
+ | Set cn = Nothing | ||
+ | Set rs = Nothing | ||
+ | End Sub | ||
+ | | ||
+ | Sub ProcessorCheck () | ||
+ | Dim WshShell, WshSysEnv | ||
+ | |||
+ | Set WshShell = WScript.CreateObject(" | ||
+ | Set WshSysEnv = WshShell.Environment(" | ||
+ | Proc = WshSysEnv(" | ||
+ | End Sub | ||
+ | |||
+ | Sub CheckBackup () | ||
+ | Dim cn, rs, sqlStr, strStatus, htmlcolorcode ,strResult | ||
+ | Set cn = CreateObject (" | ||
+ | cn.Open " | ||
+ | Set rs = CreateObject (" | ||
+ | htmlcolorcode = "# | ||
+ | strResult = vbcrlf & "< | ||
+ | " | ||
+ | " | ||
+ | sqlStr = _ | ||
+ | " | ||
+ | "FROM master.dbo.sysdatabases db " & _ | ||
+ | "LEFT JOIN msdb..backupset bu ON ( db.name = bu.database_name ) " & _ | ||
+ | "WHERE db.name != ' | ||
+ | "group by db.name" | ||
+ | Set rs = cn.Execute(sqlStr) | ||
+ | ' | ||
+ | Do While Not rs.EOF | ||
+ | strResult = strResult &_ | ||
+ | "< | ||
+ | | ||
+ | rs.MoveNext | ||
+ | Loop | ||
+ | strResult = strResult & "</ | ||
+ | testString = testString & vbcrlf & "< | ||
+ | Wscript.Echo strStatus & strResult | ||
+ | testString = testString & strResult | ||
+ | End Sub | ||
+ | |||
+ | Sub CheckTransactionlog () | ||
+ | Dim cn, rs, sqlStr, strStatus, htmlcolorcode ,strResult | ||
+ | Set cn = CreateObject (" | ||
+ | cn.Open " | ||
+ | Set rs = CreateObject (" | ||
+ | htmlcolorcode = "# | ||
+ | strResult = vbcrlf & "< | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | sqlStr = _ | ||
+ | "DBCC SQLPERF (logspace)" | ||
+ | Set rs = cn.Execute(sqlStr) | ||
+ | ' | ||
+ | Do While Not rs.EOF | ||
+ | strResult = strResult &_ | ||
+ | "< | ||
+ | | ||
+ | | ||
+ | rs.MoveNext | ||
+ | Loop | ||
+ | strResult = strResult & "</ | ||
+ | testString = testString & vbcrlf & "< | ||
+ | Wscript.Echo strStatus & strResult | ||
+ | testString = testString & strResult | ||
+ | End Sub | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Known Bugs and Issues ===== | ||
+ | |||
+ | ===== To Do ===== | ||
+ | I still have to implement some alerting on | ||
+ | * the latest finished Database Backup date and time check | ||
+ | * “Log Size” and “Log space used” of the transaction log check | ||
+ | |||
+ | ===== Credits ===== | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * **2003-11-24 ** | ||
+ | * Initial release: Downloaded from deadcat.net | ||
+ | |||
+ | * **2006-05-20** bbsql-server-v2.0 | ||
+ | * Changed the SQL connection string. Authentication to a trusted server -> No password information required in this script. | ||
+ | * 32 bit/64 bit processor architecture check. | ||
+ | |||
+ | * **2010-03-25** | ||
+ | * Check the latest finished Database Backup date and time | ||
+ | * Check "Log Size" and "Log space used" of the transaction log. | ||
+ | * **2010-04-16** bbsql-server-v3.0.1 | ||
+ | * Minor bug fix around line 122 (Thank you Richard Finegold) the script only opened the file if it exists, then deletes immediately after reading instead of after the variable assignment. | ||
+ | * changed <td> to <th> in table headers (Thank you Richard Finegold) | ||
+ | |||