diff --git a/src/NewRelic.Microsoft.SqlServer.Plugin/NewRelic.Microsoft.SqlServer.Plugin.csproj b/src/NewRelic.Microsoft.SqlServer.Plugin/NewRelic.Microsoft.SqlServer.Plugin.csproj index d097816..975abf2 100644 --- a/src/NewRelic.Microsoft.SqlServer.Plugin/NewRelic.Microsoft.SqlServer.Plugin.csproj +++ b/src/NewRelic.Microsoft.SqlServer.Plugin/NewRelic.Microsoft.SqlServer.Plugin.csproj @@ -83,6 +83,7 @@ + @@ -172,7 +173,9 @@ - + + + diff --git a/src/NewRelic.Microsoft.SqlServer.Plugin/Queries/ResourceStats.AzureSql.sql b/src/NewRelic.Microsoft.SqlServer.Plugin/Queries/ResourceStats.AzureSql.sql new file mode 100644 index 0000000..27ab9fb --- /dev/null +++ b/src/NewRelic.Microsoft.SqlServer.Plugin/Queries/ResourceStats.AzureSql.sql @@ -0,0 +1,15 @@ +-- sys.dm_db_resource_stats exposes 'fine-grained', near real-time resource consumption data, +-- expressed as a percentage of the maximum allowed DTU limits for the service tier/performance +-- level that the db is running (https://msdn.microsoft.com/en-us/library/dn800981.aspx) + +SELECT + AVG(avg_cpu_percent) AS [AvgCpuPercent], + MAX(avg_cpu_percent) AS [MaxCpuPercent], + AVG(avg_data_io_percent) AS [AvgDataIoPercent], + MAX(avg_data_io_percent) AS [MaxDataIoPercent], + AVG(avg_log_write_percent) AS [AvgLogWritePercent], + MAX(avg_log_write_percent) AS [MaxLogWritePercent], + AVG(avg_memory_usage_percent) AS [AvgMemoryUsagePercent], + MAX(avg_memory_usage_percent) AS [MaxMemoryUsagePercent] +FROM (SELECT TOP 4 * FROM sys.dm_db_resource_stats) t +-- TOP 4 since plugin works in 1min interval, table is filled in 15sec interval \ No newline at end of file diff --git a/src/NewRelic.Microsoft.SqlServer.Plugin/QueryTypes/ResourceStats.cs b/src/NewRelic.Microsoft.SqlServer.Plugin/QueryTypes/ResourceStats.cs new file mode 100644 index 0000000..22d9525 --- /dev/null +++ b/src/NewRelic.Microsoft.SqlServer.Plugin/QueryTypes/ResourceStats.cs @@ -0,0 +1,52 @@ +using NewRelic.Microsoft.SqlServer.Plugin.Core; + +using System; + +namespace NewRelic.Microsoft.SqlServer.Plugin.QueryTypes +{ + [AzureSqlQuery("ResourceStats.AzureSql.sql", "ResourceStats/{MetricName}", QueryName = "Resource Stats", Enabled = true)] + public class ResourceStats + { + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Avg_Cpu")] + public decimal AvgCpuPercent { get; set; } + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Max_Cpu")] + public decimal MaxCpuPercent { get; set; } + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Avg_Data_Io")] + public decimal AvgDataIoPercent { get; set; } + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Max_Data_Io")] + public decimal MaxDataIoPercent { get; set; } + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Avg_Log_Write")] + public decimal AvgLogWritePercent { get; set; } + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Max_Log_Write")] + public decimal MaxLogWritePercent { get; set; } + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Avg_Memory_Usage")] + public decimal AvgMemoryUsagePercent { get; set; } + + [Metric(MetricValueType = MetricValueType.Value, Units = "%_Max_Memory_Usage")] + public decimal MaxMemoryUsagePercent { get; set; } + + public override string ToString() + { + return string.Format( "AvgCpuPercent: {0},\t" + + "MaxCpuPercent: {1},\t" + + "AvgDataIoPercent: {2},\t" + + "MaxDataIoPercent: {3},\t" + + "AvgLogWritePercent: {4},\t" + + "MaxLogWritePercent: {5},\t" + + "AvgMemoryUsagePercent: {6},\t" + + "MaxMemoryUsagePercent: {7},\t", + AvgCpuPercent, MaxCpuPercent, + AvgDataIoPercent, MaxDataIoPercent, + AvgLogWritePercent, MaxLogWritePercent, + AvgMemoryUsagePercent, MaxMemoryUsagePercent); + } + + } +}