Module 18 Monitoring SQL Server 2008 R2. Module Overview Monitoring Activity Capturing and Managing...

Preview:

Citation preview

Module 18

Monitoring SQL Server 2008 R2

Module Overview

• Monitoring Activity

• Capturing and Managing Performance Data

• Analyzing Collected Performance Data

Lesson 1: Monitoring Activity

• Overview of Dynamic Management Views and Functions

• Viewing Activity using Dynamic Management Views

• Demonstration 1A: Viewing Activity using Dynamic Management Views

• Working with Activity Monitor in SQL Server Management Studio

• Demonstration 1B: Working with Activity Monitor in SQL Server Management Studio

• Working with Reliability and Performance Monitor

• Working with SQL Server Counters

• Demonstration 1C: Working with Reliability and Performance Monitor

Overview of Dynamic Management Views and Functions

• Organized by category

• Many other categories available

Category Description

sys.dm_exec_% Execution and Connection

sys.dm_os_% SQL OS related information

sys.dm_tran_% Transaction Management

sys.dm_io_% I/O related information

sys.dm_db_% Database scoped information

Dynamic Management Objects are virtual views and functions that provide state data for SQL Server systems.

Viewing Activity using Dynamic Management Views

• Must be referenced using the sys schema

• Two basic types: Current status information

Accumulated historical information

SELECT s.original_login_name, s.program_name, t.wait_type, t.wait_duration_ms

FROM sys.dm_os_waiting_tasks AS tINNER JOIN sys.dm_exec_sessions AS sON t.session_id = s.session_idWHERE s.is_user_process = 1AND t.wait_duration_ms > 3000;

SELECT * FROM sys.dm_os_wait_statsORDER BY wait_time_ms DESC;

SELECT s.original_login_name, s.program_name, t.wait_type, t.wait_duration_ms

FROM sys.dm_os_waiting_tasks AS tINNER JOIN sys.dm_exec_sessions AS sON t.session_id = s.session_idWHERE s.is_user_process = 1AND t.wait_duration_ms > 3000;

SELECT * FROM sys.dm_os_wait_statsORDER BY wait_time_ms DESC;

Demonstration 1A: Viewing Activity using Dynamic Management Views

• In this demonstration, you will see how to use DMVs to view performance information

Working with Activity Monitor in SQL Server Management Studio

• Shows information about SQL Server Processes, Waits, I/O and expensive Queries

• Accesses SQL Server through Dynamic Management Objects• Requires VIEW SERVER STATE permission• Can be used to kill processes that block others

• Shows information about SQL Server Processes, Waits, I/O and expensive Queries

• Accesses SQL Server through Dynamic Management Objects• Requires VIEW SERVER STATE permission• Can be used to kill processes that block others

Demonstration 1B: Working with Activity Monitor in SQL Server Management Studio

• In this demonstration, you will see: How to use Activity Monitor to view process information

How to kill a process using Activity Monitor

Working with Reliability and Performance Monitor

• Used to collect and view system metrics

• Provides real time monitoring of health and performance counters

• Creates data collector sets that capture data from different data collectors either on demand or scheduled

Key areas to monitor

• CPU• Memory• Disk System• Network• SQL Server Counters

Key areas to monitor

• CPU• Memory• Disk System• Network• SQL Server Counters

Working with SQL Server Counters

• SQL Server exposes objects to Performance and Reliability Monitor Each object contains one or more counters

Each counter can have one or more instances

Multi-instance counters also provide a total

• Also available through sys.dm_os_performance_counters

Object Counter Instance

Demonstration 1C: Working with Reliability and Performance Monitor

• In this demonstration, you will see how to use Windows Reliability and Performance Monitor

Lesson 2: Capturing and Managing Performance Data

• Overview of Data Collector

• Designing a Data Collector Topology

• Configuring Data Collector

• Data Collector Security

• Monitoring Data Collector

• Demonstration 2A: Configuring Data Collector

Overview of Data Collector

Low overhead data collection

Persistence of diagnostics data

Data retention

Rich reporting

Easy extensibility

Central repository for several SQL Server instances

Data Collector is a component of SQL Server that collects capacity planning and performance data over time.

Designing a Data Collector Topology

• SSIS and SQL Agent jobs are used to send data to the central database

• SSMS is used to access Reports

Data Repository

Centralized Data Storage

Reporting

Data Collector

Performance CounterSQL TraceT-SQL

Data Collector

Performance CounterSQL TraceT-SQL

Configuring Data Collector

• Wizard-based Setup

• Two-step process:

1. Create the Management Data Warehouse

2. Configure Data Collector on all instances to be monitored

• Plan for enough space inManagement Data Warehouse

• Configuration creates System Data Collection Sets Data to be collected

Frequency of collection

Retention period

• Custom Data Collection Sets can be added

Data Collector Security

Role Description

mdw_admin Full access to the management data warehouse

mdw_writer Write and read access. Needed by data collectors

mdw_reader Read access. Needed by users accessing Reports

Role Description

dc_admin Full administrator access to the configuration

dc_operator Read and update access to the configuration

dc_proxy Read access to the configuration

Roles for the Management Data Warehouse:

Roles for Configuring the Data Collector:

Monitoring Data Collector

• Configuration and Log written to msdb Implemented via stored procedures and SSIS logging features

• Three logging levels are available

• Retention is based on collection set retention

• Logs can be viewed using T-SQL or Log File Viewer

Demonstration 2A: Configuring Data Collector

• In this demonstration you will see how to configure data collector

Lesson 3: Analyzing Collected Performance Data

• Overview of Data Collector Reports

• Disk Usage Report

• Demonstration 3A: Disk Usage Report

• Server Activity Report

• Demonstration 3B: Server Activity Report

• Query Statistics Report

• Demonstration 3C: Query Statistics Report

Overview of Data Collector Reports

• Disk Usage Summary Trends and details on disk and file usage

• Query Statistics History Most expensive queries ranked by: CPU, Duration, Reads,

Writes

• Server Activity History CPU, Memory, Disk and Network I/O SQL Server Waits and SQL Server Activity

Data Collector provides a series of cross-linked reports on historical data. The reports are visible from within SQL Server Management Studio.

Disk Usage Report

Based on Disk Usage System Data Collection Set

• T-SQL collector type

• Not cached, runs every 6 hours by default

• Stored for 730 days by default

Demonstration 3A: Disk Usage Report

• In this demonstration, you will see the information that is available in a disk usage report

Server Activity Report

• Based on Server Activity System Data Collection Set DMV snapshot and performance counter collector types

Runs every 60 seconds and uploaded every 15 minutes by default

Retained for 14 days by default

• Provides many sub-reportswith detailed informationon SQL Server and Windowsprocesses

• Crossed linked to Query Statistics Reports

Demonstration 3B: Server Activity Report

• In this demonstration, you will see the information that is available in a server activity report

Query Statistics Report

• Based on Query Statistics System Data Collection Set Query activity collector type

Runs every 10 seconds and uploaded every 15 minutes by default

Retained for 14 days by default

• Expensive queries are gathered including both thequery text and the query plan

Demonstration 3C: Query Statistics Report

• In this demonstration, you will see the information that is available in a query statistics report

Lab 18: Monitoring SQL Server 2008 R2

• Exercise 1: Investigating DMVs

• Exercise 2: Configure Management Data Warehouse

• Exercise 3: Configure Instances for Data Collection

• Challenge Exercise 4: Work with Data Collector Reports (Only if time permits)

Logon information

Estimated time: 45 minutes

Virtual machine 623XB-MIA-SQL

User name AdventureWorks\Administrator

Password Pa$$w0rd

Lab Scenario

The earlier versions of SQL Server that you have worked with did not include dynamic management functions and views. You have recently read about these and are interested to see how they might be used for collecting performance information.

Rather than collecting information separately for each SQL Server instance, you have decided to collect all the performance information to a central server. This will help when dealing with issues that were not reported to the helpdesk at the time they occurred.

Lab Review

• How can you locate long running queries using the Data Collector reports?

• When performance counters have multiple instances, how do you view the total for all instances?

Module Review and Takeaways

• Review Questions

• Best Practices

Recommended