public override Task OnActivateAsync()
        {
            try
            {
                logger = GetLogger(nameof(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;
            }
        }
        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");

                        ActivateClusterMetricsTimer();
                    }
                    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;
            }
        }
示例#3
0
        public MetricsTrackerTelemetryConsumer(IProviderRuntime runtime, TaskScheduler taskScheduler)
        {
            try
            {
                Runtime       = runtime;
                TaskScheduler = taskScheduler;

                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> >();

                PreviousInterceptor = Runtime.GetInvokeInterceptor();

                // 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();
                //Task.Factory.StartNew(() => StartMessagePump(), CancellationToken.None, TaskCreationOptions.None, TaskScheduler);
                var dispatchTask = Dispatch(() => StartMessagePump());

                Management = Runtime.GrainFactory.GetGrain <IManagementGrain>(0);
            }
            catch (Exception ex)
            {
                logger.TrackException(ex);
                throw;
            }
        }
示例#4
0
        // 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();

                ConfigureSiloInterceptor(enable: Configuration.NeedSiloInterceptor);
            }
            catch (Exception ex)
            {
                logger.TrackException(ex);
                throw;
            }
            finally
            {
                LastConfigCheck = DateTime.UtcNow;
            }
        }
示例#5
0
 public void Configure(MetricsConfiguration config)
 {
 }