コード例 #1
0
        public virtual void TestGetMetricsAndJmx()
        {
            // create test source with a single metric counter of value 0
            TestMetricsSourceAdapter.TestSource source = new TestMetricsSourceAdapter.TestSource
                                                             ("test");
            MetricsSourceBuilder sb           = MetricsAnnotations.NewSourceBuilder(source);
            MetricsSource        s            = sb.Build();
            IList <MetricsTag>   injectedTags = new AList <MetricsTag>();
            MetricsSourceAdapter sa           = new MetricsSourceAdapter("test", "test", "test desc", s
                                                                         , injectedTags, null, null, 1, false);
            // all metrics are initially assumed to have changed
            MetricsCollectorImpl            builder        = new MetricsCollectorImpl();
            IEnumerable <MetricsRecordImpl> metricsRecords = sa.GetMetrics(builder, true);
            // Validate getMetrics and JMX initial values
            MetricsRecordImpl metricsRecord = metricsRecords.GetEnumerator().Next();

            Assert.Equal(0L, metricsRecord.Metrics().GetEnumerator().Next(
                             ).Value());
            Thread.Sleep(100);
            // skip JMX cache TTL
            Assert.Equal(0L, (Number)sa.GetAttribute("C1"));
            // change metric value
            source.IncrementCnt();
            // validate getMetrics and JMX
            builder        = new MetricsCollectorImpl();
            metricsRecords = sa.GetMetrics(builder, true);
            metricsRecord  = metricsRecords.GetEnumerator().Next();
            Assert.True(metricsRecord.Metrics().GetEnumerator().HasNext());
            Thread.Sleep(100);
            // skip JMX cache TTL
            Assert.Equal(1L, (Number)sa.GetAttribute("C1"));
        }
コード例 #2
0
        private void SnapshotMetrics(MetricsSourceAdapter sa, MetricsBufferBuilder bufferBuilder
                                     )
        {
            long startTime = Time.Now();

            bufferBuilder.Add(sa.Name(), sa.GetMetrics(collector, true));
            collector.Clear();
            snapshotStat.Add(Time.Now() - startTime);
            Log.Debug("Snapshotted source " + sa.Name());
        }