Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Monitoring SQL Server With Alerts and Notifications

Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Module 10

Monitoring SQL Server with Alerts


and Notifications
Module Overview

• Monitoring SQL Server Errors


• Configuring Database Mail
• Operators, Alerts, and Notifications
• Alerts in Azure SQL Database
Lesson 1: Monitoring SQL Server Errors

• What Is an Error?
• Error Severity Levels
• Configuring the SQL Server Error Log
• Demonstration: Working with the Database Engine
Error Log
What Is an Error?

• Errors raised by Database Engine have the


following properties:
Property Description
Error number Unique identifying number.
Error message String describing the cause of the error.
Severity Integer describing the seriousness of the error.
State Integer describing the condition of the error.
Procedure name String containing the name of the stored
procedure or trigger where the error occurred.
Line number Integer containing the line number at which the
error occurred.
Error Severity Levels

• The severity of an error indicates the type of


problem that SQL Server encounters:
Range Description
0 to 9 Informational messages.
10 Informational messages that return status information or
report non-sever errors.
11 to 16 Errors that can be corrected by the user.
17 to 19 Software errors that cannot be corrected by the user.
20 – 24 Serious system errors.
Error Severity Example
Configuring the SQL Server Error Log

• SQL Server writes severe errors to the


Application event log and SQL Server logs

• SQL Server
creates a new
error log file
when it starts:
• Retains six log
files by default
• Uses sp_cycle_errorlog to force a new file
• Default size of each log is unlimited
SQL Log File Viewer
Lesson 2: Configuring Database Mail

• Overview of Database Mail


• Database Mail Profiles
• Database Mail Security
• Database Mail Logs and Retention
• Demonstration: Configuring Database Mail
Overview of Database Mail

• An implementation of an SMTP client, used to


enable database components to send email:
• As part of a job
• In response to an alert
• From a stored procedure
• Set up by using the Database Mail Configuration
Wizard, or through msdb.dbo.sysmail… stored
procedures
Database Mail Profiles

• Collection of one or more accounts


• Defines configuration fro sending mail
• Enables multiple accounts for reliability
Profile Description
Private Accessible only to members of sysadmin role or those
granted permission by members of sysadmin role.
Public Accessible to any member of the sysadmin role or the
DatabaseMailUserRole database role in msdb.

• A default private profile takes precedence over the


default public profile
Database Mail Security

• Control access to Database Mail by:


• SQL Server service account
• Global enable/disable—disabled by default
• Membership of msdb.DatabaseMailUserRole
• Users’ access to private profiles
• You can prohibit the use of specific file extensions and
set file attachment size limits
• If SQL Server runs as a local service, it does not have
permission to make outgoing network connections
• Meaning, Database Mail cannot contact an email server located on
a different computer
Database Mail Logs and Retention

• Database Mail logs event messages at a level:


• Normal
• Extended
• Verbose

• Database Mail stores all email and attachments


• Need to plan a retention policy

EXECUTE
dbo.sysmail_delete_mailitems_sp
@sent_before = @CutoffDate;

EXECUTE dbo.sysmail_delete_log_sp
@logged_before = @CutoffDate;
Lesson 3: Operators, Alerts, and Notifications

• SQL Server Agent Operator Overview


• Demonstration: Configuring SQL Server Agent
Operators
• Overview of SQL Server Alerts
• Creating Alerts
• Configuring Alert Actions
• Troubleshooting Alerts and Notifications
• Demonstration: Configuring SQL Server Agent
Alerts
SQL Server Agent Operator Overview

• An operator is a person or group of people who


can receive notifications from a job or alert
• Operators can be notified by using:
• Email
• Pager (deprecated)
• Net send (deprecated)

• Configure SQL Server Agent jobs to notify an


operator on success, failure, or both
Overview of SQL Server Alerts

• An alert is a predefined response to an event

• Alerts can be triggered by:


• Logged SQL Server events
• SQL Server performance conditions
• WMI events

• Alerts can:
• Notify an operator
• Start a job
WMI Event from 411 (Group Policy)
On Another Windows Note…
Creating Alerts

• Create alerts:
• Using SSMS
• Using sp_add_alert

• Alerts are triggered only when the associated


error is written to the Windows Event Log
• Check sys.messages.is_event_logged to determine
which errors are automatically logged
• Amend error definition or raise errors using the
RAISERROR WITH LOG option to force an error to
be logged
Configuring Alert Actions

• Actions:
• Execute a job
• Notify one or more operator

• When using notifications, you can optionally use


tokens to add more detail
Troubleshooting Alerts and Notifications

1. Ensure that SQL Server Agent is running


2. Ensure that SQL Server Agent is configured to
send email
3. Check that the error message is written to the
Application Log
4. Ensure that the alert is enabled
5. Check that the alert was raised
6. Check if the alert was raised, but no action was
taken
Lesson 4: Alerts in Azure SQL Database

• Alerts in Azure SQL Database Overview


• Configuring Alerts in Azure SQL Database
• Demonstration: Configuring Alerts in Azure SQL
Database
Alerts in Azure SQL Database Overview

• Alerting uses the common Azure alerts system


• Azure SQL Database alerts can only be defined:
• At database level
• On predefined metrics

• Alerts can be delivered:


• By email
• To an HTTP/HTTPS endpoint

• A message is sent each time the alert threshold is


crossed:
• When the alert is triggered
• When the alert metric returns to normal
Configuring Alerts in Azure SQL Database

• Create alerts using the Azure portal, or using


Azure PowerShell
• Define the attributes of the alert:
• Alert resource (what is being monitored)
• Alert name (give your alert a name)
• Alert metric (what you are alerting on)
• Alert condition (>, >=, <, or <=)
• Alert threshold (value that is not good)
• Alert period (how long you want to monitor for)
Lab: Monitoring SQL Server with Alerts and
Notifications

• Exercise 1: Configuring Database Mail


• Exercise 2: Configuring Operators
• Exercise 3: Configuring Alerts and Notifications
• Exercise 4: Testing Alerts and Notifications

Logon Information
Virtual machine: 20764C-MIA-SQL
User name: ADVENTUREWORKS\Student
Password: Pa55w.rd

Estimated Time: 60 minutes

You might also like