31
31
import org .openqa .selenium .WebDriverException ;
32
32
import org .openqa .selenium .concurrent .Regularly ;
33
33
import org .openqa .selenium .events .EventBus ;
34
+ import org .openqa .selenium .grid .data .Availability ;
34
35
import org .openqa .selenium .grid .data .CreateSessionRequest ;
35
36
import org .openqa .selenium .grid .data .CreateSessionResponse ;
36
37
import org .openqa .selenium .grid .data .NodeDrainComplete ;
53
54
import org .openqa .selenium .remote .SessionId ;
54
55
import org .openqa .selenium .remote .http .HttpRequest ;
55
56
import org .openqa .selenium .remote .http .HttpResponse ;
57
+ import org .openqa .selenium .remote .server .jmx .JMXHelper ;
58
+ import org .openqa .selenium .remote .server .jmx .ManagedAttribute ;
59
+ import org .openqa .selenium .remote .server .jmx .ManagedService ;
56
60
import org .openqa .selenium .remote .tracing .AttributeKey ;
57
61
import org .openqa .selenium .remote .tracing .EventAttribute ;
58
62
import org .openqa .selenium .remote .tracing .EventAttributeValue ;
91
95
import static org .openqa .selenium .remote .http .Contents .string ;
92
96
import static org .openqa .selenium .remote .http .HttpMethod .DELETE ;
93
97
98
+ @ ManagedService (objectName = "org.seleniumhq.grid:type=Node,name=LocalNode" ,
99
+ description = "Node running the webdriver sessions." )
94
100
public class LocalNode extends Node {
95
101
96
102
private static final Json JSON = new Json ();
@@ -174,6 +180,8 @@ private LocalNode(
174
180
}
175
181
}
176
182
}));
183
+
184
+ new JMXHelper ().register (this );
177
185
}
178
186
179
187
@ Override
@@ -182,11 +190,53 @@ public boolean isReady() {
182
190
}
183
191
184
192
@ VisibleForTesting
193
+ @ ManagedAttribute (name = "CurrentSessions" )
185
194
public int getCurrentSessionCount () {
186
195
// It seems wildly unlikely we'll overflow an int
187
196
return Math .toIntExact (currentSessions .size ());
188
197
}
189
198
199
+ @ ManagedAttribute (name = "MaxSessions" )
200
+ public int getMaxSessionCount () {
201
+ return maxSessionCount ;
202
+ }
203
+
204
+ @ ManagedAttribute (name = "Status" )
205
+ public Availability getAvailability () {
206
+ return isDraining () ? DRAINING : UP ;
207
+ }
208
+
209
+ @ ManagedAttribute (name = "TotalSlots" )
210
+ public int getTotalSlots () {
211
+ return factories .size ();
212
+ }
213
+
214
+ @ ManagedAttribute (name = "UsedSlots" )
215
+ public long getUsedSlots () {
216
+ return factories .stream ().filter (sessionSlot -> !sessionSlot .isAvailable ()).count ();
217
+ }
218
+
219
+ @ ManagedAttribute (name = "Load" )
220
+ public float getLoad () {
221
+ long inUse = factories .stream ().filter (sessionSlot -> !sessionSlot .isAvailable ()).count ();
222
+ return inUse / (float ) maxSessionCount * 100f ;
223
+ }
224
+
225
+ @ ManagedAttribute (name = "RemoteNodeUri" )
226
+ public URI getExternalURI () {
227
+ return externalUri ;
228
+ }
229
+
230
+ @ ManagedAttribute (name = "GridUri" )
231
+ public URI getGridURI () {
232
+ return gridUri ;
233
+ }
234
+
235
+ @ ManagedAttribute (name = "NodeId" )
236
+ public String getNodeId () {
237
+ return getId ().toString ();
238
+ }
239
+
190
240
@ Override
191
241
public boolean isSupporting (Capabilities capabilities ) {
192
242
return factories .parallelStream ().anyMatch (factory -> factory .test (capabilities ));
0 commit comments