GithubHelp home page GithubHelp logo

isabella232 / riemann-java-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from forter/riemann-java-client

0.0 0.0 0.0 322 KB

License: Apache License 2.0

Java 98.99% Shell 0.25% Protocol Buffer 0.76%

riemann-java-client's Introduction

Getting started

This project encompasses:

  1. A Java client for the Riemann protocol
  2. The Riemann protocol buffer definition, and
  3. Its corresponding (autogenerated) Java classes

Artifacts are available through clojars which you can add to your maven repository like so:

<repository>
  <id>clojars.org</id>
  <url>http://clojars.org/repo</url>
</repository>

Example

RiemannClient c = RiemannClient.tcp("my.riemann.server", 5555);
c.connect();
c.event().
  service("fridge").
  state("running").
  metric(5.3).
  tags("appliance", "cold").
  send();

c.query("tagged \"cold\" and metric > 0"); // => List<Event>;
c.disconnect();

Clients will automatically attempt to reconnect every 5 seconds. Writes will fail instantaneously when no connection is available.

.send() proceeds asynchronously and returns as soon as Netty flushes the write possible. .send() returns a com.aphyr.riemann.client.IPromise containing the response from the write (which also supports Clojure's Deref protocol). If you do not deref this promise, the client makes no guarantees about event delivery: it will, for example, discard writes when there are too many messages outstanding on the wire, when Riemann cannot keep up with load, and so on. You should deref and retry IOExceptions on important writes.

try {
  if (!c.event().
      service("fridge").
      state("running").
      send().
      deref(1, java.util.concurrent.TimeUnit.SECONDS)) {
    throw new IOException("Timed out.")
  }
} catch (IOException e) {
  retry();
}

This code blocks for 1 second before retrying, returns a Message if the write succeeded, null if the promise is still outstanding, and throws if a failure is known to have occurred. This means you can send multiple copies of an event if latencies exceed 1000 ms. There is no reliable way to distinguish between failure and delay in an asynchronous network, so think ahead. .deref() blocks indefinitely, but will return as soon as the Netty connection fails, so it may be the safest option when arbitrary delays are acceptable.

Each client allows thousands of outstanding concurrent requests at any time, so a small number of threads can efficiently pipeline many operations over the same client. I suggest performing writes on a special monitoring thread or threads, and pushing the response futures onto a threadpoolexecutor for derefing.

For higher performance (by orders of magnitude) you can also send multiple events batched in a single message. Use RiemannClient.aSendEvents(...) to send multiple events at once.

Hacking

You'll need protoc 2.5.0. After that, mvn package should build a JAR, and mvn install will drop it in your local repository.

riemann-java-client's People

Contributors

aphyr avatar b avatar chids avatar dlobue avatar eribeiro avatar eric avatar itaifriendingerforter avatar lassic avatar mallman avatar mblair avatar michaelfairley avatar neotyk avatar tazle avatar tcrayford avatar vlad-patras 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.