Пример #1
0
        public IHttpActionResult GetSingleEndpointMetrics(string endpointName)
        {
            var metricByInstanceLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointInstanceId> >().ToDictionary(i => i.GetType());

            var metricByQueueLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointInputQueue> >().ToDictionary(i => i.GetType());

            var metricByMessageTypeLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointMessageType> >().ToDictionary(i => i.GetType());

            var period = ExtractHistoryPeriod();

            var instances = GetMonitoredEndpointInstances(endpointRegistry, endpointName, activityTracker);

            var digest        = new MonitoredEndpointDigest();
            var metricDetails = new MonitoredEndpointMetricDetails();

            foreach (var metric in InstanceMetrics)
            {
                var store     = metricByInstanceLookup[metric.StoreType];
                var intervals = store.GetIntervals(period, DateTime.UtcNow);

                var intervalsByEndpoint = intervals.ToLookup(k => k.Id.EndpointName);

                var endpointValues = metric.Aggregate(intervalsByEndpoint[endpointName].ToList(), period);

                if (DetailedMetrics.Contains(metric.ReturnName))
                {
                    var details = new MonitoredValuesWithTimings
                    {
                        Points         = endpointValues.Points,
                        Average        = endpointValues.Average,
                        TimeAxisValues = GetTimeAxisValues(intervalsByEndpoint[endpointName])
                    };

                    metricDetails.Metrics.Add(metric.ReturnName, details);
                }

                var metricDigest = new MonitoredEndpointMetricDigest
                {
                    Latest  = endpointValues.Points.LastOrDefault(),
                    Average = endpointValues.Average
                };

                digest.Metrics.Add(metric.ReturnName, metricDigest);

                var intervalsByInstanceId = intervals.ToLookup(k => k.Id);

                foreach (var instance in instances)
                {
                    var instanceId = new EndpointInstanceId(endpointName, instance.Id, instance.Name);

                    var instanceValues = metric.Aggregate(intervalsByInstanceId[instanceId].ToList(), period);

                    instance.Metrics.Add(metric.ReturnName, instanceValues);
                }
            }

            foreach (var metric in QueueMetrics)
            {
                var store     = metricByQueueLookup[metric.StoreType];
                var intervals = store.GetIntervals(period, DateTime.UtcNow);

                var intervalsByEndpoint = intervals.ToLookup(k => k.Id.EndpointName);

                var endpointValues = metric.Aggregate(intervalsByEndpoint[endpointName].ToList(), period);

                if (DetailedMetrics.Contains(metric.ReturnName))
                {
                    var details = new MonitoredValuesWithTimings
                    {
                        Points         = endpointValues.Points,
                        Average        = endpointValues.Average,
                        TimeAxisValues = GetTimeAxisValues(intervalsByEndpoint[endpointName])
                    };

                    metricDetails.Metrics.Add(metric.ReturnName, details);
                }

                var metricDigest = new MonitoredEndpointMetricDigest
                {
                    Latest  = endpointValues.Points.LastOrDefault(),
                    Average = endpointValues.Average
                };

                digest.Metrics.Add(metric.ReturnName, metricDigest);
            }

            var messageTypes = GetMonitoredMessageTypes(messageTypeRegistry.GetForEndpointName(endpointName));

            foreach (var metric in MessageTypeMetrics)
            {
                var store     = metricByMessageTypeLookup[metric.StoreType];
                var intervals = store.GetIntervals(period, DateTime.UtcNow).ToLookup(k => k.Id);

                foreach (var messageType in messageTypes)
                {
                    var values = metric.Aggregate(intervals[new EndpointMessageType(endpointName, messageType.Id)].ToList(), period);

                    messageType.Metrics.Add(metric.ReturnName, values);
                }
            }

            var data = new MonitoredEndpointDetails
            {
                Digest        = digest,
                Instances     = instances,
                MessageTypes  = messageTypes,
                MetricDetails = metricDetails
            };

            return(Ok(data));
        }
Пример #2
0
        /// <summary>
        /// Initializes the metric API module.
        /// </summary>
        public MonitoredEndpointsModule(IProvideBreakdown[] breakdownProviders, EndpointRegistry endpointRegistry, EndpointInstanceActivityTracker activityTracker, MessageTypeRegistry messageTypeRegistry)
        {
            var metricByInstanceLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointInstanceId> >().ToDictionary(i => i.GetType());

            var metricByQueueLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointInputQueue> >().ToDictionary(i => i.GetType());

            var metricByMessageTypeLookup = breakdownProviders.OfType <IProvideBreakdownBy <EndpointMessageType> >().ToDictionary(i => i.GetType());

            var instanceMetrics = new[]
            {
                CreateMetric <EndpointInstanceId, ProcessingTimeStore>("ProcessingTime", Aggregator.ToAverages),
                CreateMetric <EndpointInstanceId, CriticalTimeStore>("CriticalTime", Aggregator.ToAverages),
                CreateMetric <EndpointInstanceId, RetriesStore>("Retries", Aggregator.ToTotalMeasurementsPerSecond),
                CreateMetric <EndpointInstanceId, ProcessingTimeStore>("Throughput", Aggregator.ToTotalMeasurementsPerSecond)
            };

            var queueMetrics = new[]
            {
                CreateMetric <EndpointInputQueue, QueueLengthStore>("QueueLength", Aggregator.ToRoundedSumOfBreakdownAverages)
            };

            var messageTypeMetrics = new[]
            {
                CreateMetric <EndpointMessageType, ProcessingTimeStore>("ProcessingTime", Aggregator.ToAverages),
                CreateMetric <EndpointMessageType, CriticalTimeStore>("CriticalTime", Aggregator.ToAverages),
                CreateMetric <EndpointMessageType, RetriesStore>("Retries", Aggregator.ToTotalMeasurementsPerSecond),
                CreateMetric <EndpointMessageType, ProcessingTimeStore>("Throughput", Aggregator.ToTotalMeasurementsPerSecond)
            };

            var detailedMetrics = new HashSet <string>
            {
                "Throughput",
                "QueueLength",
                "ProcessingTime",
                "CriticalTime",
                "Retries"
            };

            Get["/monitored-endpoints"] = parameters =>
            {
                var endpoints = GetMonitoredEndpoints(endpointRegistry, activityTracker);
                var period    = ExtractHistoryPeriod();

                foreach (var metric in instanceMetrics)
                {
                    var store     = metricByInstanceLookup[metric.StoreType];
                    var intervals = store.GetIntervals(period, DateTime.UtcNow).ToLookup(k => k.Id.EndpointName);

                    foreach (var endpoint in endpoints)
                    {
                        var values = metric.Aggregate(intervals[endpoint.Name].ToList(), period);

                        endpoint.Metrics.Add(metric.ReturnName, values);
                    }
                }

                foreach (var metric in queueMetrics)
                {
                    var store     = metricByQueueLookup[metric.StoreType];
                    var intervals = store.GetIntervals(period, DateTime.UtcNow).ToLookup(k => k.Id.EndpointName);

                    foreach (var endpoint in endpoints)
                    {
                        var values = metric.Aggregate(intervals[endpoint.Name].ToList(), period);

                        endpoint.Metrics.Add(metric.ReturnName, values);
                    }
                }

                return(Negotiate.WithModel(endpoints));
            };

            Get["/monitored-endpoints/{endpointName}"] = parameters =>
            {
                var endpointName = (string)parameters.EndpointName;
                var period       = ExtractHistoryPeriod();

                var instances = GetMonitoredEndpointInstances(endpointRegistry, endpointName, activityTracker);

                var digest        = new MonitoredEndpointDigest();
                var metricDetails = new MonitoredEndpointMetricDetails();

                foreach (var metric in instanceMetrics)
                {
                    var store     = metricByInstanceLookup[metric.StoreType];
                    var intervals = store.GetIntervals(period, DateTime.UtcNow);

                    var intervalsByEndpoint = intervals.ToLookup(k => k.Id.EndpointName);

                    var endpointValues = metric.Aggregate(intervalsByEndpoint[endpointName].ToList(), period);

                    if (detailedMetrics.Contains(metric.ReturnName))
                    {
                        var details = new MonitoredValuesWithTimings
                        {
                            Points         = endpointValues.Points,
                            Average        = endpointValues.Average,
                            TimeAxisValues = GetTimeAxisValues(intervalsByEndpoint[endpointName])
                        };

                        metricDetails.Metrics.Add(metric.ReturnName, details);
                    }

                    var metricDigest = new MonitoredEndpointMetricDigest
                    {
                        Latest  = endpointValues.Points.LastOrDefault(),
                        Average = endpointValues.Average
                    };

                    digest.Metrics.Add(metric.ReturnName, metricDigest);

                    var intervalsByInstanceId = intervals.ToLookup(k => k.Id);

                    foreach (var instance in instances)
                    {
                        var instanceId = new EndpointInstanceId(endpointName, instance.Id, instance.Name);

                        var instanceValues = metric.Aggregate(intervalsByInstanceId[instanceId].ToList(), period);

                        instance.Metrics.Add(metric.ReturnName, instanceValues);
                    }
                }

                foreach (var metric in queueMetrics)
                {
                    var store     = metricByQueueLookup[metric.StoreType];
                    var intervals = store.GetIntervals(period, DateTime.UtcNow);

                    var intervalsByEndpoint = intervals.ToLookup(k => k.Id.EndpointName);

                    var endpointValues = metric.Aggregate(intervalsByEndpoint[endpointName].ToList(), period);

                    if (detailedMetrics.Contains(metric.ReturnName))
                    {
                        var details = new MonitoredValuesWithTimings
                        {
                            Points         = endpointValues.Points,
                            Average        = endpointValues.Average,
                            TimeAxisValues = GetTimeAxisValues(intervalsByEndpoint[endpointName])
                        };

                        metricDetails.Metrics.Add(metric.ReturnName, details);
                    }

                    var metricDigest = new MonitoredEndpointMetricDigest
                    {
                        Latest  = endpointValues.Points.LastOrDefault(),
                        Average = endpointValues.Average
                    };

                    digest.Metrics.Add(metric.ReturnName, metricDigest);
                }

                var messageTypes = GetMonitoredMessageTypes(messageTypeRegistry.GetForEndpointName(endpointName));

                foreach (var metric in messageTypeMetrics)
                {
                    var store     = metricByMessageTypeLookup[metric.StoreType];
                    var intervals = store.GetIntervals(period, DateTime.UtcNow).ToLookup(k => k.Id);

                    foreach (var messageType in messageTypes)
                    {
                        var values = metric.Aggregate(intervals[new EndpointMessageType(endpointName, messageType.Id)].ToList(), period);

                        messageType.Metrics.Add(metric.ReturnName, values);
                    }
                }

                var data = new MonitoredEndpointDetails
                {
                    Digest        = digest,
                    Instances     = instances,
                    MessageTypes  = messageTypes,
                    MetricDetails = metricDetails
                };

                return(Negotiate.WithModel(data));
            };
        }