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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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;
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        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);
 }
예제 #8
0
 private static void WriteGauge(StringBuilder sb, GaugeMetric gauge)
 {
     sb.Append("    value = ");
     sb.AppendLine(gauge.ValueAsString);
 }
예제 #9
0
 private static void WriteGauge(TextWriter writer, GaugeMetric gauge)
 {
     writer.Write("    value = ");
     writer.WriteLine(gauge.ValueAsString);
 }
예제 #10
0
 private static void AppendGauge(StringBuilder sb, GaugeMetric gauge)
 {
     sb.Append("{\"value\":").Append(gauge.ValueAsString).Append('}');
 }
예제 #11
0
 protected void WriteGauge(StringBuilder sb, GaugeMetric gauge)
 {
     sb.Append("    value = ");
     sb.AppendLine(gauge.ValueAsString);
 }