Skip to content

Commit

Permalink
SQL: Named instance support
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCraver committed Jan 31, 2016
1 parent 7e186f6 commit 514bfcf
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 25 deletions.
8 changes: 5 additions & 3 deletions Opserver.Core/Data/SQL/SQLInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand Down Expand Up @@ -32,10 +33,11 @@ public partial class SQLInstance : PollNode, ISearchableNode
public SQLInstance(SQLSettings.Instance settings) : base(settings.Name)
{
Settings = settings;
// TODO: Object Name regex for not SQLServer but InstanceName, e.g. "MSSQL$MyInstance" from "MyServer\\MyInstance"
// ...or ConnectionStringBuilder?
ObjectName = settings.ObjectName.IsNullOrEmptyReturn("SQLServer");
ConnectionString = settings.ConnectionString.IsNullOrEmptyReturn(Current.Settings.SQL.DefaultConnectionString.Replace("$ServerName$", settings.Name));
// Grab the instance name for performance counters and such
var csb = new SqlConnectionStringBuilder(ConnectionString);
var parts = csb.DataSource?.Split(StringSplits.BackSlash);
ObjectName = parts?.Length == 2 ? "MSSQL$" + parts[1].ToUpper() : "SQLServer";
}

public static SQLInstance Get(string name)
Expand Down
26 changes: 10 additions & 16 deletions Opserver/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.Web;
using System.Web.Mvc;
using Jil;
using StackExchange.Opserver.Data;
using StackExchange.Opserver.Data.SQL;
using StackExchange.Opserver.Helpers;
Expand All @@ -19,34 +20,27 @@ public static class WebExtensionMethods
/// <summary>
/// returns Url Encoded string
/// </summary>
public static string UrlEncode(this string s)
{
return s.HasValue() ? HttpUtility.UrlEncode(s) : s;
}
public static string UrlEncode(this string s) => s.HasValue() ? HttpUtility.UrlEncode(s) : s;

/// <summary>
/// Returns a url encoded string with any + converted to %20 for better query string transport.
/// </summary>
public static string QueryStringEncode(this string s)
{
return s.HasValue() ? HtmlUtilities.QueryStringEncode(s) : s;
}
public static string QueryStringEncode(this string s) => s.HasValue() ? HtmlUtilities.QueryStringEncode(s) : s;

/// <summary>
/// returns Html Encoded string
/// </summary>
public static string HtmlEncode(this string s)
{
return s.HasValue() ? HttpUtility.HtmlEncode(s) : s;
}
public static string HtmlEncode(this string s) => s.HasValue() ? HttpUtility.HtmlEncode(s) : s;

/// <summary>
/// Title cases a string given the current culture
/// </summary>
public static string ToTitleCase(this string s)
{
return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s);
}
public static string ToTitleCase(this string s) => CultureInfo.CurrentCulture.TextInfo.ToTitleCase(s);

/// <summary>
/// Encodes an object as JSON for direct use without quote crazy
/// </summary>
public static IHtmlString ToJson(this object o) => JSON.Serialize(o).AsHtml();

public static IHtmlString ToStatusSpan(this Data.HAProxy.Item item)
{
Expand Down
9 changes: 4 additions & 5 deletions Opserver/Views/Dashboard/Node.Graph.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using StackExchange.Exceptional.Extensions
@using StackExchange.Opserver.Views.Dashboard
@using StackExchange.Opserver.Views.Dashboard
@model NodeGraphModel
@{
Layout = null;
Expand All @@ -17,7 +16,7 @@
$('.js-dashboard-chart').cpuGraph({
id: '@Model.Node.Id',
width: 858,
data: @Model.GraphData.ToJson().AsHtml()
data: @Model.GraphData.ToJson()
});
</script>
break;
Expand All @@ -27,7 +26,7 @@
id: '@Model.Node.Id',
width: 858,
max: @((Model.Node.TotalMemory/1024/1024).ToString()),
data: @Model.GraphData.ToJson().AsHtml()
data: @Model.GraphData.ToJson()
});
</script>
break;
Expand All @@ -37,7 +36,7 @@
id: '@Model.Node.Id',
iid: '@(Model.Interface?.Id)',
width: 858,
data: @Model.GraphData.ToJson().AsHtml()
data: @Model.GraphData.ToJson()
});
</script>
break;
Expand Down
2 changes: 1 addition & 1 deletion Opserver/Views/SQL/Dashboard.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script>
$(function() {
Status.Dashboard.init({ refresh: @(Model.Refresh.ToString()) });
Status.SQL.init({ node: '@(Model.CurrentInstance != null ? Model.CurrentInstance.Name : "")' });
Status.SQL.init({ node: @(Model.CurrentInstance?.Name.ToJson()) });
});
</script>
}
Expand Down

0 comments on commit 514bfcf

Please sign in to comment.