我如何知道詹金斯的工作在等待队列中已经等了多久

我如何知道詹金斯的工作在等待队列中已经等了多久

本文介绍了工作结束后,我如何知道詹金斯的工作在等待队列中已经等了多久?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于统计数据,我想看看等候队列中的工作有多长时间,因此我可以调整系统以使工作按时完成。



如果工作只是在队列中,可以在首页的等待队列中找到。 queuingDurationMillis 是我想要的数据。

 actions:[
{
queuingDurationMillis:33,
totalDurationMillis:3067
}
],

Groovy脚本:我们也可以通过内部数据在groovy中获取这些数据,在Jenkins脚本控制台中检查以下代码 $ b

  job = hudson.model.Hudson.instance.getItem(demo)
build = job.getLastBuild()
action = build.getAction(jenkins.metrics.impl.TimeInQueueAction.class)
println action.getQueuingDurationMillis()

你可以在docker下面运行并在浏览器中打开for demo job

  docker run -it -p 8080:8080 larrycai / jenkins-metrics 


For the statistics, I want to see how long the job is in the waiting queue, therefore I can tune the system to make the job is run in time.

If the job is just in queue, it is possible to find in waiting queue in front page see How can I tell how long a Jenkins job has been in the wait queue?

Or the http://<jenkins_url>/queue/api/json?pretty=true

Is it possible to check somewhere to get "Time waiting in queue" for the specific job after the job is finished ?

Will be nice if it can be gotten in public jenkins API.

解决方案

// got answer from colleague

It can be achieved by installing Jenkins Metrics Plugin, after it is installed, in the build result page, you will see

Jenkins REST API: Then you can get wait time in queue from http://localhost:8080/job/demo/1/api/json?pretty=true&depth=2 . queuingDurationMillis is the data I wanted.

"actions" : [
{
  "queuingDurationMillis" : 33,
  "totalDurationMillis" : 3067
}
],

Groovy script: Also we can get this data in groovy via internal data, check below code in Jenkins Script console http://localhost:8080/script

job = hudson.model.Hudson.instance.getItem("demo")
build = job.getLastBuild()
action = build.getAction(jenkins.metrics.impl.TimeInQueueAction.class)
println action.getQueuingDurationMillis()

You can see the demo using docker by running below and open in browser for demo job

docker run -it -p 8080:8080 larrycai/jenkins-metrics

这篇关于工作结束后,我如何知道詹金斯的工作在等待队列中已经等了多久?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 04:10