Home

Awesome

Build Status

vert.x Bosun

This library allows you to send data to a Bosun cluster. Which is an alerting system built around OpenTsDb.

####To use this library you must have a Bosun instance(s) running on your network.

The library creates a long lived HTTP connection to every Bosun endpoint you configure.

Getting Started

Add a dependency to vertx-bosun:

<dependency>
    <groupId>com.cyngn.vertx</groupId>
    <artifactId>vertx-bosun</artifactId>
    <version>0.1.0</version>
</dependency>

Configuration

The vertx-bosun module takes the following configuration:

{
    "address" : <address>,
    "hosts" : [{"host" : <host1>, "port" : <host1Port>}, {"host" : <host2>, "port" : <host2Port>}],
    "max_tags" : <default 8>,
    "max_index_cache_size" : <default 1000000>,
    "index_expiry_minutes" : <default 10>,
    "default_timeout_ms" : <default 3000>
}

For example:

{
    "address" : "vertx.bosun-reporter",
    "hosts" : [{"host" : "localhost", "port" : 8070}],
    "max_tags" : 4,
    "max_index_cache_size" : 10000,
    "index_expiry_minutes" : 30,
    "default_timeout_ms" : 1000
}

Field breakdown:

Operations

Put

Adds a metric to be sent to OpenTsDb through Bosun, this allows Bosun to index it and to deliver it to OpenTsDb

To add a metric send a JSON message to the module main address:

{
    "action" : "put",
    "metric" : <metricName>,
    "value" : <metricValue>,
    "tags" : { "key1" : "value1",
               "key2" : "value2"
     }
}

Where:

An example:

{
    "action" : "put",
    "metric" : "api.add_item.time",
    "value" : "150.23",
    "tags" : {"type" : "t"}
}

When the add completes successfully (which can be ignored), a reply message is sent back to the sender with the following data:

{
    "result" : "ok"
}

If an error occurs when adding the metric you will get back a response as failed and you need to check the 'cause' method for the issue, ie

BosunPublisher publisher = new BosunPublisher("vertx.bosun-reporter", eventBusRef)

JsonObject tags = new JsonObject().put("host", "my.server.com");
publisher.put("my.rest.endpoint.timing", 20.5, tags, AsyncResult<Message<JsonObject>> result -> {
	if(result.failed()) {
      System.out.println("Got error ex: ", result.cause())
    }
});

Index

Tells Bosun to index a metric but DON'T send it to OpenTsDb

To index a metric send a JSON message to the module main address:

{
    "action" : "index",
    "metric" : <metricName>,
    "value" : <metricValue>,
    "tags" : { "key1" : "value1",
               "key2" : "value2"
     }
}

Where:

An example:

{
    "action" : "put",
    "metric" : "api.add_item.time",
    "value" : "150.23",
    "tags" : {"type" : "t"}
}

When the add completes successfully (which can be ignored), a reply message is sent back to the sender with the following data:

{
    "result" : "ok"
}

If you have already indexed this metric recently and we have it in the cache of metrics already you will receive the following data:

{
    "result" : "exists"
}

If an error occurs when adding the metric you will get back a response as failed and you need to check the 'cause' method for the issue, ie

BosunPublisher publisher = new BosunPublisher("vertx.bosun-reporter", eventBusRef)

JsonObject tags = new JsonObject().put("host", "my.server.com");
publisher.index("my.rest.endpoint.timing", 20.5, tags, AsyncResult<Message<JsonObject>> result -> {
	if(result.failed()) {
      System.out.println("Got error ex: ", result.cause())
    }
});

Example code

You can send the messages to the library directly via the event bus but it's easiest just to use the provided BosunPublisher class as follows:

 BosunPublisher publisher = new BosunPublisher("vertx.bosun-reporter", eventBusRef)

 JsonObject tags = new JsonObject().put("host", "my.server.com");
 publisher.index("my.rest.endpoint.timing", 20.5, tags);
 publisher.put("my.other.rest.endpoint.timing", 31.5, tags);

 publisher.index("my.rest.endpoint.timing", 20.5, tags, (AsyncResult<Message<JsonObject>> response) -> {
        System.out.println(response.result().body());
 });