Пример #1
0
        internal virtual MutableMetric NewForField(FieldInfo field, Metric annotation, MetricsRegistry
                                                   registry)
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug("field " + field + " with annotation " + annotation);
            }
            MetricsInfo   info   = GetInfo(annotation, field);
            MutableMetric metric = NewForField(field, annotation);

            if (metric != null)
            {
                registry.Add(info.Name(), metric);
                return(metric);
            }
            Type cls = field.FieldType;

            if (cls == typeof(MutableCounterInt))
            {
                return(registry.NewCounter(info, 0));
            }
            if (cls == typeof(MutableCounterLong))
            {
                return(registry.NewCounter(info, 0L));
            }
            if (cls == typeof(MutableGaugeInt))
            {
                return(registry.NewGauge(info, 0));
            }
            if (cls == typeof(MutableGaugeLong))
            {
                return(registry.NewGauge(info, 0L));
            }
            if (cls == typeof(MutableRate))
            {
                return(registry.NewRate(info.Name(), info.Description(), annotation.Always()));
            }
            if (cls == typeof(MutableRates))
            {
                return(new MutableRates(registry));
            }
            if (cls == typeof(MutableStat))
            {
                return(registry.NewStat(info.Name(), info.Description(), annotation.SampleName(),
                                        annotation.ValueName(), annotation.Always()));
            }
            throw new MetricsException("Unsupported metric field " + field.Name + " of type "
                                       + field.FieldType.FullName);
        }
Пример #2
0
        internal virtual MutableMetric NewForMethod(object source, MethodInfo method, Metric
                                                    annotation, MetricsRegistry registry)
        {
            if (Log.IsDebugEnabled())
            {
                Log.Debug("method " + method + " with annotation " + annotation);
            }
            MetricsInfo   info   = GetInfo(annotation, method);
            MutableMetric metric = NewForMethod(source, method, annotation);

            metric = metric != null ? metric : new MethodMetric(source, method, info, annotation
                                                                .Type());
            registry.Add(info.Name(), metric);
            return(metric);
        }
Пример #3
0
        public virtual void TestAddByName()
        {
            MetricsRecordBuilder rb = MetricsAsserts.MockMetricsRecordBuilder();
            MetricsRegistry      r  = new MetricsRegistry("test");

            r.Add("s1", 42);
            r.Get("s1").Snapshot(rb);
            Org.Mockito.Mockito.Verify(rb).AddCounter(Interns.Info("S1NumOps", "Number of ops for s1"
                                                                   ), 1L);
            Org.Mockito.Mockito.Verify(rb).AddGauge(Interns.Info("S1AvgTime", "Average time for s1"
                                                                 ), 42.0);
            r.NewCounter("c1", "test add", 1);
            r.NewGauge("g1", "test add", 1);
            ExpectMetricsException("Unsupported add", new _Runnable_114(r));
            ExpectMetricsException("Unsupported add", new _Runnable_119(r));
        }
Пример #4
0
 /// <summary>Add a rate sample for a rate metric</summary>
 /// <param name="name">of the rate metric</param>
 /// <param name="elapsed">time</param>
 public virtual void Add(string name, long elapsed)
 {
     registry.Add(name, elapsed);
 }