In the just-released riemann-java-client 0.0.6, riemann-clojure-client 0.0.6, riemann-ruby-client 0.0.8, and the upcoming riemann 0.1.4 (presently in master), Riemann will support two new types of metrics for events.

# signed 64-bit integers (variable-width-encoded)
optional sint64 metric_sint64 = 13;
# double-precision IEEE 754 floats
optional double metric_d = 14;

Events still have only a single logical metric; this change simply allows the protocol to represent a broader range of numbers. Clients should prefer metric_sint64 for all integer values from -2^63 to 2^63 - 1, and prefer metric_d for double-precision floats. Clients should also write metric_f wherever possible and fall back to reading metric_f, for compatibility with older versions of Riemann.

Here’s how the Ruby client does it. Note that Ruby’s Float is actually a double.

def metric
  metric_d ||
    metric_sint64 ||

def metric=(m)
  if Integer === m and (-(2**63)...2**63) === m
    # Long
    self.metric_sint64 = m
    self.metric_f = m.to_f
    self.metric_d = m.to_f
    self.metric_f = m.to_f

Javascript has only one numeric type: double-precision IEE754 floats (sort of). Riemann uses Cheshire and will emit JSON numbers which may exceed the scale or resolution of a JS VM, e.g.:


… which in V8 will be parsed as the number 12345678901234567000. Larger values may become +/- Infinity when parsed. Rationals are serialized as decimals.

Since most JS clients are engaged in visualization, loss of precision seems preferable to emitting JSON strings (e.g. 123 -> “123”) and forcing clients to use arbitrary-precision bignum libraries with custom operators. I’d like your feedback. :)

Post a Comment

Comments are moderated. Links have nofollow. Seriously, spammers, give it a rest.

Please avoid writing anything here unless you're a computer. This is also a trap:

Supports Github-flavored Markdown, including [links](, *emphasis*, _underline_, `code`, and > blockquotes. Use ```clj on its own line to start an (e.g.) Clojure code block, and ``` to end the block.