Skip to content

Instantly share code, notes, and snippets.

@mbostock
Created January 4, 2012 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbostock/1557990 to your computer and use it in GitHub Desktop.
Save mbostock/1557990 to your computer and use it in GitHub Desktop.
Cube Metrics Client (Node.js + WebSockets)
var websocket = require("websocket");
var client = new websocket.client();
client.on("connect", function(connection) {
var remaining = 762; // based on start, stop, and step
connection.on("message", function(message) {
if (message.type === "utf8") {
if (!--remaining) connection.close();
console.log(message.utf8Data);
}
});
connection.sendUTF(JSON.stringify({
expression: "sum(request)",
start: "2011-09-10T12:37:12Z",
stop: "2011-09-13T04:00:02Z",
step: 300000
}));
});
client.connect("ws://localhost:1081/1.0/metric/get");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment