Skip to content

Commit

Permalink
#143 allow customization of metric name formatting and data keys in t…
Browse files Browse the repository at this point in the history
…he ascii metric builder
  • Loading branch information
alhardy committed May 25, 2017
1 parent 4d37e08 commit bbdd780
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 59 deletions.
1 change: 1 addition & 0 deletions sandbox/App.Metrics.Sandbox/App.Metrics.Sandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="App.Metrics.Extensions.Reporting.InfluxDB" Version="1.2.0-alpha-0372" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
Expand Down
112 changes: 58 additions & 54 deletions sandbox/App.Metrics.Sandbox/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using App.Metrics.Extensions.Reporting.InfluxDB;
using App.Metrics.Extensions.Reporting.InfluxDB.Client;
using App.Metrics.Filtering;
using App.Metrics.Reporting.Interfaces;
using App.Metrics.Sandbox.JustForTesting;
using App.Metrics.Tagging;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -88,60 +92,60 @@ public void ConfigureServices(IServiceCollection services)
AddJsonMetricsSerialization().
AddAsciiHealthSerialization().
AddAsciiMetricsTextSerialization().
// AddReporting(
// factory =>
// {
// if (ReportTypes.Any(r => r == ReportType.InfluxDB))
// {
// factory.AddInfluxDb(
// new InfluxDBReporterSettings
// {
// HttpPolicy = new HttpPolicy
// {
// FailuresBeforeBackoff = 3,
// BackoffPeriod = TimeSpan.FromSeconds(30),
// Timeout = TimeSpan.FromSeconds(10)
// },
// InfluxDbSettings = new InfluxDBSettings(InfluxDbDatabase, InfluxDbUri),
// ReportInterval = TimeSpan.FromSeconds(5)
// },
// reportFilter);
// }

// if (ReportTypes.Any(r => r == ReportType.ElasticSearch))
// {
// factory.AddElasticSearch(
// new ElasticSearchReporterSettings
// {
// HttpPolicy = new Extensions.Reporting.ElasticSearch.HttpPolicy
// {
// FailuresBeforeBackoff = 3,
// BackoffPeriod = TimeSpan.FromSeconds(30),
// Timeout = TimeSpan.FromSeconds(10)
// },
// ElasticSearchSettings = new ElasticSearchSettings(ElasticSearchUri, ElasticSearchIndex),
// ReportInterval = TimeSpan.FromSeconds(5)
// },
// reportFilter);
// }

// if (ReportTypes.Any(r => r == ReportType.ElasticSearch))
// {
// factory.AddGraphite(
// new GraphiteReporterSettings
// {
// HttpPolicy = new Extensions.Reporting.Graphite.HttpPolicy
// {
// FailuresBeforeBackoff = 3,
// BackoffPeriod = TimeSpan.FromSeconds(30),
// Timeout = TimeSpan.FromSeconds(3)
// },
// GraphiteSettings = new GraphiteSettings(GraphiteUri),
// ReportInterval = TimeSpan.FromSeconds(5)
// });
// }
// }).
AddHealthChecks(
AddReporting(
factory =>
{
if (ReportTypes.Any(r => r == ReportType.InfluxDB))
{
factory.AddInfluxDb(
new InfluxDBReporterSettings
{
HttpPolicy = new HttpPolicy
{
FailuresBeforeBackoff = 3,
BackoffPeriod = TimeSpan.FromSeconds(30),
Timeout = TimeSpan.FromSeconds(10)
},
InfluxDbSettings = new InfluxDBSettings(InfluxDbDatabase, InfluxDbUri),
ReportInterval = TimeSpan.FromSeconds(5)
},
reportFilter);
}}).

// if (ReportTypes.Any(r => r == ReportType.ElasticSearch))
// {
// factory.AddElasticSearch(
// new ElasticSearchReporterSettings
// {
// HttpPolicy = new Extensions.Reporting.ElasticSearch.HttpPolicy
// {
// FailuresBeforeBackoff = 3,
// BackoffPeriod = TimeSpan.FromSeconds(30),
// Timeout = TimeSpan.FromSeconds(10)
// },
// ElasticSearchSettings = new ElasticSearchSettings(ElasticSearchUri, ElasticSearchIndex),
// ReportInterval = TimeSpan.FromSeconds(5)
// },
// reportFilter);
// }

// if (ReportTypes.Any(r => r == ReportType.ElasticSearch))
// {
// factory.AddGraphite(
// new GraphiteReporterSettings
// {
// HttpPolicy = new Extensions.Reporting.Graphite.HttpPolicy
// {
// FailuresBeforeBackoff = 3,
// BackoffPeriod = TimeSpan.FromSeconds(30),
// Timeout = TimeSpan.FromSeconds(3)
// },
// GraphiteSettings = new GraphiteSettings(GraphiteUri),
// ReportInterval = TimeSpan.FromSeconds(5)
// });
// }
// }).
AddHealthChecks(
factory =>
{
factory.RegisterPingHealthCheck("google ping", "google.com", TimeSpan.FromSeconds(10));
Expand Down
18 changes: 13 additions & 5 deletions src/App.Metrics/Formatting/Ascii/AsciiMetricPayloadBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,21 @@ public class AsciiMetricPayloadBuilder : IMetricPayloadBuilder<AsciiMetricPayloa
private readonly Func<string, string, string> _metricNameFormatter;
private AsciiMetricPayload _payload;

public AsciiMetricPayloadBuilder()
public AsciiMetricPayloadBuilder(Func<string, string, string> metricNameFormatter = null, MetricValueDataKeys dataKeys = null)
{
_payload = new AsciiMetricPayload();
_metricNameFormatter = (metricContext, metricName) => metricContext.IsMissing()
? metricName
: $"[{metricContext}] {metricName}";
DataKeys = new MetricValueDataKeys();
if (_metricNameFormatter == null)
{
_metricNameFormatter = (metricContext, metricName) => metricContext.IsMissing()
? metricName
: $"[{metricContext}] {metricName}";
}
else
{
_metricNameFormatter = metricNameFormatter;
}

DataKeys = dataKeys ?? new MetricValueDataKeys();
}

public MetricValueDataKeys DataKeys { get; }
Expand Down
4 changes: 4 additions & 0 deletions src/App.Metrics/Reporting/ReportRunner{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ public async Task<bool> EndAndFlushReportRunAsync(IMetrics metrics)
return result;
}

// TODO: Remove in 2.0.0
[Obsolete("Remove in 2.0.0 - Doesn't make sense to report environment info as part of metric reporting")]
public void ReportEnvironment(EnvironmentInfo environmentInfo) { }

// TODO: Remove in 2.0.0
[Obsolete("Remove in 2.0.0 - Doesn't make sense to report health status as part of metric reporting, health check results are reported as guages as well")]
public void ReportHealth(
GlobalMetricTags globalTags,
IEnumerable<HealthCheck.Result> healthyChecks,
Expand Down

0 comments on commit bbdd780

Please sign in to comment.