<p>I'm trying to monitor a CronJob running on GKE and I cannot see an easy way of checking if the CronJob is actually running. I want to trigger an alert if the CronJob is not running for more than a X amount of time and Stackdriver does not seem to support that.</p>
<p>At the moment I tried using alerts based on logging metrics but that only serves me to alert in case of an app crash or specific errors not for the platform errors themselves.</p>
<p>I investigated a solution using Prometheus alerts, can that be integrated into Stackdriver?</p>
<p>UPDATE:
Just a follow up, ended up developing a simple solution using log based alerts on Stackdriver. If the log doesn't appear after X time then it will trigger an alert. It's not perfect but its ok for the use case i had.</p>

<p>Seeing as though its a cronjob, that starts standard Kubernetes Jobs, you could query for the job and then check it's start time, and compare that to the current time.</p>
<p>Note: I'm not familiar with stackdriver, so this may not be what you want, but...</p>
<p>E.g. with bash:</p>
<pre class="lang-bash prettyprint-override"><code>START_TIME=$(kubectl -n=your-namespace get job your-job-name -o json | jq '.status.startTime')
echo $START_TIME
</code></pre>
<p>You can also get the current status of the job as a JSON blob like this:</p>
<p><code>kubectl -n=your-namespace get job your-job-name -o json | jq '.status'</code></p>
<p>This would give a result like:</p>
<pre class="lang-json prettyprint-override"><code>{
  &quot;completionTime&quot;: &quot;2019-09-06T17:13:51Z&quot;,
  &quot;conditions&quot;: [
    {
      &quot;lastProbeTime&quot;: &quot;2019-09-06T17:13:51Z&quot;,
      &quot;lastTransitionTime&quot;: &quot;2019-09-06T17:13:51Z&quot;,
      &quot;status&quot;: &quot;True&quot;,
      &quot;type&quot;: &quot;Complete&quot;
    }
  ],
  &quot;startTime&quot;: &quot;2019-09-06T17:13:49Z&quot;,
  &quot;succeeded&quot;: 1
}
</code></pre>
<p>You can use a tool like jq in your checking script to look at the <strong>succeeded</strong> or <strong>type</strong> fields to see if the job was successful or not.</p>
<p>So with your START_TIME value you could get the current time or the job completion time (<strong>completionTime</strong>) and if the result is less than your minimum job time threshold you can then trigger your alert - e.g. POST to a slack webhook to send a notification or whatever other alert system you use.</p>
