public void CreateMetrics_LastValueAgg_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var tagsComponent = new TagsComponent(); var tagger = tagsComponent.Tagger; var ep = new MicrometerMetricWriter(opts, stats); IMeasureDouble testMeasure = MeasureDouble.Create("test.total", "test", MeasureUnit.Bytes); SetupTestView(stats, LastValue.Create(), testMeasure, "test.test1"); ITagContext context1 = tagger .EmptyBuilder .Put(TagKey.Create("a"), TagValue.Create("v1")) .Put(TagKey.Create("b"), TagValue.Create("v1")) .Put(TagKey.Create("c"), TagValue.Create("v1")) .Build(); long allKeyssum = 0; for (int i = 0; i < 10; i++) { allKeyssum = allKeyssum + i; stats.StatsRecorder.NewMeasureMap().Put(testMeasure, i).Record(context1); } var viewData = stats.ViewManager.GetView(ViewName.Create("test.test1")); Assert.NotNull(viewData); var aggMap = viewData.AggregationMap; Assert.Single(aggMap); var tagValues = aggMap.Keys.Single(); var data = aggMap.Values.Single(); Assert.NotNull(tagValues); Assert.NotNull(data); var result = ep.CreateMetrics(viewData, data, tagValues, 1L); Assert.NotNull(result); Assert.Single(result); var metric = result[0]; Assert.Equal("test.test1", metric.Name); Assert.Equal(1L, metric.Timestamp); Assert.Equal("gauge", metric.Type); Assert.Equal("bytes", metric.Unit); Assert.Equal(9, metric.Value); var tags = metric.Tags; Assert.Equal("value", tags["statistic"]); Assert.Equal("v1", tags["a"]); Assert.Equal("v1", tags["b"]); Assert.Equal("v1", tags["c"]); }
public void TestMatch() { List <IAggregation> aggregations = new List <IAggregation>() { Sum.Create(), Count.Create(), Mean.Create(), Distribution.Create(BucketBoundaries.Create(new List <double>() { -10.0, 1.0, 5.0 })), LastValue.Create() }; List <String> actual = new List <String>(); foreach (IAggregation aggregation in aggregations) { actual.Add( aggregation.Match( (arg) => { return("SUM"); }, (arg) => { return("COUNT"); }, (arg) => { return("MEAN"); }, (arg) => { return("DISTRIBUTION"); }, (arg) => { return("LASTVALUE"); }, (arg) => { throw new ArgumentException(); })); } Assert.Equal(new List <string>() { "SUM", "COUNT", "MEAN", "DISTRIBUTION", "LASTVALUE" }, actual); }
public bool AddNewLastValue(int id, double value) { LastValue lastValue = Entities.LastValues.FirstOrDefault(x => x.Id == id); lastValue.Value = value; lastValue.Date = DateTime.Now; if (Entities.SaveChanges() > 0) { return(true); } return(false); }
public void PreventAggregationAndAggregationDataMismatch_LastValueDouble_LastValueLong() { var tagValues = TagValues.Create(new List <string>() { V1, V2 }); AggregationAndAggregationDataMismatch( CreateView(LastValue.Create(), MEASURE_DOUBLE), new Dictionary <TagValues, IAggregationData>() { { tagValues, LastValueDataLong.Create(100) }, }); }
public void PreventAggregationAndAggregationDataMismatch_LastValueLong_LastValueDouble() { var tagValues = TagValues.Create(new List <ITagValue>() { V1, V2 }); AggregationAndAggregationDataMismatch( CreateView(LastValue.Create(), MEASURE_LONG), new Dictionary <TagValues, IAggregationData>() { { tagValues, LastValueDataDouble.Create(100) } }); }
public void GetTwoLabel() { AggregatorStore <LastValue> store = new AggregatorStore <LastValue>(() => new LastValue()); KeyValuePair <string, object?>[] labels1 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("color", "red"), new KeyValuePair <string, object?>("name", "ned") }; KeyValuePair <string, object?>[] labels2 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("color", "blue"), new KeyValuePair <string, object?>("name", "ned") }; KeyValuePair <string, object?>[] labels3 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("size", 1), new KeyValuePair <string, object?>("name", "ned") }; KeyValuePair <string, object?>[] labels4 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("size", "eight"), new KeyValuePair <string, object?>("name", "ned") }; var span1 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels1, 0, 2); var span2 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels2, 0, 2); var span3 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels3, 0, 2); var span4 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels4, 0, 2); LastValue val1 = store.GetAggregator(span1); Assert.NotNull(val1); Assert.Equal(val1, store.GetAggregator(span1)); LastValue val2 = store.GetAggregator(span2); Assert.NotNull(val2); Assert.NotEqual(val1, val2); Assert.Equal(val2, store.GetAggregator(span2)); Assert.Equal(val1, store.GetAggregator(span1)); LastValue val3 = store.GetAggregator(span3); Assert.NotNull(val3); Assert.NotEqual(val1, val3); Assert.NotEqual(val2, val3); Assert.Equal(val3, store.GetAggregator(span3)); LastValue val4 = store.GetAggregator(span4); Assert.NotNull(val4); Assert.NotEqual(val1, val4); Assert.NotEqual(val2, val4); Assert.NotEqual(val3, val4); Assert.Equal(val4, store.GetAggregator(span4)); Assert.Equal(val4, store.GetAggregator(span4)); Assert.Equal(val3, store.GetAggregator(span3)); Assert.Equal(val1, store.GetAggregator(span1)); Assert.Equal(val2, store.GetAggregator(span2)); Assert.Equal(val4, store.GetAggregator(span4)); Assert.Equal(val2, store.GetAggregator(span2)); Assert.Equal(val3, store.GetAggregator(span3)); Assert.Equal(val3, store.GetAggregator(span3)); }
public override string ToString() { if (TotalSamples > 0) { return(string.Format("{0} .. {1}, {2} ({3} smps)", MinValue.ToString(FmtString, CultureInfo.InvariantCulture), MaxValue.ToString(FmtString, CultureInfo.InvariantCulture), LastValue.ToString(FmtString, CultureInfo.InvariantCulture), TotalSamples)); } else { return("- - -"); } }
public void Teest() { ConnectionReader connectionNoW = new ConnectionReader(); connectionNoW.Start(); ConnectionNoW connectionNoW2 = new ConnectionNoW(); connectionNoW2.Start(); NumberWorkers numberWorkers = new NumberWorkers(); numberWorkers.Number(); ValuesFromInterval valuesFromInterval = new ValuesFromInterval(); Refreshing refreshing = new Refreshing(); LastValue lastValue = new LastValue(); }
public void GetStatistic_ReturnsExpected() { var opts = new CloudFoundryForwarderOptions(); var stats = new OpenCensusStats(); var ep = new MicrometerMetricWriter(opts, stats); var m1 = MeasureDouble.Create("test.totalTime", "test", MeasureUnit.Seconds); var result = ep.GetStatistic(Sum.Create(), m1); Assert.Equal("totalTime", result); var m2 = MeasureDouble.Create("test.value", "test", MeasureUnit.Seconds); result = ep.GetStatistic(LastValue.Create(), m2); Assert.Equal("value", result); var m3 = MeasureDouble.Create("test.count", "test", MeasureUnit.Seconds); result = ep.GetStatistic(Count.Create(), m3); Assert.Equal("count", result); var m4 = MeasureDouble.Create("test.sum", "test", MeasureUnit.Bytes); result = ep.GetStatistic(Sum.Create(), m4); Assert.Equal("total", result); var m5 = MeasureDouble.Create("foobar", "test", MeasureUnit.Seconds); result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 1.0, 5.0, 10.0, 100.0 })), m5); Assert.Equal("totalTime", result); var m6 = MeasureDouble.Create("foobar", "test", MeasureUnit.Bytes); result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 1.0, 5.0, 10.0, 100.0 })), m6); Assert.Equal("total", result); }
public void GetStatistic_ReturnsExpected() { var opts = new MetricsEndpointOptions(); var stats = new OpenCensusStats(); var ep = new MetricsEndpoint(opts, stats); var m1 = MeasureDouble.Create("test.totalTime", "test", MeasureUnit.Seconds); var result = ep.GetStatistic(Sum.Create(), m1); Assert.Equal(MetricStatistic.TOTALTIME, result); var m2 = MeasureDouble.Create("test.value", "test", MeasureUnit.Seconds); result = ep.GetStatistic(LastValue.Create(), m2); Assert.Equal(MetricStatistic.VALUE, result); var m3 = MeasureDouble.Create("test.count", "test", MeasureUnit.Seconds); result = ep.GetStatistic(Count.Create(), m3); Assert.Equal(MetricStatistic.COUNT, result); var m4 = MeasureDouble.Create("test.sum", "test", MeasureUnit.Bytes); result = ep.GetStatistic(Sum.Create(), m4); Assert.Equal(MetricStatistic.TOTAL, result); var m5 = MeasureDouble.Create("foobar", "test", MeasureUnit.Seconds); result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 1.0, 5.0, 10.0, 100.0 })), m5); Assert.Equal(MetricStatistic.TOTALTIME, result); var m6 = MeasureDouble.Create("foobar", "test", MeasureUnit.Bytes); result = ep.GetStatistic(Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 1.0, 5.0, 10.0, 100.0 })), m6); Assert.Equal(MetricStatistic.TOTAL, result); }
public void GetTwoLabelUnordered() { AggregatorStore <LastValue> store = new AggregatorStore <LastValue>(() => new LastValue()); KeyValuePair <string, object?>[] labels1 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("color", "red"), new KeyValuePair <string, object?>("name", "ned") }; KeyValuePair <string, object?>[] labels2 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("name", "ned"), new KeyValuePair <string, object?>("color", "red") }; var span1 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels1, 0, 2); var span2 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels2, 0, 2); LastValue val1 = store.GetAggregator(span1); Assert.NotNull(val1); Assert.Equal(val1, store.GetAggregator(span1)); LastValue val2 = store.GetAggregator(span2); Assert.NotNull(val2); Assert.Equal(val2, store.GetAggregator(span2)); Assert.Equal(val1, val2); }
public void TestEquals() { IAggregation a1 = Sum.Create(); IAggregation a2 = Sum.Create(); IAggregation a3 = Count.Create(); IAggregation a4 = Count.Create(); IAggregation a5 = Distribution.Create(BucketBoundaries.Create(new List <double>() { -10.0, 1.0, 5.0 })); IAggregation a6 = Distribution.Create(BucketBoundaries.Create(new List <double>() { -10.0, 1.0, 5.0 })); IAggregation a7 = Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 1.0, 5.0 })); IAggregation a8 = Distribution.Create(BucketBoundaries.Create(new List <double>() { 0.0, 1.0, 5.0 })); IAggregation a9 = Mean.Create(); IAggregation a10 = Mean.Create(); IAggregation a11 = LastValue.Create(); IAggregation a12 = LastValue.Create(); Assert.Equal(a1, a2); Assert.Equal(a3, a4); Assert.Equal(a5, a6); Assert.Equal(a7, a8); Assert.Equal(a9, a10); Assert.Equal(a11, a12); }
public LastValue2 GetLastValue(int id) { Entities = new MonitoringEntities(); LastValue lastValue = Entities.LastValues.FirstOrDefault(x => x.Id == id); LastValue2 result = new LastValue2(); if (lastValue != null) { result.Id = id; result.Date = lastValue.Date; if (lastValue.Date != null) { result.PersianDateString = ((DateTime)lastValue.Date).ToPersianString(); } result.Value = lastValue.Value; result.HasError = false; } return(result); }
public void CreateMutableAggregation() { IBucketBoundaries bucketBoundaries = BucketBoundaries.Create(new List <double>() { -1.0, 0.0, 1.0 }); Assert.InRange(((MutableSum)MutableViewData.CreateMutableAggregation(Sum.Create())).Sum, 0.0 - EPSILON, 0.0 + EPSILON); Assert.Equal(0, ((MutableCount)MutableViewData.CreateMutableAggregation(Count.Create())).Count); Assert.InRange(((MutableMean)MutableViewData.CreateMutableAggregation(Mean.Create())).Mean, 0.0 - EPSILON, 0.0 + EPSILON); Assert.True(Double.IsNaN(((MutableLastValue)MutableViewData.CreateMutableAggregation(LastValue.Create())).LastValue)); MutableDistribution mutableDistribution = (MutableDistribution) MutableViewData.CreateMutableAggregation(Distribution.Create(bucketBoundaries)); Assert.Equal(double.PositiveInfinity, mutableDistribution.Min); Assert.Equal(double.NegativeInfinity, mutableDistribution.Max); Assert.InRange(mutableDistribution.SumOfSquaredDeviations, 0.0 - EPSILON, 0.0 + EPSILON); Assert.Equal(new long[4], mutableDistribution.BucketCounts); }
public async Task NotRegisterSensor_WhenSensorIsBooleanAndNonZeroValuesAreSetToMinAndMaxValue() { // Arrange // arrange controller Mock <ApplicationDbContext> mockApplicationDbContext = new Mock <ApplicationDbContext>(); Mock <SensorDbService> mockSensorDbService = new Mock <SensorDbService>(mockApplicationDbContext.Object); Mock <HttpClient> mockHttpClient = new Mock <HttpClient>(); Mock <SensorApiService> mockSensorApiService = new Mock <SensorApiService>(mockHttpClient.Object); //arrange RegisterNewSensorViewModel DateTime testDateTime1 = DateTime.Now; Sensor testSensor = new Sensor { SensorId = 8, Name = "dsadas", DescriptionGivenByTheUser = "******", MeasurementType = "C", IsPublic = true, OperatingRange = "This sensor will return true or false value", //reference MinValue = 13.4, //invalid testing value MaxValue = 14.4, //invalid testing value AddedOn = testDateTime1, Measurements = new HashSet <Measurement>(), SharedWith = new HashSet <ApplicationUser>() }; DateTime testDateTime2 = DateTime.Now; LastValue testLastValue = new LastValue { SensorId = 45, Sensor = testSensor, SensorIdICB = "SensorIdICB", PollingInterval = 10, Value = "Value", LastUpdatedOn = testDateTime2 }; testSensor.LastValue = testLastValue; RegisterNewSensorViewModel expected = new RegisterNewSensorViewModel { Sensor = testSensor }; //koleto. Zaradi validaciite SensorType sensorType = new SensorType { Id = 342, SensorIdICB = "SensorIdICB", IsNumericValue = true, MeasureType = "C", MinPollingIntervalInSeconds = 2, Tag = "Tag" }; mockSensorDbService.Setup(x => x.GetSpecificSensorType("SensorIdICB")) .Returns(sensorType); IDictionary <string, SensorReadInData> mockSensorsFromAPI = new Dictionary <string, SensorReadInData>(); mockSensorsFromAPI.Add("SensorIdICB", new SensorReadInData() { Tag = "Tag", MinPollingIntervalInSeconds = 0, MeasureType = "C", Description = "This sensor will return values between 6 and 18", SensorId = "SensorIdICB" }); mockSensorApiService.Setup(x => x.ListSensorsFromAPI()) .Returns(Task.Run(() => mockSensorsFromAPI)); //arrange username string loggeduser = "******"; // arrange actual controller SensorControllerMock controller = new SensorControllerMock(loggeduser, mockSensorDbService.Object, mockSensorApiService.Object); //act await controller.RegisterNewSensor(expected); // assert mockSensorDbService.Verify(x => x.RegisterNewSensor(loggeduser, testSensor), Times.Never); }
public void GetFourLabelUnordered() { AggregatorStore <LastValue> store = new AggregatorStore <LastValue>(() => new LastValue()); KeyValuePair <string, object?>[] labels1 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("alpha", 15), new KeyValuePair <string, object?>("color", "red"), new KeyValuePair <string, object?>("name", "ned"), new KeyValuePair <string, object?>("four", 44) }; KeyValuePair <string, object?>[] labels2 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("alpha", 15), new KeyValuePair <string, object?>("name", "ned"), new KeyValuePair <string, object?>("four", 44), new KeyValuePair <string, object?>("color", "red") }; KeyValuePair <string, object?>[] labels3 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("four", 44), new KeyValuePair <string, object?>("color", "red"), new KeyValuePair <string, object?>("alpha", 15), new KeyValuePair <string, object?>("name", "ned") }; KeyValuePair <string, object?>[] labels4 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("name", "ned"), new KeyValuePair <string, object?>("four", 44), new KeyValuePair <string, object?>("alpha", 15), new KeyValuePair <string, object?>("color", "red") }; KeyValuePair <string, object?>[] labels5 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("color", "red"), new KeyValuePair <string, object?>("name", "ned"), new KeyValuePair <string, object?>("alpha", 15), new KeyValuePair <string, object?>("four", 44) }; KeyValuePair <string, object?>[] labels6 = new KeyValuePair <string, object?>[] { new KeyValuePair <string, object?>("four", 44), new KeyValuePair <string, object?>("name", "ned"), new KeyValuePair <string, object?>("color", "red"), new KeyValuePair <string, object?>("alpha", 15) }; var span1 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels1, 0, 4); var span2 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels2, 0, 4); var span3 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels3, 0, 4); var span4 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels4, 0, 4); var span5 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels5, 0, 4); var span6 = new ReadOnlySpan <KeyValuePair <string, object?> >(labels6, 0, 4); LastValue val1 = store.GetAggregator(span1); Assert.NotNull(val1); LastValue val2 = store.GetAggregator(span2); Assert.Equal(val1, val2); LastValue val3 = store.GetAggregator(span3); Assert.Equal(val1, val3); LastValue val4 = store.GetAggregator(span4); Assert.Equal(val1, val4); LastValue val5 = store.GetAggregator(span5); Assert.Equal(val1, val5); LastValue val6 = store.GetAggregator(span6); Assert.Equal(val1, val6); }
public void SetQuery() { HandleField(); switch (LastQueryBase) { case TermQuery termQuery: termQuery.Field = LastFiled; termQuery.Value = LastValue; break; case BoolQuery boolQuery: boolQuery.MustNot = new List <QueryContainer> { new TermQuery { Field = LastFiled, Value = LastValue } }; break; case TermRangeQuery termRangeQuery: termRangeQuery.Field = LastFiled; termRangeQuery.GreaterThan = !string.IsNullOrWhiteSpace(termRangeQuery.GreaterThan) ? LastValue.ToString() : null; termRangeQuery.GreaterThanOrEqualTo = !string.IsNullOrWhiteSpace(termRangeQuery.GreaterThanOrEqualTo) ? LastValue.ToString() : null; termRangeQuery.LessThan = !string.IsNullOrWhiteSpace(termRangeQuery.LessThan) ? LastValue.ToString() : null; termRangeQuery.LessThanOrEqualTo = !string.IsNullOrWhiteSpace(termRangeQuery.LessThanOrEqualTo) ? LastValue.ToString() : null; break; case MatchPhraseQuery matchPhraseQuery: matchPhraseQuery.Field = LastFiled; matchPhraseQuery.Query = LastValue.ToString(); break; case QueryStringQuery queryStringQuery: queryStringQuery.Fields = new[] { LastFiled }; queryStringQuery.Query = "*" + LastValue + "*"; break; } if (QueryContainer == null) { QueryContainer = LastQueryBase; } else { switch (LastOperator) { case ExpressionType.And: case ExpressionType.AndAlso: QueryContainer &= LastQueryBase; break; case ExpressionType.Or: case ExpressionType.OrElse: QueryContainer |= LastQueryBase; break; } } }