UNPKG

2.36 kBJavaScriptView Raw
1/*
2 * Copyright (c) 2012 Dmitri Melikyan
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to permit
9 * persons to whom the Software is furnished to do so, subject to the
10 * following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
18 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24
25var nt = require('../nodetime');
26var proxy = require('../proxy');
27var samples = require('../samples');
28
29var commands = [
30 'get',
31 'count',
32 'set',
33 'remove',
34 'truncate',
35 'use',
36 'addKeySpace',
37 'dropKeySpace'
38];
39
40module.exports = function(obj) {
41 // not tested, skip
42 return;
43
44 commands.forEach(function(command) {
45 proxy.before(obj.ColumnFamily.prototype, command, function(obj, args) {
46 var cf = obj;
47 var trace = samples.stackTrace();
48 var params = args.length > 1 && Array.isArray(args[1]) ? args[1] : undefined;
49 var time = samples.time("Cassandra", command);
50
51 proxy.callback(args, -1, function(obj, args) {
52 if(!time.done()) return;
53 if(nt.paused) return;
54
55 var error = args.length > 0 ? (args[0] ? args[0].message : undefined) : undefined;
56 var obj = {'Type': 'Cassandra',
57 'Connection': {host: cf.client_.host, port: cf.client_.port, keyspace: cf.client_.keyspace, columnFamily: cf.name},
58 'Command': command,
59 'Arguments': samples.truncate(params),
60 'Stack trace': trace,
61 'Error': error};
62
63 samples.add(time, obj, 'Cassandra: ' + obj['Command']);
64 });
65 });
66 });
67};
68