@@ -1189,7 +1189,7 @@ AND st.text NOT LIKE 'sp_server_diagnostics%'
1189
/// </summary>
1189
/// </summary>
1190
/// <param name="s"></param>
1190
/// <param name="s"></param>
1191
/// <returns></returns>
1191
/// <returns></returns>
1192
- public static DataTable DashboardPLE ( this smo . Server s )
1192
+ public static DataTable DashboardPle ( this smo . Server s )
1193
{
1193
{
1194
smo . Database d = s . Databases [ "master" ] ;
1194
smo . Database d = s . Databases [ "master" ] ;
1195
string sql = @"SELECT[cntr_value] as PLE
1195
string sql = @"SELECT[cntr_value] as PLE
@@ -1199,6 +1199,45 @@ WHERE object_name LIKE '%Manager%'
1199
return d . ExecuteWithResults ( sql ) . Tables [ 0 ] ;
1199
return d . ExecuteWithResults ( sql ) . Tables [ 0 ] ;
1200
}
1200
}
1201
1201
1202
+ /// <summary>
1203
+ /// Get the sql and system cpu average of the last 30 minutes
1204
+ /// </summary>
1205
+ /// <param name="s"></param>
1206
+ /// <returns></returns>
1207
+ public static DataTable DashboardCpu ( this smo . Server s )
1208
+ {
1209
+ smo . Database d = s . Databases [ "master" ] ;
1210
+ const string sql = @"DECLARE @ts_now bigint
1211
+ SELECT @ts_now = cpu_ticks / (cpu_ticks / ms_ticks)
1212
+ FROM sys.dm_os_sys_info
1213
+ ;WITH ring AS
1214
+ (
1215
+ SELECT
1216
+ record.value('(Record/@id)[1]', 'int') AS record_id,
1217
+ DATEADD (ms, -1 * (@ts_now - [timestamp]), GETDATE()) AS EventTime,
1218
+ 100 - record.value('(Record/SchedulerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') AS system_cpu_utilization_post_sp2,
1219
+ record.value('(Record/SchedulerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int') AS sql_cpu_utilization_post_sp2 ,
1220
+ 100 - record.value('(Record/SchedluerMonitorEvent/SystemHealth/SystemIdle)[1]', 'int') AS system_cpu_utilization_pre_sp2,
1221
+ record.value('(Record/SchedluerMonitorEvent/SystemHealth/ProcessUtilization)[1]', 'int') AS sql_cpu_utilization_pre_sp2
1222
+ FROM (
1223
+ SELECT TOP 30 timestamp, CONVERT (xml, record) AS record
1224
+ FROM sys.dm_os_ring_buffers
1225
+ WHERE ring_buffer_type = 'RING_BUFFER_SCHEDULER_MONITOR'
1226
+ AND record LIKE '%<SystemHealth>%'
1227
+ ORDER BY timestamp DESC) AS t
1228
+ ), cte AS
1229
+ (
1230
+ SELECT EventTime
1231
+ , CASE WHEN system_cpu_utilization_post_sp2 IS NOT NULL THEN system_cpu_utilization_post_sp2 ELSE system_cpu_utilization_pre_sp2 END AS system_cpu
1232
+ , CASE WHEN sql_cpu_utilization_post_sp2 IS NOT NULL THEN sql_cpu_utilization_post_sp2 ELSE sql_cpu_utilization_pre_sp2 END AS sql_cpu
1233
+ FROM ring
1234
+ )
1235
+ SELECT AVG(system_cpu) AS system_cpu
1236
+ , AVG(CASE WHEN sql_cpu > system_cpu THEN sql_cpu / 2 ELSE sql_cpu END) AS cpu
1237
+ FROM cte" ;
1238
+ return d . ExecuteWithResults ( sql ) . Tables [ 0 ] ;
1239
+ }
1240
+
1202
1241
1203
public static bool IsOleAutomationProcedureActivated ( this smo . Server s )
1242
public static bool IsOleAutomationProcedureActivated ( this smo . Server s )
1204
{
1243
{
0 commit comments