-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
1 parent
4d81c2b
commit 32c7004
Showing
17 changed files
with
368 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
namespace Promitor.Core.Scraping.Sinks | ||
using System.Threading.Tasks; | ||
using Promitor.Integrations.AzureMonitor; | ||
|
||
namespace Promitor.Core.Scraping.Sinks | ||
{ | ||
public interface IMetricSink | ||
{ | ||
MetricSinkType SinkType { get; } | ||
MetricSinkType Type { get; } | ||
|
||
void ReportMetric(string metricName, string metricDescription, ScrapeResult scrapedMetricResult); | ||
Task ReportMetricAsync(string metricName, string metricDescription, MeasuredMetric measuredMetric); | ||
} | ||
} |
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,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using GuardNet; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Promitor.Core.Scraping.Sinks | ||
{ | ||
public class MetricSinkWriter | ||
{ | ||
private readonly List<IMetricSink> _configuredSinks; | ||
private ILogger Logger { get; } | ||
|
||
public MetricSinkWriter(IEnumerable<IMetricSink> configuredSinks, ILogger<MetricSinkWriter> logger) | ||
{ | ||
var metricSinks = configuredSinks?.ToList(); | ||
Guard.NotNull(metricSinks, nameof(configuredSinks)); | ||
Guard.NotNull(logger, nameof(logger)); | ||
|
||
Logger = logger; | ||
_configuredSinks = metricSinks; | ||
} | ||
|
||
public async Task ReportMetricAsync(string metricName, string metricDescription, ScrapeResult scrapedMetricResult) | ||
{ | ||
Guard.NotNullOrWhitespace(metricName, nameof(metricName)); | ||
Guard.NotNull(scrapedMetricResult, nameof(scrapedMetricResult)); | ||
|
||
var reportTasks = new List<Task>(); | ||
foreach (var sink in _configuredSinks) | ||
{ | ||
var reportTask = ReportMetricAsync(sink, metricName, metricDescription, scrapedMetricResult); | ||
reportTasks.Add(reportTask); | ||
} | ||
|
||
await Task.WhenAll(reportTasks); | ||
} | ||
|
||
private async Task ReportMetricAsync(IMetricSink sink, string metricName, string metricDescription, ScrapeResult scrapedMetricResult) | ||
{ | ||
Guard.NotNull(sink, nameof(sink)); | ||
Guard.NotNullOrWhitespace(metricName, nameof(metricName)); | ||
Guard.NotNull(scrapedMetricResult, nameof(scrapedMetricResult)); | ||
Guard.NotNull(scrapedMetricResult.MetricValues, nameof(scrapedMetricResult.MetricValues)); | ||
|
||
foreach (var measuredMetric in scrapedMetricResult.MetricValues) | ||
{ | ||
try | ||
{ | ||
await sink.ReportMetricAsync(metricName, metricDescription, measuredMetric); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogCritical(ex, "Failed to write {MetricName} metric for sink {SinkType}", metricName, sink.Type); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
20 changes: 0 additions & 20 deletions
20
src/Promitor.Integrations.Sinks.Core/Promitor.Integrations.Sinks.Core.csproj
This file was deleted.
Oops, something went wrong.
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
21 changes: 15 additions & 6 deletions
21
src/Promitor.Integrations.Sinks.Statsd/StatsdMetricSink.cs
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,30 +1,39 @@ | ||
using GuardNet; | ||
using System.Threading.Tasks; | ||
using GuardNet; | ||
using JustEat.StatsD; | ||
using Microsoft.Extensions.Logging; | ||
using Promitor.Core.Scraping.Sinks; | ||
using Promitor.Integrations.AzureMonitor; | ||
using Promitor.Integrations.Sinks.Core; | ||
|
||
namespace Promitor.Integrations.Sinks.Statsd | ||
{ | ||
public class StatsdMetricSink : MetricSink | ||
public class StatsdMetricSink : IMetricSink | ||
{ | ||
private readonly ILogger<StatsdMetricSink> _logger; | ||
private readonly IStatsDPublisher _statsDPublisher; | ||
|
||
public StatsdMetricSink(IStatsDPublisher statsDPublisher, ILogger<StatsdMetricSink> logger) | ||
: base(logger) | ||
{ | ||
Guard.NotNull(statsDPublisher, nameof(statsDPublisher)); | ||
Guard.NotNull(logger, nameof(logger)); | ||
|
||
_statsDPublisher = statsDPublisher; | ||
_logger = logger; | ||
} | ||
|
||
public override MetricSinkType SinkType => MetricSinkType.StatsD; | ||
public MetricSinkType Type => MetricSinkType.StatsD; | ||
|
||
public override void ReportMetric(string metricName, string metricDescription, MeasuredMetric measuredMetric) | ||
public Task ReportMetricAsync(string metricName, string metricDescription, MeasuredMetric measuredMetric) | ||
{ | ||
Guard.NotNullOrEmpty(metricName, nameof(metricName)); | ||
Guard.NotNull(measuredMetric, nameof(measuredMetric)); | ||
|
||
var metricValue = measuredMetric.Value ?? 0; | ||
_statsDPublisher.Gauge(metricValue, metricName); | ||
|
||
_logger.LogTrace("Metric {MetricName} with value {MetricValue} was written to StatsD server", metricName, metricValue); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
Oops, something went wrong.