Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Hartej Arora March 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 com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegateimport groovy.transform.BaseScript import javax.ws.rs.core.MultivaluedMapimport javax.ws.rs.core.Responseimport 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
TAGS
AUG Leaders

Atlassian Community Events