public void Timings_intervals_are_merged_by_interval_start()
        {
            var intervals = new List <IntervalsStore <BreakdownId> .IntervalsBreakdown>
            {
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    Intervals = new []
                    {
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now, TotalMeasurements = 1, TotalValue = 1
                        }
                    }
                },
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    Intervals = new []
                    {
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now, TotalMeasurements = 2, TotalValue = 2
                        }
                    }
                }
            };

            var values = Aggregator.ToAverages(intervals, HistoryPeriod.FromMinutes(5));

            Assert.AreEqual(1, values.Points.Length);
            Assert.AreEqual(1.0d, values.Points[0]);
        }
        public void MetricAggregationByInstanceIsScopedToLogicalEndpoint()
        {
            var instanceAId = new EndpointInstanceId("EndpointA", "instance");
            var instanceBId = new EndpointInstanceId("EndpointB", "instance");

            endpointRegistry.Record(instanceAId);
            endpointRegistry.Record(instanceBId);

            var period = HistoryPeriod.FromMinutes(DiagramApiController.DefaultHistory);
            var now    = DateTime.UtcNow.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals));

            var dataA = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 5
            };
            var dataB = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 10
            };

            processingTimeStore.Store(new[] { dataA }, instanceAId, EndpointMessageType.Unknown(instanceAId.EndpointName));
            processingTimeStore.Store(new[] { dataB }, instanceBId, EndpointMessageType.Unknown(instanceBId.EndpointName));

            var result = apiController.GetSingleEndpointMetrics(instanceAId.EndpointName);

            var contentResult = result as OkNegotiatedContentResult <MonitoredEndpointDetails>;
            var model         = contentResult.Content;

            Assert.AreEqual(5, model.Instances[0].Metrics["ProcessingTime"].Average);
        }
        public void Timings_average_is_sum_of_total_values_by_total_measurements()
        {
            var intervals = new List <IntervalsStore <BreakdownId> .IntervalsBreakdown>
            {
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    TotalMeasurements = 2,
                    TotalValue        = 2,
                    Intervals         = EmptyIntervals
                },
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    TotalMeasurements = 4,
                    TotalValue        = 1,
                    Intervals         = EmptyIntervals
                }
            };

            var values = Aggregator.ToAverages(intervals, HistoryPeriod.FromMinutes(5));

            Assert.AreEqual(0.5d, values.Average);
        }
Exemple #4
0
        public void Point_value_is_sum_of_averages_per_input_queue()
        {
            var intervals = new List <IntervalsStore <EndpointInputQueue> .IntervalsBreakdown>
            {
                new IntervalsStore <EndpointInputQueue> .IntervalsBreakdown
                {
                    Id        = new EndpointInputQueue(endpointName: "", inputQueue: "queue-1"),
                    Intervals = new []
                    {
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now, TotalValue = 3, TotalMeasurements = 4
                        },
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now.AddSeconds(1), TotalValue = 2, TotalMeasurements = 3
                        },
                    }
                },
                new IntervalsStore <EndpointInputQueue> .IntervalsBreakdown
                {
                    Id        = new EndpointInputQueue(endpointName: "", inputQueue: "queue-2"),
                    Intervals = new []
                    {
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now, TotalValue = 5, TotalMeasurements = 6
                        },
                    }
                }
            };

            var values = Aggregator.ToRoundedSumOfBreakdownAverages(intervals, HistoryPeriod.FromMinutes(5));

            Assert.AreEqual(Math.Round(3d / 4d + 5d / 6d), values.Points[0]);
            Assert.AreEqual(Math.Round(2d / 3d), values.Points[1]);
        }
Exemple #5
0
        public void Total_measurements_per_second_are_merged_by_interval_start()
        {
            const long ridiculouslyBigLong1 = 374859734593849583;
            const long ridiculouslyBigLong2 = 898394895890348954;

            var intervals = new List <IntervalsStore <BreakdownId> .IntervalsBreakdown>
            {
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    Intervals = new []
                    {
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now, TotalValue = ridiculouslyBigLong1, TotalMeasurements = 4
                        },
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now.AddSeconds(2), TotalValue = ridiculouslyBigLong2, TotalMeasurements = 5
                        }
                    },
                    TotalMeasurements = 4 + 5
                },
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    Intervals = new []
                    {
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now, TotalValue = ridiculouslyBigLong1, TotalMeasurements = 6
                        },
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now.AddSeconds(2), TotalValue = ridiculouslyBigLong2, TotalMeasurements = 7
                        },
                    },
                    TotalMeasurements = 6 + 7
                }
            };

            var period  = HistoryPeriod.FromMinutes(5);
            var seconds = period.IntervalSize.TotalSeconds;
            var values  = Aggregator.ToTotalMeasurementsPerSecond(intervals, period);

            Assert.AreEqual((4d + 5d + 6d + 7d) / 2 / seconds, values.Average);
            Assert.AreEqual(2, values.Points.Length);
            Assert.AreEqual((4d + 6d) / seconds, values.Points[0]);
            Assert.AreEqual((5d + 7d) / seconds, values.Points[1]);
        }
Exemple #6
0
        public void Total_measurements_per_second_are_sum_of_total_measurements_by_number_of_unique_intervals_by_seconds()
        {
            var intervals = new List <IntervalsStore <BreakdownId> .IntervalsBreakdown>
            {
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    Intervals = new []
                    {
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now, TotalMeasurements = 7
                        },
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now.AddSeconds(1)
                        }
                    }
                },
                new IntervalsStore <BreakdownId> .IntervalsBreakdown
                {
                    Id = new BreakdownId {
                        Id = 0
                    },
                    Intervals = new []
                    {
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now
                        },
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now.AddSeconds(1), TotalMeasurements = 9
                        },
                        new IntervalsStore <BreakdownId> .TimeInterval {
                            IntervalStart = now
                        }
                    }
                }
            };

            var period  = HistoryPeriod.FromMinutes(5);
            var seconds = period.IntervalSize.TotalSeconds;

            var values = Aggregator.ToTotalMeasurementsPerSecond(intervals, period);

            Assert.AreEqual((7d + 9d) / 2 / seconds, values.Average);
        }
Exemple #7
0
        public void Intervals_are_merged_by_interval_start()
        {
            var intervals = new List <IntervalsStore <EndpointInputQueue> .IntervalsBreakdown>
            {
                new IntervalsStore <EndpointInputQueue> .IntervalsBreakdown
                {
                    Id        = new EndpointInputQueue(endpointName: "", inputQueue: "queue-1"),
                    Intervals = new[]
                    {
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now
                        },
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now.AddSeconds(2)
                        }
                    }
                },
                new IntervalsStore <EndpointInputQueue> .IntervalsBreakdown
                {
                    Id        = new EndpointInputQueue(endpointName: "", inputQueue: "queue-2"),
                    Intervals = new[]
                    {
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now
                        },
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now.AddSeconds(2)
                        },
                        new IntervalsStore <EndpointInputQueue> .TimeInterval {
                            IntervalStart = now.AddSeconds(3)
                        }
                    }
                }
            };

            var values = Aggregator.ToRoundedSumOfBreakdownAverages(intervals, HistoryPeriod.FromMinutes(5));

            Assert.AreEqual(3, values.Points.Length);
        }
        public void ValidateIfConnectivityMathIsCorrect()
        {
            var endpointName = "Endpoint";

            var instanceIds = new[] { "a", "b", "c" };
            var instances   = instanceIds.Select(instanceId => new EndpointInstanceId(endpointName, instanceId)).ToArray();

            Array.ForEach(instances, instance => endpointRegistry.Record(instance));

            var period = HistoryPeriod.FromMinutes(DiagramApiController.DefaultHistory); // 5 minutes, 5 second period

            var now       = DateTime.UtcNow;
            var timestamp = now.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals)); // now - 5 seconds

            var samples = new[] {
                new RawMessage.Entry {
                    DateTicks = timestamp.Ticks, Value = 5
                },
                new RawMessage.Entry {
                    DateTicks = timestamp.Ticks, Value = 10
                }
            };

            var connected = instances.Take(2).ToArray();

            Array.ForEach(connected, instance => activityTracker.Record(instance, now));
            Array.ForEach(connected, instance => processingTimeStore.Store(samples, instance, EndpointMessageType.Unknown(instance.EndpointName)));

            var result        = apiController.GetAllEndpointsMetrics();
            var contentResult = result as OkNegotiatedContentResult <MonitoredEndpoint[]>;
            var model         = contentResult.Content;
            var item          = model[0];

            Assert.AreEqual(3, item.EndpointInstanceIds.Length, nameof(item.EndpointInstanceIds));
            Assert.AreEqual(2, item.ConnectedCount, nameof(item.ConnectedCount));
            Assert.AreEqual(1, item.DisconnectedCount, nameof(item.DisconnectedCount));
        }
Exemple #9
0
        public void Total_average_is_sum_of_averages_per_input_queue()
        {
            var intervals = new List <IntervalsStore <EndpointInputQueue> .IntervalsBreakdown>
            {
                new IntervalsStore <EndpointInputQueue> .IntervalsBreakdown
                {
                    Id                = new EndpointInputQueue(endpointName: "", inputQueue: "queue-1"),
                    TotalValue        = 3,
                    TotalMeasurements = 1,
                    Intervals         = EmptyIntervals
                },
                new IntervalsStore <EndpointInputQueue> .IntervalsBreakdown
                {
                    Id                = new EndpointInputQueue(endpointName: "", inputQueue: "queue-2"),
                    TotalValue        = 41,
                    TotalMeasurements = 5,
                    Intervals         = EmptyIntervals
                }
            };

            var values = Aggregator.ToRoundedSumOfBreakdownAverages(intervals, HistoryPeriod.FromMinutes(5));

            Assert.AreEqual(Math.Round(3d / 1d + 41d / 5d), values.Average);
        }
        public async Task MetricAggregationByInstanceIsScopedToLogicalEndpoint()
        {
            var processingTimeStore = new ProcessingTimeStore();
            var endpointRegistry    = new EndpointRegistry();

            var queryAction = CreateQuery(processingTimeStore, endpointRegistry);

            var instanceAId = new EndpointInstanceId("EndpointA", "instance");
            var instanceBId = new EndpointInstanceId("EndpointB", "instance");

            endpointRegistry.Record(instanceAId);
            endpointRegistry.Record(instanceBId);

            var period = HistoryPeriod.FromMinutes(MonitoredEndpointsModule.DefaultHistory);
            var now    = DateTime.UtcNow.Subtract(new TimeSpan(period.IntervalSize.Ticks * period.DelayedIntervals));

            var dataA = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 5
            };
            var dataB = new RawMessage.Entry {
                DateTicks = now.Ticks, Value = 10
            };

            processingTimeStore.Store(new[] { dataA }, instanceAId, EndpointMessageType.Unknown(instanceAId.EndpointName));
            processingTimeStore.Store(new[] { dataB }, instanceBId, EndpointMessageType.Unknown(instanceBId.EndpointName));

            var result = await queryAction(new
            {
                instanceAId.EndpointName
            }.ToDynamic(), new CancellationToken());

            var model = (MonitoredEndpointDetails)result.NegotiationContext.DefaultModel;


            Assert.AreEqual(5, model.Instances[0].Metrics["ProcessingTime"].Average);
        }
Exemple #11
0
        HistoryPeriod ExtractHistoryPeriod()
        {
            var query = Request.RequestUri.ParseQueryString();

            return(HistoryPeriod.FromMinutes(query["history"] == null || query["history"] == "undefined" ? DefaultHistory : int.Parse(query["history"])));
        }
Exemple #12
0
 HistoryPeriod ExtractHistoryPeriod()
 {
     return(HistoryPeriod.FromMinutes(Request.Query["history"] == null || Request.Query["history"] == "undefined" ? DefaultHistory : (int)Request.Query["history"]));
 }