This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
859 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
using NewRelic.Microsoft.SqlServer.Plugin.Core; | ||
|
||
namespace NewRelic.Microsoft.SqlServer.Plugin | ||
{ | ||
public interface IMetricQuery | ||
{ | ||
MetricTransformEnum MetricTransformEnum { get; } | ||
string QueryName { get; } | ||
Type QueryType { get; } | ||
string MetricPattern { get; } | ||
string ResultTypeName { get; } | ||
void AddMetrics(QueryContext context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using NewRelic.Microsoft.SqlServer.Plugin.Core; | ||
using NewRelic.Platform.Binding.DotNET; | ||
|
||
namespace NewRelic.Microsoft.SqlServer.Plugin | ||
{ | ||
public interface IQueryContext | ||
{ | ||
string QueryName { get; } | ||
Type QueryType { get; } | ||
IEnumerable<object> Results { get; set; } | ||
ComponentData ComponentData { get; set; } | ||
int MetricsRecorded { get; } | ||
bool DataSent { get; set; } | ||
MetricTransformEnum MetricTransformEnum { get; } | ||
|
||
string FormatMetricKey(object queryResult, string metricName, string metricUnits); | ||
void AddAllMetrics(); | ||
void AddMetric(string name, int value); | ||
void AddMetric(string name, decimal value); | ||
void AddMetric(string name, MinMaxMetricValue value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using System.Data; | ||
|
||
using NewRelic.Microsoft.SqlServer.Plugin.Core; | ||
|
||
namespace NewRelic.Microsoft.SqlServer.Plugin | ||
{ | ||
public interface ISqlQuery : IMetricQuery | ||
{ | ||
string ResourceName { get; } | ||
string CommandText { get; } | ||
|
||
/// <summary> | ||
/// Queries data from the database and returns the results. | ||
/// </summary> | ||
/// <param name="dbConnection">Open connection to the database.</param> | ||
/// <param name="endpoint">Settings for the endpoint that is queried.</param> | ||
/// <returns> | ||
/// An enumeration of a the type where the <see cref="SqlServerQueryAttribute" /> for this query object was found during initialization. | ||
/// </returns> | ||
IEnumerable<object> Query(IDbConnection dbConnection, ISqlEndpoint endpoint); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
|
||
using NewRelic.Microsoft.SqlServer.Plugin.Core; | ||
using NewRelic.Microsoft.SqlServer.Plugin.Core.Extensions; | ||
|
||
namespace NewRelic.Microsoft.SqlServer.Plugin | ||
{ | ||
public class MetricQuery : IMetricQuery | ||
{ | ||
private readonly MetricMapper[] _metricMappers; | ||
|
||
public MetricQuery(Type queryType, string queryName, string resultTypeName) | ||
{ | ||
QueryType = queryType; | ||
QueryName = queryName; | ||
ResultTypeName = resultTypeName; | ||
_metricMappers = GetMappers(QueryType); | ||
MetricPattern = string.Format("Component/{0}", QueryType.Name); | ||
} | ||
|
||
public Type QueryType { get; private set; } | ||
|
||
public string QueryName { get; private set; } | ||
|
||
public MetricTransformEnum MetricTransformEnum { get; set; } | ||
|
||
public string MetricPattern { get; protected set; } | ||
|
||
public string ResultTypeName { get; private set; } | ||
|
||
public void AddMetrics(QueryContext context) | ||
{ | ||
context.Results.ForEach(r => _metricMappers.ForEach(m => m.AddMetric(context, r))); | ||
} | ||
|
||
/// <summary> | ||
/// Sets up the mappers that take the values on the query result and records each one as a metric. | ||
/// </summary> | ||
/// <param name="type"> | ||
/// <em>QueryType</em> to look for metric properties | ||
/// </param> | ||
/// <returns> | ||
/// An array of mappers capable of creating metrics for a <em>QueryType</em> | ||
/// </returns> | ||
internal static MetricMapper[] GetMappers(Type type) | ||
{ | ||
return type.GetProperties(BindingFlags.Public | BindingFlags.Instance) | ||
.Select(MetricMapper.TryCreate) | ||
.Where(m => m != null) | ||
.ToArray(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 4 additions & 6 deletions
10
src/NewRelic.Microsoft.SqlServer.Plugin/Queries/AllDatabasesOnInstanceAzure.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
-- All Databases on instance Azure | ||
-- Must connect to master. If you connect to non master, you get master and that DB only | ||
|
||
select | ||
Name, | ||
Database_id | ||
from sys.databases | ||
|
||
select * from sys.dm_exec_requests | ||
SELECT | ||
Name, | ||
Database_id | ||
FROM sys.databases |
Oops, something went wrong.