Posts

Showing posts with the label Monitoring

Transactional Log file used space monitoring

Following is the T-SQL script to monitor the transactional log file. It specifies the size of log file and how much is being used out of it and also calculates the percentage of use. Also gives information on log file growht and size limit and mentions what it is waiting to reuse the log file. --//-------------------------------------//-- --// Credits http://sqlgear.blogspot.com //-- --//-------------------------------------//-- DECLARE @LogFilePercentUsed INT SET @LogFilePercentUsed = 60 --//Modify the value here to set the threshold SELECT db.NAME ,db.log_reuse_wait_desc ,ls.cntr_value / 1024 AS SizeMB ,lu.cntr_value / 1024 AS UsedMB ,(CAST(lu.cntr_value AS FLOAT) / CAST(ls.cntr_value AS FLOAT)) * 100 AS UsedPercent ,@LogFilePercentUsed AS Threshold ,CASE WHEN (CAST(lu.cntr_value AS FLOAT) / CAST(ls.cntr_value AS FLOAT)) * 100 > @LogFilePercentUsed THEN CASE WHEN db.NAME = 'tempdb' AND log_reuse_wait_desc NOT IN ( 'CHECKPOINT' ...

SQL Server Services Monitoring with PowerShell

Following is the PowerShell script to monitor SQL Server Services. I schedule it to run periodically on each Windows server hosting SQL Server instances, one or more than one. It checks for SQL Server database and agent services which are stopped and attempts to restart them. It also sends email if it finds a service in stopped state. $ServiceNameLike = "SQL Server (*" $Status = "Stopped" $To = "admin@email.com" $Node = gc env:computername $From = $Node +"@email.com" $smtpServer = "mail.server.com" $smtp = new-object Net.Mail.SmtpClient($smtpServer) $StoppedServices=get-service | Where-Object {$_.DisplayName -like $ServiceNameLike -and $_.Status -eq $Status} if ($StoppedServices -ne $null) { foreach ($Service in $StoppedServices) { $Subject = "Attempting to restart service " + $Service.DisplayName + " on "+ $Node $Body = "Service " + $Service.DisplayName + " on "+ ...

Get disk space warnings through PowerShell

Image
Credits Susan NYC I use powershell scripts for disk free space monitoring on servers. Following are the task performed by the script: Clears the content of D:\lowdisk.txt. Adds required headers to D:\lowdisk.txt. Checks through all drives if free disk space is less than specified threshold. If a disk has free space less than threshold then adds info to D:\lowdisk.txt. Mails to users the contents of the  D:\lowdisk.txt if any disk is having free space less than threshold. To know how to execute the PowerShell scripts go to Executing a PowerShell script . Following is the code for the script. You can schedule it using windows scheduler. #Modify the below threshold value as required. It represents the minimum percent of free disk space required. $threshold = 10 #Add the recipients below. Example $To="user1@mail.com", "user2@mail.com", "user3@mail.com" $To = "email@mail.com" $smtpServer = "mail.server.com" $Node = gc env:comput...

Make Money from Surveys