diff --git a/app.js b/app.js index a2694bf..ffc3643 100755 --- a/app.js +++ b/app.js @@ -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"); diff --git a/app/api/coreApi.js b/app/api/coreApi.js index 4f50de2..19b7f9d 100644 --- a/app/api/coreApi.js +++ b/app/api/coreApi.js @@ -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}`); } diff --git a/app/redisCache.js b/app/redisCache.js index 3efe6f6..4c46f10 100644 --- a/app/redisCache.js +++ b/app/redisCache.js @@ -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}`); } diff --git a/routes/baseActionsRouter.js b/routes/baseActionsRouter.js index 0702946..8261f1a 100644 --- a/routes/baseActionsRouter.js +++ b/routes/baseActionsRouter.js @@ -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"); diff --git a/views/admin.pug b/views/admin.pug index 12a46de..8d3cdda 100644 --- a/views/admin.pug +++ b/views/admin.pug @@ -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