博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SQL Server 性能基线和监控
阅读量:6501 次
发布时间:2019-06-24

本文共 5286 字,大约阅读时间需要 17 分钟。

就讲讲监控那些值,基线抓的是那些值。如何做告警

环境:windows 2008r2,sql server 2008r2 sp1

性能基线:

  cpu:

    \Processor(_Total)\% Processor Time

    \Processor(_Total)\% Privileged Time

    \SQLServer:SQL Statistics\Batch Requests/sec

    \SQLServer:SQL Statistics\SQL Compilations/sec
    \SQLServer:SQL Statistics\SQL Re-Compilations/sec
    \System\Processor Queue Length
    \System\Context Switches/sec

  Memory:

    \Memory\Available Bytes

    \Memory\Pages/sec
    \Memory\Page Faults/sec
    \Memory\Pages Input/sec
    \Memory\Pages Output/sec
    \Process(sqlservr)\Private Bytes
    \SQLServer:Buffer Manager\Buffer cache hit ratio
    \SQLServer:Buffer Manager\Page life expectancy
    \SQLServer:Buffer Manager\Lazy writes/sec
    \SQLServer:Memory Manager\Memory Grants Pending
    \SQLServer:Memory Manager\Target Server Memory (KB)
    \SQLServer:Memory Manager\Total Server Memory (KB)

  Disk:

    \PhysicalDisk(_Total)\% Disk Time

    \PhysicalDisk(_Total)\Current Disk Queue Length
    \PhysicalDisk(_Total)\Avg. Disk Queue Length
    \PhysicalDisk(_Total)\Disk Transfers/sec
    \PhysicalDisk(_Total)\Disk Bytes/sec
    \PhysicalDisk(_Total)\Avg. Disk sec/Read
    \PhysicalDisk(_Total)\Avg. Disk sec/Write

  SQL Server:

    \SQLServer:Access Methods\FreeSpace Scans/sec

    \SQLServer:Access Methods\Full Scans/sec
    \SQLServer:Access Methods\Table Lock Escalations/sec
    \SQLServer:Access Methods\Worktables Created/sec
    \SQLServer:General Statistics\Processes blocked
    \SQLServer:General Statistics\User Connections
    \SQLServer:Latches\Total Latch Wait Time (ms)
    \SQLServer:Locks(_Total)\Lock Timeouts (timeout > 0)/sec
    \SQLServer:Locks(_Total)\Lock Wait Time (ms)
    \SQLServer:Locks(_Total)\Number of Deadlocks/sec
    \SQLServer:SQL Statistics\Batch Requests/sec
    \SQLServer:SQL Statistics\SQL Re-Compilations/sec

以上是性能基线监控的信息,当然性能警告也是监控这些信息,其中的阀值是根据基线抓取后体现。

关于性能警告我是使用powershell 写了一个脚本,运行在SQL Agent 中。如果出现警告,就通过dbmail 发送邮件

关于powershell 脚本和一些配置信息看如下:

$server = "(local)"$uid = "sa"$db="master"$pwd="pwd"$mailprfname = "sina"$recipients = "xxxxx@qq.com"$subject = "Proformance Alter"$computernamexml = "f:\computername.xml"$alter_cpuxml = "f:\alter_cpu.xml"function GetServerName($xmlpath){    $xml = [xml] (Get-Content $xmlpath)    $return = New-Object Collections.Generic.List[string]    for($i = 0;$i -lt $xml.computernames.ChildNodes.Count;$i++)    {        if ( $xml.computernames.ChildNodes.Count -eq 1)        {            $cp = [string]$xml.computernames.computername        }        else        {            $cp = [string]$xml.computernames.computername[$i]        }        $return.Add($cp.Trim())    }    $return}function GetAlterCounter($xmlpath){    $xml = [xml] (Get-Content $xmlpath)    $return = New-Object Collections.Generic.List[string]    $list = $xml.counters.Counter    $list}function CreateAlter($message){    $SqlConnection = New-Object System.Data.SqlClient.SqlConnection     $CnnString ="Server = $server; Database = $db;User Id = $uid; Password = $pwd"     $SqlConnection.ConnectionString = $CnnString     $CC = $SqlConnection.CreateCommand();     if (-not ($SqlConnection.State -like "Open")) { $SqlConnection.Open() }         $cc.CommandText=" EXEC msdb..sp_send_dbmail             @profile_name  = '$mailprfname'            ,@recipients = '$recipients'            ,@body = '$message'            ,@subject = '$subject'"     $cc.ExecuteNonQuery()|out-null     $SqlConnection.Close();}$names = GetServerName($computernamexml)$pfcounters = GetAlterCounter($alter_cpuxml)foreach($cp in $names){    $p = New-Object Collections.Generic.List[string]    $report = ""    foreach ($pfc in $pfcounters)    {        $b = ""        $counter ="\\"+$cp+$pfc.get_InnerText().Trim()        $p.Add($counter)            }    $count = Get-Counter $p    for ($i = 0; $i -lt $count.CounterSamples.Count; $i++)    {        $v = $count.CounterSamples.Get($i).CookedValue        $pfc = $pfcounters[$i]        #$pfc.get_InnerText()        $b = ""        $lg = ""        if($pfc.operator -eq "lt")        {            if ($v -ge [double]$pfc.alter)                {
$b = "alter" $lg = "Greater Than"} } elseif ($pfc.operator -eq "gt") { if( $v -le [double]$pfc.alter) {
$b = "alter" $lg = "Less Than"} } if($b -eq "alter") { $path = "\\"+$cp+$pfc.get_InnerText() $item = "{0}:{1};{2} Threshold:{3}" -f $path,$v.ToString(),$lg,$pfc.alter.Trim() $report += $item + "`n" } } if($report -ne "") { #生产警告 参数 计数器,阀值,当前值 CreateAlter $report }}

其中涉及到2个配置文件:computernamexml,alter_cpuxml分别如下:

fanr-pc
\Processor(_Total)\% Processor Time
\Processor(_Total)\% Privileged Time
\SQLServer:SQL Statistics\Batch Requests/sec
\SQLServer:SQL Statistics\SQL Compilations/sec
\SQLServer:SQL Statistics\SQL Re-Compilations/sec
\System\Processor Queue Length
\System\Context Switches/sec

其中 alter 就是阀值,如第一条,如果 阀值 > 性能计数器值,就会发出警告。

 

    

转载地址:http://tgvyo.baihongyu.com/

你可能感兴趣的文章
ps切图教程 android,PS前端切图完整教程
查看>>
html显示服务器状态,显示服务器时间并一直显示(html代码)
查看>>
在线html代码优化,网站seo优化html代码方法
查看>>
html中嵌入flv视频直播,html中嵌入flv格式文件的代码
查看>>
我的世界html启动器资源,我的世界hmcl启动器mod
查看>>
HTML如何把输入框变成必填值,required输入框为必填项
查看>>
在html中哪一个不是链接的目标属性,HTML试题
查看>>
android otg 挂载流程,android USB OTG功能如何打开及实现
查看>>
html属性board,pin_board.html
查看>>
html定位有几种,POSITION定位有哪几种?各有什么特点?
查看>>
苹果平板可以用html么,如何将ipad苹果平板电脑中的safari浏览器禁用
查看>>
背锅侠逆袭之路
查看>>
移动互联企业级应用三大场景
查看>>
vmware的APD和PDL详细解析
查看>>
理解:思科设备上的网络地址翻译功能(NAT)功能
查看>>
演示:使用协议分析器取证IPv6的报文结构
查看>>
oracle 11gr2 rac中的4种IP解说
查看>>
为什么你找不到工作?
查看>>
一名合格的测试员应具备的素质
查看>>
SCCM 2007系列3 配置
查看>>