Giter VIP home page Giter VIP logo

oxide's Introduction

oxide.js Build Status

Oxide is a Node.js client designed for easy communicating with Carbon, a data injest tool which is a part of the Graphite project. Oxide also works well with Statsd, a fantastic little tool from the folks at Etsy designed for more powerful metrics recording.

Installation

oxide.js is a npm package, so installation couldn't be easier. To install oxide.js as a dependency, simply execute:

$ npm install oxide.js --save

And then require oxide in your project:

var Oxide = require('oxide.js');

Theory of Operation

oxide.js is a pretty simple tool. It aggregates metrics using the #record method, and then compacts them using either one of two protocols, the pickle protocol or the plaintext protocol. On a given interval (see the usage section), the protocol will compact all of the Metrics in the client's queue, send them over the socket, and dump the queue.

When using Oxide.js in Statsd mode, it will aggregate the stats using the same queueing method as in carbon mode, however, it will not use a protocol to compact the data, instead, it will pack each metric individually, create a buffer, and send that. At this time, Statsd does not allow for protocol-based metric sending over UDP.

The queuing operations are thread-safe.

Usage

Once you have the oxide.js namespace in your project, usage is pretty simple. To construct an oxide client, simply pass an object containing your arguments to the constructor, i.e.:

var Oxide = require('oxide.js');

/**
 * The following options are supported:
 *   host: the hostname of your carbon server
 *   port: the port your carbon server runs on
 *   prefix: prefixes all paths with the given value (i.e., foo -> prefix.foo)
 *   interval: the time in msec to send statistics
 *   protocol: an instance of the protocol to send statistics with
 */
var oxideClient = new Oxide.Client.CarbonClient({
  host: '127.0.0.1',
  port: 2003,
  interval: 5000
});

To write a metric into Oxide's aggregate queue, simply fire off the #record method:

// Connect to the server
oxideClient.connect();

// Start the queuing operations
oxideClient.start();

/**
 * #record takes three arguments, as described below:
 *   1) path - the path to write the metric to
 *   2) value - the value to write onto the metric
 *   3) [optional] timestamp - the time to record the metric
 */
oxideClient.record('my.path', 50, new Date());

A call to #record makes a new Oxide.Metric and dumps it in the queue. After the time specified in the interval, oxide.js will collect all statistics currently in the queue, and pack them using the protocol, then send them up the wire.

The Statsd client is more interesting, since statsd supports more metric types. All protocols described in this spec are implemented by the client using a different method call. Examples follow below:

var client = new Oxide.Client.StastdClient({ /* opts */ });
client.connect();
client.start();

// Send a counter metric to increment the `path` argument by 1, or the amount specified.
client.increment(path[, amount[, sampleRate]]);

// Send a counter metric to decrement the `path` given by 1, otherwise the amount specified.
client.decrement(path[, amount[, sampleRate]]);

// Send a gauge metric to set the value of `path` to the amount specified.
client.gauge(path, amount);

// Send a timer metric to mark the time of the `path` to the amount specified.
client.timing(path, duration); // duration in msec

That's it!

Contributing

Pull-requests are always appreciated! If you want to add a feature, close an issue or otherwise, follow the following process:

  1. Fork this repo
  2. Cut a branch (with the convention feature|bugfix/<branch-name>
  3. Write your feature/bugfix/etc
  4. Write an accompanying test
  5. Ensure that your tests pass (a call to $ npm test will verify this easily)
  6. Submit a pull-request upstream!

License

MIT

oxide's People

Contributors

ttaylorr avatar

Watchers

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