Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add views and SQL to show top writes in Opserver #437

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/Opserver.Core/Data/SQL/SQLInstance.TopOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class TopOperation : ISQLVersioned
public long AvgReads { get; internal set; }
public long TotalReads { get; internal set; }
public decimal PercentReads { get; internal set; }
public long AvgWrites { get; internal set; }
public long TotalWrites { get; internal set; }
public decimal PercentWrites { get; internal set; }
public long ExecutionCount { get; internal set; }
public decimal PercentExecutions { get; internal set; }
public decimal ExecutionsPerMinute { get; internal set; }
Expand Down Expand Up @@ -82,9 +85,9 @@ public ShowPlanXML GetShowPlanXML()
}

internal const string FetchSQL = @"
SELECT AvgCPU, AvgDuration, AvgReads, AvgCPUPerMinute,
TotalCPU, TotalDuration, TotalReads,
PercentCPU, PercentDuration, PercentReads, PercentExecutions,
SELECT AvgCPU, AvgDuration, AvgReads, AvgCPUPerMinute, AvgWrites,
TotalCPU, TotalDuration, TotalReads, TotalWrites,
PercentCPU, PercentDuration, PercentReads, PercentExecutions, PercentWrites,
ExecutionCount,
ExecutionsPerMinute,
PlanCreationTime, LastExecutionTime,
Expand All @@ -109,17 +112,20 @@ ELSE StatementEndOffset
total_worker_time / execution_count AS AvgCPU,
total_elapsed_time / execution_count AS AvgDuration,
total_logical_reads / execution_count AS AvgReads,
total_logical_writes / execution_count AS AvgWrites,
Cast(total_worker_time / age_minutes As BigInt) AS AvgCPUPerMinute,
execution_count / age_minutes AS ExecutionsPerMinute,
Cast(total_worker_time / age_minutes_lifetime As BigInt) AS AvgCPUPerMinuteLifetime,
execution_count / age_minutes_lifetime AS ExecutionsPerMinuteLifetime,
total_worker_time AS TotalCPU,
total_elapsed_time AS TotalDuration,
total_logical_reads AS TotalReads,
total_logical_writes AS TotalWrites,
execution_count ExecutionCount,
CAST(ROUND(100.00 * total_worker_time / t.TotalWorker, 2) AS MONEY) AS PercentCPU,
CAST(ROUND(100.00 * total_elapsed_time / t.TotalElapsed, 2) AS MONEY) AS PercentDuration,
CAST(ROUND(100.00 * total_logical_reads / t.TotalReads, 2) AS MONEY) AS PercentReads,
CAST(ROUND(100.00 * total_logical_writes / t.TotalWrites, 2) AS MONEY) AS PercentWrites,
CAST(ROUND(100.00 * execution_count / t.TotalExecs, 2) AS MONEY) AS PercentExecutions,
qs.creation_time AS PlanCreationTime,
qs.last_execution_time AS LastExecutionTime,
Expand All @@ -144,7 +150,8 @@ THEN DATEDIFF(second, creation_time, last_execution_time) / 60.0
CROSS JOIN(SELECT SUM(execution_count) TotalExecs,
SUM(total_elapsed_time) TotalElapsed,
SUM(total_worker_time) TotalWorker,
SUM(Cast(total_logical_reads as DECIMAL(38,0))) TotalReads
SUM(Cast(total_logical_reads as DECIMAL(38,0))) TotalReads,
SUM(Cast(total_logical_writes as DECIMAL(38,0))) TotalWrites
FROM sys.dm_exec_query_stats) AS t
CROSS APPLY sys.dm_exec_plan_attributes(qs.plan_handle) AS pa
WHERE pa.attribute = 'dbid'
Expand Down Expand Up @@ -185,7 +192,10 @@ public enum TopSorts
[Description("Percent of Total Executions")] PercentExecutions = 13,
[Description("Executions per minute")] ExecutionsPerMinute = 14,
[Description("Plan Creation Time")] PlanCreationTime = 15,
[Description("Last Execution Time")] LastExecutionTime = 16
[Description("Last Execution Time")] LastExecutionTime = 16,
[Description("Average Writes")] AvgWrites = 17,
[Description("Total Writes")] TotalWrites = 18,
[Description("Percent of Total Writes")] PercentWrites = 19
}

public class TopSearchOptions
Expand Down
25 changes: 22 additions & 3 deletions src/Opserver.Web/Views/SQL/Operations.Top.Detail.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
{
var plan = op.GetShowPlanXML();
<div class="row small">
<div class="col-md-2">
<div class="col-md-1">
<div class="panel panel-default panel-condensed">
<div class="panel-heading"><i class="fa fa-bar-chart fa-fw"></i> CPU</div>
<div class="panel-body">
Expand All @@ -45,7 +45,7 @@
</div>
</div>
</div>
<div class="col-md-2">
<div class="col-md-1">
<div class="panel panel-default panel-condensed">
<div class="panel-heading"><i class="fa fa-search fa-fw"></i> Reads</div>
<div class="panel-body">
Expand All @@ -64,7 +64,26 @@
</div>
</div>
</div>
<div class="col-md-2">
<div class="col-md-1">
<div class="panel panel-default panel-condensed">
<div class="panel-heading"><i class="fa fa-search fa-fw"></i> Writes</div>
<div class="panel-body">
<div class="value-block">
@op.TotalWrites.ToComma()
<label>Total</label>
</div>
<div class="value-block">
@op.AvgWrites.ToComma()
<label>Average</label>
</div>
<div class="value-block">
@op.PercentWrites.ToString("0.00")
<label>% of Total</label>
</div>
</div>
</div>
</div>
<div class="col-md-1">
<div class="panel panel-default panel-condensed">
<div class="panel-heading"><i class="fa fa-play fa-fw"></i> Executions</div>
<div class="panel-body">
Expand Down
6 changes: 6 additions & 0 deletions src/Opserver.Web/Views/SQL/Operations.Top.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ else
<th colspan="3">CPU</th>
<th colspan="2">Time</th>
<th colspan="2">Reads</th>
<th colspan="2">Writes</th>
<th colspan="2">Execs</th>
<th>Time</th>
<th colspan="2">Query Info</th>
Expand All @@ -74,6 +75,9 @@ else
@SortLink(SQLInstance.TopSorts.AvgReads, "Avg")
@SortLink(SQLInstance.TopSorts.TotalReads, "Total")

@SortLink(SQLInstance.TopSorts.AvgWrites, "Avg")
@SortLink(SQLInstance.TopSorts.TotalWrites, "Total")

@SortLink(SQLInstance.TopSorts.ExecutionCount, "Execs")
@SortLink(SQLInstance.TopSorts.ExecutionsPerMinute, "Execs/min")
@SortLink(SQLInstance.TopSorts.LastExecutionTime, "Last Exec")
Expand All @@ -92,6 +96,8 @@ else
<td>@ReadableTime(o.TotalDuration)</td>
<td>@o.AvgReads.ToComma()</td>
<td>@o.TotalReads.ToComma()</td>
<td>@o.AvgWrites.ToComma()</td>
<td>@o.TotalWrites.ToComma()</td>
<td>@o.ExecutionCount.ToComma()</td>
<td>@o.ExecutionsPerMinute.ToString("0.00")</td>
<td>@o.LastExecutionTime.ToRelativeTimeSpan()</td>
Expand Down