-
Notifications
You must be signed in to change notification settings - Fork 417
Collector
Wiki ▸ API Reference ▸ Collector
The collector is a server that runs (by default) on port 1080. The collector exists to receive events from emitters (client programs that you write) and save them to Cube's Mongo database. The collector also invalidates any cached metrics that were associated with the incoming events, so that the latest values are always to evaluator clients.
# /1.0/event/put
Post events to Cube. The endpoint supports both HTTP POST and WebSockets.
For HTTP POST, the body of the POST request should be a JSON-encoded array of events. For example, to post a single "request" event, you can post:
[
{
"type": "request",
"time": "2011-09-12T21:33:12Z",
"data": {
"host": "web14",
"path": "/search",
"query": {
"q": "flowers"
},
"duration_ms": 241,
"status": 200,
"user_agent": "Chrome/13.0.782.112"
}
}
]
If the post is successful, the endpoint returns a status 200 with the body "{}". If the post fails, a status 400 is returned with the body "{error: }", where is a description of what went wrong.
For WebSockets, any message you send will be interpreted as an event to save. This event should be JSON encoded. For example, to post a single "request" event:
var socket = new WebSocket("ws://localhost:1080/1.0/event/put");
socket.onopen = function() {
socket.send(JSON.stringify({
"type": "request",
"time": "2011-09-12T21:33:12Z",
"data": {
"host": "web14",
"path": "/search",
"query": {
"q": "flowers"
},
"duration_ms": 241,
"status": 200,
"user_agent": "Chrome/13.0.782.112"
}
}));
};
If the post is successful, no message is returned. If an error occurs, Cube replies with a JSON error message that you can log. For example:
socket.onerror = function(error) {
console.log("error", error);
};
# /collectd
See Collectd.
When constructing a cube.server
, you may specify a configuration object that controls its behavior. The default configuration is as follows:
{
"mongo-host": "127.0.0.1",
"mongo-port": 27017,
"mongo-database": "cube_development",
"mongo-username": null,
"mongo-password": null,
"http-port": 1080
}
The mongo-host, mongo-port and mongo-database controls where the collector saves events, and where it finds metrics to invalidate. If your Mongo database requires authentication, specify the optional mongo-username and mongo-password parameters. The http-port parameter specifies the port the collector listens to.
To start the Collector:
node bin/collector &
To stop the Collector, ^C the process:
fg
^C
Alternatively, find the process via ps
and then kill
it:
ps aux | grep -e 'collector' | grep -v grep | awk '{print $2}' | xargs -i kill -SIGINT {}