Example #1
0
 /// <summary>
 /// A timer is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence.
 /// <seealso cref="Histogram"/> and <seealso cref="Meter"/>
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all timers in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="durationUnit">Time unit for reporting durations. Defaults to Milliseconds. </param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Timer Timer(string name, Unit unit, SamplingType samplingType = SamplingType.FavourRecent,
     TimeUnit rateUnit = TimeUnit.Seconds, TimeUnit durationUnit = TimeUnit.Milliseconds, MetricTags tags = default(MetricTags))
 {
     return globalContext.Timer(name, unit, samplingType, rateUnit, durationUnit, tags);
 }
Example #2
0
        static void Test6()
        {
            Metric.Config
                .WithHttpEndpoint("http://localhost:1234/")
                .WithReporting(report => report.WithConsoleReport(TimeSpan.FromSeconds(5)));

            
            var tag = new MetricTags(new string[]{"aa", "bb"});

            var meter = Metric.Context("Http").Meter("Error", Unit.Errors, TimeUnit.Seconds, tag);
            meter.Mark();
            meter.Mark();
            var meter2 = Metric.Context("Http2").Meter("Error", Unit.Errors, TimeUnit.Seconds);
            meter2.Mark();
            meter2.Mark();

        }
Example #3
0
 /// <summary>
 /// A counter is a simple incrementing and decrementing 64-bit integer. Ex number of active requests.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all counters in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric. Tags can be string array or comma separated values in a string.
 /// ex: tags: "tag1,tag2" or tags: new[] {"tag1", "tag2"}
 /// </param>
 /// <returns>Reference to the metric</returns>
 public static Counter Counter(string name, Unit unit, MetricTags tags = default(MetricTags))
 {
     return globalContext.Counter(name, unit, tags);
 }
Example #4
0
 /// <summary>
 /// A Histogram measures the distribution of values in a stream of data: e.g., the number of results returned by a search.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all histograms in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Histogram Histogram(string name, Unit unit, SamplingType samplingType = SamplingType.FavourRecent, MetricTags tags = default(MetricTags))
 {
     return globalContext.Histogram(name, unit, samplingType, tags);
 }
Example #5
0
 /// <summary>
 /// A gauge is the simplest metric type. It just returns a value. This metric is suitable for instantaneous values.
 /// </summary>
 /// <param name="name">Name of this gauge metric. Must be unique across all gauges in this context.</param>
 /// <param name="valueProvider">Function that returns the value for the gauge.</param>
 /// <param name="unit">Description of want the value represents ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the gauge</returns>
 public static void Gauge(string name, Func<double> valueProvider, Unit unit, MetricTags tags = default(MetricTags))
 {
     globalContext.Gauge(name, valueProvider, unit, tags);
 }
Example #6
0
 /// <summary>
 /// A meter measures the rate at which a set of events occur, in a few different ways. 
 /// This metric is suitable for keeping a record of now often something happens ( error, request etc ).
 /// </summary>
 /// <remarks>
 /// The mean rate is the average rate of events. It’s generally useful for trivia, 
 /// but as it represents the total rate for your application’s entire lifetime (e.g., the total number of requests handled, 
 /// divided by the number of seconds the process has been running), it doesn’t offer a sense of recency. 
 /// Luckily, meters also record three different exponentially-weighted moving average rates: the 1-, 5-, and 15-minute moving averages.
 /// </remarks>
 /// <param name="name">Name of the metric. Must be unique across all meters in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Meter Meter(string name, Unit unit, TimeUnit rateUnit = TimeUnit.Seconds, MetricTags tags = default(MetricTags))
 {
     return globalContext.Meter(name, unit, rateUnit, tags);
 }
Example #7
0
 /// <summary>
 /// A timer is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence.
 /// <seealso cref="Histogram"/> and <seealso cref="Meter"/>
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all timers in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="durationUnit">Time unit for reporting durations. Defaults to Milliseconds. </param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Timer Timer(string name, Unit unit, SamplingType samplingType = SamplingType.Default,
                           TimeUnit rateUnit = TimeUnit.Seconds, TimeUnit durationUnit = TimeUnit.Milliseconds, MetricTags tags = default(MetricTags))
 {
     return(globalContext.Timer(name, unit, samplingType, rateUnit, durationUnit, tags));
 }
Example #8
0
 /// <summary>
 /// Register a performance counter as a Gauge metric.
 /// </summary>
 /// <param name="name">Name of this gauge metric. Must be unique across all gauges in this context.</param>
 /// <param name="counterCategory">Category of the performance counter</param>
 /// <param name="counterName">Name of the performance counter</param>
 /// <param name="counterInstance">Instance of the performance counter</param>
 /// <param name="unit">Description of want the value represents ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the gauge</returns>
 public static void PerformanceCounter(string name, string counterCategory, string counterName, string counterInstance, Unit unit, MetricTags tags = default(MetricTags))
 {
     globalContext.PerformanceCounter(name, counterCategory, counterName, counterInstance, unit, tags);
 }
Example #9
0
 /// <summary>
 /// A counter is a simple incrementing and decrementing 64-bit integer. Ex number of active requests.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all counters in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric. Tags can be string array or comma separated values in a string.
 /// ex: tags: "tag1,tag2" or tags: new[] {"tag1", "tag2"}
 /// </param>
 /// <returns>Reference to the metric</returns>
 public static Counter Counter(string name, Unit unit, MetricTags tags = default(MetricTags))
 {
     return(globalContext.Counter(name, unit, tags));
 }
Example #10
0
 /// <summary>
 /// A Histogram measures the distribution of values in a stream of data: e.g., the number of results returned by a search.
 /// </summary>
 /// <param name="name">Name of the metric. Must be unique across all histograms in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="samplingType">Type of the sampling to use (see SamplingType for details ).</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Histogram Histogram(string name, Unit unit, SamplingType samplingType = SamplingType.Default, MetricTags tags = default(MetricTags))
 {
     return(globalContext.Histogram(name, unit, samplingType, tags));
 }
Example #11
0
 /// <summary>
 /// A meter measures the rate at which a set of events occur, in a few different ways.
 /// This metric is suitable for keeping a record of now often something happens ( error, request etc ).
 /// </summary>
 /// <remarks>
 /// The mean rate is the average rate of events. It’s generally useful for trivia,
 /// but as it represents the total rate for your application’s entire lifetime (e.g., the total number of requests handled,
 /// divided by the number of seconds the process has been running), it doesn’t offer a sense of recency.
 /// Luckily, meters also record three different exponentially-weighted moving average rates: the 1-, 5-, and 15-minute moving averages.
 /// </remarks>
 /// <param name="name">Name of the metric. Must be unique across all meters in this context.</param>
 /// <param name="unit">Description of what the is being measured ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="rateUnit">Time unit for rates reporting. Defaults to Second ( occurrences / second ).</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the metric</returns>
 public static Meter Meter(string name, Unit unit, TimeUnit rateUnit = TimeUnit.Seconds, MetricTags tags = default(MetricTags))
 {
     return(globalContext.Meter(name, unit, rateUnit, tags));
 }
Example #12
0
 /// <summary>
 /// A gauge is the simplest metric type. It just returns a value. This metric is suitable for instantaneous values.
 /// </summary>
 /// <param name="name">Name of this gauge metric. Must be unique across all gauges in this context.</param>
 /// <param name="valueProvider">Function that returns the value for the gauge.</param>
 /// <param name="unit">Description of want the value represents ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the gauge</returns>
 public static void Gauge(string name, Func <double> valueProvider, Unit unit, MetricTags tags = default(MetricTags))
 {
     globalContext.Gauge(name, valueProvider, unit, tags);
 }
Example #13
0
 /// <summary>
 /// Register a performance counter as a Gauge metric.
 /// </summary>
 /// <param name="name">Name of this gauge metric. Must be unique across all gauges in this context.</param>
 /// <param name="counterCategory">Category of the performance counter</param>
 /// <param name="counterName">Name of the performance counter</param>
 /// <param name="counterInstance">Instance of the performance counter</param>
 /// <param name="unit">Description of want the value represents ( Unit.Requests , Unit.Items etc ) .</param>
 /// <param name="tags">Optional set of tags that can be associated with the metric.</param>
 /// <returns>Reference to the gauge</returns>
 public static void PerformanceCounter(string name, string counterCategory, string counterName, string counterInstance, Unit unit, MetricTags tags = default(MetricTags))
 {
     globalContext.PerformanceCounter(name, counterCategory, counterName, counterInstance, unit, tags);
 }
 public static string TagName(string name, MetricTags? tags)
 {
     if (!tags.HasValue)
     {
         return name;
     }
     return name + string.Join(".", tags.Value.Tags);
 }
 public MetricInfo(string context, string metricName, MetricTags tags, TimerMetric timer, PerfCounterGauge perfCounter)
 {
     this.Context = context;
     this.MetricName = metricName;
     this.Tags = tags;
     this.Timer = timer;
     this.PerfCounter = perfCounter;
     this.Key = TagName(this.Context + this.MetricName, this.Tags);
 }