Skip to content

Commit

Permalink
Add jmx info for OneShotNode
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Oct 4, 2021
1 parent 59055b3 commit 681eae6
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions java/src/org/openqa/selenium/grid/node/k8s/OneShotNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.openqa.selenium.events.EventBus;
import org.openqa.selenium.grid.config.Config;
import org.openqa.selenium.grid.config.ConfigException;
import org.openqa.selenium.grid.data.Availability;
import org.openqa.selenium.grid.data.CreateSessionRequest;
import org.openqa.selenium.grid.data.CreateSessionResponse;
import org.openqa.selenium.grid.data.NodeDrainComplete;
Expand All @@ -39,6 +40,9 @@
import org.openqa.selenium.grid.data.SessionClosedEvent;
import org.openqa.selenium.grid.data.Slot;
import org.openqa.selenium.grid.data.SlotId;
import org.openqa.selenium.grid.jmx.JMXHelper;
import org.openqa.selenium.grid.jmx.ManagedAttribute;
import org.openqa.selenium.grid.jmx.ManagedService;
import org.openqa.selenium.grid.log.LoggingOptions;
import org.openqa.selenium.grid.node.HealthCheck;
import org.openqa.selenium.grid.node.Node;
Expand Down Expand Up @@ -82,6 +86,8 @@
* appropriately configured Kubernetes cluster to start a new node once the
* session is finished.
*/
@ManagedService(objectName = "org.seleniumhq.grid:type=Node,name=OneShotNode",
description = "Node for running a single webdriver session.")
public class OneShotNode extends Node {

private static final Logger LOG = Logger.getLogger(OneShotNode.class.getName());
Expand Down Expand Up @@ -116,6 +122,8 @@ private OneShotNode(
this.gridUri = Require.nonNull("Public Grid URI", gridUri);
this.stereotype = ImmutableCapabilities.copyOf(Require.nonNull("Stereotype", stereotype));
this.driverInfo = Require.nonNull("Driver info", driverInfo);

new JMXHelper().register(this);
}

public static Node create(Config config) {
Expand Down Expand Up @@ -365,4 +373,44 @@ public HealthCheck getHealthCheck() {
public boolean isReady() {
return events.isReady();
}

@ManagedAttribute(name = "MaxSessions")
public int getMaxSessionCount() {
return 1;
}

@ManagedAttribute(name = "Status")
public Availability getAvailability() {
return isDraining() ? DRAINING : UP;
}

@ManagedAttribute(name = "TotalSlots")
public int getTotalSlots() {
return 1;
}

@ManagedAttribute(name = "UsedSlots")
public long getUsedSlots() {
return client == null ? 0 : 1;
}

@ManagedAttribute(name = "Load")
public float getLoad() {
return client == null ? 0f : 100f;
}

@ManagedAttribute(name = "RemoteNodeUri")
public URI getExternalUri() {
return this.getUri();
}

@ManagedAttribute(name = "GridUri")
public URI getGridUri() {
return this.gridUri;
}

@ManagedAttribute(name = "NodeId")
public String getNodeId() {
return getId().toString();
}
}

0 comments on commit 681eae6

Please sign in to comment.