MySQL Server 慢查询百分比监视器

Microsoft.MySQLServer.ManagedServer.Unix.SlowQueryPct.Monitor (UnitMonitor)

Knowledge Base article:

摘要

MySQL Server 慢查询占所有查询的百分数。慢查询是指 MySQL 数据库上运行的、运行时长超过全局变量“long_query_time”的查询。此监视器从全局变量“Slow_queries”获取慢查询的数量,然后除以全局状态变量“Queries”中的查询数量。对于 MySQL 5.0 和 5.1,查询数量是以下全局状态变量之和:“Questions”、“Com_ping”、“Com_statistics”、“Com_stmt_prepare”、“Com_stmt_close”和“Com_stmt_reset”。此监视器阈值是按照轮询过程中返回给代理的平均值分析的,其中“样本数”参数控制平均值计算中所包含的样本数。

原因

运行不正常状态表示运行时长大于全局变量“long_query_time”的查询的百分比高。

解决方案

要解决慢查询百分比高的问题,可在配置文件中打开慢查询日志记录来确定慢查询。要完成此操作,可在实例组选项下添加以下行和目标日志文件路径:“log-slow-queries= file path to log”。或者可使用以下选项启动服务器:“--log-slow-queries=file path to log”。

配置

默认配置

参数

默认值

警告阈值

大于 15

错误阈值

大于 25

样本数

3

替代可用于更改以上为所有实例或为特定实例或组定义的参数值。

Element properties:

TargetMicrosoft.MySQLServer.ManagedServer.Unix
Parent MonitorMicrosoft.MySQLServer.RowOperationsPerformanceRollup
CategoryPerformanceHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityMatchMonitorHealth
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.Oss.WSManEnumeration.GreaterThanThreshold.ThreeState.MonitorType
RemotableTrue
AccessibilityPublic
Alert Message
MySQL Server 慢查询百分比
MySQL Server 的当前慢查询百分比 ({0}\%) 高
RunAsDefault

Source Code:

<UnitMonitor ID="Microsoft.MySQLServer.ManagedServer.Unix.SlowQueryPct.Monitor" Accessibility="Public" Target="Microsoft.MySQLServer.ManagedServer.Unix" TypeID="Oss!Microsoft.Oss.WSManEnumeration.GreaterThanThreshold.ThreeState.MonitorType" Enabled="onStandardMonitoring" ParentMonitorID="Microsoft.MySQLServer.RowOperationsPerformanceRollup">
<Category>PerformanceHealth</Category>
<AlertSettings AlertMessage="Microsoft.MySQLServer.ManagedServer.Unix.SlowQueryPct.AlertMessage">
<AlertOnState>Warning</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>MatchMonitorHealth</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Data/Context/Value$</AlertParameter1>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState HealthState="Success" MonitorTypeStateID="StatusOK" ID="UnderThreshold"/>
<OperationalState HealthState="Warning" MonitorTypeStateID="StatusWarning" ID="OverWarningThreshold"/>
<OperationalState HealthState="Error" MonitorTypeStateID="StatusError" ID="OverErrorThreshold"/>
</OperationalStates>
<Configuration>
<Interval>300</Interval>
<TargetSystem>$Target/Host/Property[Type="Unix!Microsoft.Unix.Computer"]/NetworkName$</TargetSystem>
<Uri>http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/MySQL_ServerStatistics?__cimnamespace=root/mysql</Uri>
<WSManFilter/>
<ObjectName>MySQL Server</ObjectName>
<CounterName>Slow Query Pct</CounterName>
<InstanceXPath>/DataItem/WsManData/*[local-name(.)='MySQL_ServerStatistics']/*[local-name(.)='InstanceID']</InstanceXPath>
<InstanceName>$Target/Property[Type="Microsoft.MySQLServer.Installation"]/InstanceID$</InstanceName>
<Value>$Data/WsManData/*[local-name(.)='MySQL_ServerStatistics']/*[local-name(.)='SlowQueryPct']$</Value>
<WarningThreshold>15</WarningThreshold>
<ErrorThreshold>25</ErrorThreshold>
<NumSamples>3</NumSamples>
</Configuration>
</UnitMonitor>