From 94f2e50883b7ff2e20594800083c44484f68477c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sat, 22 Apr 2023 16:41:27 -0400 Subject: [PATCH] feat: add hits/sec for cache --- public/openapi/read/admin/advanced/cache.yaml | 2 ++ src/controllers/admin/cache.js | 3 ++- src/views/admin/advanced/cache.tpl | 19 +++++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/public/openapi/read/admin/advanced/cache.yaml b/public/openapi/read/admin/advanced/cache.yaml index 62217e50ae..c80fe41937 100644 --- a/public/openapi/read/admin/advanced/cache.yaml +++ b/public/openapi/read/admin/advanced/cache.yaml @@ -39,6 +39,8 @@ get: type: number hits: type: string + hitsPerSecond: + type: number misses: type: string hitRatio: diff --git a/src/controllers/admin/cache.js b/src/controllers/admin/cache.js index 6d5c385a22..43d6f4ddca 100644 --- a/src/controllers/admin/cache.js +++ b/src/controllers/admin/cache.js @@ -10,7 +10,7 @@ cacheController.get = async function (req, res) { const groupCache = require('../../groups').cache; const { objectCache } = require('../../database'); const localCache = require('../../cache'); - + const uptimeInSeconds = process.uptime(); function getInfo(cache) { return { length: cache.length, @@ -21,6 +21,7 @@ cacheController.get = async function (req, res) { ((cache.length / cache.maxSize) * 100).toFixed(2) : ((cache.itemCount / cache.max) * 100).toFixed(2), hits: utils.addCommas(String(cache.hits)), + hitsPerSecond: (cache.hits / uptimeInSeconds).toFixed(2), misses: utils.addCommas(String(cache.misses)), hitRatio: ((cache.hits / (cache.hits + cache.misses) || 0)).toFixed(4), enabled: cache.enabled, diff --git a/src/views/admin/advanced/cache.tpl b/src/views/admin/advanced/cache.tpl index a1c27d08ae..af1c616847 100644 --- a/src/views/admin/advanced/cache.tpl +++ b/src/views/admin/advanced/cache.tpl @@ -11,25 +11,28 @@ -
{{{if ../length}}}{../length}{{{else}}}{../itemCount}{{{end}}} / {{{if ../max}}}{../max}{{{else}}}{../maxSize}{{{end}}}
+
{{{if ./length}}}{./length}{{{else}}}{./itemCount}{{{end}}} / {{{if ./max}}}{./max}{{{else}}}{./maxSize}{{{end}}}
-
- [[admin/advanced/cache:percent-full, {../percentFull}]] +
+ [[admin/advanced/cache:percent-full, {./percentFull}]]
- {../hits} + {./hits}
- {../misses} + {./misses}
- {../hitRatio} + {./hitRatio} +
+
+ {./hitsPerSecond}
- {{{if ../ttl}}} + {{{if ./ttl}}}
- {../ttl} + {./ttl}
{{{end}}} {{{if (@key == "post")}}}