Skip to content

Commit

Permalink
feat: add hits/sec for cache
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Apr 22, 2023
1 parent 9894d05 commit 94f2e50
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions public/openapi/read/admin/advanced/cache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ get:
type: number
hits:
type: string
hitsPerSecond:
type: number
misses:
type: string
hitRatio:
Expand Down
3 changes: 2 additions & 1 deletion src/controllers/admin/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
19 changes: 11 additions & 8 deletions src/views/admin/advanced/cache.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,28 @@
<input class="form-check-input" type="checkbox" {{{if caches.enabled}}}checked{{{end}}}>
</div>

<div class="mb-3">{{{if ../length}}}{../length}{{{else}}}{../itemCount}{{{end}}} / {{{if ../max}}}{../max}{{{else}}}{../maxSize}{{{end}}}</div>
<div class="mb-3">{{{if ./length}}}{./length}{{{else}}}{./itemCount}{{{end}}} / {{{if ./max}}}{./max}{{{else}}}{./maxSize}{{{end}}}</div>
<div class="progress mb-3" style="height:20px;">
<div class="progress-bar" role="progressbar" aria-valuenow="{../percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {../percentFull}%;">
[[admin/advanced/cache:percent-full, {../percentFull}]]
<div class="progress-bar" role="progressbar" aria-valuenow="{./percentFull}" aria-valuemin="0" aria-valuemax="100" style="width: {./percentFull}%;">
[[admin/advanced/cache:percent-full, {./percentFull}]]
</div>
</div>
<div class="mb-2">
<label>Hits:</label> <span>{../hits}</span>
<label>Hits:</label> <span>{./hits}</span>
</div>
<div class="mb-2">
<label>Misses:</label> <span>{../misses}</span>
<label>Misses:</label> <span>{./misses}</span>
</div>
<div class="mb-2">
<label>Hit Ratio:</label> <span>{../hitRatio}</span>
<label>Hit Ratio:</label> <span>{./hitRatio}</span>
</div>
<div class="mb-2">
<label>Hits / Sec:</label> <span>{./hitsPerSecond}</span>
</div>

{{{if ../ttl}}}
{{{if ./ttl}}}
<div class="mb-2">
<label>TTL:</label> <span>{../ttl}</span>
<label>TTL:</label> <span>{./ttl}</span>
</div>
{{{end}}}
{{{if (@key == "post")}}}
Expand Down

0 comments on commit 94f2e50

Please sign in to comment.