static AppMetrics() { string default_metrics_registry_class = ConfigurationManager.AppSettings[kDefaultMetricsRegistryKey]; if (default_metrics_registry_class != null) { var runtime_type = new RuntimeType(default_metrics_registry_class); Type type = RuntimeType.GetSystemType(runtime_type); if (type != null) { ForCurrentProcess = RuntimeTypeFactory <IMetricsRegistry> .CreateInstanceFallback(runtime_type); } } if (ForCurrentProcess == null) { ForCurrentProcess = new MetricsRegistry(); } process_tags_ = new Tags.Builder(); Configure(); // Mark the class as not configured to allow users to // overrite the default behavior. configured_ = false; }
/// <summary> /// Register a <see cref="ICompositeMetric"/> that is a composite for all /// metric fields and annotated attributes of a given object. /// </summary> /// <remarks> /// Object to search for metrics on. All fields of type /// <see cref="IMetric"/> and fields/methods with a /// <see cref="MetricAttribute"/> attribute will be extracted and /// returned using <see cref="ICompositeMetric.Metrics"/> /// <para> /// Note that the <see cref="RegisterObject(object)"/> will use /// reflection to add all instances of <see cref="IMetric"/> that have /// been declared, and also add a tag with the value set to class simple /// name (<see cref="Type.Name"/>) and namespace (<see cref="Type.Namespace"/>). /// </para> /// </remarks> /// <returns> /// A <see cref="ICompositeMetric"/> based on the fields of the class of /// <paramref name="obj"/>. /// </returns> public static ICompositeMetric RegisterObject(object obj) { // The tags defined at the class level should be merged with the tags // defined for the fields and methods of the class. Type klass = obj.GetType(); Tags tags = new Tags.Builder() .WithTags(process_tags_.Build()) .WithTags(GetTags(klass, true)) // static class tags .WithTags(GetTagsList(obj)) // dynamic class tags .WithTag("class", klass.Name) .WithTag("namespace", klass.Namespace) .Build(); var metrics = new List <IMetric>(); for (Type type = klass; type != null; type = type.BaseType) { AddMetrics(metrics, tags, obj, type); } var config = new MetricConfig("annotated", tags); var composite = new BasicCompositeMetric(config, metrics); Register((IMetric)composite); return(composite); }
/// <summary> /// Initializes a new instance of the <see cref="MetricConfig"/> class by /// using the given name and tags. /// </summary> /// <param name="name"> /// A string that, in conjuction with the tags, uniquely identifies a /// metric. /// </param> /// <param name="tags"> /// A collection of key/value pairs that, in conjuction with the name /// uniquely identifies the metric. /// </param> public MetricConfig(string name, Tags tags) { Name = name; Tags = new Tags.Builder() .WithTags(tags) .Build(); }
static IMetric Wrap(IMetric metric, Tags tags, FieldInfo field) { var field_tags = new Tags.Builder(tags) .WithTags(tags) .WithTags(metric.Config.Tags) .WithTags(GetTags(field)) .Build(); return(Wrap(metric, field_tags)); }
/// <summary> /// Define the collection of tags that should be associated with /// all metrics registered through the <see cref="AppMetrics"/>. /// </summary> /// <param name="tags"> /// The list of tags to be associated with all metrics registered /// through the <see cref="AppMetrics"/>. /// </param> /// <remarks> /// This method should be used only if you want to remove all the /// tags that is automatically created by the metrics library and /// provide your own list of tags. If the intend is to increment /// the default list of tags, use the <see cref="WithAdditionalTags(Tags)"/> /// method instead. /// </remarks> public Configurer WithTags(Tags tags) { process_tags_ = new Tags.Builder(tags); return(this); }