public MetricsTrackerTelemetryConsumer(IProviderRuntime runtime) { try { Runtime = runtime; logger = Runtime.GetLogger(nameof(MetricsTrackerTelemetryConsumer)); Configuration = new MetricsConfiguration(); Counters = new ConcurrentDictionary <string, long>(); CounterHistory = new ConcurrentDictionary <string, ConcurrentQueue <long> >(); Metrics = new ConcurrentDictionary <string, double>(); MetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <double> >(); TimeSpanMetrics = new ConcurrentDictionary <string, TimeSpan>(); TimeSpanMetricHistory = new ConcurrentDictionary <string, ConcurrentQueue <TimeSpan> >(); Requests = new ConcurrentDictionary <string, MeasuredRequest>(); RequestHistory = new ConcurrentDictionary <string, ConcurrentQueue <MeasuredRequest> >(); // start a message pump to give ourselves the right synchronization context // from which we can communicate with grains via normal grain references // TODO: don't start the pump until it's been requested StartMessagePump().Ignore(); Management = Runtime.GrainFactory.GetGrain <IManagementGrain>(0); } catch (Exception ex) { logger.TrackException(ex); throw; } }
public override Task OnActivateAsync() { try { logger = GetLogger("ClusterMetricsGrain"); Configuration = new MetricsConfiguration(); ClusterSnapshot = new MetricsSnapshot { Source = nameof(ClusterMetricsGrain) }; SiloSnapshots = new Dictionary <string, MetricsSnapshot>(); Subscribers = new ObserverSubscriptionManager <IClusterMetricsGrainObserver>(); return(base.OnActivateAsync()); } catch (Exception ex) { if (logger != null) { logger.TrackException(ex); } throw; } }
// TODO: figure out how to subscribe with a GrainObserver, or some other method // so that the server can push messages to this telemetry consumer async Task UpdateConfiguration() { try { var oldConfig = Configuration; var metricsGrain = Runtime.GrainFactory.GetGrain <IClusterMetricsGrain>(Guid.Empty); Configuration = await metricsGrain.GetMetricsConfiguration(); if (Configuration.HistoryLength != oldConfig.HistoryLength) { TrimHistories(); } // TODO: figure out if this will interfere with other silo interceptors ConfigureSiloInterceptor(enable: Configuration.NeedSiloInterceptor); } catch (Exception ex) { logger.TrackException(ex); throw; } finally { LastConfigCheck = DateTime.UtcNow; } }
public async Task Configure(MetricsConfiguration config) { try { Configuration = config; // TODO: figure out how to get MetricsTrackerTelemetryConsumer to get notifications // using grain observables if (Subscribers != null) { Subscribers.Notify(o => o.Configure(config)); } // using streams if (!string.IsNullOrWhiteSpace(Configuration.StreamingProviderName)) { try { StreamProvider = GrainClient.GetStreamProvider(Configuration.StreamingProviderName); ClusterSnapshotStream = StreamProvider.GetStream <MetricsSnapshot>(Guid.Empty, "ClusterMetricSnapshots"); SiloSnapshotStream = StreamProvider.GetStream <MetricsSnapshot>(Guid.Empty, "SiloMetricSnapshots"); } catch (Exception ex) { // probably here because stream provider wasn't found // TODO: handle better logger.TrackException(ex); // don't rethrow the exception } } else { if (ClusterSnapshotStream != null) { await ClusterSnapshotStream.OnCompletedAsync(); } if (SiloSnapshotStream != null) { await SiloSnapshotStream.OnCompletedAsync(); } ClusterSnapshotStream = null; SiloSnapshotStream = null; } logger.IncrementMetric("ClusterMetricsConfigured"); } catch (Exception ex) { logger.TrackException(ex); throw; } }
public void Configure(MetricsConfiguration config) { }