Source:
protected void doRun() throws Exception { try { logger.fine("doRun called: Computing Node metrics"); DatadogClient client = DatadogUtilities.getDatadogClient(); String hostname = DatadogUtilities.getHostname("null"); long nodeCount = 0; long nodeOffline = 0; long nodeOnline = 0; Computer[] computers = Jenkins.getInstance().getComputers(); for (Computer computer : computers) { nodeCount++; if (computer.isOffline()) { nodeOffline++; } if (computer.isOnline()) { nodeOnline++; } int executorCount = computer.countExecutors(); int inUse = computer.countBusy(); int free = computer.countIdle(); Set<LabelAtom> labels = null; try { labels = computer.getNode().getAssignedLabels(); } catch (NullPointerException e){ logger.fine("Could not retrieve labels"); } String nodeHostname = computer.getHostName(); String nodeName; if (computer instanceof Jenkins.MasterComputer) { nodeName = "master"; } else { nodeName = computer.getName(); } JSONArray tags = new JSONArray(); tags.add("node-name:" + nodeName); if(nodeHostname != null){ tags.add("node-hostname:" + nodeHostname); } if(labels != null){ for (LabelAtom label: labels){ tags.add("node-label:" + label.getName()); } } client.gauge("jenkins.executor.count", executorCount, hostname, tags); client.gauge("jenkins.executor.in-use", inUse, hostname, tags); client.gauge("jenkins.executor.free", free, hostname, tags); } client.gauge("jenkins.node.count", nodeCount, hostname, null); client.gauge("jenkins.node.offline", nodeOffline, hostname, null); client.gauge("jenkins.node.online", nodeOnline, hostname, null); } catch (Exception e) { logger.warning("Unexpected exception occurred - " + e.getMessage()); } }

Target:
protected void doRun() throws Exception { try { logger.fine("doRun called: Computing Node metrics"); DatadogClient client = DatadogUtilities.getDatadogClient(); String hostname = DatadogUtilities.getHostname("null"); long nodeCount = 0; long nodeOffline = 0; long nodeOnline = 0; Computer[] computers = Jenkins.getInstance().getComputers(); for (Computer computer : computers) { nodeCount++; if (computer.isOffline()) { nodeOffline++; } if (computer.isOnline()) { nodeOnline++; } int executorCount = computer.countExecutors(); int inUse = computer.countBusy(); int free = computer.countIdle(); Set<LabelAtom> labels = null; try { labels = computer.getNode().getAssignedLabels(); } catch (NullPointerException e){ logger.fine("Could not retrieve labels"); } String nodeHostname = computer.getHostName(); String nodeName; if (computer instanceof Jenkins.MasterComputer) { nodeName = "master"; } else { nodeName = computer.getName(); } JSONArray tags = new JSONArray(); tags.add("node_name:" + nodeName); if(nodeHostname != null){ tags.add("node_hostname:" + nodeHostname); } if(labels != null){ for (LabelAtom label: labels){ tags.add("node_label:" + label.getName()); } } client.gauge("jenkins.executor.count", executorCount, hostname, tags); client.gauge("jenkins.executor.in_use", inUse, hostname, tags); client.gauge("jenkins.executor.free", free, hostname, tags); } client.gauge("jenkins.node.count", nodeCount, hostname, null); client.gauge("jenkins.node.offline", nodeOffline, hostname, null); client.gauge("jenkins.node.online", nodeOnline, hostname, null); } catch (Exception e) { logger.warning("Unexpected exception occurred - " + e.getMessage()); } }