/// <summary>
        ///     Plots all configured metric information into an ASCII table
        /// </summary>
        public void PlotOverviewInAsciiTable()
        {
            var metricsDeclaration = _metricsDeclarationProvider.Get();

            PlotAzureMetadataInAsciiTable(metricsDeclaration.AzureMetadata);
            PlotMetricsInAsciiTable(metricsDeclaration.Metrics);
        }
Beispiel #2
0
        public ValidationResult Run()
        {
            var errorReporter      = new ErrorReporter();
            var metricsDeclaration = _metricsDeclarationProvider.Get(applyDefaults: true, errorReporter: errorReporter);

            if (metricsDeclaration == null)
            {
                return(ValidationResult.Failure(ComponentName, "Unable to deserialize configured metrics declaration"));
            }

            LogDeserializationMessages(errorReporter);

            if (errorReporter.HasErrors)
            {
                return(ValidationResult.Failure(ComponentName, "Errors were found while deserializing the metric configuration."));
            }

            LogMetricsDeclaration(metricsDeclaration);

            var validationErrors           = new List <string>();
            var azureMetadataErrorMessages = ValidateAzureMetadata(metricsDeclaration.AzureMetadata);

            validationErrors.AddRange(azureMetadataErrorMessages);

            var metricDefaultErrorMessages = ValidateMetricDefaults(metricsDeclaration.MetricDefaults);

            validationErrors.AddRange(metricDefaultErrorMessages);

            var metricsErrorMessages = ValidateMetrics(metricsDeclaration.Metrics, metricsDeclaration.MetricDefaults);

            validationErrors.AddRange(metricsErrorMessages);

            return(validationErrors.Any() ? ValidationResult.Failure(ComponentName, validationErrors) : ValidationResult.Successful(ComponentName));
        }
Beispiel #3
0
        public ValidationResult Run()
        {
            var rawMetricsConfiguration = metricsDeclarationProvider.GetSerializedDeclaration();

            LogMessage("Following metrics configuration was configured:");
            LogMessage(rawMetricsConfiguration);

            var metricsDeclaration = metricsDeclarationProvider.Get();

            if (metricsDeclaration == null)
            {
                return(ValidationResult.Failure(ComponentName, "Unable to deserialize configured metrics declaration"));
            }

            var validationErrors           = new List <string>();
            var azureMetadataErrorMessages = ValidateAzureMetadata(metricsDeclaration.AzureMetadata);

            validationErrors.AddRange(azureMetadataErrorMessages);

            var metricsErrorMessages = ValidateMetrics(metricsDeclaration.Metrics);

            validationErrors.AddRange(metricsErrorMessages);

            return(validationErrors.Any() ? ValidationResult.Failure(ComponentName, validationErrors) : ValidationResult.Successful(ComponentName));
        }
Beispiel #4
0
        public IActionResult GetMetricDeclaration()
        {
            var scrapeConfiguration = _metricsDeclarationProvider.Get(true);

            var serializedResources = JsonConvert.SerializeObject(scrapeConfiguration.Metrics, _serializerSettings);

            var response = Content(serializedResources, "application/json");

            response.StatusCode = (int)HttpStatusCode.OK;
            return(response);
        }
Beispiel #5
0
        private Dictionary <string, string> DetermineLabels(PrometheusMetricDefinition metricDefinition, ScrapeResult scrapeResult, MeasuredMetric measuredMetric, Dictionary <string, string> defaultLabels)
        {
            var labels = new Dictionary <string, string>(scrapeResult.Labels.Select(label => new KeyValuePair <string, string>(label.Key.SanitizeForPrometheusLabelKey(), label.Value)));

            if (measuredMetric.IsDimensional)
            {
                labels.Add(measuredMetric.DimensionName.SanitizeForPrometheusLabelKey(), measuredMetric.DimensionValue);
            }

            if (metricDefinition?.Labels?.Any() == true)
            {
                foreach (var customLabel in metricDefinition.Labels)
                {
                    var customLabelKey = customLabel.Key.SanitizeForPrometheusLabelKey();
                    if (labels.ContainsKey(customLabelKey))
                    {
                        _logger.LogWarning("Custom label {CustomLabelName} was already specified with value '{LabelValue}' instead of '{CustomLabelValue}'. Ignoring...", customLabel.Key, labels[customLabelKey], customLabel.Value);
                        continue;
                    }

                    labels.Add(customLabelKey, customLabel.Value);
                }
            }

            foreach (var defaultLabel in defaultLabels)
            {
                var defaultLabelKey = defaultLabel.Key.SanitizeForPrometheusLabelKey();
                if (labels.ContainsKey(defaultLabelKey) == false)
                {
                    labels.Add(defaultLabelKey, defaultLabel.Value);
                }
            }

            // Add the tenant id
            var metricsDeclaration = _metricsDeclarationProvider.Get(applyDefaults: true);

            if (labels.ContainsKey("tenant_id") == false)
            {
                labels.Add("tenant_id", metricsDeclaration.AzureMetadata.TenantId);
            }

            // Transform labels, if need be
            if (_prometheusConfiguration.CurrentValue.Labels != null)
            {
                labels = LabelTransformer.TransformLabels(_prometheusConfiguration.CurrentValue.Labels.Transformation, labels);
            }

            var orderedLabels = labels.OrderBy(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            return(orderedLabels);
        }
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Scraping Azure Monitor - {Timestamp}", DateTimeOffset.UtcNow);

            var scrapeConfiguration = _metricsDeclarationProvider.Get();

            try
            {
                await ScrapeMetric(scrapeConfiguration.AzureMetadata, _metric);
            }
            catch (Exception exception)
            {
                _logger.LogCritical(exception, "Failed to scrape: {Exception}", exception.Message);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Sets a new value for a measurement on a gauge
        /// </summary>
        /// <param name="name">Name of the metric</param>
        /// <param name="description">Description of the metric</param>
        /// <param name="value">New measured value</param>
        /// <param name="labels">Labels that are applicable for this measurement</param>
        public void WriteGaugeMeasurement(string name, string description, double value, Dictionary <string, string> labels)
        {
            var enableMetricTimestamps = _prometheusConfiguration.CurrentValue.EnableMetricTimestamps;

            var metricsDeclaration = _metricsDeclarationProvider.Get(applyDefaults: true);

            if (labels.ContainsKey("tenant_id") == false)
            {
                labels.Add("tenant_id", metricsDeclaration.AzureMetadata.TenantId);
            }

            var orderedLabels = labels.OrderByDescending(kvp => kvp.Key).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            _prometheusMetricsCollector.WriteGaugeMeasurement(name, description, value, orderedLabels, enableMetricTimestamps);
        }
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Scraping Azure Monitor - {timestamp}", DateTimeOffset.Now);

            var scrapeConfiguration = _metricsDeclarationProvider.Get();

            var scrapingTasks = new List <Task>();

            foreach (var metricDefinition in scrapeConfiguration.Metrics)
            {
                var scrapingTask = ScrapeMetric(scrapeConfiguration.AzureMetadata, metricDefinition);
                scrapingTasks.Add(scrapingTask);
            }

            await Task.WhenAll(scrapingTasks);
        }
Beispiel #9
0
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Scraping Azure Monitor - {timestamp}", DateTimeOffset.Now);

            var scrapeConfiguration = _metricsDeclarationProvider.Get();

            try
            {
                await ScrapeMetric(scrapeConfiguration.AzureMetadata, _metric);
            }
            catch (Exception exception)
            {
                _logger.LogError($"Failed to scrape: {exception.Message}");
                _exceptionTracker.Track(exception);
            }
        }
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine($"Scraping Azure Monitor - {DateTimeOffset.Now}");

            var scrapeConfiguration = metricsDeclarationProvider.Get();

            var scrapingTasks = new List <Task>();

            foreach (var metricDefinition in scrapeConfiguration.Metrics)
            {
                var scrapingTask = ScrapeMetric(scrapeConfiguration.AzureMetadata, metricDefinition);
                scrapingTasks.Add(scrapingTask);
            }

            await Task.WhenAll(scrapingTasks);
        }
Beispiel #11
0
        public async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            _logger.LogInformation("Scraping Azure Monitor - {timestamp}", DateTimeOffset.Now);

            try
            {
                var scrapeConfiguration = _metricsDeclarationProvider.Get();

                var scrapingTasks = new List <Task>();

                foreach (var metricDefinition in scrapeConfiguration.Metrics)
                {
                    var scrapingTask = ScrapeMetric(scrapeConfiguration.AzureMetadata, scrapeConfiguration.MetricDefaults, metricDefinition);
                    scrapingTasks.Add(scrapingTask);
                }

                await Task.WhenAll(scrapingTasks);
            }
            catch (Exception exception)
            {
                _logger.LogError($"Failed to scrape: {exception.Message}");
                _exceptionTracker.Track(exception);
            }
        }
        public IActionResult GetMetricDeclaration()
        {
            var scrapeConfiguration = _metricsDeclarationProvider.Get(true);

            return(Ok(scrapeConfiguration.Metrics));
        }
        public IEnumerable <MetricDefinition> Get()
        {
            var scrapeConfiguration = _metricsDeclarationProvider.Get();

            return(scrapeConfiguration.Metrics);
        }
Beispiel #14
0
        public ValidationResult Run()
        {
            var currentRuntimeConfiguration      = _runtimeConfiguration.Value;
            var atlassianStatuspageConfiguration = currentRuntimeConfiguration?.MetricSinks?.AtlassianStatuspage;

            if (atlassianStatuspageConfiguration == null)
            {
                return(ValidationResult.Successful(ComponentName));
            }

            var errorMessages = new List <string>();

            if (string.IsNullOrWhiteSpace(atlassianStatuspageConfiguration.PageId))
            {
                errorMessages.Add("No page id of Atlassian Status page is configured");
            }

            if (atlassianStatuspageConfiguration.SystemMetricMapping?.Any() != true)
            {
                errorMessages.Add("No system metrics mappings are configured which means no metrics can be reported");
            }
            else
            {
                if (atlassianStatuspageConfiguration.SystemMetricMapping.Select(map => map.Id).Distinct().Count() != atlassianStatuspageConfiguration.SystemMetricMapping?.Count)
                {
                    errorMessages.Add("System metric with duplicate id(s) mappings are configured");
                }

                var metricsDeclaration = _metricsDeclarationProvider.Get(true);

                if (atlassianStatuspageConfiguration.SystemMetricMapping == null)
                {
                    return(errorMessages.Any() ? ValidationResult.Failure(ComponentName, errorMessages) : ValidationResult.Successful(ComponentName));
                }

                foreach (var systemMetric in atlassianStatuspageConfiguration.SystemMetricMapping)
                {
                    if (string.IsNullOrWhiteSpace(systemMetric.Id))
                    {
                        errorMessages.Add($"System metric mapping defined without specifying a system metric id (Promitor metric name: {systemMetric.PromitorMetricName})");
                    }
                    if (string.IsNullOrWhiteSpace(systemMetric.PromitorMetricName))
                    {
                        errorMessages.Add($"System metric mapping defined without specifying a Promitor metric name (System metric id: {systemMetric.Id})");
                    }

                    var matchingPromitorMetric = metricsDeclaration.Metrics.FirstOrDefault(metricDefinition => metricDefinition.PrometheusMetricDefinition.Name.Equals(systemMetric.PromitorMetricName));
                    if (matchingPromitorMetric == null)
                    {
                        errorMessages.Add($"Statuspage metric Id '{systemMetric.Id}' is mapped to a metric called '{systemMetric.PromitorMetricName}', but no metric was found with that name");
                    }
                    else
                    {
                        if (matchingPromitorMetric.ResourceDiscoveryGroups?.Any() == true)
                        {
                            errorMessages.Add("Scraping with resource discovery is not supported");
                        }

                        if (matchingPromitorMetric.Resources?.Count > 1)
                        {
                            errorMessages.Add("Scraping multiple resources for one metric is not supported");
                        }
                    }
                }
            }

            return(errorMessages.Any() ? ValidationResult.Failure(ComponentName, errorMessages) : ValidationResult.Successful(ComponentName));
        }
        private bool DetermineIfDiscoveryGroupsAreDefined()
        {
            var metricsDeclaration = _metricsDeclarationProvider.Get(applyDefaults: true);

            return(metricsDeclaration.Metrics.Any(metricDefinition => metricDefinition.ResourceDiscoveryGroups?.Count >= 1));
        }