/// <inheritdoc/> protected override void OnStarting() { try { Logger.Info(string.Format(CultureInfo.InvariantCulture, "Starting metrics stream server on '{0}'.", this.HttpListenerPrefix)); this.listener = new HttpListener(); this.listener.Prefixes.Add(this.HttpListenerPrefix); this.listener.Start(); this.sampler = new HystrixMetricsSampler(this.SampleInterval, dataProvider); } catch (Exception e) { if (this.listener != null) { this.listener.Stop(); } Logger.ErrorException("Failed to start stream server.", e); throw; } base.OnStarting(); }
/// <summary> /// Initializes a new instance of the <see cref="HystrixMetricsStreamer"/> class. /// </summary> /// <param name="sampler">The sampler to use to get metrics data.</param> /// <param name="context">The context of the client connection.</param> public HystrixMetricsStreamer(HystrixMetricsSampler sampler, HttpListenerContext context) : base(string.Format(CultureInfo.InvariantCulture, ThreadNameFormat, nextId)) { if (sampler == null) { throw new ArgumentNullException(nameof(sampler)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } this.sampler = sampler; this.context = context; this.Id = nextId++; }
/// <summary> /// Initializes a new instance of the <see cref="HystrixMetricsStreamServer"/> class. /// </summary> /// <param name="httpListenerPrefix">The http listener prefix for listening incoming connections. /// For examples 'http://+:8888/hystrix/' which accepts connections on any domain on the port 8888 for the url '/hystrix/'.</param> /// <param name="maxConcurrentConnections">The maximum number of concurrent connections. New clients will be refused if /// the number of concurrent connections reach this maximum.</param> /// <param name="sampleInterval">The interval between sampling the Hystrix metrics. /// Passed through to the <see cref="HystrixMetricsSampler"/></param> public HystrixMetricsStreamServer(string httpListenerPrefix, int maxConcurrentConnections, TimeSpan sampleInterval, ISampleDataProvider dataProvider = null) : base(ThreadName) { if (string.IsNullOrEmpty(httpListenerPrefix)) { throw new ArgumentNullException("httpListenerPrefix"); } if (maxConcurrentConnections <= 0) { throw new ArgumentException("Maximum number of concurrent connections must be a positive number.", "maxConcurrentConnections"); } this.HttpListenerPrefix = httpListenerPrefix; this.MaxConcurrentConnections = maxConcurrentConnections; this.SampleInterval = sampleInterval; this.dataProvider = dataProvider ?? new HystrixSampleDataProvider(); this.sampler = new HystrixMetricsSampler(sampleInterval, this.dataProvider); }