Skip to content

Commit

Permalink
Support 6.9.x and new metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
andreymarkelov authored and andreymarkelov committed Jul 30, 2019
1 parent 0bb7504 commit 6084195
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 6 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

[Tags on this repository](https://github.com/AndreyVMarkelov/bamboo-prometheus-exporter/releases)

## [Unreleased]

## [1.0.5] (v5.8.x-6.9.x)

- Added new metric: bamboo_plans_gauge (plans count)
- Added new metric: bamboo_plans_workers_idle_gauge
- Added new metric: bamboo_plans_workers_busy_gauge
- Added new metric: bamboo_plans_workers_queue_gauge
- Support Bamboo v6.9.x
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ru.andreymarkelov.atlas.plugins</groupId>
<artifactId>prom-bamboo-exporter</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
<packaging>atlassian-plugin</packaging>

<name>Prometheus Exporter For Bamboo</name>
Expand Down Expand Up @@ -84,7 +84,7 @@
</build>

<properties>
<bamboo.version>5.4.2</bamboo.version>
<bamboo.version>5.8.0</bamboo.version>
<bamboo.data.version>${bamboo.version}</bamboo.data.version>
<amps.version>6.3.21</amps.version>
<prometheus.version>0.6.0</prometheus.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ru.andreymarkelov.atlas.plugins.prombambooexporter.manager;

import java.util.ArrayList;
import java.util.List;

import com.atlassian.bamboo.buildqueue.manager.AgentManager;
import com.atlassian.bamboo.event.spi.ExecutorStats;
import com.atlassian.bamboo.license.BambooLicenseManager;
import com.atlassian.bamboo.plan.NonBlockingPlanExecutionService;
import com.atlassian.bamboo.plan.PlanManager;
import com.atlassian.bamboo.plan.TopLevelPlan;
import com.atlassian.bamboo.plan.branch.ChainBranch;
import com.atlassian.extras.api.bamboo.BambooLicense;
import io.prometheus.client.Collector;
import io.prometheus.client.CollectorRegistry;
Expand All @@ -16,6 +18,9 @@
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import java.util.ArrayList;
import java.util.List;

import static java.util.Collections.emptyList;
import static java.util.concurrent.TimeUnit.DAYS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
Expand All @@ -26,6 +31,8 @@ public class MetricCollectorImpl extends Collector implements MetricCollector, I
private final CollectorRegistry registry;
private final BambooLicenseManager bambooLicenseManager;
private final AgentManager agentManager;
private final NonBlockingPlanExecutionService nonBlockingPlanExecutionService;
private final PlanManager planManager;

//--> Common

Expand Down Expand Up @@ -81,6 +88,7 @@ public class MetricCollectorImpl extends Collector implements MetricCollector, I
.create();

//--> License

private final Gauge maintenanceExpiryDaysGauge = Gauge.build()
.name("bamboo_maintenance_expiry_days_gauge")
.help("Maintenance Expiry Days Gauge")
Expand All @@ -96,14 +104,45 @@ public class MetricCollectorImpl extends Collector implements MetricCollector, I
.help("Allowed Users Gauge")
.create();

//--> Plans

private final Gauge plansGauge = Gauge.build()
.name("bamboo_plans_gauge")
.help("Plans By Type (top, branch) Gauge")
.labelNames("type")
.create();

//--> Workers

private final Gauge planWorkerIdleGauge = Gauge.build()
.name("bamboo_plans_workers_idle_gauge")
.help("Plan Workers Idle Gauge")
.create();

private final Gauge planWorkerBusyGauge = Gauge.build()
.name("bamboo_plans_workers_busy_gauge")
.help("Plan Workers Busy Gauge")
.create();

private final Gauge planWorkerQueueGauge = Gauge.build()
.name("bamboo_plans_workers_queue_gauge")
.help("Plan Workers Queue Size Gauge")
.create();

public MetricCollectorImpl(
BambooLicenseManager bambooLicenseManager,
AgentManager agentManager) {
AgentManager agentManager,
NonBlockingPlanExecutionService nonBlockingPlanExecutionService,
PlanManager planManager) {
this.bambooLicenseManager = bambooLicenseManager;
this.agentManager = agentManager;
this.nonBlockingPlanExecutionService = nonBlockingPlanExecutionService;
this.planManager = planManager;
this.registry = CollectorRegistry.defaultRegistry;
}

// Implementations

//--> Common

@Override
Expand Down Expand Up @@ -157,18 +196,37 @@ private List<MetricFamilySamples> collectInternal() {
activeAgentsGauge.set(agentManager.getActiveAndEnabledAgents().size());
busyAgentsGauge.set(agentManager.getBusyBuildAgents().size());

// plans
plansGauge.labels("top").set(planManager.getPlanCount(TopLevelPlan.class));
plansGauge.labels("branch").set(planManager.getPlanCount(ChainBranch.class));

// workers
final ExecutorStats planExecutorStats = this.nonBlockingPlanExecutionService.getExecutorStats();
final int planExecutorStatsActiveCount = planExecutorStats.getActiveCount();
planWorkerIdleGauge.set(planExecutorStats.getPoolSize() - planExecutorStatsActiveCount);
planWorkerBusyGauge.set(planExecutorStatsActiveCount);
planWorkerQueueGauge.set(planExecutorStats.getEventsQueue().size());

List<MetricFamilySamples> result = new ArrayList<>();
result.addAll(errorsCounter.collect());
result.addAll(finishedBuildsCounter.collect());
result.addAll(canceledBuildsCounter.collect());
result.addAll(finishedDeploysCounter.collect());
result.addAll(buildQueueTimeoutCounter.collect());
// license
result.addAll(maintenanceExpiryDaysGauge.collect());
result.addAll(licenseExpiryDaysGauge.collect());
result.addAll(allowedUsersGauge.collect());
// agents
result.addAll(allAgentsGauge.collect());
result.addAll(activeAgentsGauge.collect());
result.addAll(busyAgentsGauge.collect());
// plans
result.addAll(plansGauge.collect());
// workers
result.addAll(planWorkerIdleGauge.collect());
result.addAll(planWorkerBusyGauge.collect());
result.addAll(planWorkerQueueGauge.collect());

return result;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6084195

Please sign in to comment.