Display more cache info in web interface

* Show total miss and percent
* Move breakdown into tooltip
* Show item crit, submission, and comment cache stats in breakdown
This commit is contained in:
FoxxMD
2021-08-02 15:44:25 -04:00
parent af1ea5543e
commit 931dfa67fd
4 changed files with 38 additions and 13 deletions

View File

@@ -440,6 +440,8 @@ const rcbServer = function (options: OperatorConfig): ([() => Promise<void>, App
acc[curr].missPercent = `${formatNumber(per, {toFixed: 0})}%`;
return acc;
}, cumRaw);
const cacheReq = subManagerData.reduce((acc, curr) => acc + curr.stats.cache.totalRequests, 0);
const cacheMiss = subManagerData.reduce((acc, curr) => acc + curr.stats.cache.totalMiss, 0);
let allManagerData: any = {
name: 'All',
linkName: 'All',
@@ -463,7 +465,9 @@ const rcbServer = function (options: OperatorConfig): ([() => Promise<void>, App
cache: {
currentKeyCount: await bot.subManagers[0].resources.getCacheKeyCount(),
isShared: false,
totalRequests: subManagerData.reduce((acc, curr) => acc + curr.stats.cache.totalRequests, 0),
totalRequests: cacheReq,
totalMiss: cacheMiss,
missPercent: `${formatNumber(cacheMiss === 0 || cacheReq === 0 ? 0 :(cacheMiss/cacheReq) * 100, {toFixed: 0})}%`,
types: {
...cumRaw,
}

View File

@@ -460,9 +460,32 @@
<span><%= data.stats.cache.currentKeyCount %></span>
<label>Calls</label>
<span><span><%= data.stats.cache.totalRequests %></span> <span>(<%= data.stats.cache.requestRate %>/10min)</span></span>
<label>Missed^</label>
<span><span><%= data.stats.cache.totalMiss %></span> <span>(<%= data.stats.cache.missPercent %>)</span></span>
</div>
<div class="text-left py-2">
<span class="font-semibold">Calls Breakdown</span>
<span class="has-tooltip">
<span style="margin-top:30px;"
class='tooltip rounded shadow-lg p-1 bg-gray-100 text-black -mt-2 space-y-3 p-2'>
<div class="stats">
<label>Author</label>
<span><%= data.stats.cache.types.author.requests %> (<%= data.stats.cache.types.author.missPercent %> miss)</span>
<label>Author Criteria</label>
<span><%= data.stats.cache.types.authorCrit.requests %> (<%= data.stats.cache.types.authorCrit.missPercent %> miss)</span>
<label>Item Criteria</label>
<span><%= data.stats.cache.types.itemCrit.requests %> (<%= data.stats.cache.types.itemCrit.missPercent %> miss)</span>
<label>Submissions</label>
<span><%= data.stats.cache.types.submission.requests %> (<%= data.stats.cache.types.submission.missPercent %> miss)</span>
<label>Comments</label>
<span><%= data.stats.cache.types.comment.requests %> (<%= data.stats.cache.types.comment.missPercent %> miss)</span>
<label>Content</label>
<span><%= data.stats.cache.types.content.requests %> (<%= data.stats.cache.types.content.missPercent %> miss)</span>
<label>UserNote</label>
<span><%= data.stats.cache.types.userNotes.requests %> (<%= data.stats.cache.types.userNotes.missPercent %> miss)</span>
</div>
</span>
<span class="font-semibold underline" style="text-decoration-style: dotted">Calls Breakdown</span>
</span>
<span class="has-tooltip">
<span style="right: 0;"
class='tooltip rounded shadow-lg p-1 bg-gray-100 text-black -mt-2 space-y-3 p-2'>
@@ -502,16 +525,6 @@
</span>
</span>
</div>
<div class="stats">
<label>Author</label>
<span><%= data.stats.cache.types.author.requests %> (<%= data.stats.cache.types.author.missPercent %> miss)</span>
<label>Criteria</label>
<span><%= data.stats.cache.types.authorCrit.requests %> (<%= data.stats.cache.types.authorCrit.missPercent %> miss)</span>
<label>Content</label>
<span><%= data.stats.cache.types.content.requests %> (<%= data.stats.cache.types.content.missPercent %> miss)</span>
<label>UserNote</label>
<span><%= data.stats.cache.types.userNotes.requests %> (<%= data.stats.cache.types.userNotes.missPercent %> miss)</span>
</div>
</div>
</div>
</div>

View File

@@ -158,6 +158,8 @@ export class Manager {
currentKeyCount: 0,
isShared: false,
totalRequests: 0,
totalMiss: 0,
missPercent: '0%',
requestRate: 0,
types: cacheStats()
},

View File

@@ -136,10 +136,16 @@ export class SubredditResources {
}
getStats() {
const totals = Object.values(this.stats.cache).reduce((acc, curr) => ({
miss: acc.miss + curr.miss,
req: acc.req + curr.requests,
}), {miss: 0, req: 0});
return {
cache: {
// TODO could probably combine these two
totalRequests: Object.values(this.stats.cache).reduce((acc, curr) => acc + curr.requests, 0),
totalRequests: totals.req,
totalMiss: totals.miss,
missPercent: `${formatNumber(totals.miss === 0 || totals.req === 0 ? 0 :(totals.miss/totals.req) * 100, {toFixed: 0})}%`,
types: Object.keys(this.stats.cache).reduce((acc, curr) => {
const per = acc[curr].miss === 0 ? 0 : formatNumber(acc[curr].miss / acc[curr].requests) * 100;
// @ts-ignore