Skip to content
This repository has been archived by the owner on Mar 26, 2019. It is now read-only.

Implementation App.Metrics.Reporting via Socket layer #53

Merged
merged 1 commit into from
Jun 28, 2018
Merged
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
7 changes: 7 additions & 0 deletions Reporting.sln
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{82BE5E48
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App.Metrics.Reporting.Http", "src\App.Metrics.Reporting.Http\App.Metrics.Reporting.Http.csproj", "{A4FCA5FE-5866-419D-B2BE-AAF31751C476}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App.Metrics.Reporting.Socket", "src\App.Metrics.Reporting.Socket\App.Metrics.Reporting.Socket.csproj", "{7DA4DF65-A890-4ACD-8981-AFAAF344C2C0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReportingSandbox", "sandbox\ReportingSandbox\ReportingSandbox.csproj", "{96B005A1-B339-408F-BAAE-5C95566A7DF1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "App.Metrics.Reporting.Console.Facts", "test\App.Metrics.Reporting.Console.Facts\App.Metrics.Reporting.Console.Facts.csproj", "{5A9AEB7B-FB2A-4933-96D3-DBAF9E25A9B0}"
Expand Down Expand Up @@ -84,6 +86,10 @@ Global
{A4FCA5FE-5866-419D-B2BE-AAF31751C476}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4FCA5FE-5866-419D-B2BE-AAF31751C476}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4FCA5FE-5866-419D-B2BE-AAF31751C476}.Release|Any CPU.Build.0 = Release|Any CPU
{7DA4DF65-A890-4ACD-8981-AFAAF344C2C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DA4DF65-A890-4ACD-8981-AFAAF344C2C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DA4DF65-A890-4ACD-8981-AFAAF344C2C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DA4DF65-A890-4ACD-8981-AFAAF344C2C0}.Release|Any CPU.Build.0 = Release|Any CPU
{96B005A1-B339-408F-BAAE-5C95566A7DF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{96B005A1-B339-408F-BAAE-5C95566A7DF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{96B005A1-B339-408F-BAAE-5C95566A7DF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -119,6 +125,7 @@ Global
{2B01FDF8-8E73-4904-9B2C-5BFA505BFF5F} = {2D805782-756E-4C98-B22E-F502BEE95318}
{82BE5E48-3A8F-4B09-8A3A-03448C6D2B4D} = {31A4DDB1-952E-4EED-96EF-29C669279A86}
{A4FCA5FE-5866-419D-B2BE-AAF31751C476} = {2D805782-756E-4C98-B22E-F502BEE95318}
{7DA4DF65-A890-4ACD-8981-AFAAF344C2C0} = {2D805782-756E-4C98-B22E-F502BEE95318}
{96B005A1-B339-408F-BAAE-5C95566A7DF1} = {887BC5A0-8ED7-4460-851D-5EFC4AE828DE}
{5A9AEB7B-FB2A-4933-96D3-DBAF9E25A9B0} = {DD2E4647-7125-4CE3-9BA5-B45A26113A31}
{457CACEF-A3DB-4A0B-8665-A5E20AA925E0} = {DD2E4647-7125-4CE3-9BA5-B45A26113A31}
Expand Down
5 changes: 3 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ var linkSources = HasArgument("LinkSources") ? Argument<bool>("LinkSources")
var packDirs = new []
{
Directory("./src/App.Metrics.Reporting.Console"),
Directory("./src/App.Metrics.Reporting.TextFile"),
Directory("./src/App.Metrics.Reporting.Http")
Directory("./src/App.Metrics.Reporting.Http"),
Directory("./src/App.Metrics.Reporting.Socket"),
Directory("./src/App.Metrics.Reporting.TextFile")
};
var artifactsDir = (DirectoryPath) Directory("./artifacts");
var testResultsDir = (DirectoryPath) artifactsDir.Combine("test-results");
Expand Down
4 changes: 4 additions & 0 deletions sandbox/ReportingSandbox/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Threading.Tasks;
using App.Metrics;
using App.Metrics.Formatters.InfluxDB;
using Microsoft.AspNetCore.Hosting;
using ReportingSandbox.JustForTesting;
using Serilog;
Expand Down Expand Up @@ -48,6 +49,9 @@ private static void Init()
.Report.ToTextFile(@"C:\metrics\sample.txt", TimeSpan.FromSeconds(5))
.Report.OverHttp("http://localhost:50001/metrics-receive", TimeSpan.FromSeconds(10))
.Report.OverHttp("http://localhost:50002/api/metrics", TimeSpan.FromSeconds(10))
// .Report.OverTcp(new MetricsInfluxDbLineProtocolOutputFormatter(), "localhost", 8094)
.Report.OverUdp(new MetricsInfluxDbLineProtocolOutputFormatter(), "localhost", 8094)
// .Report.OverUds(new MetricsInfluxDbLineProtocolOutputFormatter(), "/tmp/telegraf.sock")
.Build();
}
}
Expand Down
2 changes: 2 additions & 0 deletions sandbox/ReportingSandbox/ReportingSandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<PackageReference Include="App.Metrics" Version="$(AppMetricsCoreVersion)" />
<PackageReference Include="App.Metrics.Extensions.DependencyInjection" Version="$(AppMetricsCoreVersion)" />
<PackageReference Include="App.Metrics.Extensions.Hosting" Version="$(AppMetricsCoreVersion)" />
<PackageReference Include="App.Metrics.Formatters.InfluxDB" Version="$(AppMetricsCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="$(AspNetCoreVersion)" />
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.1-dev-00044" />
Expand All @@ -21,6 +22,7 @@
<ItemGroup>
<ProjectReference Include="..\..\src\App.Metrics.Reporting.Console\App.Metrics.Reporting.Console.csproj" />
<ProjectReference Include="..\..\src\App.Metrics.Reporting.Http\App.Metrics.Reporting.Http.csproj" />
<ProjectReference Include="..\..\src\App.Metrics.Reporting.Socket\App.Metrics.Reporting.Socket.csproj" />
<ProjectReference Include="..\..\src\App.Metrics.Reporting.TextFile\App.Metrics.Reporting.TextFile.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\..\build\common.props" />

<PropertyGroup>
<Description>Provides reporting capability to App Metrics via sockets</Description>
<TargetFrameworks>netstandard1.6</TargetFrameworks>
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">$(TargetFrameworks);net452</TargetFrameworks>
<PackageTags>appmetrics;reporting;socket;tcp;udp;uds</PackageTags>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="App.Metrics.Core" Version="$(AppMetricsCoreVersion)" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<Reference Include="System" />
<Reference Include="System.Net.Http" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<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/CSharpLanguageProject/LanguageLevel/@EntryValue">CSharp71</s:String></wpf:ResourceDictionary>
155 changes: 155 additions & 0 deletions src/App.Metrics.Reporting.Socket/Builder/MetricsTcpReporterBuilder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// <copyright file="MetricsTcpReporterBuilder.cs" company="App Metrics Contributors">
// Copyright (c) App Metrics Contributors. All rights reserved.
// </copyright>

using System;
using System.Net.Sockets;
using App.Metrics.Builder;
using App.Metrics.Formatters;
using App.Metrics.Reporting.Socket;
using App.Metrics.Reporting.Socket.Client;

// ReSharper disable CheckNamespace
namespace App.Metrics
// ReSharper restore CheckNamespace
{
/// <summary>
/// Builder for configuring metrics TCP reporting using an
/// <see cref="IMetricsReportingBuilder" />.
/// </summary>
public static class MetricsTcpReporterBuilder
{
/// <summary>
/// Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
/// </summary>
/// <param name="reportingBuilder">
/// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
/// </param>
/// <param name="options">The Socket reporting options to use.</param>
/// <returns>
/// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
/// </returns>
public static IMetricsBuilder OverTcp(
this IMetricsReportingBuilder reportingBuilder,
MetricsReportingSocketOptions options)
{
if (reportingBuilder == null)
{
throw new ArgumentNullException(nameof(reportingBuilder));
}

options.SocketSettings.ProtocolType = ProtocolType.Tcp;

var provider = new SocketMetricsReporter(options);

return reportingBuilder.Using(provider);
}

/// <summary>
/// Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
/// </summary>
/// <param name="reportingBuilder">
/// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
/// </param>
/// <param name="setupAction">The Socket reporting options to use.</param>
/// <returns>
/// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
/// </returns>
public static IMetricsBuilder OverTcp(
this IMetricsReportingBuilder reportingBuilder,
Action<MetricsReportingSocketOptions> setupAction)
{
if (reportingBuilder == null)
{
throw new ArgumentNullException(nameof(reportingBuilder));
}

var options = new MetricsReportingSocketOptions();

setupAction?.Invoke(options);

options.SocketSettings.ProtocolType = ProtocolType.Tcp;

var provider = new SocketMetricsReporter(options);

return reportingBuilder.Using(provider);
}

/// <summary>
/// Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
/// </summary>
/// <param name="reportingBuilder">
/// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
/// </param>
/// <param name="metricsOutputFormatter">
/// The <see cref="IMetricsOutputFormatter" /> used to configure metrics output formatter.
/// </param>
/// <param name="address">The TCP endpoint address where metrics are POSTed.</param>
/// <param name="port">The TCP endpoint port where metrics are POSTed.</param>
/// <returns>
/// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
/// </returns>
public static IMetricsBuilder OverTcp(
this IMetricsReportingBuilder reportingBuilder,
IMetricsOutputFormatter metricsOutputFormatter,
string address,
int port)
{
if (reportingBuilder == null)
{
throw new ArgumentNullException(nameof(reportingBuilder));
}

var options = new MetricsReportingSocketOptions
{
SocketSettings = new SocketSettings(ProtocolType.Tcp, address, port),
MetricsOutputFormatter = metricsOutputFormatter
};
var provider = new SocketMetricsReporter(options);

return reportingBuilder.Using(provider);
}

/// <summary>
/// Add the <see cref="SocketMetricsReporter" /> allowing metrics to be reported over TCP.
/// </summary>
/// <param name="reportingBuilder">
/// The <see cref="IMetricsReportingBuilder" /> used to configure metrics reporters.
/// </param>
/// <param name="metricsOutputFormatter">
/// The <see cref="IMetricsOutputFormatter" /> used to configure metrics reporters.
/// </param>
/// <param name="address">The TCP endpoint address where metrics are POSTed.</param>
/// <param name="port">The TCP endpoint port where metrics are POSTed.</param>
/// <param name="flushInterval">
/// The <see cref="T:System.TimeSpan" /> interval used if intended to schedule metrics
/// reporting.
/// </param>
/// <returns>
/// An <see cref="IMetricsBuilder" /> that can be used to further configure App Metrics.
/// </returns>
public static IMetricsBuilder OverTcp(
this IMetricsReportingBuilder reportingBuilder,
IMetricsOutputFormatter metricsOutputFormatter,
string address,
int port,
TimeSpan flushInterval)
{
if (reportingBuilder == null)
{
throw new ArgumentNullException(nameof(reportingBuilder));
}

var options = new MetricsReportingSocketOptions
{
SocketSettings = new SocketSettings(ProtocolType.Tcp, address, port),
MetricsOutputFormatter = metricsOutputFormatter,
FlushInterval = flushInterval
};

var provider = new SocketMetricsReporter(options);

return reportingBuilder.Using(provider);
}
}
}
Loading