-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Couchbase Probe #494
Comments
'use strict';
var Probe = require('../lib/probe.js');
var aspect = require('../lib/aspect.js');
var util = require('util');
var am = require('../');
function CouchbaseProbe() {
Probe.call(this, 'couchbase');
}
util.inherits(CouchbaseProbe, Probe);
CouchbaseProbe.prototype.aspectBucketMethod = function(bucket, method) {
var that = this;
aspect.before(bucket, method, function(target, methodName, methodArgs, probeData) {
that.metricsProbeStart(probeData, method, methodArgs);
if (aspect.findCallbackArg(methodArgs) != undefined) {
aspect.aroundCallback(methodArgs, probeData, function(target, args) {
that.metricsProbeEnd(probeData, method, methodArgs);
});
}
});
};
// Most used couchbase bucket methods
const bucketMethods = ['upsert', 'insert', 'replace', 'remove', 'get', 'getMulti'];
CouchbaseProbe.prototype.attach = function(name, target) {
var that = this;
if (name != 'couchbase') return target;
if (target.__ddProbeAttached__) return target;
target.__ddProbeAttached__ = true;
var mock = target['Mock']['Cluster'].prototype;
var cluster = target['Cluster'].prototype;
var data = {};
aspect.after(mock, 'openBucket', data, function(target, methodName, args, probeData, bucket) {
for(key in bucketMethods) {
that.aspectBucketMethod(bucket, bucketMethods[key]);
}
return bucket;
});
aspect.after(cluster, 'openBucket', data, function(target, methodName, args, probeData, bucket) {
for(key in bucketMethods) {
that.aspectBucketMethod(bucket, bucketMethods[key]);
}
return bucket;
});
return target;
};
/*
* Lightweight metrics probe for couchbase queries
*
* These provide:
* time: time event started
* bucket: The bucket executed on
* method: the method called on the bucket
* duration: the time for the request to respond
*/
CouchbaseProbe.prototype.metricsEnd = function(probeData, method, methodArgs) {
if (probeData && probeData.timer) {
probeData.timer.stop();
var eventTimer = probeData.timer;
am.emit('couchbase', {
time: eventTimer.startTimeMillis,
bucket: methodArgs[0],
method: method,
duration: eventTimer.timeDelta,
});
}
};
module.exports = CouchbaseProbe; |
@astub Please go ahead and raise a pull request. We will need you to agree to the CLA terms https://github.com/RuntimeTools/appmetrics/blob/master/CONTRIBUTING.md before we can accept your request |
@astub.. what might be the benefits of visualising couchbase metrics on appmetrics-dash? |
@NikCanvin it would be good to see response times and error rates if any occur when making couchbase queries. |
This was referenced Nov 3, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to add a couchbase-probe to time some of the common bucket methods from couchnode.
The text was updated successfully, but these errors were encountered: