/// <summary> /// Creates a new metric that can be used to add manual timings into the system. A manual timing /// is a timing that is measured not by the metrics system but by the client site and must be added /// into metrics as an additional measurement. /// </summary> /// <param name="owner">The type that owns the metric</param> /// <param name="name">The metric name</param> /// <param name="durationUnit">The duration scale unit of the new timer</param> /// <param name="rateUnit">The rate unit of the new timer</param> /// <returns></returns> public ManualTimerMetric ManualTimer(Type owner, String name, TimeUnit durationUnit, TimeUnit rateUnit) { var metricName = new MetricName(owner, name); IMetric existingMetric; if (_metrics.TryGetValue(metricName, out existingMetric)) { return((ManualTimerMetric)existingMetric); } var metric = new ManualTimerMetric(durationUnit, rateUnit); var justAddedMetric = _metrics.GetOrAdd(metricName, metric); return(justAddedMetric == null ? metric : (ManualTimerMetric)justAddedMetric); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ private void SendData(object pState) { foreach (string path in vTimerPaths) { ManualTimerMetric mtm = Metrics.ManualTimer(GetType(), path, TimeUnit.Milliseconds, TimeUnit.Milliseconds); double[] perc = mtm.Percentiles(0.95, 0.99); vGraphite.Send(path + ".timer.mean", mtm.Mean); vGraphite.Send(path + ".timer.p95", perc[0]); vGraphite.Send(path + ".timer.p99", perc[1]); mtm.Clear(); } foreach (string path in vMeanPaths) { HistogramMetric hm = Metrics.Histogram(GetType(), path); vGraphite.Send(path + ".mean", hm.Mean); hm.Clear(); } foreach (string path in vCounterPaths) { CounterMetric cm = Metrics.Counter(GetType(), path); vGraphite.Send(path + ".counter", cm.Count); cm.Clear(); } foreach (string path in vGaugePaths) { GaugeMetric <long> gm = Metrics.Gauge <long>(GetType(), path, null); vGraphite.Send(path + ".gauge", gm.Value); } ResetPaths(); }