Giter Club home page Giter Club logo

cronitor-java's Introduction

Cronitor Ping API Client

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.

Install

You can download the cronitor client JAR from the Maven central repository. https://repo.maven.apache.org/maven2/io/cronitor/client/1.6.0/

Install with Maven

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>

Usage with Spring

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;

Usage without Spring

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');

Examples

send a run event (a job has started)

    cronitorClient.run("nightly-data-export");

send a complete event (a job has completed successfully)

    cronitorClient.complete("nightly-data-export");

send a failure event (a job has failed)

    cronitorClient.fail("nightly-data-export");

send a tick event (heartbeat events)

    cronitorClient.tick("heartbeat-monitor");

pause a monitor

    cronitorClient.pause("nightly-data-export", numberOfHours);

unpause a monitor

    cronitorClient.unpause("nightly-data-export");

including messages

    // 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());

including metrics

    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);

Development

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].

Authors

cronitor-java's People

Contributors

aflanagan avatar solutionsmedias360 avatar lboix avatar ovalente avatar methodlevelanalyzer avatar nnerny avatar firone avatar shaneharter avatar vcanuel avatar akaderive avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.