Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Is there an easy way to get a report on Bamboo Agent's idle time

Is the below script runner based Bamboo core JAVA API call still the best way to get this report?


import com.atlassian.bamboo.resultsummary.AgentResultsSummaryManagerimport com.atlassian.bamboo.resultsummary.BuildResultsSummaryimport com.atlassian.bamboo.util.TextProviderUtilsimport com.atlassian.bamboo.utils.DurationUtilsimport com.atlassian.sal.api.component.ComponentLocatorimport groovy.transform.BaseScript import java.util.concurrent.TimeUnit @BaseScript CustomEndpointDelegate delegate /** * End point to retrieve Bamboo agent build activity details. * * @return Response wrapping build activity details */ getAgentActivityDetails(httpMethod: "GET", groups: ["bamboo-admin"]) {    MultivaluedMap queryParams, String body ->        RequestParams requestParams = RequestParams.from(queryParams);        AgentActivityDetailsDto agentActivityDetialsDto = doGetAgentActivityDetialsDto(requestParams)        return Response.ok(agentActivityDetialsDto).build()} /** * Implementation for retrieving Bamboo agent's activity details. * * @Param params from request. * @return Agent activity details wrapped in an object. * */def doGetAgentActivityDetialsDto(RequestParams params) {    def AgentActivityDetailsDto agentActivityDetialsDto = new AgentActivityDetailsDto();    def AgentResultsSummaryManager agentManager = ComponentLocator.getComponent(AgentResultsSummaryManager)    List<BuildResultsSummary> allBuildsSummary = agentManager.getAllBuildResultsSummariesForAgent(params.agentId)    def long totalQueueDuration = 0L    def long totalDuration = 0L    def long totalProcessingDuration = 0L    def long reportingDaysMills = TimeUnit.DAYS.toMillis(params.reportingDays)    def long idleMillis = reportingDaysMills - totalProcessingDuration      allBuildsSummary.each {        buildSummary ->            long duration = buildSummary.duration            long queueDuration = buildSummary.queueDuration            long processingDuration = buildSummary.processingDuration            totalQueueDuration += queueDuration            totalProcessingDuration += processingDuration            totalDuration += duration    }     agentActivityDetialsDto.setTotalBuildsCount(allBuildsSummary.size())    agentActivityDetialsDto.setIdleTime(formatMillisToTime(idleMillis))    agentActivityDetialsDto.setTotalProcessingDuration(formatMillisToTime(totalProcessingDuration))    agentActivityDetialsDto.setTotalDuration(formatMillisToTime(totalDuration))    agentActivityDetialsDto.setTotalQueueDuration(formatMillisToTime(totalQueueDuration))     return agentActivityDetialsDto} /** * Formats time in milli second to pretty printing in minutes. * * @Param millis * @return pretty time * */def String formatMillisToTime(long millis) {    double processingDuration = (double) millis;    return processingDuration > 0.0D ? DurationUtils.getPrettyPrint((long) processingDuration) : TextProviderUtils            .getText("global.unknown"); } class AgentActivityDetailsDto {    int totalBuildsCount;    String idleTime;    String totalDuration;    String totalQueueDuration;    String totalProcessingDuration} class RequestParams {    int agentId;    int startPage;    int pageSize;    int reportingDays;     static RequestParams from(MultivaluedMap queryParams) {        RequestParams requestParams = new RequestParams();        requestParams.setAgentId(queryParams.get("agentId"))        requestParams.setReportingDays(queryParams.get("reportingDays"))        requestParams.setStartPage(queryParams.get("startPage"))        requestParams.setPageSize(queryParams.get("pageSize"))        return requestParams    }}

0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Bamboo

Bamboo Data Center 8.1 is now available

G’day Bamboo customers, Bamboo DC 8.1 is now available with it the following features and programs: SAML 2.0, OpenID Connect, and Crowd SSO In order to help admins with a simplified user manage...

167 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you