Created
May 16, 2015 01:38
-
-
Save annymsMthd/651f7e5b4872c266b4f3 to your computer and use it in GitHub Desktop.
Simple Collector
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
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using CentralStation.Actors.Services; | |
using CentralStation.Core; | |
using CentralStation.Core.Actors.Collectors; | |
using CentralStation.Core.Messages.Collectors; | |
using CentralStation.Core.PatternMatching; | |
using Syncromatics.Instrumentation.InfluxDb; | |
namespace CentralStation.Actors.Collectors | |
{ | |
public class InfluxStatsCollectorActor : IInfluxStatsCollectorActor | |
{ | |
private readonly IStatPointsWriter _influxDbClient; | |
public event MetricDelegate MetricUpdates; | |
public event UnHandledMessageDelegate UnHandledMessage; | |
private readonly List<InfluxDbPoint> _points = new List<InfluxDbPoint>(); | |
public InfluxStatsCollectorActor(IStatPointsWriter influxDbClient) | |
{ | |
_influxDbClient = influxDbClient; | |
} | |
public Task TellAsync(object message) | |
{ | |
return message.TaskMatch() | |
.With<InfluxDbPoint>(point => CollectPoint(point)) | |
.With<Collect>(async _ => await CollectPoints()) | |
.Execute(); | |
} | |
public void Tell(object message) | |
{ | |
TellAsync(message).Wait(); | |
} | |
private void CollectPoint(InfluxDbPoint point) | |
{ | |
_points.Add(point); | |
} | |
private async Task CollectPoints() | |
{ | |
await _influxDbClient.WriteAsync(_points); | |
_points.Clear(); | |
} | |
public void Dispose() | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment