private void ConfigureCsvReports() { try { var csvMetricsPath = ConfigurationManager.AppSettings["Metrics.CSV.Path"]; var csvMetricsInterval = ConfigurationManager.AppSettings["Metrics.CSV.Interval.Seconds"]; if (!string.IsNullOrEmpty(csvMetricsPath) && !string.IsNullOrEmpty(csvMetricsInterval)) { int seconds; if (int.TryParse(csvMetricsInterval, out seconds) && seconds > 0) { WithReporting(r => r.WithCSVReports(csvMetricsPath, TimeSpan.FromSeconds(seconds))); log.Debug($"Metrics: Storing CSV reports in {csvMetricsPath} every {seconds} seconds."); } } } catch (Exception x) { MetricsErrorHandler.Handle(x, "Invalid Metrics Configuration: Metrics.CSV.Path must be a valid path and Metrics.CSV.Interval.Seconds must be an integer > 0 "); } }
/// <summary> /// Create HTTP endpoint where metrics will be available in various formats: /// GET / => visualization application /// GET /json => metrics serialized as JSON /// GET /text => metrics in human readable text format /// </summary> /// <param name="httpUriPrefix">prefix where to start HTTP endpoint</param> /// <param name="maxRetries">maximum number of attempts to start the http listener. Note the retry time between attemps is dependent on this value</param> /// <returns>Chain-able configuration object.</returns> public MetricsConfig WithHttpEndpoint(string httpUriPrefix, int maxRetries = 3) { if (!isDisabled) { var retries = maxRetries; do { try { using (this.listener) { } this.listener = new MetricsHttpListener(httpUriPrefix, this.context.DataProvider, this.healthStatus); this.listener.Start(); if (retries != maxRetries) { log.InfoFormat("HttpListener started successfully after {0} retries", maxRetries - retries); } retries = 0; } catch (Exception x) { retries--; if (retries > 0) { log.WarnException("Unable to start HTTP Listener. Sleeping for {0} sec and retrying {1} more times", x, maxRetries - retries, retries); Thread.Sleep(1000 * (maxRetries - retries)); } else { MetricsErrorHandler.Handle(x, string.Format("Unable to start HTTP Listener. Retried {0} times, giving up...", maxRetries)); } } } while (retries > 0); } return(this); }
public static void Handle(Exception exception) { MetricsErrorHandler.Handle(exception, string.Empty); }