public void can_create_gauge_from_value_source() { var valueSource = new GaugeValueSource("test", new FunctionGauge(() => 2.0), Unit.Bytes, MetricTags.Empty); var gauge = GaugeMetric.FromGauge(valueSource); gauge.Value.Should().Be(2.0); gauge.Name.Should().Be("test"); gauge.Tags.Should().BeEmpty(); Assert.True(gauge.Unit == Unit.Bytes); }
public void Can_gauge_scalar_value() { var queue = new Queue <int>(); var gauge = new GaugeMetric <int>(() => queue.Count); queue.Enqueue(5); Assert.Equal(1, gauge.Value); queue.Enqueue(6); queue.Dequeue(); Assert.Equal(1, gauge.Value); queue.Dequeue(); Assert.Equal(0, gauge.Value); }
static void Main(string[] args) { try { var metrics = new Metrics(); //DataDogReporterConfigModel dataDogReporterConfigModel = new DataDogReporterConfigModel("appdev", 8125, "ApplicationName", "DomainName", "Development"); ITransport transport = new UdpTransport.Builder().WithPort(8125) .WithStatsdHost("appdev") .Build(); string host = "hostName"; string environment = "testEnv"; string[] path = { "ApplicationName", "DomainName" }; //IMetricNameFormatter formatter = new AppendMetricNameToPathFormatter(); IMetricNameFormatter formatter = new AppendMetricNameToPathFormatter(); var reporter = new DataDogReporter(metrics, transport, formatter, environment, host, path); reporter.Start(5, TimeUnit.Seconds); CounterMetric counter = metrics.Counter("test", "CounterMetric"); HistogramMetric histogramMetric = metrics.Histogram("test", "HistogramMetric"); GaugeMetric gaugeMetric = metrics.Gauge("test", "GaugeMetric", GetNumberOfUsersLoggedIn); var rand = new Random(); int runs = 0; while (runs < 1000) { System.Console.WriteLine("Loop " + (runs++) + " of 1000"); counter.Increment(); counter.Increment(); counter.Increment(); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); histogramMetric.Update(rand.Next(100)); Thread.Sleep(5000); } } catch (Exception e) { throw; } }
public void MetricConverterTest() { var metrics = new Metrics(); CounterMetric counter = metrics.Counter("test", "CounterMetric"); HistogramMetric histogramMetric = metrics.Histogram("test", "HistogramMetric"); GaugeMetric gaugeMetric = metrics.Gauge("test", "GaugeMetric", GetNumberOfUsersLoggedIn); DataDogReporter reporter = CreateDefaultReporter(metrics); TestRequest request = new TestRequest(); reporter.TransformMetrics(request, metrics, 0); IDictionary <string, DatadogSeries> convertedMetrics = request.Metrics; Assert.AreEqual(12, convertedMetrics.Count); }
public void SingleGaugeTest() { var metrics = new Metrics(); string metricName = "GaugeMetric"; GaugeMetric gaugeMetric = metrics.Gauge("test", metricName, GetNumberOfUsersLoggedIn); DataDogReporter reporter = CreateDefaultReporter(metrics); TestRequest request = new TestRequest(); reporter.TransformMetrics(request, metrics, 0); IDictionary <string, DatadogSeries> convertedMetrics = request.Metrics; Assert.AreEqual(1, convertedMetrics.Count); DatadogSeries metric = convertedMetrics[APP + "." + DOMAIN + "." + metricName]; Assert.NotNull(metric); Assert.IsTrue(metric is DatadogGauge); ValidateDefaultTags(metric.Tags); }
//////////////////////////////////////////////////////////////////////////////////////////////// /*--------------------------------------------------------------------------------------------*/ 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(); }
private void LogGauge(IRequest request, MetricName metricName, GaugeMetric metric, long timestamp) { LogGauge(request, metricName.Name, System.Convert.ToInt64(metric.ValueAsString), timestamp); }
private static void WriteGauge(StringBuilder sb, GaugeMetric gauge) { sb.Append(" value = "); sb.AppendLine(gauge.ValueAsString); }
private static void WriteGauge(TextWriter writer, GaugeMetric gauge) { writer.Write(" value = "); writer.WriteLine(gauge.ValueAsString); }
private static void AppendGauge(StringBuilder sb, GaugeMetric gauge) { sb.Append("{\"value\":").Append(gauge.ValueAsString).Append('}'); }
protected void WriteGauge(StringBuilder sb, GaugeMetric gauge) { sb.Append(" value = "); sb.AppendLine(gauge.ValueAsString); }