A node.js client for graphite.
npm install graphite
You first have to define the Graphite client:
vargraphite=require('graphite');varclient=graphite.createClient('plaintext://graphite.example.org:2003/');You can send metrics without a timestamp. The current Unix epoch will then be used in place:
varmetrics={foo: 23};client.write(metrics,function(err){// if err is null, your data was sent to graphite!});If you wish to set your own timestamp, you must use Date.now() (millisecond precision) as parameter and not Math.floor(Date.now() / 1000) (second precision), otherwise your metrics will probably get ignored by Graphite:
varmetrics={foo: 23};vartimestamp=Date.now();client.write(metrics,timestamp,function(err){// if err is null, your data was sent to graphite!});In Graphite 1.1.1 (21.12.17), tagging becomes available. You can send tagged metrics as follows:
varmetrics={foo: 23};vartags={'name': 'foo.bar','some.fancy.tag': 'somefancyvalue'};client.writeTagged(metrics,tags,function(err){// if err is null, your data was sent to graphite!});- More docs
Licensed under the MIT license.