Example #1
0
        public MetricScrapingJob(ScrapeDefinition <AzureResourceDefinition> metric,
                                 IMetricsDeclarationProvider metricsDeclarationProvider,
                                 IPrometheusMetricWriter prometheusMetricWriter,
                                 IRuntimeMetricsCollector runtimeMetricsCollector,
                                 MetricScraperFactory metricScraperFactory,
                                 ILogger logger, IExceptionTracker exceptionTracker)
        {
            Guard.NotNull(metric, nameof(metric));
            Guard.NotNull(metricsDeclarationProvider, nameof(metricsDeclarationProvider));
            Guard.NotNull(prometheusMetricWriter, nameof(prometheusMetricWriter));
            Guard.NotNull(runtimeMetricsCollector, nameof(runtimeMetricsCollector));
            Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory));
            Guard.NotNull(logger, nameof(logger));
            Guard.NotNull(exceptionTracker, nameof(exceptionTracker));

            _metric = metric;
            _metricsDeclarationProvider = metricsDeclarationProvider;
            _prometheusMetricWriter     = prometheusMetricWriter;
            _runtimeMetricsCollector    = runtimeMetricsCollector;
            _exceptionTracker           = exceptionTracker;
            _logger = logger;

            _metricScraperFactory = metricScraperFactory;

            ConfigureJob();
        }
        private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefinition metricDefinitionDefinition)
        {
            _logger.LogInformation("Scraping '{metricName}' for resource type '{resourceType}'", metricDefinitionDefinition.Name, metricDefinitionDefinition.ResourceType);

            var scraper = MetricScraperFactory.CreateScraper(azureMetadata, metricDefinitionDefinition.ResourceType, _logger, _exceptionTracker);
            await scraper.ScrapeAsync(metricDefinitionDefinition);
        }
Example #3
0
        public MetricScrapingJob(string jobName,
                                 ScrapeDefinition <IAzureResourceDefinition> metricScrapeDefinition,
                                 MetricSinkWriter metricSinkWriter,
                                 IPrometheusMetricWriter prometheusMetricWriter,
                                 MetricScraperFactory metricScraperFactory,
                                 AzureMonitorClient azureMonitorClient,
                                 ILogger <MetricScrapingJob> logger)
        {
            Guard.NotNull(metricScrapeDefinition, nameof(metricScrapeDefinition));
            Guard.NotNull(prometheusMetricWriter, nameof(prometheusMetricWriter));
            Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory));
            Guard.NotNull(azureMonitorClient, nameof(azureMonitorClient));
            Guard.NotNullOrWhitespace(jobName, nameof(jobName));
            Guard.NotNull(logger, nameof(logger));

            Name = jobName;

            _metricScrapeDefinition = metricScrapeDefinition;
            _prometheusMetricWriter = prometheusMetricWriter;
            _metricSinkWriter       = metricSinkWriter;
            _logger = logger;

            _metricScraperFactory = metricScraperFactory;
            _azureMonitorClient   = azureMonitorClient;
        }
        public ResourceDiscoveryGroupScrapingJob(string jobName, string resourceDiscoveryGroupName, AzureMetadata azureMetadata, MetricDefinition metricDefinition, ResourceDiscoveryRepository resourceDiscoveryRepository,
                                                 MetricSinkWriter metricSinkWriter,
                                                 MetricScraperFactory metricScraperFactory,
                                                 AzureMonitorClientFactory azureMonitorClientFactory, IRuntimeMetricsCollector runtimeMetricCollector, IConfiguration configuration, IOptions <AzureMonitorLoggingConfiguration> azureMonitorLoggingConfiguration, ILoggerFactory loggerFactory,
                                                 ILogger <ResourceDiscoveryGroupScrapingJob> logger)
            : base(jobName, logger)
        {
            Guard.NotNullOrWhitespace(resourceDiscoveryGroupName, nameof(resourceDiscoveryGroupName));
            Guard.NotNull(resourceDiscoveryRepository, nameof(resourceDiscoveryRepository));
            Guard.NotNull(metricDefinition, nameof(metricDefinition));
            Guard.NotNull(azureMetadata, nameof(azureMetadata));
            Guard.NotNullOrWhitespace(jobName, nameof(jobName));
            Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory));
            Guard.NotNull(azureMonitorClientFactory, nameof(azureMonitorClientFactory));
            Guard.NotNull(runtimeMetricCollector, nameof(runtimeMetricCollector));
            Guard.NotNull(configuration, nameof(configuration));
            Guard.NotNull(azureMonitorLoggingConfiguration, nameof(azureMonitorLoggingConfiguration));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));
            Guard.NotNull(metricSinkWriter, nameof(metricSinkWriter));

            ResourceDiscoveryGroupName = resourceDiscoveryGroupName;

            _azureMetadata               = azureMetadata;
            _metricDefinition            = metricDefinition;
            _resourceDiscoveryRepository = resourceDiscoveryRepository;
            _metricSinkWriter            = metricSinkWriter;

            _runtimeMetricCollector           = runtimeMetricCollector;
            _azureMonitorClientFactory        = azureMonitorClientFactory;
            _configuration                    = configuration;
            _azureMonitorLoggingConfiguration = azureMonitorLoggingConfiguration;
            _loggerFactory                    = loggerFactory;

            _metricScraperFactory = metricScraperFactory;
        }
        private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefinition metricDefinitionDefinition)
        {
            Console.WriteLine($"\t> Scraping {metricDefinitionDefinition.Name} of type {metricDefinitionDefinition.ResourceType}");

            var scraper = MetricScraperFactory.CreateScraper(azureMetadata, metricDefinitionDefinition.ResourceType);
            await scraper.ScrapeAsync(metricDefinitionDefinition);
        }
Example #6
0
        private async Task ScrapeMetric(AzureMetadata azureMetadata, MetricDefinition metricDefinitionDefinition)
        {
            _logger.LogInformation("Scraping '{MetricName}' for resource type '{ResourceType}'", metricDefinitionDefinition.Name, metricDefinitionDefinition.ResourceType);

            var scraper = MetricScraperFactory.CreateScraper(metricDefinitionDefinition.ResourceType, azureMetadata, _logger, _exceptionTracker);
            int subscriptionReadLimit = await scraper.ScrapeAsync(metricDefinitionDefinition);

            HealthMonitor.Instance.setSubscriptionLimitCount(subscriptionReadLimit);
        }
Example #7
0
        /// <summary>
        /// Create a metrics scraping job for one or more resources, either enumerated specifically or
        /// identified via resource definition groups. All metrics included are expected to have
        /// the same scraping schedule.
        /// </summary>
        /// <param name="jobName">name of scheduled job</param>
        /// <param name="metricsDeclaration">declaration of which metrics to collect from which resources</param>
        /// <param name="resourceDiscoveryRepository">repository source for discovering resources via criteria</param>
        /// <param name="metricSinkWriter">destination for metric reporting output</param>
        /// <param name="metricScraperFactory">means of obtaining a metrics scraper for a particular type of resource</param>
        /// <param name="azureMonitorClientFactory">means of obtaining a Azure Monitor client</param>
        /// <param name="azureScrapingPrometheusMetricsCollector">metrics collector to write metrics to Prometheus</param>
        /// <param name="resourceMetricDefinitionMemoryCache">cache of metric definitions by resource ID</param>
        /// <param name="scrapingTaskMutex">semaphore used to limit concurrency of tasks if configured, or null for no limiting</param>
        /// <param name="configuration">Promitor configuration</param>
        /// <param name="azureMonitorIntegrationConfiguration">options for Azure Monitor integration</param>
        /// <param name="azureMonitorLoggingConfiguration">options for Azure Monitor logging</param>
        /// <param name="loggerFactory">means to obtain a logger</param>
        /// <param name="logger">logger to use for scraping detail</param>
        public ResourcesScrapingJob(string jobName,
                                    MetricsDeclaration metricsDeclaration,
                                    ResourceDiscoveryRepository resourceDiscoveryRepository,
                                    MetricSinkWriter metricSinkWriter,
                                    MetricScraperFactory metricScraperFactory,
                                    AzureMonitorClientFactory azureMonitorClientFactory,
                                    IAzureScrapingPrometheusMetricsCollector azureScrapingPrometheusMetricsCollector,
                                    IMemoryCache resourceMetricDefinitionMemoryCache,
                                    IScrapingMutex scrapingTaskMutex,
                                    IConfiguration configuration,
                                    IOptions <AzureMonitorIntegrationConfiguration> azureMonitorIntegrationConfiguration,
                                    IOptions <AzureMonitorLoggingConfiguration> azureMonitorLoggingConfiguration,
                                    ILoggerFactory loggerFactory,
                                    ILogger <ResourcesScrapingJob> logger)
            : base(jobName, logger)
        {
            Guard.NotNullOrWhitespace(jobName, nameof(jobName));
            Guard.NotNull(metricsDeclaration, nameof(metricsDeclaration));
            Guard.NotNull(metricsDeclaration.AzureMetadata, $"{nameof(metricsDeclaration)}.{nameof(metricsDeclaration.AzureMetadata)}");
            Guard.NotNull(metricsDeclaration.Metrics, $"{nameof(metricsDeclaration)}.{nameof(metricsDeclaration.Metrics)}");
            Guard.NotNull(resourceDiscoveryRepository, nameof(resourceDiscoveryRepository));
            Guard.NotNull(metricSinkWriter, nameof(metricSinkWriter));
            Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory));
            Guard.NotNull(azureMonitorClientFactory, nameof(azureMonitorClientFactory));
            Guard.NotNull(azureScrapingPrometheusMetricsCollector, nameof(azureScrapingPrometheusMetricsCollector));
            Guard.NotNull(resourceMetricDefinitionMemoryCache, nameof(resourceMetricDefinitionMemoryCache));
            Guard.NotNull(configuration, nameof(configuration));
            Guard.NotNull(azureMonitorIntegrationConfiguration, nameof(azureMonitorIntegrationConfiguration));
            Guard.NotNull(azureMonitorLoggingConfiguration, nameof(azureMonitorLoggingConfiguration));
            Guard.NotNull(loggerFactory, nameof(loggerFactory));

            // all metrics must have the same scraping schedule or it is not possible for them to share the same job
            VerifyAllMetricsHaveSameScrapingSchedule(metricsDeclaration);

            _metricsDeclaration                      = metricsDeclaration;
            _resourceDiscoveryRepository             = resourceDiscoveryRepository;
            _metricSinkWriter                        = metricSinkWriter;
            _metricScraperFactory                    = metricScraperFactory;
            _azureMonitorClientFactory               = azureMonitorClientFactory;
            _azureScrapingPrometheusMetricsCollector = azureScrapingPrometheusMetricsCollector;
            _resourceMetricDefinitionMemoryCache     = resourceMetricDefinitionMemoryCache;
            _scrapingTaskMutex                       = scrapingTaskMutex;
            _configuration = configuration;
            _azureMonitorIntegrationConfiguration = azureMonitorIntegrationConfiguration;
            _azureMonitorLoggingConfiguration     = azureMonitorLoggingConfiguration;
            _loggerFactory = loggerFactory;
        }
Example #8
0
        public ResourceScrapingJob(string jobName,
                                   ScrapeDefinition <IAzureResourceDefinition> metricScrapeDefinition,
                                   MetricSinkWriter metricSinkWriter,
                                   MetricScraperFactory metricScraperFactory,
                                   AzureMonitorClient azureMonitorClient,
                                   ILogger <ResourceScrapingJob> logger)
            : base(jobName, logger)
        {
            Guard.NotNull(metricScrapeDefinition, nameof(metricScrapeDefinition));
            Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory));
            Guard.NotNull(azureMonitorClient, nameof(azureMonitorClient));
            Guard.NotNull(metricSinkWriter, nameof(metricSinkWriter));

            _metricScrapeDefinition = metricScrapeDefinition;
            _metricSinkWriter       = metricSinkWriter;

            _metricScraperFactory = metricScraperFactory;
            _azureMonitorClient   = azureMonitorClient;
        }
Example #9
0
        public MetricScrapingJob(ScrapeDefinition <IAzureResourceDefinition> metric,
                                 IMetricsDeclarationProvider metricsDeclarationProvider,
                                 IPrometheusMetricWriter prometheusMetricWriter,
                                 MetricScraperFactory metricScraperFactory,
                                 AzureMonitorClient azureMonitorClient,
                                 ILogger <MetricScrapingJob> logger)
        {
            Guard.NotNull(metric, nameof(metric));
            Guard.NotNull(metricsDeclarationProvider, nameof(metricsDeclarationProvider));
            Guard.NotNull(prometheusMetricWriter, nameof(prometheusMetricWriter));
            Guard.NotNull(metricScraperFactory, nameof(metricScraperFactory));
            Guard.NotNull(azureMonitorClient, nameof(azureMonitorClient));
            Guard.NotNull(logger, nameof(logger));

            _metric = metric;
            _metricsDeclarationProvider = metricsDeclarationProvider;
            _prometheusMetricWriter     = prometheusMetricWriter;
            _logger = logger;

            _metricScraperFactory = metricScraperFactory;
            _azureMonitorClient   = azureMonitorClient;
            ConfigureJob();
        }