How to get the executors used on client masters from CJOC?


  • How to get the executors used on client masters from CJOC
  • How can I continuously monitor the number of executors used and track their usage?


  • CloudBees Jenkins Operations Center



On CJOC you can create alerts. See our documentation for more information about how to set-up one.

The metrics you are looking for are under operations-center.jenkins.licensing.*.

You have several options in order to monitor the number of executors used:

  • Configure alerts for license usage Manage Jenkins–>Alerts–>Add New (http://[JOC_URL]/configure navigate to Alert section and then Add New).
  • You can set a condition for the alert to be triggered, set for a local gauge within range (and there you can select license usage), or License usage threshold.
  • You can send mails upon license usage.
  • You can trigger a job executing the script described below (check this article to learn how-to).

These are but a few of the options available, and you can combine them to get a more complex behaviour that will cover your needs.

Groovy Scripting

You have to go to Manage Jenkins-Script Console (or just navigate to http://[JOC_URL]/script). There you can use the following Groovy scripting:

import com.cloudbees.opscenter.server.model.OperationsCenter;
import com.cloudbees.opscenter.server.model.*;
import com.cloudbees.opscenter.server.persistence.*;

OperationsCenter.LicensingCount licensingCount = OperationsCenter.getInstance().getLicensingCount();
OperationsCenter.LicensingCount licensingLimit = OperationsCenter.getInstance().getLicensingLimit();

final Jenkins jenkins = Jenkins.getActiveInstance();
List<SlaveTraderItem> slaveTraderItems = jenkins.getAllItems(SlaveTraderItem.class);

int totalSharedExecutorsDeclared;

for (SlaveTraderItem slaveTraderItem : slaveTraderItems) {
  SlaveTraderExecutorUsage slaveTraderExecutorUsage = slaveTraderItem.getExecutorUsage();
  totalSharedExecutorsDeclared += slaveTraderExecutorUsage.getProvisioned();

println("OC Master Executors Count " + Jenkins.getInstance().getNumExecutors());
println("OC Shared Items Executors Count " + totalSharedExecutorsDeclared);


println("Total Masters Count " + licensingCount.getMasters() + " / Total Masters License Limit " + licensingLimit.getMasters());
println("Total Test Masters Count " + licensingCount.getTestMasters() + " / Total Test Masters License Limit " +  licensingLimit.getTestMasters());
println("Total Executors Count " + licensingCount.getExecutors() + " / Total Executors License Limit " +  licensingLimit.getExecutors());


Map<ConnectedMaster, Integer> connectedMasters = new HashMap<ConnectedMaster, Integer>();

for (ConnectedMaster connectedMaster : OperationsCenter.getInstance().getConnectedMasters()) {
  connectedMasters.put(connectedMaster, connectedMaster.getProperties().get(ConnectedMasterLicenseServerProperty.class).getExecutors());

for (SlaveTraderItem slaveTraderItem : slaveTraderItems) {
  int leasedExecutors = slaveTraderItem.getExecutorUsage().getProvisioned();
  Map<LeaseRecord, ConnectedMaster> leaseDetails = slaveTraderItem.getLeaseDetails();
  for (ConnectedMaster connectedMaster : leaseDetails.values()) {
    Integer dedicatedExecutors = connectedMasters.get(connectedMaster);
    connectedMasters.put(connectedMaster , dedicatedExecutors + leasedExecutors);

for (Map.Entry<ConnectedMaster, Integer> entry : connectedMasters.entrySet()) {
  println(entry.getKey().getName() + " has currently provisioned " + entry.getValue() + " executors");

Have more questions?


  • 0
    Kay Likes

    I only see the information on setting alerts, but I do not see information on the following:

    • How to get the executors used on client masters from CJOC
  • 0
    Denys Digtiar

    Hi Kay,

    I believe the Groovy script is suggested way of doing it.

Please sign in to leave a comment.