示例#1
0
        public PrometheusExporterHostedServiceTests()
        {
            _exporters = new Mock <IEnumerable <IExporter> >();

            var configuration = new PrometheusExporterConfiguration()
            {
                Port = 9561,
            };

            _configurationOptions = new Mock <IOptions <PrometheusExporterConfiguration> >();
            _configurationOptions.Setup(f => f.Value).Returns(configuration);

            _logger = new Mock <ILogger <PrometheusExporterHostedService> >();

            _prometheusExporterService = new PrometheusExporterHostedService(_exporters.Object, _configurationOptions.Object, _logger.Object);
        }
示例#2
0
        public void Validate_Attributes_Should_Pass(PrometheusExporterConfiguration conf, bool expectedResult)
        {
            try
            {
                conf.Validate();
            }
            catch (Exception e)
            {
                if (expectedResult)
                {
                    throw;
                }

                e.Should().BeOfType <AggregateException>();
            }
        }
        public PrometheusExporterHostedService(
            IEnumerable <IExporter> exporters,
            IOptions <PrometheusExporterConfiguration> configuration,
            ILogger <PrometheusExporterHostedService> logger)
        {
            _exporters     = exporters;
            _configuration = configuration.Value;
            _logger        = logger;
            _metricServer  = new MetricServer(_configuration.Port);

            // Init metrics
            TotalScrapeActivations = Metrics.CreateCounter(
                "total_activations",
                "Total activations of the exporter",
                new CounterConfiguration()
            {
                SuppressInitialValue = true
            });
            TotalSuccessfulScrapeActivations = Metrics.CreateCounter(
                "total_success_activations",
                "Total successful activation of the exporter",
                new CounterConfiguration()
            {
                SuppressInitialValue = true
            });
            IsSuccessful = Metrics.CreateGauge(
                "is_successful_scrape",
                "Indication to if the last scrape was successful",
                new GaugeConfiguration()
            {
                SuppressInitialValue = true
            });
            ScrapeTime = Metrics.CreateSummary(
                "scrape_time",
                "Total scraping time of the exporter",
                new SummaryConfiguration()
            {
                SuppressInitialValue = true,
                Objectives           = new[]
                {
                    new QuantileEpsilonPair(0.5, 0.05),
                    new QuantileEpsilonPair(0.9, 0.05),
                    new QuantileEpsilonPair(0.95, 0.01),
                    new QuantileEpsilonPair(0.99, 0.01),
                }
            });
        }