コード例 #1
0
 internal virtual void Add(string name, MutableMetric metric)
 {
     lock (this)
     {
         CheckMetricName(name);
         metricsMap[name] = metric;
     }
 }
コード例 #2
0
ファイル: MethodMetric.cs プロジェクト: orf53975/hadoop.net
 internal MethodMetric(object obj, MethodInfo method, MetricsInfo info, Metric.Type
                       type)
 {
     this.obj    = Preconditions.CheckNotNull(obj, "object");
     this.method = Contracts.CheckArg(method, Runtime.GetParameterTypes(method
                                                                        ).Length == 0, "Metric method should have no arguments");
     this.info = Preconditions.CheckNotNull(info, "info");
     impl      = NewImpl(Preconditions.CheckNotNull(type, "metric type"));
 }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
 private void Add(object source, FieldInfo field)
 {
     foreach (Annotation.Annotation annotation in field.GetAnnotations())
     {
         if (!(annotation is Metric))
         {
             continue;
         }
         try
         {
             // skip fields already set
             if (field.GetValue(source) != null)
             {
                 continue;
             }
         }
         catch (Exception e)
         {
             Log.Warn("Error accessing field " + field + " annotated with" + annotation, e);
             continue;
         }
         MutableMetric mutable = factory.NewForField(field, (Metric)annotation, registry);
         if (mutable != null)
         {
             try
             {
                 field.SetValue(source, mutable);
                 hasAtMetric = true;
             }
             catch (Exception e)
             {
                 throw new MetricsException("Error setting field " + field + " annotated with " +
                                            annotation, e);
             }
         }
     }
 }
コード例 #6
0
 /// <summary>Add sample to a stat metric by name.</summary>
 /// <param name="name">of the metric</param>
 /// <param name="value">of the snapshot to add</param>
 public virtual void Add(string name, long value)
 {
     lock (this)
     {
         MutableMetric m = metricsMap[name];
         if (m != null)
         {
             if (m is MutableStat)
             {
                 ((MutableStat)m).Add(value);
             }
             else
             {
                 throw new MetricsException("Unsupported add(value) for metric " + name);
             }
         }
         else
         {
             metricsMap[name] = NewRate(name);
             // default is a rate metric
             Add(name, value);
         }
     }
 }
コード例 #7
0
 public virtual MutableRate NewRate(string name, string desc, bool extended, bool
                                    returnExisting)
 {
     lock (this)
     {
         if (returnExisting)
         {
             MutableMetric rate = metricsMap[name];
             if (rate != null)
             {
                 if (rate is MutableRate)
                 {
                     return((MutableRate)rate);
                 }
                 throw new MetricsException("Unexpected metrics type " + rate.GetType() + " for "
                                            + name);
             }
         }
         CheckMetricName(name);
         MutableRate ret = new MutableRate(name, desc, extended);
         metricsMap[name] = ret;
         return(ret);
     }
 }