Permalink
Browse files

Rename event to riak.request.finish.

Add examples on using instrumentation for logging and metrics.
  • Loading branch information...
1 parent 0d9dd0e commit a142c6711ad27afb3360031d05222ba6a767117a @roidrage roidrage committed Nov 13, 2012
Showing with 29 additions and 5 deletions.
  1. +12 −0 examples/logger.js
  2. +15 −0 examples/metrics.js
  3. +2 −5 lib/http-request.js
View
@@ -0,0 +1,12 @@
+var db = require('../lib').getClient();
+
+var instrument = {
+ 'riak.request.start': function(event) {
+ console.log('[riak-js] ' + event.method.toUpperCase() + ' ' + event.path);
+ }
+}
+
+db.registerListener(instrument);
+
+db.get('airlines', 'KLM')
+db.save('airlines', 'Lufthansa', {country: 'DE'})
View
@@ -0,0 +1,15 @@
+var db = require('../lib').getClient();
+var lynx = require('lynx');
+var metrics = new lynx('localhost', 8125);
+
+var instrument = {
+ 'riak.request.end': function(event) {
+ var runtime = event.finished_at - event.started_at;
+ metrics.timing('riak.request.' + event.method.toLowerCase(), runtime);
+ }
+}
+
+db.registerListener(instrument);
+
+db.get('airlines', 'KLM')
+db.save('airlines', 'Lufthansa', {country: 'DE'})
View
@@ -25,8 +25,6 @@ HttpRequest.prototype.execute = function() {
var self = this,
callback = meta.callback;
- if (meta.logger) meta.logger.write('[riak-js] ' + meta.method.toUpperCase() + ' ' + meta.path + '\n');
-
this.client.emit('riak.request.start', this.event)
var request = http.request(meta, function(response) {
@@ -90,7 +88,7 @@ HttpRequest.prototype.execute = function() {
err = self.handleError(buffer);
}
- self.client.emit('riak.request.finished', this.event);
+ self.client.emit('riak.request.finish', this.event);
callback(err, buffer, meta);
});
});
@@ -112,7 +110,6 @@ HttpRequest.prototype.execute = function() {
}
request.end();
-
}
HttpRequest.prototype.mapReduceChunk = function(chunk) {
@@ -145,7 +142,7 @@ HttpRequest.prototype.extractMultipartResponse = function(buffer) {
HttpRequest.prototype.handleRequestEnd = function(buffer) {
this.event.finished_at = new Date();
- this.client.emit('request.end', this.event)
+ this.client.emit('riak.request.end', this.event)
// if there is an emitter associated to this chunked response then emit 'end'
if (this.meta._emitter) {

0 comments on commit a142c67

Please sign in to comment.