protected override void ReportTimer(string name, TimerValue value, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
 {
     this.WriteMetricName(name);
     this.WriteValue("Active Sessions", value.ActiveSessions.ToString());
     this.WriteMeter(value.Rate, unit, rateUnit);
     this.WriteHistogram(value.Histogram, unit, durationUnit);
 }
 protected override void ReportGauge(string name, double value, Unit unit, MetricTags tags)
 {
     if (!double.IsNaN(value) && !double.IsInfinity(value))
     {
         Pack(name, value, tags);
     }
 }
        public void MetricTags_CanCreateFromString()
        {
            MetricTags tags = "tag";
            tags.Tags.Should().Equal(new[] { "tag" });

            tags = new MetricTags("tag");
            tags.Tags.Should().Equal(new[] { "tag" });
        }
        public void MetricTags_CanCreateFromCSV()
        {
            MetricTags tags = "tag1,tag2";
            tags.Tags.Should().Equal(new[] { "tag1", "tag2" });

            tags = new MetricTags("tag1,tag2");
            tags.Tags.Should().Equal(new[] { "tag1", "tag2" });
        }
        public void MetricTags_CanCreateFromStringArray()
        {
            MetricTags tags = new[] { "tag1", "tag2" };
            tags.Tags.Should().Equal(new[] { "tag1", "tag2" });

            tags = new MetricTags(new[] { "tag1", "tag2" });
            tags.Tags.Should().Equal(new[] { "tag1", "tag2" });
        }
Example #6
0
        protected override void ReportTimer(string name, TimerValue value, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
        {
            var values = MeterValues(value.Rate, unit, rateUnit)
                .Concat(HistogramValues(value.Histogram, unit, durationUnit))
                .Concat(new[] { new Value("Active Sessions", value.ActiveSessions) });

            Write("Timer", name, values);
        }
 protected override void ReportGauge(string name, double value, Unit unit, MetricTags tags)
 {
     if (!double.IsNaN(value) && !double.IsInfinity(value))
     {
         Pack("Gauge", name, unit, tags, new[] { 
             new JsonProperty("Value", value),
         });
     }
 }
        internal InfluxDbRecord(string name, object data, MetricTags tags, ConfigOptions config, Tuple<string, string>[] moreTags = null)
            : this(config)
        {
            var record = BuildRecordPreamble(name, tags, moreTags);

            record.Append("value=").Append(StringifyValue(data));

            LineProtocol = record.ToString();
        }
        protected override void ReportHistogram(string name, MetricData.HistogramValue value, Unit unit, MetricTags tags)
        {
            var data = new Dictionary<string, object>();

            value.AddHistogramValues(data);

            var keys = data.Keys.ToList();
            var values = keys.Select(k => data[k]);

            Pack(name, keys, values, tags);
        }
        protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
        {
            var itemProperties = value.Items.SelectMany(i => new[] 
            {
                new JsonProperty(i.Item + " - Count", i.Count), 
                new JsonProperty(i.Item + " - Percent", i.Percent),
            });

            Pack("Counter", name, unit, tags, new[] { 
                new JsonProperty("Count", value.Count),
            }.Concat(itemProperties));
        }
 private void Pack(string type, string name, Unit unit, MetricTags tags, IEnumerable<JsonProperty> properties)
 {
     this.data.Add(new ESDocument
     {
         Index = this.elasticSearchIndex,
         Type = type,
         Object = new JsonObject(new[] { 
                  new JsonProperty("Timestamp", Clock.FormatTimestamp(this.CurrentContextTimestamp)),
                  new JsonProperty("Type",type),
                  new JsonProperty("Name",name),
                  new JsonProperty("Unit", unit.ToString()),
                  new JsonProperty("Tags", tags.Tags)
              }.Concat(properties))
     });
 }
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
     this.WriteMetricName(name);
     WriteValue("Count", unit.FormatCount(value.Count));
     if (value.Items.Length > 0)
     {
         WriteValue("Total Items", value.Items.Length.ToString());
     }
     for (int i = 0; i < value.Items.Length; i++)
     {
         var key = "Item " + i.ToString();
         var item = value.Items[i];
         var val = string.Format("{0:00.00}% {1,5} {2} [{3}]", item.Percent, item.Count, unit.Name, item.Item);
         WriteValue(key, val);
     }
 }
        internal InfluxDbRecord(string name, IEnumerable<string> columns, IEnumerable<object> data, MetricTags tags, ConfigOptions config, Tuple<string, string>[] moreTags = null)
            : this(config)
        {
            var record = BuildRecordPreamble(name, tags, moreTags);

            var fieldKeypairs = new List<string>();

            foreach (var pair in columns.Zip(data, (col, dat) => new { col, dat }))
            {
                fieldKeypairs.Add(string.Format("{0}={1}", Escape(pair.col), StringifyValue(pair.dat)));
            }

            record.Append(string.Join(",", fieldKeypairs));

            LineProtocol = record.ToString();
        }
        protected override void ReportCounter(string name, MetricData.CounterValue value, Unit unit, MetricTags tags)
        {
            if (!value.Items.Any())
            {
                Pack(name, value.Count, tags);
                return;
            }

            var cols = new List<string>(new[] { "total" });
            cols.AddRange(value.Items.Select(x => x.Item));

            var data = new List<object>(new object[] { value.Count });
            data.AddRange(value.Items.Select(x => (object)x.Count));

            Pack(name, cols, data, tags);
        }
        internal StringBuilder BuildRecordPreamble(string name, MetricTags tags, Tuple<string, string>[] moreTags = null)
        {
            var record = new StringBuilder();
            record.Append(Escape(_config.MetricNameConverter(name)));

            var allTags = GetAllTags(tags);

            if (moreTags != null && moreTags.Length > 0)
            {
                allTags = allTags.Union(moreTags);
            }

            if (allTags.Any())
            {
                record.Append(",");
                record.Append(string.Join(",", allTags.Select(t => string.Format("{0}={1}", Escape(t.Item1), Escape(t.Item2)))));
            }

            record.Append(" ");

            return record;
        }
 private static void Register(this MetricsContext context, string name, Unit unit,
     string category, string counter, string instance = null,
     Func<double, double> derivate = null,
     MetricTags tags = default(MetricTags))
 {
     try
     {
         WrappedRegister(context, name, unit, category, counter, instance, derivate, tags);
     }
     catch (UnauthorizedAccessException x)
     {
         var message = "Error reading performance counter data. The application is currently running as user " + GetIdentity() +
            ". Make sure the user has access to the performance counters. The user needs to be either Admin or belong to Performance Monitor user group.";
         MetricsErrorHandler.Handle(x, message);
     }
     catch (Exception x)
     {
         var message = "Error reading performance counter data. The application is currently running as user " + GetIdentity() +
            ". Make sure the user has access to the performance counters. The user needs to be either Admin or belong to Performance Monitor user group.";
         MetricsErrorHandler.Handle(x, message);
     }
 }
 /// <inheritdoc />
 public void Write(string context, string name, string field, object value, MetricTags tags, DateTime timestamp)
 {
     Sampler.Add(context, name, field, value, tags, _metricMetricStringSerializer, timestamp);
 }
Example #18
0
 public Timer Timer(string name, Unit unit, SamplingType samplingType, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
 {
     throw new ReadOnlyMetricsContextException();
 }
Example #19
0
 public Meter Meter(string name, Unit unit, TimeUnit rateUnit, MetricTags tags)
 {
     throw new ReadOnlyMetricsContextException();
 }
Example #20
0
 public static double GetGaugeValue(this IProvideMetricValues valueService, string context, string metricName, MetricTags tags)
 {
     return(valueService.GetForContext(context).Gauges.ValueFor(tags.AsMetricName(metricName)));
 }
 /// <inheritdoc />
 public void Write(string context, string name, IEnumerable <string> columns, IEnumerable <object> values, MetricTags tags, DateTime timestamp)
 {
     Sampler.Add(context, name, columns, values, tags, _metricMetricStringSerializer, timestamp);
 }
        ///<inheritdoc/>
        protected override void ReportCounter(string name, MetricData.CounterValue value, Unit unit, MetricTags tags)
        {
            var itemColumns = value.Items.SelectMany(i => new[] { i.Item + " - Count", i.Item + " - Percent" });
            var columns     = CounterColumns.Concat(itemColumns);

            var itemValues = value.Items.SelectMany(i => new[] { Value(i.Count), Value(i.Percent) });
            var data = new[] { Value(value.Count) }.Concat(itemValues);

            Pack(name, columns, data);
        }
 private void Pack(string name, IEnumerable<string> columns, IEnumerable<object> values, MetricTags tags)
 {
     _data.Add(new InfluxDbRecord(name, columns, values, tags, _config));
 }
Example #24
0
 public Timer Timer <T>(string name, Func <T> builder, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
     where T : TimerImplementation
 {
     return(this.timers.GetOrAdd(name, () =>
     {
         T timer = builder();
         return Tuple.Create((Timer)timer, new TimerValueSource(name, timer, unit, rateUnit, durationUnit, tags));
     }));
 }
Example #25
0
 public void Gauge(string name, Func <MetricValueProvider <double> > valueProvider, Unit unit, MetricTags tags)
 {
     this.gauges.GetOrAdd(name, () =>
     {
         MetricValueProvider <double> gauge = valueProvider();
         return(Tuple.Create(gauge, new GaugeValueSource(name, gauge, unit, tags)));
     });
 }
Example #26
0
 public Meter Meter <T>(string name, Func <T> builder, Unit unit, TimeUnit rateUnit, MetricTags tags)
     where T : MeterImplementation
 {
     return(this.meters.GetOrAdd(name, () =>
     {
         T meter = builder();
         return Tuple.Create((Meter)meter, new MeterValueSource(name, meter, unit, rateUnit, tags));
     }));
 }
Example #27
0
 public CounterValueSource(string name, MetricValueProvider <CounterValue> value, Unit unit, MetricTags tags)
     : base(name, value, unit, tags)
 {
 }
Example #28
0
 public EventValueSource(string name, MetricValueProvider <EventValue> value, MetricTags tags)
     : base(name, value, tags)
 {
 }
Example #29
0
 private void Send(string context, MetricTags tags, GraphiteMetricName name, GraphiteValue value)
 {
     _graphiteSender.Send(_metricNameFormatter.Format(context, tags, name), value.ToString());
 }
        ///<inheritdoc/>
        protected override void ReportMeter(string name, MetricData.MeterValue value, Unit unit, TimeUnit rateUnit, MetricTags tags)
        {
            var itemColumns = value.Items.SelectMany(i => new[]
            {
                i.Item + " - Count",
                i.Item + " - Percent",
                i.Item + " - Mean Rate",
                i.Item + " - 1 Min Rate",
                i.Item + " - 5 Min Rate",
                i.Item + " - 15 Min Rate"
            });
            var columns = MeterColumns.Concat(itemColumns);

            var itemValues = value.Items.SelectMany(i => new[]
            {
                Value(i.Value.Count),
                Value(i.Percent),
                Value(i.Value.MeanRate),
                Value(i.Value.OneMinuteRate),
                Value(i.Value.FiveMinuteRate),
                Value(i.Value.FifteenMinuteRate)
            });

            var data = new[]
            {
                Value(value.Count),
                Value(value.MeanRate),
                Value(value.OneMinuteRate),
                Value(value.FiveMinuteRate),
                Value(value.FifteenMinuteRate)
            }.Concat(itemValues);

            Pack(name, columns, data);
        }
Example #31
0
 public void PerformanceCounter(string name, string counterCategory, string counterName, string counterInstance, Unit unit, MetricTags tags)
 {
     throw new ReadOnlyMetricsContextException();
 }
 ///<inheritdoc/>
 protected override void ReportHistogram(string name, MetricData.HistogramValue value, Unit unit, MetricTags tags)
 {
     Pack(name, HistogramColumns, new[] {
         Value(value.Count),
         Value(value.LastValue),
         Value(value.LastUserValue),
         Value(value.Min),
         Value(value.MinUserValue),
         Value(value.Mean),
         Value(value.Max),
         Value(value.MaxUserValue),
         Value(value.StdDev),
         Value(value.Median),
         Value(value.Percentile75),
         Value(value.Percentile95),
         Value(value.Percentile98),
         Value(value.Percentile99),
         Value(value.Percentile999),
         Value(value.SampleSize)
     });
 }
Example #33
0
 public void DeregisterEvent(string name, MetricTags tags)
 {
 }
 ///<inheritdoc/>
 protected override void ReportTimer(string name, MetricData.TimerValue value, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
 {
     Pack(name, TimerColumns, new[] {
         Value(value.Rate.Count),
         Value(value.ActiveSessions),
         Value(value.Rate.MeanRate),
         Value(value.Rate.OneMinuteRate),
         Value(value.Rate.FiveMinuteRate),
         Value(value.Rate.FifteenMinuteRate),
         Value(value.Histogram.LastValue),
         Value(value.Histogram.LastUserValue),
         Value(value.Histogram.Min),
         Value(value.Histogram.MinUserValue),
         Value(value.Histogram.Mean),
         Value(value.Histogram.Max),
         Value(value.Histogram.MaxUserValue),
         Value(value.Histogram.StdDev),
         Value(value.Histogram.Median),
         Value(value.Histogram.Percentile75),
         Value(value.Histogram.Percentile95),
         Value(value.Histogram.Percentile98),
         Value(value.Histogram.Percentile99),
         Value(value.Histogram.Percentile999),
         Value(value.Histogram.SampleSize)
     });
 }
Example #35
0
 public void DeregisterGauge(string name, MetricTags tags)
 {
 }
Example #36
0
 protected MetricValueSource(string name, MetricValueProvider <T> valueProvider, Unit unit, MetricTags tags)
 {
     this.Name          = name;
     this.Unit          = unit;
     this.ValueProvider = valueProvider;
     this.Tags          = tags.Tags;
 }
        protected override void ReportMeter(string name, MeterValue value, Unit unit, TimeUnit rateUnit, MetricTags tags)
        {
            var itemProperties = value.Items.SelectMany(i => new[] 
            {
                new JsonProperty(i.Item + " - Count", i.Value.Count), 
                new JsonProperty(i.Item + " - Percent", i.Percent),
                new JsonProperty(i.Item + " - Mean Rate", i.Value.MeanRate),
                new JsonProperty(i.Item + " - 1 Min Rate", i.Value.OneMinuteRate),
                new JsonProperty(i.Item + " - 5 Min Rate", i.Value.FiveMinuteRate),
                new JsonProperty(i.Item + " - 15 Min Rate", i.Value.FifteenMinuteRate)
            });

            Pack("Meter", name, unit, tags, new[] { 
                new JsonProperty("Count", value.Count),
                new JsonProperty("Mean Rate", value.MeanRate),
                new JsonProperty("1 Min Rate", value.OneMinuteRate),
                new JsonProperty("5 Min Rate", value.FiveMinuteRate),
                new JsonProperty("15 Min Rate", value.FifteenMinuteRate)
            }.Concat(itemProperties));
        }
        internal IEnumerable<Tuple<string, string>> GetAllTags(MetricTags tags)
        {
            var allTags = new List<Tuple<string, string>> 
            {
                new Tuple<string, string>("host", Environment.MachineName.ToLower ()),
                new Tuple<string, string>("user", Environment.UserName.ToLower ()),
                new Tuple<string, string>("pid", Process.GetCurrentProcess ().Id.ToString ()),
            };

            if (tags.Tags != null && tags.Tags.Length > 0)
            {
                allTags.AddRange(tags.Tags.Select(t => new Tuple<string, string>(Escape(t), "true")));
            }

            return allTags;
        }
Example #39
0
 public Histogram Histogram(string name, Unit unit, SamplingType samplingType, MetricTags tags)
 {
     throw new ReadOnlyMetricsContextException();
 }
 protected override void ReportCounter(string name, CounterValue value, Unit unit, MetricTags tags)
 {
   this.metricName = name;
   base.ReportCounter(name, value, unit, tags);
 }
        private static void WrappedRegister(MetricsContext context, string name, Unit unit,
            string category, string counter, string instance = null,
            Func<double, double> derivate = null,
            MetricTags tags = default(MetricTags))
        {
            log.Debug(() => string.Format("Registering performance counter [{0}] in category [{1}] for instance [{2}]", counter, category, instance ?? "none"));

            if (PerformanceCounterCategory.Exists(category))
            {
                if (instance == null || PerformanceCounterCategory.InstanceExists(instance, category))
                {
                    if (PerformanceCounterCategory.CounterExists(counter, category))
                    {
                        var counterTags = new MetricTags(tags.Tags.Concat(new[] { "PerfCounter" }));
                        if (derivate == null)
                        {
                            context.Advanced.Gauge(name, () => new PerformanceCounterGauge(category, counter, instance), unit, counterTags);
                        }
                        else
                        {
                            context.Advanced.Gauge(name, () => new DerivedGauge(new PerformanceCounterGauge(category, counter, instance), derivate), unit, counterTags);
                        }
                        return;
                    }
                }
            }

            log.ErrorFormat("Performance counter does not exist [{0}] in category [{1}] for instance [{2}]", counter, category, instance ?? "none");
        }
 protected override void ReportTimer(string name, TimerValue value, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
 {
   this.metricName = name;
   base.ReportTimer(name, value, unit, rateUnit, durationUnit, tags);
 }
Example #43
0
 public Counter Counter(string name, Unit unit, MetricTags tags)
 {
     throw new ReadOnlyMetricsContextException();
 }
Example #44
0
 private MetricTags AllTags(MetricTags metricTags)
 {
     return(MetricTags.Concat(metricTags, _globalTags));
 }
        /// <inheritdoc />
        public void Write(string context, string name, IEnumerable <string> columns, IEnumerable <object> values, MetricTags tags, DateTime timestamp)
        {
            var fields = columns.Zip(values, (column, data) => new { column, data }).ToDictionary(pair => pair.column, pair => pair.data);

            var measurement = _metricNameFormatter(context, name);

            _points.Add(new LineProtocolPoint(measurement, fields, tags, timestamp));
        }
 public static BucketHistogramValue GetBucketHistogramValue(this IProvideMetricValues valueService, string context, string metricName, MetricTags tags)
 {
     return(valueService.GetForContext(context).BucketHistograms.ValueFor(tags.AsMetricName(metricName)));
 }
 protected override void ReportGauge(string name, double value, Unit unit, MetricTags tags)
 {
   this.metricName = name;
   base.ReportGauge(name, value, unit, tags);
 }
        protected IMeter CreateMeter(string contextName, string name, bool suppressExportMetrics, MetricTags tags)
        {
            var meterOptions = new MeterOptions
            {
                Context        = contextName,
                Name           = name,
                ReportSetItems = !suppressExportMetrics
            };

            return(new Meter(_metrics.Provider.Meter, _metrics.Measure.Meter, meterOptions, tags));
        }
 protected override void ReportHistogram(string name, HistogramValue value, Unit unit, MetricTags tags)
 {
   this.metricName = name;
   base.ReportHistogram(name, value, unit, tags);
 }
Example #50
0
 public void Gauge(string name, Func <double> valueProvider, Unit unit, MetricTags tags)
 {
     throw new ReadOnlyMetricsContextException();
 }
 protected override void ReportGauge(string name, double value, Unit unit, MetricTags tags)
 {
     this.WriteMetricName(name);
     this.WriteValue("value", unit.FormatValue(value));
 }
Example #52
0
 public void DeregisterHistogram(string name, MetricTags tags)
 {
 }
 protected override void ReportHistogram(string name, HistogramValue value, Unit unit, MetricTags tags)
 {
     this.WriteMetricName(name);
     this.WriteHistogram(value, unit);
 }
 protected override void ReportHistogram(string name, HistogramValue value, Unit unit, MetricTags tags)
 {
     Pack("Histogram", name, unit, tags, new[] { 
         new JsonProperty("Total Count",value.Count),
         new JsonProperty("Last", value.LastValue),
         new JsonProperty("Last User Value", value.LastUserValue),
         new JsonProperty("Min",value.Min),
         new JsonProperty("Min User Value",value.MinUserValue),
         new JsonProperty("Mean",value.Mean),
         new JsonProperty("Max",value.Max),
         new JsonProperty("Max User Value",value.MaxUserValue),
         new JsonProperty("StdDev",value.StdDev),
         new JsonProperty("Median",value.Median),
         new JsonProperty("Percentile 75%",value.Percentile75),
         new JsonProperty("Percentile 95%",value.Percentile95),
         new JsonProperty("Percentile 98%",value.Percentile98),
         new JsonProperty("Percentile 99%",value.Percentile99),
         new JsonProperty("Percentile 99.9%" ,value.Percentile999),
         new JsonProperty("Sample Size", value.SampleSize)
     });
 }
 private void Pack(string name, object value, MetricTags tags)
 {
     _data.Add(new InfluxDbRecord(name, value, tags, _config));
 }
 protected override void ReportTimer(string name, TimerValue value, Unit unit, TimeUnit rateUnit, TimeUnit durationUnit, MetricTags tags)
 {
     Pack("Timer", name, unit, tags, new[] { 
         new JsonProperty("Total Count",value.Rate.Count),
         new JsonProperty("Active Sessions",value.ActiveSessions),
         new JsonProperty("Mean Rate", value.Rate.MeanRate),
         new JsonProperty("1 Min Rate", value.Rate.OneMinuteRate),
         new JsonProperty("5 Min Rate", value.Rate.FiveMinuteRate),
         new JsonProperty("15 Min Rate", value.Rate.FifteenMinuteRate),
         new JsonProperty("Last", value.Histogram.LastValue),
         new JsonProperty("Last User Value", value.Histogram.LastUserValue),
         new JsonProperty("Min",value.Histogram.Min),
         new JsonProperty("Min User Value",value.Histogram.MinUserValue),
         new JsonProperty("Mean",value.Histogram.Mean),
         new JsonProperty("Max",value.Histogram.Max),
         new JsonProperty("Max User Value",value.Histogram.MaxUserValue),
         new JsonProperty("StdDev",value.Histogram.StdDev),
         new JsonProperty("Median",value.Histogram.Median),
         new JsonProperty("Percentile 75%",value.Histogram.Percentile75),
         new JsonProperty("Percentile 95%",value.Histogram.Percentile95),
         new JsonProperty("Percentile 98%",value.Histogram.Percentile98),
         new JsonProperty("Percentile 99%",value.Histogram.Percentile99),
         new JsonProperty("Percentile 99.9%" ,value.Histogram.Percentile999),
         new JsonProperty("Sample Size", value.Histogram.SampleSize)
     });
 }
 /// <inheritdoc />
 public void Update(HistogramOptions options, MetricTags tags, long value, string userValue)
 {
     _registry.Histogram(options, tags, () => _histogramBuilder.Build(options.Reservoir)).Update(value, userValue);
 }
Example #58
0
 public void DeregisterTimer(string name, MetricTags tags)
 {
 }
Example #59
0
 protected override void ReportHistogram(string name, HistogramValue value, Unit unit, MetricTags tags)
 {
     Write("Histogram", name, HistogramValues(value, unit));
 }
Example #60
0
 /// <inheritdoc />
 public IMeter Instance <T>(MeterOptions options, MetricTags tags, Func <T> builder)
     where T : IMeterMetric
 {
     return(_registry.Meter(options, tags, builder));
 }