Skip to content

Commit

Permalink
added extra conditions for counting executors (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulkaukuntla authored Jun 21, 2024
1 parent aa51fc8 commit c4a5434
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public static void publishMetrics(DatadogClient client) {
nodeOnline++;
metrics.gauge("jenkins.node_status.up", 1, hostname, tags);
}
int executorCount = computer.countExecutors();
int inUse = computer.countBusy();
int free = computer.countIdle();
int executorCount = computer.isOnline() ? computer.countExecutors() : 0;
int inUse = computer.isOnline() ? computer.countBusy() : 0;
int free = ((computer.isOnline() || computer.isConnecting()) && computer.isAcceptingTasks()) ? computer.countIdle() : 0;

metrics.gauge("jenkins.node_status.count", 1, hostname, tags);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public void testJenkinsNodeMetrics() throws Exception {

client.assertMetric("jenkins.node_status.count", 1, hostname, expectedTags);
client.assertMetric("jenkins.node_status.up", 1, hostname, expectedTags);
client.assertMetric("jenkins.executor.count", 2, hostname, expectedTags);
client.assertMetric("jenkins.executor.in_use", 0, hostname, expectedTags);
// All of the executors are online, so jenkins.executor.count == jenkins.executor.in_use + jenkins.executor.free
client.assertMetric("jenkins.executor.free", 2, hostname, expectedTags);

// if we set the computer to offline, the metrics should reflect that
for (Computer computer: jenkins.jenkins.getComputers()){
Expand All @@ -56,7 +60,9 @@ public void testJenkinsNodeMetrics() throws Exception {
computerPublisher.doRun();
client.assertMetric("jenkins.node_status.count", 1, hostname, expectedTags);
client.assertMetric("jenkins.node_status.up", 0, hostname, expectedTags);

client.assertMetric("jenkins.executor.count", 0, hostname, expectedTags);
client.assertMetric("jenkins.executor.in_use", 0, hostname, expectedTags);
client.assertMetric("jenkins.executor.free", 0, hostname, expectedTags);
}

@Test
Expand Down

0 comments on commit c4a5434

Please sign in to comment.