Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Jenkins Metrics data through API

What I need with the API call

What I need with the API call

I need the timeline info for each of the builds via the API call for Jenkins metrics plugin. I am using a web API to get data for my jobs in my jenkins. However, calling $JenkinsUrl/metrics/APIkey is leading me nowhere. Any idea how can I achieve the information?

like image 813
imujjwalanand Avatar asked Oct 16 '25 08:10

imujjwalanand


1 Answers

All three bits of timeline info for each build (queue time, building time, total time) are available via the "get build" API.

On the screen where it shows "8.1 sec waiting in the queue" etc, click on the "REST API" link in the page footer, then "JSON API", then add &depth=2 to the end of the resulting API URL.

note, if you're searching for specific values in the API json, that the times will be in milliseconds. after you parse the json, build time is under the "duration" property, and the other two are in the array under the "actions" property. for me, it was the third element of the array, but that may vary (find the one with _class "jenkins.metrics.impl.TimeInQueueAction"):

{
  "_class": "jenkins.metrics.impl.TimeInQueueAction",
  "queuingDurationMillis": 16,
  "totalDurationMillis": 4365
}

so in my example the build time was 4349 and the queue time was 16, so the total time was 4349 + 16 = 4365 milliseconds.

Instead of adding &depth=2 to the end of the url, you might be able to get exactly the three values you want by appending this to the url: &tree=duration,actions[queuingDurationMillis,totalDurationMillis]

like image 191
burnettk Avatar answered Oct 19 '25 00:10

burnettk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!