/
client.js
46 lines (32 loc) · 997 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var dgram = require("dgram"),
util = require("util");
var Client = function(host, port) {
this.host = host;
this.port = port;
// Create socket (ignore errors)
this.socket = dgram.createSocket("udp4");
this.socket.on("error", function() {});
};
Client.prototype.timing = function(bucket, value) {
this.send(bucket, value + "|ms");
};
Client.prototype.count = function(bucket, value) {
this.send(bucket, value + "|c");
};
Client.prototype.increment = function(bucket) {
this.count(bucket, 1);
};
Client.prototype.decrement = function(bucket) {
this.count(bucket, -1);
};
Client.prototype.gauge = function(bucket, value) {
this.send(bucket, value + "|g");
};
Client.prototype.send = function(bucket, value) {
var buffer = new Buffer(bucket + ":" + value);
// Send (ignore errors)
this.socket.send(buffer, 0, buffer.length, this.port, this.host,
function (err, bytes) {}
);
};
exports.Client = Client;