Пример #1
0
            //generate a new key per each call
            public virtual void GetMetrics(MetricsCollector collector, bool all)
            {
                MetricsRecordBuilder rb = collector.AddRecord("purgablesource").SetContext("test"
                                                                                           );

                this.lastKeyName = "key" + this.nextKey++;
                rb.AddGauge(Interns.Info(this.lastKeyName, "desc"), 1);
            }
Пример #2
0
        /// <summary>
        /// Adds a gauge with a name built by using the specified phase's name as prefix
        /// and then appending the specified suffix.
        /// </summary>
        /// <param name="builder">MetricsRecordBuilder to receive counter</param>
        /// <param name="phase">Phase to add</param>
        /// <param name="nameSuffix">String suffix of metric name</param>
        /// <param name="descSuffix">String suffix of metric description</param>
        /// <param name="value">float gauge value</param>
        private static void AddGauge(MetricsRecordBuilder builder, Phase phase, string nameSuffix
                                     , string descSuffix, float value)
        {
            MetricsInfo metricsInfo = Interns.Info(phase.GetName() + nameSuffix, phase.GetDescription
                                                       () + descSuffix);

            builder.AddGauge(metricsInfo, value);
        }
Пример #3
0
 /// <summary>
 /// Asserts that the NumOps and quantiles for a metric have been changed at
 /// some point to a non-zero value.
 /// </summary>
 /// <param name="prefix">of the metric</param>
 /// <param name="rb">MetricsRecordBuilder with the metric</param>
 public static void AssertQuantileGauges(string prefix, MetricsRecordBuilder rb)
 {
     Org.Mockito.Mockito.Verify(rb).AddGauge(EqName(Interns.Info(prefix + "NumOps", string.Empty
                                                                 )), AdditionalMatchers.Geq(0l));
     foreach (Quantile q in MutableQuantiles.quantiles)
     {
         string nameTemplate = prefix + "%dthPercentileLatency";
         int    percentile   = (int)(100 * q.quantile);
         Org.Mockito.Mockito.Verify(rb).AddGauge(EqName(Interns.Info(string.Format(nameTemplate
                                                                                   , percentile), string.Empty)), AdditionalMatchers.Geq(0l));
     }
 }
        public virtual void RecordBuilderShouldNoOpIfFiltered()
        {
            SubsetConfiguration  fc = new ConfigBuilder().Add("p.exclude", "foo").Subset("p");
            MetricsCollectorImpl mb = new MetricsCollectorImpl();

            mb.SetRecordFilter(TestPatternFilter.NewGlobFilter(fc));
            MetricsRecordBuilderImpl rb = mb.AddRecord("foo");

            ((MetricsRecordBuilderImpl)rb.Tag(Interns.Info("foo", string.Empty), "value")).AddGauge
                (Interns.Info("g0", string.Empty), 1);
            Assert.Equal("no tags", 0, rb.Tags().Count);
            Assert.Equal("no metrics", 0, rb.Metrics().Count);
            NUnit.Framework.Assert.IsNull("null record", rb.GetRecord());
            Assert.Equal("no records", 0, mb.GetRecords().Count);
        }
        public virtual void TestPerMetricFiltering()
        {
            SubsetConfiguration  fc = new ConfigBuilder().Add("p.exclude", "foo").Subset("p");
            MetricsCollectorImpl mb = new MetricsCollectorImpl();

            mb.SetMetricFilter(TestPatternFilter.NewGlobFilter(fc));
            MetricsRecordBuilderImpl rb = mb.AddRecord("foo");

            ((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl)rb.Tag(Interns.Info("foo",
                                                                                      string.Empty), string.Empty)).AddCounter(Interns.Info("c0", string.Empty), 0)).AddGauge
                (Interns.Info("foo", string.Empty), 1);
            Assert.Equal("1 tag", 1, rb.Tags().Count);
            Assert.Equal("1 metric", 1, rb.Metrics().Count);
            Assert.Equal("expect foo tag", "foo", rb.Tags()[0].Name());
            Assert.Equal("expect c0", "c0", rb.Metrics()[0].Name());
        }
Пример #6
0
 private MetricsInfo[] GetGcInfo(string gcName)
 {
     MetricsInfo[] gcInfo = gcInfoCache[gcName];
     if (gcInfo == null)
     {
         gcInfo    = new MetricsInfo[2];
         gcInfo[0] = Interns.Info("GcCount" + gcName, "GC Count for " + gcName);
         gcInfo[1] = Interns.Info("GcTimeMillis" + gcName, "GC Time for " + gcName);
         MetricsInfo[] previousGcInfo = gcInfoCache.PutIfAbsent(gcName, gcInfo);
         if (previousGcInfo != null)
         {
             return(previousGcInfo);
         }
     }
     return(gcInfo);
 }
Пример #7
0
        private void CheckMetricsRecords(IList <MetricsRecord> recs)
        {
            Log.Debug(recs);
            MetricsRecord r = recs[0];

            Assert.Equal("name", "s1rec", r.Name());
            MoreAsserts.AssertEquals("tags", new MetricsTag[] { Interns.Tag(MsInfo.Context, "test"
                                                                            ), Interns.Tag(MsInfo.Hostname, hostname) }, r.Tags());
            MoreAsserts.AssertEquals("metrics", ((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl
                                                                             )((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl)MetricsLists.Builder(string.Empty
                                                                                                                                                         ).AddCounter(Interns.Info("C1", "C1 desc"), 1L)).AddGauge(Interns.Info("G1", "G1 desc"
                                                                                                                                                                                                                                ), 2L)).AddCounter(Interns.Info("S1NumOps", "Number of ops for s1"), 1L)).AddGauge
                                                     (Interns.Info("S1AvgTime", "Average time for s1"), 0.0)).Metrics(), r.Metrics());
            r = recs[1];
            Assert.True("NumActiveSinks should be 3", Iterables.Contains(r.
                                                                         Metrics(), new MetricGaugeInt(MsInfo.NumActiveSinks, 3)));
        }
Пример #8
0
        public virtual void GetMetrics(MetricsCollector collector, bool all)
        {
            StartupProgressView  prog    = startupProgress.CreateView();
            MetricsRecordBuilder builder = collector.AddRecord(StartupProgressMetricsInfo);

            builder.AddCounter(Interns.Info("ElapsedTime", "overall elapsed time"), prog.GetElapsedTime
                                   ());
            builder.AddGauge(Interns.Info("PercentComplete", "overall percent complete"), prog
                             .GetPercentComplete());
            foreach (Phase phase in prog.GetPhases())
            {
                AddCounter(builder, phase, "Count", " count", prog.GetCount(phase));
                AddCounter(builder, phase, "ElapsedTime", " elapsed time", prog.GetElapsedTime(phase
                                                                                               ));
                AddCounter(builder, phase, "Total", " total", prog.GetTotal(phase));
                AddGauge(builder, phase, "PercentComplete", " percent complete", prog.GetPercentComplete
                             (phase));
            }
        }
Пример #9
0
 internal ContainerMetrics(MetricsSystem ms, ContainerId containerId, long flushPeriodMs
                           , long delayMs)
 {
     // Use a multiplier of 1000 to avoid losing too much precision when
     // converting to integers
     // This tracks overall CPU percentage of the machine in terms of percentage
     // of 1 core similar to top
     // Thus if you use 2 cores completely out of 4 available cores this value
     // will be 200
     // Metrics publishing status
     // true if period elapsed
     // true if container finished
     // unregister
     // lazily initialized
     // Create a timer to unregister container metrics,
     // whose associated thread run as a daemon.
     this.recordInfo        = Interns.Info(SourceName(containerId), RecordInfo.Description());
     this.registry          = new MetricsRegistry(recordInfo);
     this.metricsSystem     = ms;
     this.containerId       = containerId;
     this.flushPeriodMs     = flushPeriodMs;
     this.unregisterDelayMs = delayMs < 0 ? 0 : delayMs;
     ScheduleTimerTaskIfRequired();
     this.pMemMBsStat = registry.NewStat(PmemUsageMetricName, "Physical memory stats",
                                         "Usage", "MBs", true);
     this.cpuCoreUsagePercent = registry.NewStat(PhyCpuUsageMetricName, "Physical Cpu core percent usage stats"
                                                 , "Usage", "Percents", true);
     this.milliVcoresUsed = registry.NewStat(VcoreUsageMetricName, "1000 times Vcore usage"
                                             , "Usage", "MilliVcores", true);
     this.pMemLimitMbs = registry.NewGauge(PmemLimitMetricName, "Physical memory limit in MBs"
                                           , 0);
     this.vMemLimitMbs = registry.NewGauge(VmemLimitMetricName, "Virtual memory limit in MBs"
                                           , 0);
     this.cpuVcoreLimit = registry.NewGauge(VcoreLimitMetricName, "CPU limit in number of vcores"
                                            , 0);
 }
Пример #10
0
        public virtual void TestCommon()
        {
            MetricsVisitor         visitor  = Org.Mockito.Mockito.Mock <MetricsVisitor>();
            MetricsRegistry        registry = new MetricsRegistry("test");
            IList <AbstractMetric> metrics  = ((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl
                                                                           )((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl)((MetricsRecordBuilderImpl
                                                                                                                                    )((MetricsRecordBuilderImpl)MetricsLists.Builder("test").AddCounter(Interns.Info
                                                                                                                                                                                                            ("c1", "int counter"), 1)).AddCounter(Interns.Info("c2", "long counter"), 2L)).AddGauge
                                                                                                            (Interns.Info("g1", "int gauge"), 5)).AddGauge(Interns.Info("g2", "long gauge"),
                                                                                                                                                           6L)).AddGauge(Interns.Info("g3", "float gauge"), 7f)).AddGauge(Interns.Info("g4"
                                                                                                                                                                                                                                       , "double gauge"), 8d)).Metrics();

            foreach (AbstractMetric metric in metrics)
            {
                metric.Visit(visitor);
            }
            Org.Mockito.Mockito.Verify(visitor).Counter(c1.Capture(), Eq(1));
            Assert.Equal("c1 name", "c1", c1.GetValue().Name());
            Assert.Equal("c1 description", "int counter", c1.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Counter(c2.Capture(), Eq(2L));
            Assert.Equal("c2 name", "c2", c2.GetValue().Name());
            Assert.Equal("c2 description", "long counter", c2.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g1.Capture(), Eq(5));
            Assert.Equal("g1 name", "g1", g1.GetValue().Name());
            Assert.Equal("g1 description", "int gauge", g1.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g2.Capture(), Eq(6L));
            Assert.Equal("g2 name", "g2", g2.GetValue().Name());
            Assert.Equal("g2 description", "long gauge", g2.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g3.Capture(), Eq(7f));
            Assert.Equal("g3 name", "g3", g3.GetValue().Name());
            Assert.Equal("g3 description", "float gauge", g3.GetValue().Description
                             ());
            Org.Mockito.Mockito.Verify(visitor).Gauge(g4.Capture(), Eq(8d));
            Assert.Equal("g4 name", "g4", g4.GetValue().Name());
            Assert.Equal("g4 description", "double gauge", g4.GetValue().Description
                             ());
        }
Пример #11
0
        public static float GetFloatGauge(string name, MetricsRecordBuilder rb)
        {
            ArgumentCaptor <float> captor = ArgumentCaptor.ForClass <float>();

            Org.Mockito.Mockito.Verify(rb, Org.Mockito.Mockito.AtLeast(0)).AddGauge(EqName(Interns.Info
                                                                                               (name, string.Empty)), captor.Capture());
            CheckCaptured(captor, name);
            return(captor.GetValue());
        }
Пример #12
0
        public static long GetLongCounter(string name, MetricsRecordBuilder rb)
        {
            ArgumentCaptor <long> captor = ArgumentCaptor.ForClass <long>();

            Org.Mockito.Mockito.Verify(rb, Org.Mockito.Mockito.AtLeast(0)).AddCounter(EqName(
                                                                                          Interns.Info(name, string.Empty)), captor.Capture());
            CheckCaptured(captor, name);
            return(captor.GetValue());
        }
Пример #13
0
 private MetricsTag MakeTag(string name, string value)
 {
     return(new MetricsTag(Interns.Info(name, string.Empty), value));
 }
Пример #14
0
 public virtual MetricsRecordBuilderImpl AddRecord(string name)
 {
     return(AddRecord(Interns.Info(name, name + " record")));
 }