-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
57 lines (48 loc) · 1.31 KB
/
debug.js
File metadata and controls
57 lines (48 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
var hostname = require('os').hostname();
var caches = {};
var index = 0;
var debug = {
register: function(cache, name) {
var cname = name || ('anon_' + index++);
caches[cname] = cache;
return cache;
},
view: function(req, res, _next) {
var data = [];
var cnames = Object.keys(caches);
cnames.forEach(function(cname) {
var cache = caches[cname];
var cachestats = cache.stats;
var total = cachestats.hit + cachestats.miss;
var stats = {
name: cname,
size: cache.store.size(),
keycount: cache.store.keycount(),
hitrate: ((cachestats.hit * 100) / (total || 1)) | 0,
resets: cachestats.reset,
pending: cachestats.pending
};
if (req.query) {
if (req.query.detail === cname && cache.store.values) {
stats.values = cache.store.values();
} else if (req.method === 'POST' && req.query.flush === cname) {
cache.store.reset();
stats.resets++;
cache.stats.reset++;
}
}
data.push(stats);
});
res.json({
pid: process.pid,
uptime: process.uptime(),
host: hostname,
data: data
});
},
log: function(cb) {
debug.view({ query: {} }, { json: cb || console.log }, function() {});
}
};
module.exports = debug;