Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-63132

Metrics to find the Duration of a Running Jenkins Job

    Details

    • Similar Issues:

      Description

      In Prometheus metrics plugin for jenkins, there is no metrics to find the duration of running jobs, or all running jobs, this is required and can be helpful to send alerts or kill such a jobs that perform production critical tasks.

      I faced a similar situation and came up with the idea to report it here.

      I tried to find may plugins that capture such metrics and also let prometheus scrap it, but honestly could not find one.

      I was able to come up with a running groovy code that can fetch the time of runing job in seconds and minutes but want it to be added in this plugin so that prometheus can scrap it.

      Code

      ------------

      int MAX_ALLOWED_DURATION_IN_SECONDS = 100 // 6 hours

      def busyExecutors = Jenkins.instance.computers
      .collect

      { c -> c.executors.findAll \{ it.isBusy() }

      }
      .flatten() // reminder: transforms list(list(executor)) into list(executor)

      def ok = true

      println "Busy Executors list"
      busyExecutors.each { e ->
      println e ;
      int durationInSeconds = (System.currentTimeMillis() - e.executable.getTimeInMillis())/1000.0
      int durationInMinutes = (System.currentTimeMillis() - e.executable.getTimeInMillis())/1000.0/60.0
      if(durationInSeconds > MAX_ALLOWED_DURATION_IN_SECONDS)

      { ok = false; println "\t duration=$durationInSeconds" println "\t duration=$durationInMinutes" println ""; }

      else

      { println "bye" }

      }
      println "Done"

      return ok

      --------------------------------------------------

      Hi Marky kindly help me in getting this metrics introduced in Prometheus plugin for Jenkins.

      Thanks.

        Attachments

          Activity

          Hide
          jequals5 Marky Jackson added a comment -

          Kindly open an issue in the Github repo as a feature request.

          Show
          jequals5 Marky Jackson added a comment - Kindly open an issue in the Github repo as a feature request.

            People

            • Assignee:
              jequals5 Marky Jackson
              Reporter:
              ishkapila ish kapila
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: