示例#1
0
        public void CanReadOptions(MetricFlags options, bool includeTimestamp, bool suppressEmptySamples)
        {
            var config = new MetricConfiguration("test_name", string.Empty, null, options);

            Assert.Equal(includeTimestamp, config.IncludeTimestamp);
            Assert.Equal(suppressEmptySamples, config.SuppressEmptySamples);
        }
        public void ShouldIgnoreTsIfDisabled()
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), false);

            var metric = new DummyMetric(config, Array.Empty <string>(), null);

            metric.Observe(1586594808);

            Assert.False(metric.Timestamp.HasValue);
        }
        public void TimestampTests(long now, long?ts, long expectedTs)
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), true);

            var metric = new DummyMetric(config, Array.Empty <string>(), () => DateTimeOffset.FromUnixTimeMilliseconds(now));

            metric.Observe(ts);

            Assert.Equal(expectedTs, metric.Timestamp);
        }
 /// <summary>
 /// Gets or creates a metric container that you can use to track, aggregate and send metric values.<br />
 /// Optionally specify a metric configuration to control how the tracked values are aggregated.
 /// </summary>
 /// <param name="telemetryClient">The aggregated values will be sent to the <c>TelemetryConfiguration</c>
 /// associated with this client.<br />
 /// The aggregation scope of the fetched<c>Metric</c> is <c>TelemetryConfiguration</c>; this
 /// means that all values tracked for a given metric ID and dimensions will be aggregated together
 /// across all clients that share the same <c>TelemetryConfiguration</c>.</param>
 /// <param name="metricIdentifier">A grouping containing the Namespace, the ID (name) and the dimension names of the metric.</param>
 /// <param name="metricConfiguration">Determines how tracked values will be aggregated. <br />
 /// Use presets in <see cref="MetricConfigurations.Common"/> or specify your own settings. </param>
 /// <returns>A <c>Metric</c> with the specified ID and dimensions. If you call this method several times
 /// with the same metric ID and dimensions for a given aggregation scope, you will receive the same
 /// instance of <c>Metric</c>.</returns>
 /// <exception cref="ArgumentException">If you previously created a metric with the same namespace, ID, dimensions
 /// and aggregation scope, but with a different configuration. When calling this method to get a previously
 /// created metric, you can simply avoid specifying any configuration (or specify null) to imply the
 /// configuration used earlier.</exception>
 public static Metric GetMetric(
     this TelemetryClient telemetryClient,
     MetricIdentifier metricIdentifier,
     MetricConfiguration metricConfiguration)
 {
     return(GetOrCreateMetric(
                telemetryClient,
                MetricAggregationScope.TelemetryConfiguration,
                metricIdentifier,
                metricConfiguration));
 }
 /// <summary>
 /// Gets or creates a metric container that you can use to track, aggregate and send metric values.<br />
 /// Optionally specify a metric configuration to control how the tracked values are aggregated.
 /// </summary>
 /// <param name="telemetryClient">The aggregated values will be sent to the <c>TelemetryConfiguration</c>
 /// associated with this client.<br />
 /// The aggregation scope of the fetched<c>Metric</c> is <c>TelemetryConfiguration</c>; this
 /// means that all values tracked for a given metric ID and dimensions will be aggregated together
 /// across all clients that share the same <c>TelemetryConfiguration</c>.</param>
 /// <param name="metricId">The ID (name) of the metric.
 ///   (The namespace specified in <see cref="MetricIdentifier.DefaultMetricNamespace"/> will be used.
 ///   To specify another namespace, user an overload that takes a <c>MetricIdentifier</c> paramater instead.)</param>
 /// <param name="metricConfiguration">Determines how tracked values will be aggregated. <br />
 /// Use presets in <see cref="MetricConfigurations.Common"/> or specify your own settings. </param>
 /// <returns>A <c>Metric</c> with the specified ID and dimensions. If you call this method several times
 /// with the same metric ID and dimensions for a given aggregation scope, you will receive the same
 /// instance of <c>Metric</c>.</returns>
 /// <exception cref="ArgumentException">If you previously created a metric with the same namespace, ID, dimensions
 /// and aggregation scope, but with a different configuration. When calling this method to get a previously
 /// created metric, you can simply avoid specifying any configuration (or specify null) to imply the
 /// configuration used earlier.</exception>
 public static Metric GetMetric(
     this TelemetryClient telemetryClient,
     string metricId,
     MetricConfiguration metricConfiguration)
 {
     return(GetOrCreateMetric(
                telemetryClient,
                MetricAggregationScope.TelemetryConfiguration,
                new MetricIdentifier(metricId),
                metricConfiguration: metricConfiguration));
 }
 /// <summary>
 /// Gets or creates a metric container that you can use to track, aggregate and send metric values.<br />
 /// Optionally specify a metric configuration to control how the tracked values are aggregated.
 /// </summary>
 /// <param name="telemetryClient">The aggregated values will be sent to the <c>TelemetryConfiguration</c>
 /// associated with this client.<br />
 /// The aggregation scope of the fetched<c>Metric</c> is <c>TelemetryConfiguration</c>; this
 /// means that all values tracked for a given metric ID and dimensions will be aggregated together
 /// across all clients that share the same <c>TelemetryConfiguration</c>.</param>
 /// <param name="metricId">The ID (name) of the metric.
 ///   (The namespace specified in <see cref="MetricIdentifier.DefaultMetricNamespace"/> will be used.
 ///   To specify another namespace, user an overload that takes a <c>MetricIdentifier</c> paramater instead.)</param>
 /// <param name="dimension1Name">The name of the first dimension.</param>
 /// <param name="metricConfiguration">Determines how tracked values will be aggregated. <br />
 /// Use presets in <see cref="MetricConfigurations.Common"/> or specify your own settings. </param>
 /// <returns>A <c>Metric</c> with the specified ID and dimensions. If you call this method several times
 /// with the same metric ID and dimensions for a given aggregation scope, you will receive the same
 /// instance of <c>Metric</c>.</returns>
 /// <exception cref="ArgumentException">If you previously created a metric with the same namespace, ID, dimensions
 /// and aggregation scope, but with a different configuration. When calling this method to get a previously
 /// created metric, you can simply avoid specifying any configuration (or specify null) to imply the
 /// configuration used earlier.</exception>
 public static Metric GetMetric(
     this TelemetryClient telemetryClient,
     string metricId,
     string dimension1Name,
     MetricConfiguration metricConfiguration)
 {
     return(GetOrCreateMetric(
                telemetryClient,
                MetricAggregationScope.TelemetryConfiguration,
                new MetricIdentifier(MetricIdentifier.DefaultMetricNamespace, metricId, dimension1Name),
                metricConfiguration: metricConfiguration));
 }
        public void ShouldIgnoreTsIfCurrentIsMore()
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), true);

            var metric = new DummyMetric(config, Array.Empty <string>(), null);

            metric.Observe(1586594808);

            metric.Observe(1586594700);

            Assert.Equal(1586594808, metric.Timestamp);
        }
        private static Metric GetOrCreateMetric(
            TelemetryClient telemetryClient,
            MetricAggregationScope aggregationScope,
            MetricIdentifier metricIdentifier,
            MetricConfiguration metricConfiguration)
        {
            Util.ValidateNotNull(telemetryClient, nameof(telemetryClient));

            MetricManager metricManager = telemetryClient.GetMetricManager(aggregationScope);
            Metric        metric        = metricManager.Metrics.GetOrCreate(metricIdentifier, metricConfiguration);

            return(metric);
        }
        public void GetMetricDefinitions()
        {
            var path = Environment.GetEnvironmentVariable("STATSIFY_RABBITMQ_PATH");

            if (string.IsNullOrWhiteSpace(path))
            {
                System.Diagnostics.Debug.WriteLine("Missing %STATSIFY_RABBITMQ_PATH% environment variable, is Rabbit installed?");
                return;
            }

            var configuration = new MetricConfiguration("rabbit_mq", "rabbit-mq", path, AggregationStrategy.Counter, null);
            var metricSource  = new RabbitMqMetricSource(configuration);

            CollectionAssert.IsNotEmpty(metricSource.GetMetricDefinitions());
        }
示例#10
0
        public void SetUp()
        {
            _configuration = new Mock <ISpectatorConfiguration>();
            _source        = new Mock <IQueryableSource>();
            _sourceFactory = new Mock <IQueryableSourceFactory>();
            _publisher     = new Mock <IMetricPublisher>();
            _formatter     = new Mock <IMetricFormatter>();
            _service       = new SpectatorServiceTestHarness(_configuration.Object, _sourceFactory.Object, _publisher.Object, _formatter.Object);

            var metricConfiguration = new MetricConfiguration();

            _sourceFactory.Setup(m => m.Create(metricConfiguration.Source)).Returns(_source.Object);
            _source.Setup(m => m.QueryValue(metricConfiguration.Path)).Returns(new[] { new Sample("instance", 10d) });
            _formatter.Setup(m => m.Format(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns("metricname");
            _configuration.Setup(m => m.Metrics).Returns(new List <MetricConfiguration> {
                metricConfiguration
            });

            _service.Spectate(new CancellationToken(), TaskScheduler.Current);
        }
        public void GetMetricDefinitions()
        {
            var configuration         = new MetricConfiguration("memcached", "memcached", "tcp://mow1aps2:11211", AggregationStrategy.Gauge, null);
            var memcachedMetricSource = new MemcachedMetricSource(configuration);

            try
            {
                var metricDefinitions = memcachedMetricSource.GetMetricDefinitions().ToList();

                Assert.IsNotEmpty(metricDefinitions);

                foreach (var metricDefinition in metricDefinitions)
                {
                    Console.WriteLine("{0} - {1}", metricDefinition.Name, metricDefinition.GetNextValue());
                }
            }
            catch (System.Net.Sockets.SocketException e)
            {
                System.Diagnostics.Debug.WriteLine("Memcached not installed. No test run");
            }
        }
示例#12
0
        private IGauge <long> CreateGauge()
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), false);

            return(new GaugeInt64(config, Array.Empty <string>()));
        }
示例#13
0
        private Counter CreateCounter()
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), false);

            return(new Counter(config, Array.Empty <string>()));
        }
示例#14
0
 /// <summary>
 /// Gets the current end for the specified metric.
 /// </summary>
 /// <param name="metricValue"></param>
 /// <param name="configuration"></param>
 /// <returns></returns>
 private static DateTime GetEnd(MetricValue metricValue, MetricConfiguration configuration)
 {
     return(metricValue.LastInstance.Subtract(metricValue.FirstInstance) >= configuration.Interval.TimeOfDay ? metricValue.LastInstance : DateTime.UtcNow);
 }
示例#15
0
        private IUntyped CreateUntyped()
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), false);

            return(new Untyped(config, Array.Empty <string>()));
        }
示例#16
0
        private IUntyped CreateUntyped(MetricFlags options = MetricFlags.Default)
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), options);

            return(new Untyped(config, Array.Empty <string>()));
        }
示例#17
0
 /// <summary>
 /// Determines if a metric should be generated.
 /// </summary>
 /// <param name="start"></param>
 /// <param name="end"></param>
 /// <param name="configuration"></param>
 /// <returns></returns>
 private static bool GenerateMetric(DateTime start, DateTime end, MetricConfiguration configuration)
 {
     return(end.Subtract(start) >= configuration.Interval.TimeOfDay);
 }
示例#18
0
        private IGauge CreateGauge(MetricFlags options = MetricFlags.Default)
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), options);

            return(new Gauge(config, Array.Empty <string>()));
        }
示例#19
0
 /// <summary>
 /// Gets a information about the speficied counter,
 /// </summary>
 /// <param name="metricConfiguration"></param>
 /// <returns></returns>
 private static CounterCreationData GetCounter(MetricConfiguration metricConfiguration)
 {
     return(new CounterCreationData {
         CounterType = PerformanceCounterType.NumberOfItems32, CounterName = GetCounterName(metricConfiguration.Class, metricConfiguration.Name)
     });
 }
示例#20
0
        private Counter CreateCounter(MetricFlags options = MetricFlags.Default)
        {
            var config = new MetricConfiguration("test", string.Empty, Array.Empty <string>(), options);

            return(new Counter(config, Array.Empty <string>()));
        }