Jenkins uptime - how long since last restart

前端 未结 3 1223
迷失自我
迷失自我 2021-02-09 03:34

Is it possible to see how long a Jenkins instance/master has been running?

I\'ve tried looking around in \"Manage Jenkins\" but can\'t find it there. I know I could log

3条回答
  •  闹比i
    闹比i (楼主)
    2021-02-09 03:56

    You can run groovy script on Jenkins web-ui from: Manage Jenkins > Script Console, and use Jenkins API. If you want to know how many days Jenkins has been running:

    import java.util.concurrent.TimeUnit
    long lastRestarted = Jenkins.instance.toComputer().getConnectTime()
    long now =  System.currentTimeMillis()
    println TimeUnit.MILLISECONDS.toDays(now - lastRestarted)
    

    getConnectTime() of the master computer should be the time when it restarted. http://javadoc.jenkins.io/hudson/model/Computer.html#getConnectTime()

提交回复
热议问题