Пример #1
0
 public static AssertionResult CreateResult(MetricName name, string unitName, double value, Assertion assertion)
 {
     var passed = assertion.Test(value);
     var passedString = passed ? "[PASS]" : "[FAIL]";
     var message = $"{passedString} Expected {name} to {assertion} {unitName}; actual value was {value:n} {unitName}.";
     return new AssertionResult(name, message, passed);
 }
Пример #2
0
        private void reportTimer(long timestamp, MetricName name, Timer timer)
        {
            Snapshot snapshot = timer.Snapshot;

            report(timestamp,
                   name,
                   "count,max,mean,min,stddev,p50,p75,p95,p98,p99,p999,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit,duration_unit",
                   timer.Count,
                   convertDuration(snapshot.Max),
                   convertDuration(snapshot.Mean),
                   convertDuration(snapshot.Min),
                   convertDuration(snapshot.StdDev),
                   convertDuration(snapshot.Median),
                   convertDuration(snapshot.Percentile75th),
                   convertDuration(snapshot.Percentile95th),
                   convertDuration(snapshot.Percentile98th),
                   convertDuration(snapshot.Percentile99th),
                   convertDuration(snapshot.Percentile999th),
                   convertRate(timer.MeanRate),
                   convertRate(timer.OneMinuteRate),
                   convertRate(timer.FiveMinuteRate),
                   convertRate(timer.FifteenMinuteRate),
                   "calls/" + getRateUnit(),
                   getDurationUnit());
        }
Пример #3
0
 protected MetricCollector(MetricName name, string unitName)
 {
     Contract.Requires(name != null);
     Contract.Requires(!string.IsNullOrEmpty(unitName));
     Name = name;
     UnitName = unitName;
 }
Пример #4
0
 public AssertionResult(MetricName metricName, string message, bool passed)
 {
     Contract.Requires(metricName != null);
     MetricName = metricName;
     Message = message;
     Passed = passed;
 }
 public PerformanceCounterValueCollector(MetricName name, string unitName, IPerformanceCounterProxy counter,
     bool disposesCounter)
     : base(name, unitName)
 {
     Counter = counter;
     DisposesCounter = disposesCounter;
 }
Пример #6
0
 public static MetricName BuildName(IProxyRequest request, string Name, bool Absolute)
 {
     MetricName metricName = null;
     if (Absolute)
         metricName = new MetricName(Name);
     else
         metricName = new MetricName(request.Target.GetType().FullName + "." + Name);
     return metricName;
 }
Пример #7
0
        public void CanRemoveMetricFromRegistry()
        {
            var name = new MetricName( "MeterTests.Can_safely_remove_metrics_from_outer_collection_without_affecting_registry");
            var meter = registry.Meter("MeterTests.Can_safely_remove_metrics_from_outer_collection_without_affecting_registry");
            meter.Mark(3);

            registry.Remove(name);
            Assert.True(!registry.Metrics.ContainsKey(name), "Metric was removed from central registry");
        }
Пример #8
0
 public IPerformanceCounterProxy Get(MetricName name)
 {
     if (!Exists(name))
     {
         return EmptyPerformanceCounterProxy.Instance;
     }
     var counter = _cachedCounters[name];
     counter.Touch(); // increment reference count
     return counter;
 }
Пример #9
0
        public bool Put(MetricName name, IPerformanceCounterProxy concreteCounter)
        {
            if (!Exists(name))
            {
                _cachedCounters[name] = new CachedPerformanceCounterProxy(() => concreteCounter);
                return true;
            }

            // already exists - not overriding
            return false;
        }
Пример #10
0
        public AggregateMetrics(MetricName name, string unit, IReadOnlyList<MetricRunReport> runs)
        {
            Contract.Requires(runs != null);
            Contract.Requires(name != null);
            Contract.Requires(!string.IsNullOrEmpty(unit));
            Name = name;
            Unit = unit;
            Runs = runs == null || runs.Count == 0 ? GetSafeRuns(name, unit) : runs;

            Stats = new BenchmarkStat(runs.Select(x => x.MetricValue));
            PerSecondStats = new BenchmarkStat(runs.Select(x => x.MetricValuePerSecond));
        }
Пример #11
0
 public MetricRunReport(MetricName name, string unit, double metricReading, long ticks)
 {
     Contract.Requires(name != null);
     Contract.Requires(!string.IsNullOrEmpty(unit));
     Ticks = Math.Max(ticks, 1);
     Name = name;
     Unit = unit;
     MetricValue = metricReading;
     ElapsedNanos = Ticks/(double) Stopwatch.Frequency*1000000000;
     ElapsedSeconds = ElapsedNanos/1000000000;
     NanosPerMetricValue = ElapsedNanos/Math.Max(MetricValue,1);
     MetricValuePerSecond = MetricValue/ElapsedSeconds;
 }
Пример #12
0
 public void Can_get_metrics_from_collection_with_registered_changes()
 {
     // Counter
     var name = new MetricName("MeterTests.counter");
     var counter = registry.Counter( "MeterTests.counter");
     Assert.IsNotNull(registry.Metrics[name], "Metric not found in central registry");
     counter.Increment(10);
     var actual = ((Counter)registry.Metrics[name]).Count;
     Assert.AreEqual(10, actual, "Immutable copy did not contain correct values for this metric");
     
     // Meter
     name = new MetricName("MeterTests.meter");
     var meter = registry.Meter( "MeterTests.meter");
     Assert.IsNotNull(registry.Metrics[name], "Metric not found in central registry");
     meter.Mark(3);
     actual = ((Meter)registry.Metrics[name]).Count;
     Assert.AreEqual(3, actual, "Immutable copy did not contain correct values for this metric");
 }
 public CounterMetricCollector(MetricName name, string unitName, AtomicCounter counter) : base(name, unitName)
 {
     _counter = counter;
 }
Пример #14
0
 public LongArrayMetric(MetricName name, long[] value, string uom) : base(name, value, uom)
 {
 }
Пример #15
0
 private void reportCounter(MetricName name, Counter counter, long timestamp)
 {
     graphite.Send(Prefix(name, "count"), format(counter.Count), timestamp);
 }
Пример #16
0
 private void reportGauge(long timestamp, MetricName name, Gauge gauge)
 {
     report(timestamp, name, "value", gauge.ValueAsString);
 }
Пример #17
0
        private void reportHistogram(long timestamp, MetricName name, Histogram histogram)
        {
            Snapshot snapshot = histogram.Snapshot;

            report(timestamp,
                   name,
                   "count,max,mean,min,stddev,p50,p75,p95,p98,p99,p999",
                   histogram.Count,
                   snapshot.Max,
                   snapshot.Mean,
                   snapshot.Min,
                   snapshot.StdDev,
                   snapshot.Median,
                   snapshot.Percentile75th,
                   snapshot.Percentile95th,
                   snapshot.Percentile98th,
                   snapshot.Percentile99th,
                   snapshot.Percentile999th);
        }
 public GcCollectionsPerGenerationCollector(MetricName name, string unitName, int generation) : base(name, unitName)
 {
     Generation = generation;
 }
Пример #19
0
 private string Prefix(MetricName name, params String[] components)
 {
     return(MetricName.join(MetricName.join(this.prefix, name), MetricName.build(components)).Key);
 }
Пример #20
0
 /// <summary>
 ///     Given a new <seealso cref="Gauge{T}" />, registers it under the given metric name.
 /// </summary>
 /// <param name="metricName">the name of the metric</param>
 /// <param name="metric">the metric</param>
 /// <typeparam name="T">the type of the value returned by the metric</typeparam>
 /// <returns>{@code metric}</returns>
 public static Gauge<T> NewGauge<T>(
     MetricName metricName,
     Gauge<T> metric)
 {
     return DEFAULT_REGISTRY.NewGauge(metricName, metric);
 }
 public override bool Equals(MetricName other)
 {
     return(other is CounterMetricName && Equals((CounterMetricName)other));
 }
 protected MetricsCollectorSelector(MetricName name, SysInfo systemInfo)
 {
     Name       = name;
     SystemInfo = systemInfo;
 }
Пример #23
0
 public PerformanceCounterSelector(MetricName name) : base(name)
 {
 }
Пример #24
0
 public PerformanceCounterMetricCollector(MetricName name, string unitName, PerformanceCounter counter,
                                          bool disposesCounter) : base(name, unitName)
 {
     _counter        = counter;
     DisposesCounter = disposesCounter;
 }
        /// <summary>
        /// Gets a collection of data points collected for a metric by the monitoring service.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="entityId">The entity ID. This is obtained from <see cref="Entity.Id">Entity.Id</see>.</param>
        /// <param name="checkId">The check ID. This is obtained from <see cref="Check.Id">Check.Id</see>.</param>
        /// <param name="metricName">The metric name. This is obtained from <see cref="Metric.Name">Metric.Name</see>.</param>
        /// <param name="points">The number of data points to return.</param>
        /// <param name="resolution">The granularity of the returned data points.</param>
        /// <param name="select">A collection of <see cref="DataPointStatistic"/> objects identifying the statistics to compute for the data.</param>
        /// <param name="from">The beginning timestamp of the items to include in the collection. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">time series collections</see>.</param>
        /// <param name="to">The ending timestamp of the items to include in the collection. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">time series collections</see>.</param>
        /// <returns>
        /// A collection of <see cref="DataPoint"/> objects describing the data points
        /// collected for the metric.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="checkId"/> is <see langword="null"/>.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="metricName"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If both <paramref name="points"/> and <paramref name="resolution"/> are <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="to"/> occurs before <paramref name="from"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="points"/> is less than or equal to 0.
        /// <para>-or-</para>
        /// <para>If <paramref name="from"/> represents a date before January 1, 1970 UTC.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="to"/> represents a date before January 1, 1970 UTC.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/metrics-api.html#fetch-data-points">Fetch Data Points (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollection<DataPoint> GetDataPoints(this IMonitoringService service, EntityId entityId, CheckId checkId, MetricName metricName, int? points, DataPointGranularity resolution, IEnumerable<DataPointStatistic> select, DateTimeOffset from, DateTimeOffset to)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.GetDataPointsAsync(entityId, checkId, metricName, points, resolution, select, from, to, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
Пример #26
0
 public DateTimeMetric(MetricName name, DateTimeOffset value, string uom) : base(name, value, uom)
 {
 }
Пример #27
0
 /// <summary>
 ///     Creates a new <seealso cref="Histogram" /> and registers it under the given
 ///     metric name.
 /// </summary>
 /// <param name="metricName">the name of the metric</param>
 /// <param name="biased">whether or not the histogram should be biased</param>
 /// <returns>a new <seealso cref="Histogram" /></returns>
 public static Histogram NewHistogram(
     MetricName metricName,
     bool biased)
 {
     return DEFAULT_REGISTRY.NewHistogram(metricName, biased);
 }
 public override bool Equals(MetricName other)
 {
     return(other is PerformanceCounterMetricName &&
            Equals((PerformanceCounterMetricName)other));
 }
 private void LogGauge(IRequest request, MetricName metricName, GaugeMetric metric, long timestamp)
 {
     LogGauge(request, metricName.Name, System.Convert.ToInt64(metric.ValueAsString), timestamp);
 }
Пример #30
0
 public bool Matches(
     MetricName name,
     Metric metric)
 {
     return(true);
 }
 public GcCollectionsPerGenerationCollector(MetricName name, int generation)
     : this(name, MetricNames.GcCollectionsUnits, generation)
 {
 }
Пример #32
0
 public override bool Equals(MetricName other)
 {
     return(other is GcMetricName && Equals((GcMetricName)other));
 }
Пример #33
0
 private void reportMeter(long timestamp, MetricName name, Meter meter)
 {
     report(timestamp,
            name,
            "count,mean_rate,m1_rate,m5_rate,m15_rate,rate_unit",
            meter.Count,
            convertRate(meter.MeanRate),
            convertRate(meter.OneMinuteRate),
            convertRate(meter.FiveMinuteRate),
            convertRate(meter.FifteenMinuteRate),
            "events/" + getRateUnit());
 }
Пример #34
0
        private void report(MetricName name, String header, IEnumerable<object> values)
        {
            try
            {
                string filePath = System.IO.Path.Combine(directory, sanitize(name.Key));
                bool fileAlreadyExists = File.Exists(filePath);
                using (StreamWriter stream = File.AppendText(filePath))
                {

                    if (!fileAlreadyExists)
                    {
                        stream.WriteLine(header);
                    }

                    stream.WriteLine(string.Join(",", values));
                }
            }
            catch (IOException e)
            {
                LOGGER.Warn("Error writing to " + name, e);
            }
        }
Пример #35
0
 private void reportCounter(long timestamp, MetricName name, Counter counter)
 {
     report(timestamp, name, "count", counter.Count);
 }
Пример #36
0
 public override bool Equals(MetricName other)
 {
     return other is CounterMetricName && Equals((CounterMetricName)other);
 }
Пример #37
0
        private void report(long timestamp, MetricName name, string header, params Object[] valuesArr)
        {
            header = "t," + header;
            List<object> values = new List<object>();
            values.Add(timestamp);
            foreach (object obj in valuesArr)
                values.Add(obj);
            report(name, header, values);

        }
Пример #38
0
 public Metric(MetricName name, T value, string uom)
 {
     this.name  = name;
     this.value = value;
     this.uom   = uom;
 }
        public void ThreadMetricsTest()
        {
            var serdes      = new StringSerDes();
            var cloneConfig = config.Clone();

            cloneConfig.ApplicationId = "consume-test";
            var producer = mockKafkaSupplier.GetProducer(cloneConfig.ToProducerConfig());
            var consumer = mockKafkaSupplier.GetConsumer(cloneConfig.ToConsumerConfig("test-consum"), null);

            consumer.Subscribe("topic2");

            thread.Start(token.Token);

            AssertExtensions.WaitUntil(() => thread.ActiveTasks.Count() == numberPartitions,
                                       TimeSpan.FromSeconds(5),
                                       TimeSpan.FromMilliseconds(100));

            int nbMessage = 1000;

            // produce ${nbMessage} messages to input topic
            for (int i = 0; i < nbMessage; ++i)
            {
                producer.Produce("topic", new Confluent.Kafka.Message <byte[], byte[]>
                {
                    Key   = serdes.Serialize("key" + i, new SerializationContext()),
                    Value = serdes.Serialize("Hi" + i, new SerializationContext())
                });
            }

            var messagesSink = new List <ConsumeResult <byte[], byte[]> >();

            AssertExtensions.WaitUntil(() =>
            {
                messagesSink.AddRange(consumer.ConsumeRecords(TimeSpan.FromSeconds(1)));
                return(messagesSink.Count == nbMessage);
            }, TimeSpan.FromSeconds(5),
                                       TimeSpan.FromMilliseconds(10));

            // waiting end of processing
            Thread.Sleep(1000);

            long now     = DateTime.Now.GetMilliseconds();
            var  sensors = streamMetricsRegistry.GetThreadScopeSensor(threadId);

            var createTaskSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.CREATE_TASK)));

            Assert.AreEqual(2, createTaskSensor.Metrics.Count());
            Assert.AreEqual(numberPartitions,
                            createTaskSensor.Metrics[MetricName.NameAndGroup(
                                                         ThreadMetrics.CREATE_TASK + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                         StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value);
            Assert.IsTrue(
                (double)(createTaskSensor.Metrics[MetricName.NameAndGroup(
                                                      ThreadMetrics.CREATE_TASK + StreamMetricsRegistry.RATE_SUFFIX,
                                                      StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value) > 0d);

            var closeTaskSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.CLOSE_TASK)));

            Assert.AreEqual(2, closeTaskSensor.Metrics.Count());
            Assert.AreEqual(0d,
                            closeTaskSensor.Metrics[MetricName.NameAndGroup(
                                                        ThreadMetrics.CLOSE_TASK + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                        StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value);
            Assert.AreEqual(0d,
                            closeTaskSensor.Metrics[MetricName.NameAndGroup(
                                                        ThreadMetrics.CLOSE_TASK + StreamMetricsRegistry.RATE_SUFFIX,
                                                        StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value);

            var commitSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.COMMIT)));

            Assert.AreEqual(4, commitSensor.Metrics.Count());
            Assert.IsTrue(
                (double)commitSensor.Metrics[MetricName.NameAndGroup(
                                                 ThreadMetrics.COMMIT + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                 StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)commitSensor.Metrics[MetricName.NameAndGroup(
                                                 ThreadMetrics.COMMIT + StreamMetricsRegistry.RATE_SUFFIX,
                                                 StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)commitSensor.Metrics[MetricName.NameAndGroup(
                                                 ThreadMetrics.COMMIT + StreamMetricsRegistry.LATENCY_SUFFIX + StreamMetricsRegistry.AVG_SUFFIX,
                                                 StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)commitSensor.Metrics[MetricName.NameAndGroup(
                                                 ThreadMetrics.COMMIT + StreamMetricsRegistry.LATENCY_SUFFIX + StreamMetricsRegistry.MAX_SUFFIX,
                                                 StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);

            var pollSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.POLL)));

            Assert.AreEqual(4, pollSensor.Metrics.Count());
            Assert.IsTrue(
                (double)pollSensor.Metrics[MetricName.NameAndGroup(
                                               ThreadMetrics.POLL + StreamMetricsRegistry.TOTAL_SUFFIX,
                                               StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)pollSensor.Metrics[MetricName.NameAndGroup(
                                               ThreadMetrics.POLL + StreamMetricsRegistry.RATE_SUFFIX,
                                               StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)pollSensor.Metrics[MetricName.NameAndGroup(
                                               ThreadMetrics.POLL + StreamMetricsRegistry.LATENCY_SUFFIX + StreamMetricsRegistry.AVG_SUFFIX,
                                               StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)pollSensor.Metrics[MetricName.NameAndGroup(
                                               ThreadMetrics.POLL + StreamMetricsRegistry.LATENCY_SUFFIX + StreamMetricsRegistry.MAX_SUFFIX,
                                               StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);

            var pollRecordsSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.POLL + StreamMetricsRegistry.RECORDS_SUFFIX)));

            Assert.AreEqual(2, pollRecordsSensor.Metrics.Count());
            Assert.IsTrue(
                (double)pollRecordsSensor.Metrics[MetricName.NameAndGroup(
                                                      ThreadMetrics.POLL + StreamMetricsRegistry.RECORDS_SUFFIX + StreamMetricsRegistry.AVG_SUFFIX,
                                                      StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)pollRecordsSensor.Metrics[MetricName.NameAndGroup(
                                                      ThreadMetrics.POLL + StreamMetricsRegistry.RECORDS_SUFFIX + StreamMetricsRegistry.MAX_SUFFIX,
                                                      StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);

            var processRecordsSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.PROCESS + StreamMetricsRegistry.RECORDS_SUFFIX)));

            Assert.AreEqual(2, processRecordsSensor.Metrics.Count());
            Assert.IsTrue(
                (double)processRecordsSensor.Metrics[MetricName.NameAndGroup(
                                                         ThreadMetrics.PROCESS + StreamMetricsRegistry.RECORDS_SUFFIX + StreamMetricsRegistry.AVG_SUFFIX,
                                                         StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)processRecordsSensor.Metrics[MetricName.NameAndGroup(
                                                         ThreadMetrics.PROCESS + StreamMetricsRegistry.RECORDS_SUFFIX + StreamMetricsRegistry.MAX_SUFFIX,
                                                         StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);

            var processRateSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.PROCESS + StreamMetricsRegistry.RATE_SUFFIX)));

            Assert.AreEqual(2, processRateSensor.Metrics.Count());
            Assert.IsTrue(
                (double)processRateSensor.Metrics[MetricName.NameAndGroup(
                                                      ThreadMetrics.PROCESS + StreamMetricsRegistry.RATE_SUFFIX + StreamMetricsRegistry.RATE_SUFFIX,
                                                      StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)processRateSensor.Metrics[MetricName.NameAndGroup(
                                                      ThreadMetrics.PROCESS + StreamMetricsRegistry.RATE_SUFFIX + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                      StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);

            var processLatencySensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.PROCESS + StreamMetricsRegistry.LATENCY_SUFFIX)));

            Assert.AreEqual(2, processLatencySensor.Metrics.Count());
            Assert.IsTrue(
                (double)processLatencySensor.Metrics[MetricName.NameAndGroup(
                                                         ThreadMetrics.PROCESS + StreamMetricsRegistry.LATENCY_SUFFIX + StreamMetricsRegistry.AVG_SUFFIX,
                                                         StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)processLatencySensor.Metrics[MetricName.NameAndGroup(
                                                         ThreadMetrics.PROCESS + StreamMetricsRegistry.LATENCY_SUFFIX + StreamMetricsRegistry.MAX_SUFFIX,
                                                         StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value > 0d);

            // ratio sensors
            var processRatioSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.PROCESS + StreamMetricsRegistry.RATIO_SUFFIX)));
            var pollRatioSensor    = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.POLL + StreamMetricsRegistry.RATIO_SUFFIX)));
            var commitRatioSensor  = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(ThreadMetrics.COMMIT + StreamMetricsRegistry.RATIO_SUFFIX)));

            Assert.AreEqual(1, processRatioSensor.Metrics.Count());
            Assert.AreEqual(1, pollRatioSensor.Metrics.Count());
            Assert.AreEqual(1, commitRatioSensor.Metrics.Count());

            var processRatioValue = (double)processRatioSensor.Metrics[MetricName.NameAndGroup(
                                                                           ThreadMetrics.PROCESS + StreamMetricsRegistry.RATIO_SUFFIX,
                                                                           StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value;

            var pollRatioValue = (double)pollRatioSensor.Metrics[MetricName.NameAndGroup(
                                                                     ThreadMetrics.POLL + StreamMetricsRegistry.RATIO_SUFFIX,
                                                                     StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value;

            var commitRatioValue = (double)commitRatioSensor.Metrics[MetricName.NameAndGroup(
                                                                         ThreadMetrics.COMMIT + StreamMetricsRegistry.RATIO_SUFFIX,
                                                                         StreamMetricsRegistry.THREAD_LEVEL_GROUP)].Value;

            double total = Math.Round(processRatioValue + pollRatioValue + commitRatioValue, 2);

            // we accept 10% of lost
            Assert.IsTrue(total >= 0.90d);
        }
Пример #40
0
        private GraphiteReporter(MetricRegistry registry,
                         GraphiteSender graphite,
                         Clock clock,
                         String prefix,
                         TimeUnit rateUnit,
                         TimeUnit durationUnit,
                         MetricFilter filter) : base(registry, "graphite-reporter", filter, rateUnit, durationUnit)
        {

            this.graphite = graphite;
            this.clock = clock;
            this.prefix = MetricName.build(prefix);
        }
Пример #41
0
 public override bool Equals(MetricName other)
 {
     return other is MemoryMetricName && Equals((MemoryMetricName)other);
 }
Пример #42
0
        private void reportTimer(MetricName name, Timer timer, long timestamp)
        {
            Snapshot snapshot = timer.Snapshot;

            graphite.Send(Prefix(name, "max"), format(convertDuration(snapshot.Max)), timestamp);
            graphite.Send(Prefix(name, "mean"), format(convertDuration(snapshot.Mean)), timestamp);
            graphite.Send(Prefix(name, "min"), format(convertDuration(snapshot.Min)), timestamp);
            graphite.Send(Prefix(name, "stddev"),
                      format(convertDuration(snapshot.StdDev)),
                      timestamp);
            graphite.Send(Prefix(name, "p50"),
                      format(convertDuration(snapshot.Median)),
                      timestamp);
            graphite.Send(Prefix(name, "p75"),
                      format(convertDuration(snapshot.Percentile75th)),
                      timestamp);
            graphite.Send(Prefix(name, "p95"),
                      format(convertDuration(snapshot.Percentile95th)),
                      timestamp);
            graphite.Send(Prefix(name, "p98"),
                      format(convertDuration(snapshot.Percentile98th)),
                      timestamp);
            graphite.Send(Prefix(name, "p99"),
                      format(convertDuration(snapshot.Percentile99th)),
                      timestamp);
            graphite.Send(Prefix(name, "p999"),
                      format(convertDuration(snapshot.Percentile999th)),
                      timestamp);

            reportMetered(name, timer, timestamp);
        }
 public CounterMetricCollector(MetricName name, AtomicCounter counter)
     : this(name, MetricNames.CounterUnits, counter)
 {
 }
Пример #44
0
 private void reportMetered(MetricName name, IMetered meter, long timestamp)
 {
     graphite.Send(Prefix(name, "count"), format(meter.Count), timestamp);
     graphite.Send(Prefix(name, "m1_rate"),
               format(convertRate(meter.OneMinuteRate)),
               timestamp);
     graphite.Send(Prefix(name, "m5_rate"),
               format(convertRate(meter.FiveMinuteRate)),
               timestamp);
     graphite.Send(Prefix(name, "m15_rate"),
               format(convertRate(meter.FifteenMinuteRate)),
               timestamp);
     graphite.Send(Prefix(name, "mean_rate"),
               format(convertRate(meter.MeanRate)),
               timestamp);
 }
Пример #45
0
 public override bool Equals(MetricName other)
 {
     return((other is TimingMetricName) && Equals((TimingMetricName)other));
 }
Пример #46
0
 private void reportHistogram(MetricName name, Histogram histogram, long timestamp)
 {
     Snapshot snapshot = histogram.Snapshot;
     graphite.Send(Prefix(name, "count"), format(histogram.Count), timestamp);
     graphite.Send(Prefix(name, "max"), format(snapshot.Max), timestamp);
     graphite.Send(Prefix(name, "mean"), format(snapshot.Mean), timestamp);
     graphite.Send(Prefix(name, "min"), format(snapshot.Min), timestamp);
     graphite.Send(Prefix(name, "stddev"), format(snapshot.StdDev), timestamp);
     graphite.Send(Prefix(name, "p50"), format(snapshot.Median), timestamp);
     graphite.Send(Prefix(name, "p75"), format(snapshot.Percentile75th), timestamp);
     graphite.Send(Prefix(name, "p95"), format(snapshot.Percentile95th), timestamp);
     graphite.Send(Prefix(name, "p98"), format(snapshot.Percentile98th), timestamp);
     graphite.Send(Prefix(name, "p99"), format(snapshot.Percentile99th), timestamp);
     graphite.Send(Prefix(name, "p999"), format(snapshot.Percentile999th), timestamp);
 }
 protected MetricsCollectorSelector(MetricName name) : this(name, SysInfo.Instance)
 {
 }
Пример #48
0
 private void reportCounter(MetricName name, Counter counter, long timestamp)
 {
     graphite.Send(Prefix(name, "count"), format(counter.Count), timestamp);
 }
        /// <summary>
        /// Gets a collection of monitoring metrics.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="entityId">The entity ID. This is obtained from <see cref="Entity.Id">Entity.Id</see>.</param>
        /// <param name="checkId">The check ID. This is obtained from <see cref="Check.Id">Check.Id</see>.</param>
        /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <returns>
        /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page
        /// of results and its associated pagination metadata.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="entityId"/> is <see langword="null"/>.
        /// <para>-or-</para>
        /// <para>If <paramref name="checkId"/> is <see langword="null"/>.</para>
        /// </exception>
        /// <exception cref="ArgumentOutOfRangeException">If <paramref name="limit"/> is less than or equal to 0.</exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/metrics-api.html#list-metrics">List Metrics (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<Metric, MetricName> ListMetrics(this IMonitoringService service, EntityId entityId, CheckId checkId, MetricName marker, int? limit)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListMetricsAsync(entityId, checkId, marker, limit, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
Пример #50
0
 private void reportGauge(MetricName name, Gauge gauge, long timestamp)
 {
     string value = format(gauge.ValueAsString);
     if (value != null)
     {
         graphite.Send(Prefix(name), value, timestamp);
     }
 }
Пример #51
0
 public TestMetricCollector(MetricName name, string unitName) : base(name, unitName)
 {
 }
Пример #52
0
 private string Prefix(MetricName name, params String[] components)
 {
     return MetricName.join(MetricName.join(this.prefix, name), MetricName.build(components)).Key;
 }
Пример #53
0
 /// <summary>
 ///     Creates a new <seealso cref="Counter" /> and registers it under the given metric
 ///     name.
 /// </summary>
 /// <param name="metricName">the name of the metric</param>
 /// <returns>a new <seealso cref="Counter" /></returns>
 public static Counter NewCounter(MetricName metricName)
 {
     return DEFAULT_REGISTRY.NewCounter(metricName);
 }
Пример #54
0
 internal PartitionUsage(UnitType?unit, MetricName name, string quotaPeriod, long?limit, long?currentValue, string partitionId, string partitionKeyRangeId) : base(unit, name, quotaPeriod, limit, currentValue)
 {
     PartitionId         = partitionId;
     PartitionKeyRangeId = partitionKeyRangeId;
 }
Пример #55
0
 /// <summary>
 ///     Creates a new non-biased <seealso cref="Histogram" /> and registers it under the
 ///     given metric name.
 /// </summary>
 /// <param name="metricName">the name of the metric</param>
 /// <returns>a new <seealso cref="Histogram" /></returns>
 public static Histogram NewHistogram(MetricName metricName)
 {
     return NewHistogram(metricName, false);
 }
Пример #56
0
 public CounterSelector(MetricName name, SysInfo systemInfo)
     : base(name, systemInfo)
 {
 }
 private void LogCounter(IRequest request, MetricName metricName, CounterMetric metric, long timestamp)
 {
     request.AddCounter(new DatadogCounter(_nameFormatter.Format(metricName.Name, _path), metric.Count, timestamp, _globalTags));
 }
 public PerformanceCounterValueCollector(MetricName name, string unitName, IPerformanceCounterProxy counter,
                                         bool disposesCounter) : base(name, unitName)
 {
     Counter         = counter;
     DisposesCounter = disposesCounter;
 }
Пример #59
0
 public CounterSelector(MetricName name, SysInfo systemInfo) : base(name, systemInfo)
 {
 }
        public void TaskMetricsTest()
        {
            var serdes      = new StringSerDes();
            var cloneConfig = config.Clone();

            cloneConfig.ApplicationId = "consume-test";
            var producer = syncKafkaSupplier.GetProducer(cloneConfig.ToProducerConfig());
            var consumer = syncKafkaSupplier.GetConsumer(cloneConfig.ToConsumerConfig("test-consum"), null);

            consumer.Subscribe("topic2");

            int nbMessage = 1000;
            // produce 1000 messages to input topic
            List <ConsumeResult <byte[], byte[]> > messages = new List <ConsumeResult <byte[], byte[]> >();
            int offset = 0;

            for (int i = 0; i < nbMessage; ++i)
            {
                messages.Add(
                    new ConsumeResult <byte[], byte[]>
                {
                    Message = new Message <byte[], byte[]>
                    {
                        Key   = serdes.Serialize($"key{i + 1}", new SerializationContext()),
                        Value = serdes.Serialize($"value{i + 1}", new SerializationContext())
                    },
                    TopicPartitionOffset = new TopicPartitionOffset(topicPartition, offset++)
                });
            }

            task.AddRecords(messages);

            while (task.CanProcess(DateTime.Now.GetMilliseconds()))
            {
                Assert.IsTrue(task.Process());
                Assert.IsTrue(task.CommitNeeded);
                task.Commit();
            }

            var messagesSink = new List <ConsumeResult <byte[], byte[]> >();

            AssertExtensions.WaitUntil(() =>
            {
                messagesSink.AddRange(consumer.ConsumeRecords(TimeSpan.FromSeconds(1)));
                return(messagesSink.Count < nbMessage);
            }, TimeSpan.FromSeconds(5),
                                       TimeSpan.FromMilliseconds(10));

            long now     = DateTime.Now.GetMilliseconds();
            var  sensors = streamMetricsRegistry.GetThreadScopeSensor(threadId);

            var processorSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.PROCESS)));

            Assert.AreEqual(2, processorSensor.Metrics.Count());
            Assert.AreEqual(nbMessage,
                            processorSensor.Metrics[MetricName.NameAndGroup(
                                                        TaskMetrics.PROCESS + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                        StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);
            Assert.IsTrue(
                (double)(processorSensor.Metrics[MetricName.NameAndGroup(
                                                     TaskMetrics.PROCESS + StreamMetricsRegistry.RATE_SUFFIX,
                                                     StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value) > 0d);

            var enforcedProcessorSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.ENFORCED_PROCESSING)));

            Assert.AreEqual(2, enforcedProcessorSensor.Metrics.Count());
            Assert.AreEqual(0,
                            enforcedProcessorSensor.Metrics[MetricName.NameAndGroup(
                                                                TaskMetrics.ENFORCED_PROCESSING + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                                StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);
            Assert.AreEqual(0,
                            enforcedProcessorSensor.Metrics[MetricName.NameAndGroup(
                                                                TaskMetrics.ENFORCED_PROCESSING + StreamMetricsRegistry.RATE_SUFFIX,
                                                                StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);

            var processLatency = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.PROCESS_LATENCY)));

            Assert.AreEqual(2, processLatency.Metrics.Count());
            Assert.IsTrue(
                (double)processLatency.Metrics[MetricName.NameAndGroup(
                                                   TaskMetrics.PROCESS_LATENCY + StreamMetricsRegistry.AVG_SUFFIX,
                                                   StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value > 0d);
            Assert.IsTrue(
                (double)processLatency.Metrics[MetricName.NameAndGroup(
                                                   TaskMetrics.PROCESS_LATENCY + StreamMetricsRegistry.MAX_SUFFIX,
                                                   StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value > 0d);

            var commitSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.COMMIT)));

            Assert.AreEqual(2, commitSensor.Metrics.Count());
            Assert.AreEqual(nbMessage,
                            commitSensor.Metrics[MetricName.NameAndGroup(
                                                     TaskMetrics.COMMIT + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                     StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);
            Assert.IsTrue(
                (double)commitSensor.Metrics[MetricName.NameAndGroup(
                                                 TaskMetrics.COMMIT + StreamMetricsRegistry.RATE_SUFFIX,
                                                 StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value > 0d);

            var droppedRecordSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.DROPPED_RECORDS)));

            Assert.AreEqual(2, droppedRecordSensor.Metrics.Count());
            Assert.AreEqual(0,
                            droppedRecordSensor.Metrics[MetricName.NameAndGroup(
                                                            TaskMetrics.DROPPED_RECORDS + StreamMetricsRegistry.TOTAL_SUFFIX,
                                                            StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);
            Assert.AreEqual(0,
                            droppedRecordSensor.Metrics[MetricName.NameAndGroup(
                                                            TaskMetrics.DROPPED_RECORDS + StreamMetricsRegistry.RATE_SUFFIX,
                                                            StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);

            var activeBufferedRecordSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.ACTIVE_TASK_PREFIX + TaskMetrics.BUFFER_COUNT)));

            Assert.AreEqual(1, activeBufferedRecordSensor.Metrics.Count());
            Assert.AreEqual(0,
                            activeBufferedRecordSensor.Metrics[MetricName.NameAndGroup(
                                                                   TaskMetrics.ACTIVE_TASK_PREFIX + TaskMetrics.BUFFER_COUNT,
                                                                   StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);

            var restorationRecordsSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.RESTORATION_RECORDS)));

            Assert.AreEqual(1, restorationRecordsSensor.Metrics.Count());
            Assert.AreEqual(0,
                            restorationRecordsSensor.Metrics[MetricName.NameAndGroup(
                                                                 TaskMetrics.RESTORATION_RECORDS,
                                                                 StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);

            var activeRestorationSensor = sensors.FirstOrDefault(s => s.Name.Equals(GetSensorName(TaskMetrics.ACTIVE_RESTORATION)));

            Assert.AreEqual(1, activeRestorationSensor.Metrics.Count());
            Assert.AreEqual(0,
                            activeRestorationSensor.Metrics[MetricName.NameAndGroup(
                                                                TaskMetrics.ACTIVE_RESTORATION,
                                                                StreamMetricsRegistry.TASK_LEVEL_GROUP)].Value);
        }