0
# Metrics Streaming
1
2
The primary servlet for streaming Hystrix command and thread pool metrics in text/event-stream format for real-time monitoring and dashboard integration.
3
4
## Capabilities
5
6
### HystrixMetricsStreamServlet
7
8
Main servlet that provides SSE streaming of Hystrix dashboard metrics including circuit breaker states, latency percentiles, and thread pool statistics.
9
10
```java { .api }
11
/**
12
* Streams Hystrix metrics in text/event-stream format.
13
* Install by including hystrix-metrics-event-stream-*.jar in classpath
14
* and configuring in web.xml with URL pattern /hystrix.stream
15
*/
16
public class HystrixMetricsStreamServlet extends HystrixSampleSseServlet {
17
18
/**
19
* Default constructor using HystrixDashboardStream and default delay
20
*/
21
public HystrixMetricsStreamServlet();
22
23
/**
24
* Package-private constructor for testing with custom stream and delay
25
* @param sampleStream Observable stream of dashboard data
26
* @param pausePollerThreadDelayInMs Delay between polling cycles in milliseconds
27
*/
28
HystrixMetricsStreamServlet(Observable<HystrixDashboardStream.DashboardData> sampleStream, int pausePollerThreadDelayInMs);
29
30
/**
31
* Returns maximum number of concurrent connections allowed (configurable via hystrix.config.stream.maxConcurrentConnections)
32
* @return Maximum concurrent connections (default: 5)
33
*/
34
protected int getMaxNumberConcurrentConnectionsAllowed();
35
36
/**
37
* Returns current number of active connections
38
* @return Current connection count
39
*/
40
protected int getNumberCurrentConnections();
41
42
/**
43
* Atomically increments and returns current concurrent connection count
44
* @return New connection count after increment
45
*/
46
protected int incrementAndGetCurrentConcurrentConnections();
47
48
/**
49
* Atomically decrements current concurrent connection count
50
*/
51
protected void decrementCurrentConcurrentConnections();
52
}
53
```
54
55
**Web.xml Configuration:**
56
57
```xml
58
<servlet>
59
<description></description>
60
<display-name>HystrixMetricsStreamServlet</display-name>
61
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
62
<servlet-class>com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet</servlet-class>
63
</servlet>
64
<servlet-mapping>
65
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
66
<url-pattern>/hystrix.stream</url-pattern>
67
</servlet-mapping>
68
```
69
70
**Usage Examples:**
71
72
```java
73
// Basic servlet deployment - just configure in web.xml
74
// No additional Java code required
75
76
// Testing servlet with curl
77
curl http://localhost:8080/app/hystrix.stream
78
79
// Custom configuration via system properties
80
System.setProperty("hystrix.config.stream.maxConcurrentConnections", "10");
81
```
82
83
## Data Format
84
85
The servlet outputs JSON events in Server-Sent Events format:
86
87
### HystrixCommand Metrics
88
89
```json
90
data: {
91
"type": "HystrixCommand",
92
"name": "PlaylistGet",
93
"group": "PlaylistGet",
94
"currentTime": 1355239617628,
95
"isCircuitBreakerOpen": false,
96
"errorPercentage": 0,
97
"errorCount": 0,
98
"requestCount": 121,
99
"rollingCountSuccess": 121,
100
"rollingCountFailure": 0,
101
"rollingCountTimeout": 0,
102
"rollingCountShortCircuited": 0,
103
"rollingCountThreadPoolRejected": 0,
104
"rollingCountSemaphoreRejected": 0,
105
"currentConcurrentExecutionCount": 0,
106
"latencyExecute_mean": 13,
107
"latencyExecute": {
108
"0": 3, "25": 6, "50": 8, "75": 14, "90": 26, "95": 37, "99": 75, "99.5": 92, "100": 252
109
},
110
"latencyTotal_mean": 15,
111
"latencyTotal": {
112
"0": 3, "25": 7, "50": 10, "75": 18, "90": 32, "95": 43, "99": 88, "99.5": 160, "100": 253
113
},
114
"propertyValue_circuitBreakerRequestVolumeThreshold": 20,
115
"propertyValue_circuitBreakerSleepWindowInMilliseconds": 5000,
116
"propertyValue_circuitBreakerErrorThresholdPercentage": 50,
117
"propertyValue_executionIsolationStrategy": "THREAD",
118
"propertyValue_executionIsolationThreadTimeoutInMilliseconds": 800,
119
"reportingHosts": 1,
120
"threadPool": "PlaylistGet"
121
}
122
```
123
124
### HystrixThreadPool Metrics
125
126
```json
127
data: {
128
"type": "HystrixThreadPool",
129
"name": "ABClient",
130
"currentTime": 1355239617628,
131
"currentActiveCount": 0,
132
"currentCompletedTaskCount": 4459519,
133
"currentCorePoolSize": 30,
134
"currentLargestPoolSize": 30,
135
"currentMaximumPoolSize": 30,
136
"currentPoolSize": 30,
137
"currentQueueSize": 0,
138
"currentTaskCount": 4459519,
139
"rollingMaxActiveThreads": 13,
140
"rollingCountThreadsExecuted": 919,
141
"propertyValue_queueSizeRejectionThreshold": 30,
142
"propertyValue_metricsRollingStatisticalWindowInMilliseconds": 30000,
143
"reportingHosts": 3
144
}
145
```
146
147
## Configuration Properties
148
149
```java { .api }
150
// System properties for configuration
151
public static final String MAX_CONCURRENT_CONNECTIONS_PROPERTY = "hystrix.config.stream.maxConcurrentConnections";
152
public static final int DEFAULT_MAX_CONCURRENT_CONNECTIONS = 5;
153
```
154
155
## Error Handling
156
157
- Returns HTTP 503 when maximum concurrent connections exceeded
158
- Graceful handling of client disconnections via PrintWriter.checkError()
159
- Automatic resource cleanup when servlet is destroyed
160
- Thread-safe connection counting using AtomicInteger