Skip to content

Commit

Permalink
Extracting Nrgs.Hub.Monitoring into Greentube.Monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-garcia committed Oct 28, 2016
0 parents commit 6c75d06
Show file tree
Hide file tree
Showing 54 changed files with 3,177 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Visual studio
.vs/
*.user
bin/
obj/
project.lock.json
10 changes: 10 additions & 0 deletions GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Reflection;

[assembly: AssemblyCompany("Greentube Internet Entertainment")]
[assembly: AssemblyCopyright("Copyright © Greentube Internet Entertainment Solutions GmbH 2016")]

[assembly: AssemblyVersion("0.0.0.0")]
[assembly: AssemblyFileVersion("0.0.0.0")]

// Replaced by TeamCity's Build Feature: Assembly Info Patcher
[assembly: AssemblyInformationalVersion("branch - 0000000000000000000000000000000000000000")]
71 changes: 71 additions & 0 deletions Greentube.Monitoring.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Greentube.Monitoring", "src\Greentube.Monitoring\Greentube.Monitoring.xproj", "{2BB29E61-02DD-4745-A3A2-145711D5FFB8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{843C8ED0-4792-40E0-8903-A3E5FF74A0A3}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Greentube.Monitoring.MongoDB", "src\Greentube.Monitoring.MongoDB\Greentube.Monitoring.MongoDB.xproj", "{5D358A61-8266-4739-845D-E6E973B71995}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Greentube.Monitoring.Redis", "src\Greentube.Monitoring.Redis\Greentube.Monitoring.Redis.xproj", "{78A6706F-599A-4CBD-B867-C6FE053788D3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{AE749C50-94C1-445C-B13F-E9D19372CBDB}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Greentube.Monitoring.MongoDB.Tests", "test\Greentube.Monitoring.MongoDB.Tests\Greentube.Monitoring.MongoDB.Tests.xproj", "{3AB84CBA-75AF-4027-A398-0AB8CD4C004E}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Greentube.Monitoring.Redis.Tests", "test\Greentube.Monitoring.Redis.Tests\Greentube.Monitoring.Redis.Tests.xproj", "{FF559CD8-5FFE-4460-A6BC-84F8F7A05CB7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Greentube.Monitoring.Tests", "test\Greentube.Monitoring.Tests\Greentube.Monitoring.Tests.xproj", "{06356707-146F-48F7-9C18-7E5D3D67E765}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{11D063CA-B13E-4EFB-9000-A47BA4B2AEC7}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
global.json = global.json
GlobalAssemblyInfo.cs = GlobalAssemblyInfo.cs
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2BB29E61-02DD-4745-A3A2-145711D5FFB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BB29E61-02DD-4745-A3A2-145711D5FFB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BB29E61-02DD-4745-A3A2-145711D5FFB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BB29E61-02DD-4745-A3A2-145711D5FFB8}.Release|Any CPU.Build.0 = Release|Any CPU
{5D358A61-8266-4739-845D-E6E973B71995}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D358A61-8266-4739-845D-E6E973B71995}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D358A61-8266-4739-845D-E6E973B71995}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D358A61-8266-4739-845D-E6E973B71995}.Release|Any CPU.Build.0 = Release|Any CPU
{78A6706F-599A-4CBD-B867-C6FE053788D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78A6706F-599A-4CBD-B867-C6FE053788D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78A6706F-599A-4CBD-B867-C6FE053788D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78A6706F-599A-4CBD-B867-C6FE053788D3}.Release|Any CPU.Build.0 = Release|Any CPU
{3AB84CBA-75AF-4027-A398-0AB8CD4C004E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3AB84CBA-75AF-4027-A398-0AB8CD4C004E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3AB84CBA-75AF-4027-A398-0AB8CD4C004E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3AB84CBA-75AF-4027-A398-0AB8CD4C004E}.Release|Any CPU.Build.0 = Release|Any CPU
{FF559CD8-5FFE-4460-A6BC-84F8F7A05CB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF559CD8-5FFE-4460-A6BC-84F8F7A05CB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF559CD8-5FFE-4460-A6BC-84F8F7A05CB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF559CD8-5FFE-4460-A6BC-84F8F7A05CB7}.Release|Any CPU.Build.0 = Release|Any CPU
{06356707-146F-48F7-9C18-7E5D3D67E765}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06356707-146F-48F7-9C18-7E5D3D67E765}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06356707-146F-48F7-9C18-7E5D3D67E765}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06356707-146F-48F7-9C18-7E5D3D67E765}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{2BB29E61-02DD-4745-A3A2-145711D5FFB8} = {843C8ED0-4792-40E0-8903-A3E5FF74A0A3}
{5D358A61-8266-4739-845D-E6E973B71995} = {843C8ED0-4792-40E0-8903-A3E5FF74A0A3}
{78A6706F-599A-4CBD-B867-C6FE053788D3} = {843C8ED0-4792-40E0-8903-A3E5FF74A0A3}
{3AB84CBA-75AF-4027-A398-0AB8CD4C004E} = {AE749C50-94C1-445C-B13F-E9D19372CBDB}
{FF559CD8-5FFE-4460-A6BC-84F8F7A05CB7} = {AE749C50-94C1-445C-B13F-E9D19372CBDB}
{06356707-146F-48F7-9C18-7E5D3D67E765} = {AE749C50-94C1-445C-B13F-E9D19372CBDB}
EndGlobalSection
EndGlobal
3 changes: 3 additions & 0 deletions Greentube.Monitoring.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/CodeAnnotations/DefaultNamespace/@EntryValue">Greentube.Monitoring</s:String>
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=Greentube_002EMonitoring/@EntryIndexedValue">True</s:Boolean>
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.0-preview2-003131"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>5d358a61-8266-4739-845d-e6e973b71995</ProjectGuid>
<RootNamespace>Greentube.Monitoring.MongoDB</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
45 changes: 45 additions & 0 deletions src/Greentube.Monitoring.MongoDB/MongoDbPingHealthCheckStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;

namespace Greentube.Monitoring.MongoDB
{
/// <summary>
/// Health Check using Ping command
/// </summary>
/// <remarks>
/// Not suitable for Replica Set: A replica set status shall be checked.
/// Ping could be successful in one of the nodes but the replica set is broken
/// </remarks>
/// <seealso cref="IHealthCheckStrategy" />
public class MongoDbPingHealthCheckStrategy : IHealthCheckStrategy
{
private readonly IMongoDatabase _database;

/// <summary>
/// Initializes a new instance of the <see cref="MongoDbPingHealthCheckStrategy"/> class.
/// </summary>
/// <param name="database">The database.</param>
/// <exception cref="ArgumentNullException"></exception>
public MongoDbPingHealthCheckStrategy(IMongoDatabase database)
{
if (database == null) throw new ArgumentNullException(nameof(database));
_database = database;
}

/// <summary>
/// Checks connectivity with MongoDB via ping command
/// </summary>
/// <param name="token">The token.</param>
/// <returns></returns>
public async Task<bool> Check(CancellationToken token)
{
await _database.RunCommandAsync((Command<BsonDocument>)"{ping:1}", cancellationToken: token)
.ConfigureAwait(false);

return true;
}
}
}
35 changes: 35 additions & 0 deletions src/Greentube.Monitoring.MongoDB/MongoDbPingMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System.Linq;
using Microsoft.Extensions.Logging;
using MongoDB.Driver;

namespace Greentube.Monitoring.MongoDB
{
/// <summary>
/// Monitors MongoDB connectivity
/// </summary>
/// <seealso cref="ResourceMonitor" />
public sealed class MongoDbPingMonitor : ResourceMonitor
{
/// <summary>
/// Initializes a new instance of the <see cref="MongoDbPingMonitor"/> class.
/// </summary>
/// <param name="mongoDatabase">The mongo database.</param>
/// <param name="logger">The logger.</param>
/// <param name="configuration">The configuration.</param>
/// <param name="resourceName">Name of the resource (If not provided: will be based on Servers EndPoints).</param>
/// <param name="isCritical">if set to <c>true</c> [is critical].</param>
public MongoDbPingMonitor(
IMongoDatabase mongoDatabase,
ILogger<MongoDbPingMonitor> logger,
ResourceMonitorConfiguration configuration,
string resourceName = null,
bool isCritical = true)
: base(resourceName ?? "MongoDB:" + string.Join(",", mongoDatabase.Client.Settings.Servers.Select(e => e.ToString())),
new MongoDbPingHealthCheckStrategy(mongoDatabase),
configuration,
logger,
isCritical)
{
}
}
}
6 changes: 6 additions & 0 deletions src/Greentube.Monitoring.MongoDB/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyProduct("Greentube.Monitoring.MongoDB")]

[assembly: Guid("5d358a61-8266-4739-845d-e6e973b71995")]
22 changes: 22 additions & 0 deletions src/Greentube.Monitoring.MongoDB/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "1.0.0-*",

"buildOptions": {
"compile": "../../GlobalAssemblyInfo.cs",
"xmlDoc": true
},

"dependencies": {
"NETStandard.Library": "1.6.0",
"mongocsharpdriver": "2.3.0-rc1",
"Greentube.Monitoring": "1.0.0"
},

"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
},
"net46": {
}
}
}
21 changes: 21 additions & 0 deletions src/Greentube.Monitoring.Redis/Greentube.Monitoring.Redis.xproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>78a6706f-599a-4cbd-b867-c6fe053788d3</ProjectGuid>
<RootNamespace>Greentube.Monitoring.Redis</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>

<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
6 changes: 6 additions & 0 deletions src/Greentube.Monitoring.Redis/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Reflection;
using System.Runtime.InteropServices;

[assembly: AssemblyProduct("Greentube.Monitoring.Redis")]

[assembly: Guid("78a6706f-599a-4cbd-b867-c6fe053788d3")]
46 changes: 46 additions & 0 deletions src/Greentube.Monitoring.Redis/RedisPingHealthCheckStrategy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using StackExchange.Redis;

namespace Greentube.Monitoring.Redis
{
/// <summary>
/// HealthCheck based on Ping command
/// </summary>
/// <seealso cref="IHealthCheckStrategy" />
public class RedisPingHealthCheckStrategy : IHealthCheckStrategy
{
private readonly IConnectionMultiplexer _multiplexer;

/// <summary>
/// Initializes a new instance of the <see cref="RedisPingHealthCheckStrategy"/> class.
/// </summary>
/// <param name="multiplexer">The multiplexer.</param>
/// <exception cref="ArgumentNullException"></exception>
public RedisPingHealthCheckStrategy(IConnectionMultiplexer multiplexer)
{
if (multiplexer == null) throw new ArgumentNullException(nameof(multiplexer));
_multiplexer = multiplexer;
}

/// <summary>
/// Checks the multiplexer is connected
/// </summary>
/// <param name="token">The token.</param>
/// <returns></returns>
public async Task<bool> Check(CancellationToken token)
{
if (_multiplexer.IsConnected)
return true;

// If not connected, make a call to let exception bubble
await _multiplexer
.GetDatabase(0)
.PingAsync(CommandFlags.DemandMaster)
.ConfigureAwait(false);

return true; // if it didn't throw, it's back up
}
}
}
45 changes: 45 additions & 0 deletions src/Greentube.Monitoring.Redis/RedisPingMonitor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Linq;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;

namespace Greentube.Monitoring.Redis
{
/// <summary>
/// Redis ping monitor
/// </summary>
/// <seealso cref="Greentube.Monitoring.ResourceMonitor" />
public sealed class RedisPingMonitor : ResourceMonitor
{
/// <summary>
/// Initializes a new instance of the <see cref="RedisPingMonitor"/> class.
/// </summary>
/// <param name="isCritical">if set to <c>true</c> [is critical Resource].</param>
/// <param name="connectionMultiplexer">The connection multiplexer.</param>
/// <param name="logger">The logger.</param>
/// <param name="configuration">The configuration.</param>
/// <param name="resourceName">Name of the resource.</param>
public RedisPingMonitor(
bool isCritical,
IConnectionMultiplexer connectionMultiplexer,
ILogger<RedisPingMonitor> logger,
ResourceMonitorConfiguration configuration,
string resourceName = null)
: base(resourceName ?? GetResourceName(connectionMultiplexer),
new RedisPingHealthCheckStrategy(connectionMultiplexer),
configuration,
logger,
isCritical)
{
}

private static string GetResourceName(IConnectionMultiplexer connectionMultiplexer)
{
if (connectionMultiplexer == null) throw new ArgumentNullException(nameof(connectionMultiplexer));

return "Redis:" + string.Join(",",
ConfigurationOptions.Parse(connectionMultiplexer.Configuration)
.EndPoints.Select(e => e.ToString()));
}
}
}
27 changes: 27 additions & 0 deletions src/Greentube.Monitoring.Redis/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "1.0.0-*",

"buildOptions": {
"compile": "../../GlobalAssemblyInfo.cs",
"xmlDoc": true
},

"dependencies": {
"NETStandard.Library": "1.6.0",
"Greentube.Monitoring": "1.0.0"
},

"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50",
"dependencies": {
"StackExchange.Redis": "1.1.604-alpha"
}
},
"net46": {
"dependencies": {
"StackExchange.Redis": "1.0.488"
}
}
}
}
Loading

0 comments on commit 6c75d06

Please sign in to comment.