backends/graphite.js
function Stats() {
  var s = this;
  this.metrics = [];
  this.add = function(key, value, ts) {
    s.metrics.push(new Metric(key, value, ts));
  };

  this.toText = function() {
    return s.metrics.map(function(m) { return m.toText(); }).join('\n') + '\n';
  };

  this.toPickle = function() {
    var body = MARK + LIST + s.metrics.map(function(m) { return m.toPickle(); }).join('') + STOP;

    // The first four bytes of the graphite pickle format
    // contain the length of the rest of the payload.
    // We use Buffer because this is binary data.
    var buf = new Buffer(4 + body.length);

    buf.writeUInt32BE(body.length,0);
    buf.write(body,4);

    return buf;
  };
}
function Stats() {
  var s = this;
  this.metrics = [];
  this.add = function(key, value, ts) {
    s.metrics.push(new Metric(key, value, ts));
  };

  this.toText = function() {
    return s.metrics.map(function(m) { return m.toText(); }).join('\n') + '\n';
  };

  this.toPickle = function() {
    var body = MARK + LIST + s.metrics.map(function(m) { return m.toPickle(); }).join('') + STOP;

    // The first four bytes of the graphite pickle format
    // contain the length of the rest of the payload.
    // We use Buffer because this is binary data.
    var buf = new Buffer(4 + body.length);

    buf.writeUInt32BE(body.length,0);
    buf.write(body,4);

    return buf;
  };
}
function Stats ( ) { var s = this ; this . metrics = [ ] ; this . add = function ( key , value , ts ) { s . metrics . push ( new Metric ( key , value , ts ) ) ; } ; this . toText = function ( ) { return s . metrics . map ( function ( m ) { return m . toText ( ) ; } ) . join ( '\n' ) + '\n' ; } ; this . toPickle = function ( ) { var body = MARK + LIST + s . metrics . map ( function ( m ) { return m . toPickle ( ) ; } ) . join ( '' ) + STOP ; // The first four bytes of the graphite pickle format // contain the length of the rest of the payload. // We use Buffer because this is binary data. var buf = new Buffer ( 4 + body . length ) ; buf . writeUInt32BE ( body . length , 0 ) ; buf . write ( body , 4 ) ; return buf ; } ; }
A collection of measurements for sending to graphite.
A collection of measurements for sending to graphite .