예제 #1
0
        public void HandleStopEvent_RecordsStats()
        {
            var options  = new MetricsEndpointOptions();
            var stats    = new OpenCensusStats();
            var tags     = new OpenCensusTags();
            var observer = new HttpClientDesktopObserver(options, stats, tags, null);

            var req = GetHttpRequestMessage();

            Activity act = new Activity("Test");

            act.Start();
            Thread.Sleep(1000);
            act.SetEndTime(DateTime.UtcNow);

            observer.HandleStopEvent(act, req, HttpStatusCode.InternalServerError);
            observer.HandleStopEvent(act, req, HttpStatusCode.OK);

            var reqData  = stats.ViewManager.GetView(ViewName.Create("http.desktop.client.request.time"));
            var aggData1 = MetricsHelpers.SumWithTags(reqData) as IDistributionData;

            Assert.InRange(aggData1.Mean, 990.0, 1025.0);
            Assert.InRange(aggData1.Max, 990.0, 1025.0);

            reqData = stats.ViewManager.GetView(ViewName.Create("http.desktop.client.request.count"));
            var aggData2 = MetricsHelpers.SumWithTags(reqData) as ISumDataLong;

            Assert.Equal(2, aggData2.Sum);

            act.Stop();
        }
예제 #2
0
        public void HandleThreadsEvent_RecordsValues()
        {
            var options  = new MetricsEndpointOptions();
            var stats    = new OpenCensusStats();
            var tags     = new OpenCensusTags();
            var observer = new CLRRuntimeObserver(options, stats, tags, null);

            CLRRuntimeSource.ThreadMetrics metrics = new CLRRuntimeSource.ThreadMetrics(100, 100, 200, 200);
            observer.HandleThreadsEvent(metrics);

            var live    = stats.ViewManager.GetView(ViewName.Create("clr.threadpool.active"));
            var aggData = MetricsHelpers.SumWithTags(live) as IMeanData;

            Assert.Equal(100, aggData.Mean);
            Assert.Equal(100, aggData.Min);
            Assert.Equal(100, aggData.Max);

            aggData = MetricsHelpers.SumWithTags(live, new List <ITagValue>()
            {
                TagValue.Create("worker")
            }) as IMeanData;
            Assert.Equal(100, aggData.Mean);
            Assert.Equal(100, aggData.Min);
            Assert.Equal(100, aggData.Max);

            aggData = MetricsHelpers.SumWithTags(live, new List <ITagValue>()
            {
                TagValue.Create("completionPort")
            }) as IMeanData;
            Assert.Equal(100, aggData.Mean);
            Assert.Equal(100, aggData.Min);
            Assert.Equal(100, aggData.Max);

            var avail = stats.ViewManager.GetView(ViewName.Create("clr.threadpool.avail"));

            aggData = MetricsHelpers.SumWithTags(avail) as IMeanData;
            Assert.Equal(100, aggData.Mean);
            Assert.Equal(100, aggData.Min);
            Assert.Equal(100, aggData.Max);

            aggData = MetricsHelpers.SumWithTags(avail, new List <ITagValue>()
            {
                TagValue.Create("worker")
            }) as IMeanData;
            Assert.Equal(100, aggData.Mean);
            Assert.Equal(100, aggData.Min);
            Assert.Equal(100, aggData.Max);

            aggData = MetricsHelpers.SumWithTags(avail, new List <ITagValue>()
            {
                TagValue.Create("completionPort")
            }) as IMeanData;
            Assert.Equal(100, aggData.Mean);
            Assert.Equal(100, aggData.Min);
            Assert.Equal(100, aggData.Max);
        }
예제 #3
0
        public void HandleHeapEvent_RecordsValues()
        {
            var options  = new MetricsEndpointOptions();
            var stats    = new OpenCensusStats();
            var tags     = new OpenCensusTags();
            var observer = new CLRRuntimeObserver(options, stats, tags, null);

            CLRRuntimeSource.HeapMetrics metrics = new CLRRuntimeSource.HeapMetrics(1000, new List <long>()
            {
                10, 20, 30
            });
            observer.HandleHeapEvent(metrics);

            var memUsedViewData = stats.ViewManager.GetView(ViewName.Create("clr.memory.used"));
            var aggData         = MetricsHelpers.SumWithTags(memUsedViewData) as IMeanData;

            Assert.Equal(1000, aggData.Mean);
            Assert.Equal(1000, aggData.Max);
            Assert.Equal(1000, aggData.Min);

            var gcViewData = stats.ViewManager.GetView(ViewName.Create("clr.gc.collections"));
            var aggData2   = MetricsHelpers.SumWithTags(gcViewData) as ISumDataLong;

            Assert.Equal(60, aggData2.Sum);

            aggData2 = MetricsHelpers.SumWithTags(gcViewData, new List <ITagValue>()
            {
                TagValue.Create("gen0")
            }) as ISumDataLong;
            Assert.Equal(10, aggData2.Sum);

            aggData2 = MetricsHelpers.SumWithTags(gcViewData, new List <ITagValue>()
            {
                TagValue.Create("gen1")
            }) as ISumDataLong;
            Assert.Equal(20, aggData2.Sum);

            aggData2 = MetricsHelpers.SumWithTags(gcViewData, new List <ITagValue>()
            {
                TagValue.Create("gen2")
            }) as ISumDataLong;
            Assert.Equal(30, aggData2.Sum);

            metrics = new CLRRuntimeSource.HeapMetrics(5000, new List <long>()
            {
                15, 25, 30
            });
            observer.HandleHeapEvent(metrics);

            memUsedViewData = stats.ViewManager.GetView(ViewName.Create("clr.memory.used"));
            aggData         = MetricsHelpers.SumWithTags(memUsedViewData) as IMeanData;
            Assert.Equal((5000 + 1000) / 2, aggData.Mean);
            Assert.Equal(5000, aggData.Max);
            Assert.Equal(1000, aggData.Min);

            gcViewData = stats.ViewManager.GetView(ViewName.Create("clr.gc.collections"));
            aggData2   = MetricsHelpers.SumWithTags(gcViewData) as ISumDataLong;
            Assert.Equal(70, aggData2.Sum);

            aggData2 = MetricsHelpers.SumWithTags(gcViewData, new List <ITagValue>()
            {
                TagValue.Create("gen0")
            }) as ISumDataLong;
            Assert.Equal(15, aggData2.Sum);

            aggData2 = MetricsHelpers.SumWithTags(gcViewData, new List <ITagValue>()
            {
                TagValue.Create("gen1")
            }) as ISumDataLong;
            Assert.Equal(25, aggData2.Sum);

            aggData2 = MetricsHelpers.SumWithTags(gcViewData, new List <ITagValue>()
            {
                TagValue.Create("gen2")
            }) as ISumDataLong;
            Assert.Equal(30, aggData2.Sum);
        }