public void SetUp() { eventReporter = Substitute.For <IMetricEventReporter>(); metricConfiguration = Substitute.For <IMetricConfiguration>(); metricConfiguration.Reporter.Returns(eventReporter); scope = new RootMetricScope(metricConfiguration); }
/// <summary> /// Compares the metrics version with server. /// </summary> /// <param name="metricConfigFromFile">The metric configuration from file.</param> /// <param name="metricConfigurationOnServer">The metric configuration on server.</param> /// <returns> /// 1 if configuration from file has a higher version number, -1 if lower, and 0 if identical. /// </returns> internal static int CompareMetricsVersionWithServer(IMetricConfiguration metricConfigFromFile, IMetricConfiguration metricConfigurationOnServer) { const string logTag = "CompareMetricsVersionWithServer"; if (metricConfigurationOnServer == null) { return(1); } if (metricConfigFromFile.Version == metricConfigurationOnServer.Version) { Logger.Log( LoggerLevel.Warning, LogId, logTag, "The version in the file is the same as the one on the server. Skip."); return(0); } if (metricConfigFromFile.Version < metricConfigurationOnServer.Version) { Logger.Log( LoggerLevel.Warning, LogId, logTag, $"The version {metricConfigFromFile.Version} in the file is less than the one {metricConfigurationOnServer.Version} on the server! Please download the latest version first. Skip."); return(-1); } return(1); }
private static void EnsureConfigurationValid( int dimensionCount, IMetricConfiguration configuration) { Util.ValidateNotNull(configuration, nameof(configuration)); Util.ValidateNotNull(configuration.SeriesConfig, nameof(configuration.SeriesConfig)); if (dimensionCount > 0 && configuration.ValuesPerDimensionLimit < 1) { throw new ArgumentException("Multidimensional metrics must allow at least one dimension-value per dimesion" + $" (but {configuration.ValuesPerDimensionLimit} was specified" + $" in {nameof(configuration)}.{nameof(configuration.ValuesPerDimensionLimit)})."); } if (configuration.SeriesCountLimit < 1) { throw new ArgumentException("Metrics must allow at least one data series" + $" (but {configuration.SeriesCountLimit} was specified)" + $" in {nameof(configuration)}.{nameof(configuration.SeriesCountLimit)})."); } if (dimensionCount > 0 && configuration.SeriesCountLimit < 2) { throw new ArgumentException("Multidimensional metrics must allow at least two data series:" + " 1 for the basic (zero-dimensional) series and 1 additional series" + $" (but {configuration.SeriesCountLimit} was specified)" + $" in {nameof(configuration)}.{nameof(configuration.SeriesCountLimit)})."); } }
internal Metric GetOrCreateMetric( string metricId, string dimension1Name, string dimension2Name, IMetricConfiguration metricConfiguration) { metricId = metricId?.Trim(); Util.ValidateNotNullOrWhitespace(metricId, nameof(metricId)); string metricObjectId = Metric.GetObjectId(metricId, dimension1Name, dimension2Name); Metric metric = _metrics.GetOrAdd(metricObjectId, (key) => new Metric( _metricManager, metricId, dimension1Name, dimension2Name, metricConfiguration ?? MetricConfigurations.Common.Default())); if (metricConfiguration != null && !metric._configuration.Equals(metricConfiguration)) { throw new ArgumentException("A Metric with the specified Id and dimension names already exists, but it has a configuration" + " that is different from the specified configuration. You may not change configurations once a" + " metric was created for the first time. Either specify the same configuration every time, or" + " specify 'null' during every invocation except the first one. 'Null' will match against any" + " previously specified configuration when retrieving existing metrics, or fall back to" + $" the default when creating new metrics. (Metric Object Id: \"{metricObjectId}\".)"); } return(metric); }
public void SetUp() { originPool = Substitute.For <IPool <MetricEventWriter> >(); metricConfiguration = Substitute.For <IMetricConfiguration>(); writer = new MetricEventWriter( originPool, metricConfiguration, m => commitAction?.Invoke(m)); }
public RabbitMqMetricSource(IMetricConfiguration metric) { name = metric.Name; aggregationStrategy = metric.AggregationStrategy; uri = new Uri(Environment.ExpandEnvironmentVariables(metric.Path)); RewriteUrl(ref uri, out credentials); jsonSerializer = new DataContractJsonSerializer(typeof(Overview)); }
private static void ReInitialize() { s_measurementDouble = new SimpleMetricConfiguration( FutureDefaults.SeriesCountLimit, FutureDefaults.ValuesPerDimensionLimit, new SimpleMetricSeriesConfiguration(restrictToUInt32Values: false)); s_accumulatorDouble = new SimpleMetricConfiguration( FutureDefaults.SeriesCountLimit, FutureDefaults.ValuesPerDimensionLimit, new AccumulatorMetricSeriesConfiguration(restrictToUInt32Values: false)); }
public RootMetricScope(IMetricConfiguration configuration) { eventWriterPool = new UnlimitedLazyPool <MetricEventWriter>( () => new MetricEventWriter( eventWriterPool, configuration, metricEvent => configuration.Reporter?.SendEvent(metricEvent))); metricWriterPool = new UnlimitedLazyPool <MetricEventWriter>( () => new MetricEventWriter( metricWriterPool, configuration, metricEvent => configuration.Reporter?.SendMetric(metricEvent))); }
/// <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.</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 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, IMetricConfiguration metricConfiguration) { return(GetOrCreateMetric( telemetryClient, MetricAggregationScope.TelemetryConfiguration, metricId, dimension1Name: null, dimension2Name: null, 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.</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 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, IMetricConfiguration metricConfiguration) { Util.ValidateNotNullOrWhitespace(dimension1Name, nameof(dimension1Name)); return(GetOrCreateMetric( telemetryClient, MetricAggregationScope.TelemetryConfiguration, metricId, dimension1Name, dimension2Name: null, metricConfiguration: metricConfiguration)); }
public MetricEventWriter( IPool <MetricEventWriter> originPool, IMetricConfiguration configuration, Action <MetricEvent> commit) { this.originPool = originPool; this.configuration = configuration; this.commit = commit; tags = new Dictionary <string, string>(); values = new Dictionary <string, double>(); metricEvent = new MetricEvent { Tags = tags, Values = values, Timestamp = DateTimeOffset.UtcNow }; }
/// <summary> /// /// </summary> /// <param name="metricConfigPresets"></param> /// <param name="defaultConfigurationForGauge"></param> public static void SetDefaultForGauge( this MetricConfigurations metricConfigPresets, SimpleMetricConfiguration defaultConfigurationForGauge) { Util.ValidateNotNull(defaultConfigurationForGauge, nameof(defaultConfigurationForGauge)); Util.ValidateNotNull( defaultConfigurationForGauge.SeriesConfig, nameof(defaultConfigurationForGauge) + "." + nameof(defaultConfigurationForGauge.SeriesConfig)); if (false == (defaultConfigurationForGauge.SeriesConfig is MetricSeriesConfigurationForGauge)) { throw new ArgumentException($"{nameof(defaultConfigurationForGauge) + "." + nameof(defaultConfigurationForGauge.SeriesConfig)}" + $" must be a \"{nameof(MetricSeriesConfigurationForGauge)}\", but it is" + $" \"{defaultConfigurationForGauge.SeriesConfig.GetType().Name}\"."); } // todo validate type of series config to be measurement. s_defaultConfigForGauge = defaultConfigurationForGauge; }
private static Metric GetOrCreateMetric( TelemetryClient telemetryClient, MetricAggregationScope aggregationScope, string metricId, string dimension1Name, string dimension2Name, IMetricConfiguration metricConfiguration) { Util.ValidateNotNull(telemetryClient, nameof(telemetryClient)); MetricManager metricManager = telemetryClient.GetMetricManager(aggregationScope); MetricsCache cache = metricManager.GetOrCreateExtensionState(MetricsCache.CreateNewInstance); if (cache == null) { throw new InvalidOperationException($"telemetryConfiguration.GetMetricManager().GetOrCreateExtensionState(..) unexpectedly returned null." + $" This indicates that multiple extensions attempt to use" + $" the \"Cache\" extension point of the {nameof(MetricManager)} in a conflicting manner."); } Metric metric = cache.GetOrCreateMetric(metricId, dimension1Name, dimension2Name, metricConfiguration); return(metric); }
public EnvironmentRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
public SpaceRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
public MemcachedMetricSource(IMetricConfiguration metric) { name = metric.Name; aggregationStrategy = metric.AggregationStrategy; uri = new Uri(Environment.ExpandEnvironmentVariables(metric.Path)); }
public TenantRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
public DeploymentRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
public ReleaseRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
public SyncLogRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
public InstanceRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
/// <summary /> /// <param name="other"></param> /// <returns></returns> public bool Equals(IMetricConfiguration other) { return(Equals((object)other)); }
protected BaseRepository(IMetricConfiguration metricConfiguration) { MetricConfiguration = metricConfiguration; }
/// <summary> /// Validates the metric configuration from file to see if they contain the expected configuration contents. /// </summary> /// <param name="metricConfigFromFile">The metric configuration from file.</param> /// <returns>True if passing validation; false otherwise.</returns> internal static bool ValidateMetricConfigFromFile(IMetricConfiguration metricConfigFromFile) { return(metricConfigFromFile is RawMetricConfiguration ? ValidateRawMetricConfigFromFile((RawMetricConfiguration)metricConfigFromFile) : ValidateCompositeMetricConfigFromFile((CompositeMetricConfiguration)metricConfigFromFile)); }
public ProjectRepository(IMetricConfiguration metricConfiguration) : base(metricConfiguration) { }
internal Metric(MetricManager metricManager, string metricId, string dimension1Name, string dimension2Name, IMetricConfiguration configuration) { Util.ValidateNotNull(metricManager, nameof(metricManager)); Util.ValidateNotNullOrWhitespace(metricId, nameof(metricId)); int dimCount; EnsureDimensionNamesValid(out dimCount, ref dimension1Name, ref dimension2Name); EnsureConfigurationValid(dimCount, configuration); _metricManager = metricManager; MetricId = metricId; DimensionsCount = dimCount; _configuration = configuration; _objectId = GetObjectId(metricId, dimension1Name, dimension2Name); _hashCode = _objectId.GetHashCode(); switch (dimCount) { case 0: _dimensionNames = new string[0]; _metricSeries = null; break; case 1: _dimensionNames = new string[1] { dimension1Name }; //_metricSeries = new MultidimensionalCube<string, MetricSeries>( // totalPointsCountLimit: configuration.SeriesCountLimit - 1, // pointsFactory: CreateNewMetricSeries, // subdimensionsCountLimits: new int[1] { configuration.ValuesPerDimensionLimit }); _metricSeries = new MultidimensionalCube2 <MetricSeries>( totalPointsCountLimit: configuration.SeriesCountLimit - 1, pointsFactory: CreateNewMetricSeries, dimensionValuesCountLimits: new int[1] { configuration.ValuesPerDimensionLimit }); break; case 2: _dimensionNames = new string[2] { dimension1Name, dimension2Name }; //_metricSeries = new MultidimensionalCube<string, MetricSeries>( // totalPointsCountLimit: configuration.SeriesCountLimit - 1, // pointsFactory: CreateNewMetricSeries, // subdimensionsCountLimits: new int[2] { configuration.ValuesPerDimensionLimit, configuration.ValuesPerDimensionLimit }); _metricSeries = new MultidimensionalCube2 <MetricSeries>( totalPointsCountLimit: configuration.SeriesCountLimit - 1, pointsFactory: CreateNewMetricSeries, dimensionValuesCountLimits: new int[2] { configuration.ValuesPerDimensionLimit, configuration.ValuesPerDimensionLimit }); break; default: throw new Exception("Internal coding bug. Please report!"); } _zeroDimSeries = CreateNewMetricSeries(dimensionValues: null); _zeroDimSeriesList = (dimCount == 0) ? new KeyValuePair <string[], MetricSeries>[1] { new KeyValuePair <string[], MetricSeries>(new string[0], _zeroDimSeries) } : null; }
public ReportingRepository(IMetricConfiguration metricConfiguration) { MetricConfiguration = metricConfiguration; }