Exemplo n.º 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);
        }