A Netflix Hystrix module that exposes circuit breaker and thread pool metrics in Server-Sent Events format for real-time monitoring and dashboard integration
npx @tessl/cli install tessl/maven-com-netflix-hystrix--hystrix-metrics-event-stream@1.5.0Hystrix Metrics Event Stream is a Java library module within the Netflix Hystrix circuit breaker framework that provides real-time streaming of circuit breaker and thread pool metrics via Server-Sent Events (SSE). The module enables monitoring dashboards and applications to receive continuous metric updates including error rates, latency percentiles, circuit breaker states, and thread pool statistics.
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-metrics-event-stream</artifactId>
<version>1.5.18</version>
</dependency>// Primary streaming servlets
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import com.netflix.hystrix.contrib.requests.stream.HystrixRequestEventsSseServlet;
import com.netflix.hystrix.contrib.sample.stream.HystrixConfigSseServlet;
import com.netflix.hystrix.contrib.sample.stream.HystrixUtilizationSseServlet;
import com.netflix.hystrix.contrib.sample.stream.HystrixSampleSseServlet;
// Legacy polling (deprecated)
import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsPoller;
// RxJava Observable types
import rx.Observable;The primary use case is to expose Hystrix metrics via HTTP Server-Sent Events:
<!-- Configure in web.xml -->
<servlet>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<servlet-class>com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<url-pattern>/hystrix.stream</url-pattern>
</servlet-mapping>Then access the stream:
curl http://hostname:port/appname/hystrix.streamThis produces continuous JSON events like:
data: {
"type": "HystrixCommand",
"name": "PlaylistGet",
"group": "PlaylistGet",
"currentTime": 1355239617628,
"isCircuitBreakerOpen": false,
"errorPercentage": 0,
"errorCount": 0,
"requestCount": 121,
"latencyExecute_mean": 13,
"latencyTotal_mean": 15
}The library is organized around several key components:
Primary servlet for streaming Hystrix command and thread pool metrics in text/event-stream format.
public class HystrixMetricsStreamServlet extends HystrixSampleSseServlet {
public HystrixMetricsStreamServlet();
HystrixMetricsStreamServlet(Observable<HystrixDashboardStream.DashboardData> sampleStream, int pausePollerThreadDelayInMs);
}Abstract base class providing Server-Sent Events functionality for all streaming servlets.
public abstract class HystrixSampleSseServlet extends HttpServlet {
protected HystrixSampleSseServlet(Observable<String> sampleStream);
protected HystrixSampleSseServlet(Observable<String> sampleStream, int pausePollerThreadDelayInMs);
// Abstract methods for connection management
protected abstract int getMaxNumberConcurrentConnectionsAllowed();
protected abstract int getNumberCurrentConnections();
protected abstract int incrementAndGetCurrentConcurrentConnections();
protected abstract void decrementCurrentConcurrentConnections();
// Lifecycle methods
public static void shutdown();
public void init() throws ServletException;
public void destroy();
}Servlet that streams individual Hystrix request events as they occur.
public class HystrixRequestEventsSseServlet extends HystrixSampleSseServlet {
public HystrixRequestEventsSseServlet();
HystrixRequestEventsSseServlet(Observable<HystrixRequestEvents> sampleStream, int pausePollerThreadDelayInMs);
}Servlet that streams Hystrix configuration information.
public class HystrixConfigSseServlet extends HystrixSampleSseServlet {
public HystrixConfigSseServlet();
HystrixConfigSseServlet(Observable<HystrixConfiguration> sampleStream, int pausePollerThreadDelayInMs);
}Servlet that streams current Hystrix command and thread pool utilization metrics.
public class HystrixUtilizationSseServlet extends HystrixSampleSseServlet {
public HystrixUtilizationSseServlet();
HystrixUtilizationSseServlet(Observable<HystrixUtilization> sampleStream, int pausePollerThreadDelayInMs);
}Polling-based metrics collection system (deprecated since 1.5.4).
@Deprecated
public class HystrixMetricsPoller {
public HystrixMetricsPoller(MetricsAsJsonPollerListener listener, int delay);
public synchronized void start();
public synchronized void pause();
public synchronized void shutdown();
public boolean isRunning();
public static interface MetricsAsJsonPollerListener {
public void handleJsonMetric(String json);
}
}All servlets support configurable maximum concurrent connections:
// System property configuration (default: 5)
hystrix.config.stream.maxConcurrentConnections=10// Core Data Classes
public class HystrixDashboardStream.DashboardData {
// Contains dashboard metrics for commands and thread pools
}
public interface HystrixRequestEvents {
// Contains detailed request execution information including events and latencies
}
public interface HystrixConfiguration {
// Contains complete configuration for commands, thread pools, and collapsers
Map<HystrixCommandKey, HystrixCommandConfiguration> getCommandConfig();
Map<HystrixThreadPoolKey, HystrixThreadPoolConfiguration> getThreadPoolConfig();
Map<HystrixCollapserKey, HystrixCollapserConfiguration> getCollapserConfig();
}
public interface HystrixUtilization {
// Contains current utilization metrics for commands and thread pools
Map<HystrixCommandKey, HystrixCommandUtilization> getCommandUtilizationMap();
Map<HystrixThreadPoolKey, HystrixThreadPoolUtilization> getThreadPoolUtilizationMap();
}
// RxJava Observable Type
public class Observable<T> {
// Reactive stream for asynchronous data processing
}
// Configuration Properties
public class DynamicIntProperty {
int get();
}