A Netflix Hystrix module that exposes circuit breaker and thread pool metrics in Server-Sent Events format for real-time monitoring and dashboard integration
—
Servlet that streams Hystrix configuration information including command properties, thread pool settings, and collapser configuration in real-time.
Servlet that streams Hystrix configuration data in text/event-stream format.
/**
* Streams Hystrix config in text/event-stream format
* Provides real-time configuration information for commands, thread pools, and collapsers
*/
public class HystrixConfigSseServlet extends HystrixSampleSseServlet {
/**
* Default constructor using HystrixConfigurationStream and default delay
*/
public HystrixConfigSseServlet();
/**
* Package-private constructor for testing with custom stream and delay
* @param sampleStream Observable stream of configuration data
* @param pausePollerThreadDelayInMs Delay between polling cycles in milliseconds
*/
HystrixConfigSseServlet(Observable<HystrixConfiguration> sampleStream, int pausePollerThreadDelayInMs);
/**
* Returns maximum number of concurrent connections allowed
* @return Maximum concurrent connections (default: 5)
*/
protected int getMaxNumberConcurrentConnectionsAllowed();
/**
* Returns current number of active connections
* @return Current connection count
*/
protected int getNumberCurrentConnections();
/**
* Atomically increments and returns current concurrent connection count
* @return New connection count after increment
*/
protected int incrementAndGetCurrentConcurrentConnections();
/**
* Atomically decrements current concurrent connection count
*/
protected void decrementCurrentConcurrentConnections();
}Legacy utility for converting configuration objects to JSON format.
/**
* Links HystrixConfigurationStream and JSON encoding
* @deprecated Since 1.5.4 - prefer mapping serialization on HystrixConfigurationStream.observe()
*/
@Deprecated
public class HystrixConfigurationJsonStream {
/**
* Default constructor using default configuration stream
*/
public HystrixConfigurationJsonStream();
/**
* Constructor with custom stream generator
* @param streamGenerator Function to generate configuration observable
*/
public HystrixConfigurationJsonStream(Func1<Integer, Observable<HystrixConfiguration>> streamGenerator);
/**
* Convert configuration object to JSON string
* @param config Configuration object to convert
* @return JSON string representation
* @throws IOException if JSON generation fails
*/
public static String convertToString(HystrixConfiguration config) throws IOException;
/**
* @deprecated Use HystrixConfigurationStream.observe() instead
*/
@Deprecated
public Observable<HystrixConfiguration> observe(int delay);
/**
* @deprecated Use HystrixConfigurationStream.observe() and convertToString() instead
*/
@Deprecated
public Observable<String> observeJson(int delay);
}Web.xml Configuration:
<servlet>
<description></description>
<display-name>HystrixConfigSseServlet</display-name>
<servlet-name>HystrixConfigSseServlet</servlet-name>
<servlet-class>com.netflix.hystrix.contrib.sample.stream.HystrixConfigSseServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HystrixConfigSseServlet</servlet-name>
<url-pattern>/hystrix/config.stream</url-pattern>
</servlet-mapping>Usage Examples:
// Deploy servlet via web.xml configuration
// Access configuration stream
curl http://localhost:8080/app/hystrix/config.stream
// Using deprecated JSON stream API
HystrixConfigurationJsonStream stream = new HystrixConfigurationJsonStream();
stream.observe(1000).subscribe(config -> {
String json = HystrixConfigurationJsonStream.convertToString(config);
System.out.println("Config: " + json);
});The servlet outputs comprehensive configuration information in JSON format:
data: {
"type": "HystrixConfig",
"commands": {
"GetUser": {
"threadPoolKey": "GetUser",
"groupKey": "UserService",
"execution": {
"isolationStrategy": "THREAD",
"threadPoolKeyOverride": null,
"requestCacheEnabled": true,
"requestLogEnabled": true,
"timeoutEnabled": true,
"fallbackEnabled": true,
"timeoutInMilliseconds": 1000,
"semaphoreSize": 10,
"fallbackSemaphoreSize": 10,
"threadInterruptOnTimeout": true
},
"metrics": {
"healthBucketSizeInMs": 500,
"percentileBucketSizeInMilliseconds": 60000,
"percentileBucketCount": 6,
"percentileEnabled": true,
"counterBucketSizeInMilliseconds": 10000,
"counterBucketCount": 10
},
"circuitBreaker": {
"enabled": true,
"isForcedOpen": false,
"isForcedClosed": false,
"requestVolumeThreshold": 20,
"errorPercentageThreshold": 50,
"sleepInMilliseconds": 5000
}
}
},
"threadpools": {
"GetUser": {
"coreSize": 10,
"maximumSize": 10,
"actualMaximumSize": 10,
"maxQueueSize": -1,
"queueRejectionThreshold": 5,
"keepAliveTimeInMinutes": 1,
"allowMaximumSizeToDivergeFromCoreSize": false,
"counterBucketSizeInMilliseconds": 10000,
"counterBucketCount": 10
}
},
"collapsers": {
"UserDataCollapser": {
"maxRequestsInBatch": 100,
"timerDelayInMilliseconds": 10,
"requestCacheEnabled": true,
"metrics": {
"percentileBucketSizeInMilliseconds": 60000,
"percentileBucketCount": 6,
"percentileEnabled": true,
"counterBucketSizeInMilliseconds": 10000,
"counterBucketCount": 10
}
}
}
}Execution Configuration:
isolationStrategy - THREAD or SEMAPHOREthreadPoolKeyOverride - Custom thread pool keyrequestCacheEnabled - Whether request caching is enabledrequestLogEnabled - Whether request logging is enabledtimeoutEnabled - Whether execution timeout is enabledfallbackEnabled - Whether fallback is enabledtimeoutInMilliseconds - Execution timeout in millisecondssemaphoreSize - Semaphore max concurrent requestsfallbackSemaphoreSize - Fallback semaphore max concurrent requeststhreadInterruptOnTimeout - Whether to interrupt thread on timeoutMetrics Configuration:
healthBucketSizeInMs - Health snapshot bucket sizepercentileBucketSizeInMilliseconds - Percentile bucket sizepercentileBucketCount - Number of percentile bucketspercentileEnabled - Whether percentile tracking is enabledcounterBucketSizeInMilliseconds - Counter bucket sizecounterBucketCount - Number of counter bucketsCircuit Breaker Configuration:
enabled - Whether circuit breaker is enabledisForcedOpen - Whether circuit breaker is forced openisForcedClosed - Whether circuit breaker is forced closed (Note: Source has bug referencing isForceOpen() instead)requestVolumeThreshold - Minimum requests before circuit breaker tripserrorPercentageThreshold - Error percentage threshold for trippingsleepInMilliseconds - Sleep window when circuit is opencoreSize - Core thread pool sizemaximumSize - Maximum thread pool sizeactualMaximumSize - Actual maximum size in usemaxQueueSize - Maximum queue size (-1 for unbounded)queueRejectionThreshold - Queue size rejection thresholdkeepAliveTimeInMinutes - Thread keep-alive timeallowMaximumSizeToDivergeFromCoreSize - Whether max size can exceed core sizecounterBucketSizeInMilliseconds - Metrics counter bucket sizecounterBucketCount - Number of metrics counter bucketsmaxRequestsInBatch - Maximum requests per batchtimerDelayInMilliseconds - Delay before executing batchrequestCacheEnabled - Whether request caching is enabledmetrics - Metrics configuration (similar to command metrics)// Old approach (deprecated)
HystrixConfigurationJsonStream jsonStream = new HystrixConfigurationJsonStream();
jsonStream.observeJson(1000).subscribe(json -> {
// process json
});
// New approach (recommended)
HystrixConfigurationStream.getInstance()
.observe()
.map(SerialHystrixConfiguration::toJsonString)
.subscribe(json -> {
// process json
});Install with Tessl CLI
npx tessl i tessl/maven-com-netflix-hystrix--hystrix-metrics-event-stream