statsd-parser
a streaming parser for the statsd protocol
installation
node.js
- install npm
npm install statsd-parser
var statsd_parser = require('statsd-parser');
usage
basics
var statsd_parser = require("statsd-parser")
, parser = statsd_parser.parser()
;
parser.onerror = function (e) {
};
parser.onstat = function (txt, obj) {
};
parser.onend = function () {
};
parser.write('foo.bar:1|c').close();
var stream = require("statsd-parser").createStream(options);
stream.on("error", function (e) {
console.error("error!", e);
this._parser.error = null;
this._parser.resume();
})
stream.on("stat", function (txt, obj) {
});
fs.createReadStream("file.statsd")
.pipe(stream)
.pipe(fs.createReadStream("file-fixed.statsd"))
you also have two helper functions to see if a string is a statsd stat isStatsd
and one to check extract values from a statsd string (or null if it's not statsd)
> var statsd = require('statsd-parser');
> statsd.isStatsd('a:1|c|@0.1')
true
> statsd.matchStatsd('a:1|c|@0.1')
{ stat: 'a',
value: '1',
type: 'c',
sample_rate: '0.1' }
> statsd.matchStatsd('b:200|s')
{ stat: 'b',
value: '200',
type: 's' }
> statsd.matchStatsd('b:200|s@INVALID')
null
contribute
everyone is welcome to contribute. patches, bug-fixes, new features
- create an issue so the community can comment on your idea
- fork
statsd-parser
- create a new branch
git checkout -b my_branch
- create tests for the changes you made
- make sure you pass both existing and newly inserted tests
- commit your changes
- push to your branch
git push origin my_branch
- create an pull request
meta
(oO)--',-
in caos