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

Hartej Arora Mar 21, 2019

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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Marketplace Apps & Integrations

Webinar alert! An IT Admin's Guide to Securing Collaboration at Scale

Hello, Atlassian Community! My name is Dave Meyer and I'm a Principal Product Manager at Atlassian. I wanted to give this community a heads up about an upcoming Webinar that might be of interest...

179 views 2 7
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