Cronitor is a service for heartbeat-style monitoring of anything that can send an HTTP request. It's particularly well suited for monitoring cron jobs, Jenkins jobs, or any other scheduled task.
This java library provides a simple abstraction for the pinging of a Cronitor monitor. For a better understanding of the API this library talks to, please see our Telemetry API docs.
You can download the cronitor client JAR from the Maven central repository. https://repo.maven.apache.org/maven2/io/cronitor/client/1.6.0/
If you are using Maven, simply add this line in your pom.xml file :
<dependency>
<groupId>io.cronitor</groupId>
<artifactId>client</artifactId>
<version>1.6.0</version>
</dependency>
Declare a new bean in your Spring configuration :
<bean id="cronitorClient" class="io.cronitor.client.CronitorClient">
<constructor-arg index="0" value="apiKey"/>
<constructor-arg index="1" value="environment"/> // optional
</bean>
Then simply inject this bean into the class containing the routine to monitor :
@Resource
private CronitorClient cronitorClient;
Simply declare a new CronitorClient instance in the class containing the routine to monitor:
CronitorClient cronitorClient = new CronitorClient('yourApiKey');
To send events to an environment other than the default ('production'), you can pass the environment as the second argument.
CronitorClient cronitorClient = new CronitorClient('yourApiKey', 'production');
cronitorClient.run("nightly-data-export");
cronitorClient.complete("nightly-data-export");
cronitorClient.fail("nightly-data-export");
cronitorClient.tick("heartbeat-monitor");
cronitorClient.pause("nightly-data-export", numberOfHours);
cronitorClient.unpause("nightly-data-export");
// each event method supports an optional message param
cronitorClient.run("nightly-data-export", "Started by user 123");
cronitorClient.complete("nightly-data-export", "Alive!");
cronitorClient.fail("nightly-data-export", e.printStackTrace());
Map<String, Integer> metrics = new HashMap<String, Integer>() {
{
put("count", 100);
put("error_count", 5);
}
};
// each event method supports an optional message param
cronitorClient.complete("nightly-data-export", "ok", metrics);
cronitorClient.fail("nightly-data-export", e.printStackTrace(), metrics);
The contained Dockerfile/docker-compose.yml file will allow you to build and test this library. Build the container with with docker-compose build
. Run tests with docker-compose up
.
If you want to share an idea, report an issue, or just say hello you can open an issue on this repo or email us at [email protected].