How to get oozie workflow duration at the end

1.7k Views Asked by At

Is there any way to email the duration of the workflow with the completion email? Is there such a variable that I can use?

2

There are 2 best solutions below

1
On

I dont think such a variable is available. But if needed you can do such using shell action. During your workflow start execute a shell script for start time and save it in a variable. At the time of workflow just finish before your email action have a another shell script which will calculate the current time - start time and use it in your email. But this makes your workflow dirty

0
On

This is a remarkable shortcoming of Oozie. Each of our workflows starts with an shell action that calls a simple bash script to get timestamp.

<action name="start-time">
  <shell xmlns="uri:oozie:shell-action:0.1">
    <job-tracker>${jobTracker}</job-tracker>
    <name-node>${nameNode}</name-node>
    <exec>utc-time.sh</exec>
    <file>../common/utc-time.sh#utc-time.sh</file>
    <capture-output/>
  </shell>
  <ok to="the-first-actual-action"/>
  <error to="fail"/>
</action>

And this is testable with Java EL in the email we send on completion, error, like so:

<action name="email">
  <email xmlns="uri:oozie:email-action:0.1">
    <to>${emailsToAlert}</to>
    <subject>COMPLETED: ${wf:name()}</subject>
    <body>
      Workflow ID: ${wf:id()}
      Workflow Name: ${wf:name()}
      Workflow app path: ${wf:appPath()}
      Start Time: ${wf:actionData('start-time')['time']}
      End Time: ${timestamp()}
    </body>
  </email>
  <ok to="end"/>
  <error to="fail"/>
</action>

Getting duration is another jump-through-hoop exercise involving passing the start and end time to a bash script.

I was investigating the Oozie SLA functionality, but I haven't found a way to extract the data.