27
Gather Microsoft SQL Server Performance Data with Windows PowerShell Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306

Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Embed Size (px)

Citation preview

Page 1: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Gather Microsoft SQL Server Performance Data with Windows PowerShellAllen WhiteUpSearch Technology ServicesSQL Server MVP

SESSION CODE: DAT306

Page 2: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

About MeSQL Server Consultant with UpsearchOver 35 years in ITCareer covered multiple disciplines – operations, development, telecommunications, network design/administration and database design and administrationStarted using Sybase in 1992, MS SQL Server in 1995Microsoft Certified IT Professional: Database Administrator and Database Developer, Microsoft Certified Trainer (MCT)Awarded Microsoft MVP Award for SQL Server for last 3 years

Page 3: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

53 MVPs Coalesce

www.SQLServerMVPDeepDives.com

Page 4: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

AgendaPerformance CountersCapture OptionsPowerShell ScriptPerformance Analysis ReportNotifications

Page 5: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Goal - Capture Performance BaselineBaseline shows normal performanceDeviations from Baseline require investigationProblem

Data comes from disparate sourcesCoordination of multiple gathering toolsSynchronizing data for true baseline analysis

SolutionPowerShell

Gather SQL Server Performance Data with PowerShell

Page 6: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Key Performance IndicatorsWhich counters show us system healthThere’s no “right” answerThese are my choices

Gather SQL Server Performance Data with PowerShell

Page 7: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Operating System Counters

Object Counter Look For

Processor % Processor Time Should be <= 80%

Memory Available MBytesLow Memory, Server Paging

Paging File(_Total) % Usage Should be < 70%

PhysicalDisk(*) Disk Reads/secBaseline, watch for unusual variations

PhysicalDisk(*) Disk Writes/secBaseline, watch for unusual variations

System Processor Queue Length> 10 threads/proc and CPU > 80% is concern

Gather SQL Server Performance Data with PowerShell

Page 8: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

SQL Server Counters

Object Counter Look For

Access Methods Forwarded Records/secShould be < 10 per 100 batch requests/sec

Access Methods Page Splits/secShould be <20 per 100 batch requests/sec

Buffer Manager Buffer cache hit ratio Should be > 90%

Buffer Manager Page life expectancy Should be >=300

General Statistics Processes blocked Baseline, check for changes

SQL Statistics Batch Requests/sec > 1000 is busy system

SQL Statistics SQL Compilations/secShould be < 10% of batch requests/sec

SQL Statistics SQL Re-Compilations/secShould be < 10% of compilations/sec

Gather SQL Server Performance Data with PowerShell

Page 9: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Sources for Performance Data

PerfmonSave data to .CSVUse SSIS or PowerShell to import results

DMVsGreat source of SQL Server data

sys.dm_os_performance_countersOnly returns SQL Server current instance counters

WMIAllows access to all aspects of serverCrunching the numbers can be tricky

Gather SQL Server Performance Data with PowerShell

Page 10: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Performance Data in PowerShellGet-Counter cmdlet (PowerShell 2.0)

Invocation sets own interval handlerSystem.Diagnostics.PerformanceCounter

Support directly within .NETResults directly match Perfmon valuesAccessible from PowerShell

Gather SQL Server Performance Data with PowerShell

Page 11: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Collecting PerformanceCounter data

DEMO

Page 12: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Performance Database

Every Admin should have oneStore Baseline DataStore Server Side Trace infoStore Server and Instance infoKeep all management info in one place

Gather SQL Server Performance Data with PowerShell

Page 13: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Scripting the Data Capture

Capture the counter dataInsert into Performance DatabaseWait defined interval and do it again

Gather SQL Server Performance Data with PowerShell

Page 14: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Capture the counter data# Initialize Perfcounters$ppt = new-object System.Diagnostics.PerformanceCounter$ppt.CategoryName = 'Processor'$ppt.CounterName = '% Processor Time'$ppt.InstanceName = '_Total'

Page 15: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Logic Flow for getperf.ps1

Gather SQL Server Performance Data with PowerShell

Connect to ServerFind Instances

Initialize Server

Counters

For Each Instance

Initialize Instance Counters

While Not EndDate

Capture Server Counters

For Each Instance

Capture Instance Counters

Page 16: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

The getperf.ps1 script

DEMO

Page 17: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Creating the Analysis Reports

Create Basic ReportAdd Table for Counter DataAdd Graphs to see TrendsAdd Dashboard Report to SSMS

Demo

Gather SQL Server Performance Data with PowerShell

Page 18: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Notifications

Once Baseline is understoodDefine deviation amount for warningDefine deviation amount for error condition

Build notification mechanismsIf warning send emailIf error send text message

SQL Server Agent Alerts can watch some counters

Gather SQL Server Performance Data with PowerShell

Page 19: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Build Alerts with PowerShell

DEMO

Page 20: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

References

Master-PowerShell | With Dr. Tobias Weltnerhttp://powershell.com/cs/blogs/ebook/default.aspx

Let PowerShell do an Inventory of your Servershttp://www.simple-talk.com/sql/database-administration/let-powershell-do-an-inventory-of-your-servers/

Initialize-SqlpsEnvironment.ps1 scripthttp://blogs.msdn.com/mwories/archive/2008/06/14/SQL2008_5F00_Powershell.aspx

Midnight DBA – PowerShell webcastshttp://midnightdba.itbookworm.com/

Gather SQL Server Performance Data with PowerShell

Page 21: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Thank you

Page 22: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

DAT Track Scratch 2 Win

Find the DAT Track Surface Table in the Yellow Section of the TLCTry your luck to win a Zune HDSimply scratch the game pieces on the DAT Track Surface Table and Match 3 Zune HDs to win

Page 23: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Resources

www.microsoft.com/teched

Sessions On-Demand & Community Microsoft Certification & Training Resources

Resources for IT Professionals Resources for Developers

www.microsoft.com/learning

http://microsoft.com/technet http://microsoft.com/msdn

Learning

Page 24: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Complete an evaluation on CommNet and enter to win!

Page 25: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

Sign up for Tech·Ed 2011 and save $500 starting June 8 – June 31st

http://northamerica.msteched.com/registration

You can also register at the

North America 2011 kiosk located at registrationJoin us in Atlanta next year

Page 26: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

© 2010 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to

be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Page 27: Allen White UpSearch Technology Services SQL Server MVP SESSION CODE: DAT306 Gather SQL Server Performance Data with PowerShell

JUNE 7-10, 2010 | NEW ORLEANS, LA