cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to monitor Crontab shell script?

edward_ma
Newcomer

We have a cron job which is scheduled to execute once a day. How to monitor its status: is it started? does it fail? etc.

7 REPLIES 7

Joe_Hoffman
Inactive

Assuming the chrontab job is running just shell scripting, we can't instrument it directly, unless it invokes something such as Java, or other supported technology. However you can monitor the status of the Chronjob using a plugin which can execute any arbitrary commandline commands. Another approach is for the chrontab to write out a status into a file and read that file via the AppMon plugin and thus put the status into AppMon (Success, failure, error, etc).

I'm new to dynatrace. 1) Yes, the crontab job invokes a go program. It is detected when it is running and is gone after it finishes. Is there a way with which we can set an alert when a cron job is not running per schedule? 2) Could you tell me if there is a sample plugin used for cron job monitoring? 3) Yes, the crontab job writes logs to a file. Is there a specific AppMon plugin for it? Are you talking about log monitoring? Thanks!

Joe_Hoffman
Inactive

Edward, Just to clarify, you've posted this question to the AppMon forum so I'm assuming you're using AppMon. But if you're using our flagship product Dynatrace, the answer would be slightly different. Please verify which product you're using.

We are using Dynatrace. I thought AppMon is a part of Dynatrace. 😞

Thanks for clarifying. I've moved this posting to the Dynatrace forum.

Joe_Hoffman
Inactive

Since you're using Dynatrace (not AppMon), one approach would be to use the Dynatrace API and have the chron job post metrics to a custom metric when it starts/finishes a job. Then you could create a custom alert and raise an alert when the metric is below a certain value over a period of time (24 hrs?). The custom events (Chron job executions) should be associated with the host where they're running, then the metrics simply show up under that hosts metrics.

Examples of posting custom events is located in the API doc. https://www.dynatrace.com/support/help/extend-dynatrace/custom-metric-ingestion-and-analysis/. I'm suggesting using the API to get the metrics into Dynatrace.

This might be a more advanced topic than can easily be described in a forum. But overall it's not difficult to do, as long as you're comfortable calling API endpoints from a chron job. Here's the doc page specifically for putting the new metric into Dynatrace. https://www.dynatrace.com/support/help/extend-dynatrace/dynatrace-api/environment-api/metric-v1/cust...

Thanks a lot, Joseph! Will check and try approached you mentioned.

Featured Posts