Exemplo n.º 1
0
 private static bool ReadGloballyDisableMetricsSetting()
 {
     try
     {
         var isDisabled = ConfigurationManager.AppSettings["Metrics.CompletelyDisableMetrics"];
         return(!string.IsNullOrEmpty(isDisabled) && isDisabled.Equals("TRUE", StringComparison.OrdinalIgnoreCase));
     }
     catch (Exception x)
     {
         MetricsErrorHandler.Handle(x, "Invalid Metrics Configuration: Metrics.CompletelyDisableMetrics must be set to true or false");
         return(false);
     }
 }
Exemplo n.º 2
0
 private void ConfigureHttpListener()
 {
     try
     {
         var httpEndpoint = ConfigurationManager.AppSettings["Metrics.HttpListener.HttpUriPrefix"];
         if (!string.IsNullOrEmpty(httpEndpoint))
         {
             WithHttpEndpoint(httpEndpoint);
             log.Debug(() => "Metrics: HttpListener configured at " + httpEndpoint);
         }
     }
     catch (Exception x)
     {
         MetricsErrorHandler.Handle(x, "Invalid Metrics Configuration: Metrics.HttpListener.HttpUriPrefix must be a valid HttpListener endpoint prefix");
     }
 }
Exemplo n.º 3
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>
 /// <returns>Chain-able configuration object.</returns>
 public MetricsConfig WithHttpEndpoint(string httpUriPrefix)
 {
     if (!isDisabled)
     {
         try
         {
             using (this.listener) { }
             this.listener = new MetricsHttpListener(httpUriPrefix, this.context.DataProvider, this.healthStatus);
             this.listener.Start();
         }
         catch (Exception x)
         {
             MetricsErrorHandler.Handle(x, "Unable to start HTTP Listener");
         }
     }
     return(this);
 }
Exemplo n.º 4
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>
        /// <returns>Chain-able configuration object.</returns>
        public MetricsConfig WithHttpEndpoint(string httpUriPrefix)
        {
            if (!isDisabled)
            {
                const int MaxRetries = 3;
                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);
        }
Exemplo n.º 5
0
        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 ");
            }
        }
Exemplo n.º 6
0
 public static void Handle(Exception exception)
 {
     MetricsErrorHandler.Handle(exception, string.Empty);
 }