Browse Source
basic cache stat tracking and display on /admin
master
Dan Janosik
5 years ago
No known key found for this signature in database
GPG Key ID: C6F8CE9FFDB2CED2
5 changed files with
44 additions and
1 deletions
-
app.js
-
app/api/coreApi.js
-
app/redisCache.js
-
routes/baseActionsRouter.js
-
views/admin.pug
|
|
@ -13,6 +13,8 @@ configPaths.filter(fs.existsSync).forEach(path => { |
|
|
|
dotenv.config({ path }); |
|
|
|
}); |
|
|
|
|
|
|
|
global.cacheStats = {}; |
|
|
|
|
|
|
|
// debug module is already loaded by the time we do dotenv.config
|
|
|
|
// so refresh the status of DEBUG env var
|
|
|
|
var debug = require("debug"); |
|
|
|
|
|
@ -26,7 +26,14 @@ const ONE_HR = 60 * ONE_MIN; |
|
|
|
const ONE_DAY = 24 * ONE_HR; |
|
|
|
const ONE_YR = 265 * ONE_DAY; |
|
|
|
|
|
|
|
|
|
|
|
global.cacheStats.memory = { |
|
|
|
hit: 0, |
|
|
|
miss: 0 |
|
|
|
}; |
|
|
|
|
|
|
|
function onCacheEvent(cacheType, hitOrMiss, cacheKey) { |
|
|
|
global.cacheStats.memory[hitOrMiss]++; |
|
|
|
//debugLog(`cache.${cacheType}.${hitOrMiss}: ${cacheKey}`);
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -11,7 +11,13 @@ if (config.redisUrl) { |
|
|
|
redisClient = redis.createClient({url:config.redisUrl}); |
|
|
|
} |
|
|
|
|
|
|
|
global.cacheStats.redis = { |
|
|
|
hit: 0, |
|
|
|
miss: 0 |
|
|
|
}; |
|
|
|
|
|
|
|
function onCacheEvent(cacheType, hitOrMiss, cacheKey) { |
|
|
|
global.cacheStats.redis[hitOrMiss]++; |
|
|
|
//console.log(`cache.${cacheType}.${hitOrMiss}: ${cacheKey}`);
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -1470,6 +1470,7 @@ router.get("/admin", function(req, res, next) { |
|
|
|
res.locals.appStartTime = global.appStartTime; |
|
|
|
res.locals.memstats = v8.getHeapStatistics(); |
|
|
|
res.locals.rpcStats = global.rpcStats; |
|
|
|
res.locals.cacheStats = global.cacheStats; |
|
|
|
|
|
|
|
res.render("admin"); |
|
|
|
|
|
|
|
|
|
@ -27,6 +27,32 @@ block content |
|
|
|
- var uptime = moment.duration(new Date().getTime() - appStartTime); |
|
|
|
span #{uptime.format()} |
|
|
|
|
|
|
|
div.card.shadow-sm.mb-3 |
|
|
|
div.card-body |
|
|
|
h3.h6 Cache Stats |
|
|
|
hr |
|
|
|
|
|
|
|
table.table.table-hover |
|
|
|
thead |
|
|
|
tr |
|
|
|
th Cache |
|
|
|
th.text-right Hit |
|
|
|
th.text-right Miss |
|
|
|
th.text-right Hit Rate |
|
|
|
|
|
|
|
tbody |
|
|
|
each item, itemName in cacheStats |
|
|
|
tr.text-monospace |
|
|
|
td #{itemName} |
|
|
|
td.text-right #{item.hit.toLocaleString()} |
|
|
|
td.text-right #{item.miss.toLocaleString()} |
|
|
|
td.text-right |
|
|
|
if (item.hit > 0 || item.miss > 0) |
|
|
|
span #{(100 * item.hit / (item.hit + item.miss)).toLocaleString()} |
|
|
|
small % |
|
|
|
else |
|
|
|
span - |
|
|
|
|
|
|
|
div.card.shadow-sm.mb-3 |
|
|
|
div.card-body |
|
|
|
h3.h6 Memory Stats |
|
|
@ -98,7 +124,8 @@ block content |
|
|
|
span.text-danger #{item.failures.toLocaleString()} |
|
|
|
|
|
|
|
td.text-right |
|
|
|
span #{new Decimal(item.successes).dividedBy(new Decimal(item.successes + item.failures)).times(100).toDP(1)}% |
|
|
|
span #{new Decimal(item.successes).dividedBy(new Decimal(item.successes + item.failures)).times(100).toDP(1)} |
|
|
|
small % |
|
|
|
|
|
|
|
div.tab-pane(id="tab-json", role="tabpanel") |
|
|
|
div.card.shadow-sm.mb-3 |
|
|
|