Beispiel #1
0
        public MetricsLogger(ILogger <DiagnosticsMonitor> logger,
                             IOptions <MetricsConfiguration> metricsConfig,
                             IOptions <ResourceConfiguration> resourceConfig)
        {
            _logger = logger;

            _metricConfig = metricsConfig.Value;
            if (string.IsNullOrEmpty(_metricConfig.AadClientId) ||
                string.IsNullOrEmpty(_metricConfig.AadClientSecret) ||
                string.IsNullOrEmpty(_metricConfig.TenantId))
            {
                _logger.LogError("Failed to bind metrics configuration. Metrics will not be collected.");
                return;
            }
            _resourceConfig = resourceConfig.Value;

            if (string.IsNullOrEmpty(_resourceConfig.AzureRegion) ||
                string.IsNullOrEmpty(_resourceConfig.AzureResourceId) ||
                string.IsNullOrEmpty(_metricConfig.TenantId))
            {
                _logger.LogError("Failed to bind azure resource configuration. Metrics will not be collected.");
                return;
            }

            //TODO Limit this
            _metricChannel           = Channel.CreateUnbounded <Metric>();
            _cancellationTokenSource = new CancellationTokenSource();
            _metricsRestClient       = new MetricsRestClient(_metricConfig, _resourceConfig);

            _processingTask = Task.Run(() => ProcessAllData(_cancellationTokenSource.Token), _cancellationTokenSource.Token);
        }
Beispiel #2
0
 public MetricsRestClient(MetricsConfiguration config, ResourceConfiguration resourceConfig)
 {
     _resourceConfig = resourceConfig;
     _client         = new HttpClient(new AuthenticationDelegatingHandler(config));
 }