Repository navigation
Expand file tree
/
Copy pathcache_monitor.html
More file actions
192 lines (177 loc) · 6.1 KB
/
Copy pathcache_monitor.html
File metadata and controls
192 lines (177 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>KBI Labs - Cache Monitor</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #0a0a0a;
color: #fff;
margin: 0;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
h1 {
text-align: center;
color: #00ff88;
margin-bottom: 40px;
}
.stats-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: 20px;
margin-bottom: 40px;
}
.stat-card {
background: #1a1a1a;
padding: 30px;
border-radius: 15px;
border: 1px solid #333;
text-align: center;
}
.stat-value {
font-size: 3em;
font-weight: bold;
color: #00ff88;
margin-bottom: 10px;
}
.stat-label {
color: #888;
font-size: 1.1em;
}
.performance-chart {
background: #1a1a1a;
padding: 30px;
border-radius: 15px;
border: 1px solid #333;
height: 400px;
}
#refreshBtn {
position: fixed;
top: 20px;
right: 20px;
background: #00ff88;
color: #000;
border: none;
padding: 10px 20px;
border-radius: 8px;
cursor: pointer;
font-weight: bold;
}
.good { color: #00ff88; }
.warning { color: #ff8800; }
.bad { color: #ff4444; }
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<button id="refreshBtn" onclick="fetchStats()">🔄 Refresh</button>
<div class="container">
<h1>Redis Cache Performance Monitor</h1>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value" id="hitRate">0%</div>
<div class="stat-label">Cache Hit Rate</div>
</div>
<div class="stat-card">
<div class="stat-value" id="totalHits">0</div>
<div class="stat-label">Total Hits</div>
</div>
<div class="stat-card">
<div class="stat-value" id="memory">0MB</div>
<div class="stat-label">Memory Used</div>
</div>
<div class="stat-card">
<div class="stat-value" id="avgSpeed">0ms</div>
<div class="stat-label">Avg Response Time</div>
</div>
</div>
<div class="performance-chart">
<canvas id="performanceChart"></canvas>
</div>
</div>
<script>
let chart;
const maxDataPoints = 20;
let chartData = {
labels: [],
datasets: [{
label: 'Hit Rate %',
data: [],
borderColor: '#00ff88',
backgroundColor: 'rgba(0, 255, 136, 0.1)',
tension: 0.4
}]
};
async function fetchStats() {
try {
const response = await fetch('/api/cache/stats');
const stats = await response.json();
// Update stats
const hitRate = stats.hit_rate || 0;
document.getElementById('hitRate').textContent = hitRate + '%';
document.getElementById('hitRate').className = 'stat-value ' +
(hitRate > 80 ? 'good' : hitRate > 50 ? 'warning' : 'bad');
document.getElementById('totalHits').textContent =
(stats.keyspace_hits || 0).toLocaleString();
document.getElementById('memory').textContent =
stats.used_memory || '0MB';
// Add to chart
const now = new Date().toLocaleTimeString();
chartData.labels.push(now);
chartData.datasets[0].data.push(hitRate);
// Keep only last N points
if (chartData.labels.length > maxDataPoints) {
chartData.labels.shift();
chartData.datasets[0].data.shift();
}
chart.update();
} catch (error) {
console.error('Failed to fetch stats:', error);
}
}
// Initialize chart
window.onload = () => {
const ctx = document.getElementById('performanceChart').getContext('2d');
chart = new Chart(ctx, {
type: 'line',
data: chartData,
options: {
responsive: true,
maintainAspectRatio: false,
plugins: {
title: {
display: true,
text: 'Cache Hit Rate Over Time',
color: '#fff',
font: { size: 16 }
},
legend: { display: false }
},
scales: {
y: {
beginAtZero: true,
max: 100,
grid: { color: '#333' },
ticks: { color: '#888' }
},
x: {
grid: { color: '#333' },
ticks: { color: '#888' }
}
}
}
});
// Initial fetch
fetchStats();
// Auto-refresh every 5 seconds
setInterval(fetchStats, 5000);
};
</script>
</body>
</html>