Exemplo n.º 1
0
        public void SettingFailScrapeOnExceptionToNonDefault()
        {
            HangfirePrometheusSettings settings = new HangfirePrometheusSettings();

            settings.FailScrapeOnException = false;
            Assert.False(settings.FailScrapeOnException);
        }
Exemplo n.º 2
0
        public void SettingsDefaultsTest()
        {
            HangfirePrometheusSettings settings = new HangfirePrometheusSettings();

            Assert.Same(Metrics.DefaultRegistry, settings.CollectorRegistry);
            Assert.True(settings.FailScrapeOnException);
        }
Exemplo n.º 3
0
        public void SettingCustomRegistryPositive()
        {
            HangfirePrometheusSettings settings          = new HangfirePrometheusSettings();
            CollectorRegistry          collectorRegistry = Metrics.NewCustomRegistry();

            settings.CollectorRegistry = collectorRegistry;
            Assert.Same(collectorRegistry, settings.CollectorRegistry);
        }
        public PrometheusExporterTests()
        {
            _autoFixture = new Fixture();

            _mockHangfireMonitor = new Mock <IHangfireMonitorService>();

            _collectorRegistry = Metrics.NewCustomRegistry();

            _settings = new HangfirePrometheusSettings
            {
                CollectorRegistry = _collectorRegistry
            };

            _classUnderTest = new HangfirePrometheusExporter(_mockHangfireMonitor.Object, _settings);
        }
        /// <summary>
        /// Initializes Prometheus Hangfire Exporter using current Hangfire job storage and default metrics registry.
        /// </summary>
        /// <param name="app">IApplicationBuilder instance</param>
        /// <returns>Provided instance of IApplicationBuilder</returns>
        public static IApplicationBuilder UsePrometheusHangfireExporter(this IApplicationBuilder app, HangfirePrometheusSettings settings = null)
        {
            settings = settings ?? new HangfirePrometheusSettings();

            JobStorage js = (JobStorage)app.ApplicationServices.GetService(typeof(JobStorage));

            if (js != null)
            {
                IHangfireMonitorService hangfireMonitor = new HangfireMonitorService(js);
                IPrometheusExporter     exporter        = new HangfirePrometheusExporter(hangfireMonitor, settings);
                Metrics.DefaultRegistry.AddBeforeCollectCallback(() => exporter.ExportHangfireStatistics());
            }

            return(app);
        }
Exemplo n.º 6
0
        public void SettingCustomRegistryToNullThrowsException()
        {
            HangfirePrometheusSettings settings = new HangfirePrometheusSettings();

            Assert.Throws <ArgumentNullException>(() => settings.CollectorRegistry = null);
        }
Exemplo n.º 7
0
        public static IAppBuilder UsePrometheusHangfireExporter(this IAppBuilder app, HangfirePrometheusSettings settings = null)
        {
            settings = settings ?? new HangfirePrometheusSettings();

            try
            {
                JobStorage js = JobStorage.Current;

                if (js != null)
                {
                    IHangfireMonitorService hangfireMonitor = new HangfireMonitorService(js);
                    IPrometheusExporter     exporter        = new HangfirePrometheusExporter(hangfireMonitor, settings);
                    Metrics.DefaultRegistry.AddBeforeCollectCallback(() => exporter.ExportHangfireStatistics());
                }
            }
            catch (Exception)
            {
                return(app);
            }

            return(app);
        }