Ejemplo n.º 1
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>
        public MetricsConfig WithHttpEndpoint(string httpUriPrefix)
        {
            if (this.isDisabled)
            {
                return this;
            }

            using (this.listener) { }
            this.listener = new MetricsHttpListener(httpUriPrefix, this.Registry, this.healthStatus);
            this.listener.Start();
            return this;
        }
Ejemplo n.º 2
0
 public static Task <MetricsHttpListener> StartHttpListenerAsync(string httpUriPrefix, MetricsDataProvider dataProvider,
                                                                 Func <HealthStatus> healthStatus, CancellationToken token, int maxRetries = 1)
 {
     return(Task.Factory.StartNew(async() =>
     {
         MetricsHttpListener listener = null;
         var remainingRetries = maxRetries;
         do
         {
             try
             {
                 listener = new MetricsHttpListener(httpUriPrefix, dataProvider, healthStatus, token);
                 listener.Start();
                 if (remainingRetries != maxRetries)
                 {
                     log.InfoFormat("HttpListener started successfully after {0} retries", maxRetries - remainingRetries);
                 }
                 remainingRetries = 0;
             }
             catch (Exception x)
             {
                 using (listener) { }
                 listener = null;
                 remainingRetries--;
                 if (remainingRetries > 0)
                 {
                     log.WarnException("Unable to start HTTP Listener. Sleeping for {0} sec and retrying {1} more times", x, maxRetries - remainingRetries, remainingRetries);
                     await Task.Delay(1000 * (maxRetries - remainingRetries), token).ConfigureAwait(false);
                 }
                 else
                 {
                     MetricsErrorHandler.Handle(x, $"Unable to start HTTP Listener. Retried {maxRetries} times, giving up...");
                 }
             }
         } while (remainingRetries > 0);
         return listener;
     }, token).Unwrap());
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     using (this.listener) { }
     this.listener = null;
 }