Cronitor integration can be done in just a few minutes by anybody comfortable with a command prompt and HTTP Requests.
To send alerts when something goes wrong Cronitor needs to know when your task runs, completes or fails. Each monitor you create is given a unique Telemetry Events API endpoint to collect these telemetry events from your server. You can send telemetry pings from anything that can make an http request:
If you are monitoring a script or command on your server, using cronitor exec
from CronitorCLI
is the easiest way to send telemetry pings to Cronitor on success or failure.
cronitor exec
, using the unique code provided in the previous step.
In this example, d3x0c1
is the unique monitor key. logrotate
directly: /usr/sbin/logrotate
logrotate
using cronitor exec
: cronitor exec d3x0c1 /usr/sbin/logrotate
ping
command or send
pings using any HTTP library to your monitor's Telemetry Events API endpoints.
logrotate
directly and use cronitor ping
to relay data to Cronitor:
/usr/sbin/logrotate && cronitor ping d3x0c1 --complete
curl
to send the same ping:
/usr/sbin/logrotate && curl -m 10 https://cronitor.link/d3x0c1/complete
# Install CronitorCLI
curl -sOL https://cronitor.io/dl/cronitor-stable-linux-amd64.tgz
sudo tar xvf cronitor-stable-linux-amd64.tgz -C /usr/bin/
sudo cronitor configure --api-key <API-KEY>
# With CronitorCLI (recommended)
# m h dom mon dow command
0 0 * * * cronitor exec nightly-job /path/to/executable
# Or without software
0 0 * * * curl https://cronitor.link/p/<API-KEY>/nightly-job?state=run -m 5 ; /path/to/executable && curl https://cronitor.link/p/<API-KEY>/nightly-job?state=complete
View on Github
CronitorCLI is the easiest way to monitor a crontab file.
pip install cronitor
import cronitor
cronitor.api_key = '<API-KEY>'
# monitor any function
@cronitor.job('nightly-job')
def nightly_background_job(args):
...
# Or embed telemetry events in your application
monitor = cronitor.Monitor('nightly-job')
# send a run event (a job/process has started)
monitor.ping(state='run')
# send a complete event (a job/process has completed successfully)
monitor.ping(state='complete')
# send a failure event
monitor.ping(state='fail')
View on Github
npm install --save cronitor
// monitor any node cron job
const cron = require('cronitor')('<API-KEY>');
cron.wraps(require('node-cron')); // also works with require('cron');
cron.schedule('SendWelcomeEmail', '*/5 * * * *', function() {
console.log('Sending welcome email to new sign ups every five minutes.');
});
// Or embed telemetry events in your application
const cronitor = require('cronitor')('<API-KEY>')
const monitor = new cronitor.Monitor('nightly-background-job');
// send a run event (a job/process has started)
monitor.ping({state: 'run'});
// send a complete event (a job/process has completed successfully)
monitor.ping({state: 'complete'});
// send a failure event
monitor.ping({state: 'fail'});
View on Github
gem install cronitor
require 'cronitor'
Cronitor.api_key = '<API-KEY>'
# monitor any function/code block
Cronitor.job 'nightly-job' do
nightly_background_job()
end
# Or, embed telemetry events in your application
monitor = Cronitor.Monitor.new('nightly-job')
# send a run event (a job/process has started)
monitor.ping(state: 'run')
# send a complete event (a job/process has completed successfully)
monitor.ping(state: 'complete')
# send a failure event
monitor.ping(state: 'fail')
View on Github
// Maven
<dependency>
<groupId>io.cronitor</groupId>
<artifactId>client</artifactId>
<version>1.4.0</version>
</dependency>
// Gradle
compile "io.cronitor:client:1.4.0
// Embed telemetry events in your application
CronitorClient cronitorClient = new CronitorClient('<API-KEY>');
// send a run event (a job/process has started)
cronitorClient.run('nightly-job');
// send a complete event (a job/process has completed successfully)
cronitorClient.complete('nightly-job');
// send a failure event
cronitorClient.fail('nightly-job');
View on Github
composer require cronitor/cronitor-php
$cronitor = new Cronitor\CronitorClient('<API-KEY>');
# monitor any function/code block
$cronitor->job('nightly-job', function() {
$nightlyBackgroundJob();
});
# Or, embed telemetry events in your application
$monitor = $cronitor->monitor('nightly-job')
# send a run event (a job/process has started)
$monitor->ping(['state' => 'run'])
# send a complete event (a job/process has completed successfully)
$monitor->ping(['state' => 'complete'])
# send a failure event
$monitor->ping(['state' => 'fail'])
View on Github
# send an event
curl https://cronitor.link/p/<API-KEY>/nightly-job
# send a run event (a job/process has started)
curl https://cronitor.link/p/<API-KEY>/nightly-job?state=run
# send a complete event (a job/process has completed successfully)
curl https://cronitor.link/p/<API-KEY>/nightly-job?state=complete
# send a failure event
curl https://cronitor.link/p/<API-KEY>/nightly-job?state=fail
This section outlines the telemetry endpoints available to you when integrating with Cronitor using curl, PowerShell or a native HTTP client directly in your application code.
Covered in detail in our Telemetry Events API Guide,
each monitor you create has a unique telemetry key. Send events via http requests to tell Cronitor the status of your
task: /run
, /complete
, /fail
and /pause
.
/run
Your /run
pings should be made when your job starts. For accurate time tracking, the request should be made as close
to the true beginning of your job as possible. This ping is used to report that the job has started but has not necessarily completed yet.
/complete
Your /complete
pings should be made when your job completes successfully. For accurate time tracking, the request should be made as close
to the true end of your job as possible. This ping is used to report that the job has run successfully.
/fail
Ping the /fail
endpoint to report a fatal error or failure of your task. Use the msg
param to capture error messages.
The most common place to send a /fail
ping is within an exception handler or after your job returns a
non-zero exit code.
/pause
The pause endpoint can be used to temporarily pause failure alerts on your monitor. When pausing, specify the number of hours to pause. Recovery notifications will still be sent if a failing monitor recovers while alerting is paused. All Cronitor alert emails include simple 1-click pause links.
cronitor configure --ping-api-key <KEY>
or set the CRONITOR_PING_API_KEY
environment variable.
If you're sending pings using Curl or a native HTTP client, provide the key via an &auth_key
parameter.
/r
, /c
and /f