1577 lines
49 KiB
TypeScript
1577 lines
49 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { config } from './config';
|
|
|
|
export interface StatsData {
|
|
totalRequests: number;
|
|
wentThrough: number;
|
|
failed: number;
|
|
cancelled: number;
|
|
inputTokens: number;
|
|
outputTokens: number;
|
|
totalTokens: number;
|
|
firstRequestAt: string | null;
|
|
lastRequestAt: string | null;
|
|
}
|
|
|
|
export interface StatsSummary {
|
|
requests: {
|
|
total: number;
|
|
wentThrough: number;
|
|
failed: number;
|
|
cancelled: number;
|
|
successRate: number;
|
|
};
|
|
tokens: {
|
|
total: number;
|
|
input: number;
|
|
output: number;
|
|
};
|
|
activeRequests: number;
|
|
uptimeSeconds: number;
|
|
uptimeFormatted: string;
|
|
startedAt: string;
|
|
lastRequestAt: string | null;
|
|
server: {
|
|
model: string;
|
|
configuredKeysCount: number;
|
|
};
|
|
}
|
|
|
|
export interface RequestTracker {
|
|
recordSuccess: (tokens: { input: number; output: number }) => void;
|
|
recordFailure: (reason?: string) => void;
|
|
recordCancelled: (tokens?: { input: number; output: number }) => void;
|
|
}
|
|
|
|
export function estimateTokens(text: string): number {
|
|
if (!text) return 0;
|
|
// Approximation: ~4 characters per token for typical text/code
|
|
return Math.max(1, Math.ceil(text.length / 4));
|
|
}
|
|
|
|
export function estimateMessagesTokens(messages: any[]): number {
|
|
if (!Array.isArray(messages) || messages.length === 0) return 0;
|
|
const fullText = messages
|
|
.map(m => (typeof m.content === 'string' ? m.content : JSON.stringify(m.content || '')))
|
|
.join('\n');
|
|
return estimateTokens(fullText);
|
|
}
|
|
|
|
export class StatsTracker {
|
|
private stats: StatsData = {
|
|
totalRequests: 0,
|
|
wentThrough: 0,
|
|
failed: 0,
|
|
cancelled: 0,
|
|
inputTokens: 0,
|
|
outputTokens: 0,
|
|
totalTokens: 0,
|
|
firstRequestAt: null,
|
|
lastRequestAt: null
|
|
};
|
|
|
|
private activeRequests: number = 0;
|
|
private serverStartedAt: Date = new Date();
|
|
private statsFilePath: string;
|
|
private saveTimeout: NodeJS.Timeout | null = null;
|
|
|
|
constructor() {
|
|
this.statsFilePath = path.join(config.logDir, 'stats.json');
|
|
this.ensureLogDir();
|
|
this.loadStats();
|
|
|
|
// Ensure save on process termination
|
|
process.on('SIGINT', () => this.saveSync());
|
|
process.on('SIGTERM', () => this.saveSync());
|
|
}
|
|
|
|
private ensureLogDir(): void {
|
|
if (!fs.existsSync(config.logDir)) {
|
|
try {
|
|
fs.mkdirSync(config.logDir, { recursive: true });
|
|
} catch (err) {
|
|
console.error('[STATS] Failed to create log directory:', err);
|
|
}
|
|
}
|
|
}
|
|
|
|
private loadStats(): void {
|
|
try {
|
|
if (fs.existsSync(this.statsFilePath)) {
|
|
const raw = fs.readFileSync(this.statsFilePath, 'utf8');
|
|
const parsed = JSON.parse(raw);
|
|
this.stats = {
|
|
totalRequests: Number(parsed.totalRequests) || 0,
|
|
wentThrough: Number(parsed.wentThrough) || 0,
|
|
failed: Number(parsed.failed) || 0,
|
|
cancelled: Number(parsed.cancelled) || 0,
|
|
inputTokens: Number(parsed.inputTokens) || 0,
|
|
outputTokens: Number(parsed.outputTokens) || 0,
|
|
totalTokens: Number(parsed.totalTokens) || 0,
|
|
firstRequestAt: parsed.firstRequestAt || null,
|
|
lastRequestAt: parsed.lastRequestAt || null
|
|
};
|
|
// Sanity check total calculation
|
|
if (this.stats.totalRequests < (this.stats.wentThrough + this.stats.failed + this.stats.cancelled)) {
|
|
this.stats.totalRequests = this.stats.wentThrough + this.stats.failed + this.stats.cancelled;
|
|
}
|
|
if (this.stats.totalTokens < (this.stats.inputTokens + this.stats.outputTokens)) {
|
|
this.stats.totalTokens = this.stats.inputTokens + this.stats.outputTokens;
|
|
}
|
|
console.log('[STATS] Loaded existing stats from disk:', {
|
|
requests: this.stats.totalRequests,
|
|
tokens: this.stats.totalTokens
|
|
});
|
|
return;
|
|
}
|
|
|
|
// If stats.json does not exist, check if there are historical log files
|
|
this.rebuildFromExistingLogs();
|
|
} catch (err) {
|
|
console.error('[STATS] Error loading stats file, initializing fresh stats:', err);
|
|
}
|
|
}
|
|
|
|
private rebuildFromExistingLogs(): void {
|
|
try {
|
|
if (!fs.existsSync(config.logDir)) return;
|
|
const files = fs.readdirSync(config.logDir).filter(f => f.startsWith('api-logs-') && f.endsWith('.json'));
|
|
if (files.length === 0) return;
|
|
|
|
console.log(`[STATS] Scanning ${files.length} existing log file(s) to aggregate initial stats...`);
|
|
for (const file of files) {
|
|
const filePath = path.join(config.logDir, file);
|
|
const content = fs.readFileSync(filePath, 'utf8');
|
|
const lines = content.split('\n');
|
|
|
|
for (const line of lines) {
|
|
if (!line.trim()) continue;
|
|
try {
|
|
const entry = JSON.parse(line);
|
|
if (entry.type === 'response') {
|
|
const status = entry.data?.statusCode || 200;
|
|
if (status >= 200 && status < 400) {
|
|
this.stats.wentThrough++;
|
|
const usage = entry.data?.response?.usage;
|
|
if (usage) {
|
|
this.stats.inputTokens += Number(usage.prompt_tokens) || 0;
|
|
this.stats.outputTokens += Number(usage.completion_tokens) || 0;
|
|
}
|
|
} else {
|
|
this.stats.failed++;
|
|
}
|
|
if (!this.stats.firstRequestAt || entry.timestamp < this.stats.firstRequestAt) {
|
|
this.stats.firstRequestAt = entry.timestamp;
|
|
}
|
|
if (!this.stats.lastRequestAt || entry.timestamp > this.stats.lastRequestAt) {
|
|
this.stats.lastRequestAt = entry.timestamp;
|
|
}
|
|
} else if (entry.type === 'error') {
|
|
this.stats.failed++;
|
|
if (!this.stats.lastRequestAt || entry.timestamp > this.stats.lastRequestAt) {
|
|
this.stats.lastRequestAt = entry.timestamp;
|
|
}
|
|
}
|
|
} catch {
|
|
// ignore malformed line
|
|
}
|
|
}
|
|
}
|
|
|
|
this.stats.totalRequests = this.stats.wentThrough + this.stats.failed + this.stats.cancelled;
|
|
this.stats.totalTokens = this.stats.inputTokens + this.stats.outputTokens;
|
|
this.saveSync();
|
|
console.log('[STATS] Rebuilt historical stats successfully:', {
|
|
requests: this.stats.totalRequests,
|
|
tokens: this.stats.totalTokens
|
|
});
|
|
} catch (err) {
|
|
console.error('[STATS] Error scanning historical logs:', err);
|
|
}
|
|
}
|
|
|
|
private scheduleSave(): void {
|
|
if (this.saveTimeout) return;
|
|
this.saveTimeout = setTimeout(() => {
|
|
this.saveTimeout = null;
|
|
this.saveSync();
|
|
}, 1000);
|
|
}
|
|
|
|
public saveSync(): void {
|
|
try {
|
|
this.ensureLogDir();
|
|
const tmpPath = `${this.statsFilePath}.tmp`;
|
|
fs.writeFileSync(tmpPath, JSON.stringify(this.stats, null, 2), 'utf8');
|
|
fs.renameSync(tmpPath, this.statsFilePath);
|
|
} catch (err) {
|
|
console.error('[STATS] Error saving stats to file:', err);
|
|
}
|
|
}
|
|
|
|
private updateTimestamps(): void {
|
|
const now = new Date().toISOString();
|
|
if (!this.stats.firstRequestAt) {
|
|
this.stats.firstRequestAt = now;
|
|
}
|
|
this.stats.lastRequestAt = now;
|
|
}
|
|
|
|
public startRequest(endpoint?: string): RequestTracker {
|
|
this.activeRequests++;
|
|
let resolved = false;
|
|
|
|
return {
|
|
recordSuccess: (tokens: { input: number; output: number }) => {
|
|
if (resolved) return;
|
|
resolved = true;
|
|
this.activeRequests = Math.max(0, this.activeRequests - 1);
|
|
this.stats.totalRequests++;
|
|
this.stats.wentThrough++;
|
|
const safeInput = Math.max(0, Math.round(tokens.input || 0));
|
|
const safeOutput = Math.max(0, Math.round(tokens.output || 0));
|
|
this.stats.inputTokens += safeInput;
|
|
this.stats.outputTokens += safeOutput;
|
|
this.stats.totalTokens += safeInput + safeOutput;
|
|
this.updateTimestamps();
|
|
this.scheduleSave();
|
|
},
|
|
|
|
recordFailure: (_reason?: string) => {
|
|
if (resolved) return;
|
|
resolved = true;
|
|
this.activeRequests = Math.max(0, this.activeRequests - 1);
|
|
this.stats.totalRequests++;
|
|
this.stats.failed++;
|
|
this.updateTimestamps();
|
|
this.scheduleSave();
|
|
},
|
|
|
|
recordCancelled: (tokens?: { input: number; output: number }) => {
|
|
if (resolved) return;
|
|
resolved = true;
|
|
this.activeRequests = Math.max(0, this.activeRequests - 1);
|
|
this.stats.totalRequests++;
|
|
this.stats.cancelled++;
|
|
if (tokens) {
|
|
const safeInput = Math.max(0, Math.round(tokens.input || 0));
|
|
const safeOutput = Math.max(0, Math.round(tokens.output || 0));
|
|
this.stats.inputTokens += safeInput;
|
|
this.stats.outputTokens += safeOutput;
|
|
this.stats.totalTokens += safeInput + safeOutput;
|
|
}
|
|
this.updateTimestamps();
|
|
this.scheduleSave();
|
|
}
|
|
};
|
|
}
|
|
|
|
public recordDirectSuccess(tokens: { input: number; output: number }, _endpoint?: string): void {
|
|
this.stats.totalRequests++;
|
|
this.stats.wentThrough++;
|
|
const safeInput = Math.max(0, Math.round(tokens.input || 0));
|
|
const safeOutput = Math.max(0, Math.round(tokens.output || 0));
|
|
this.stats.inputTokens += safeInput;
|
|
this.stats.outputTokens += safeOutput;
|
|
this.stats.totalTokens += safeInput + safeOutput;
|
|
this.updateTimestamps();
|
|
this.scheduleSave();
|
|
}
|
|
|
|
public recordDirectFailure(_reason?: string, _endpoint?: string): void {
|
|
this.stats.totalRequests++;
|
|
this.stats.failed++;
|
|
this.updateTimestamps();
|
|
this.scheduleSave();
|
|
}
|
|
|
|
public recordDirectCancelled(tokens?: { input: number; output: number }, _endpoint?: string): void {
|
|
this.stats.totalRequests++;
|
|
this.stats.cancelled++;
|
|
if (tokens) {
|
|
const safeInput = Math.max(0, Math.round(tokens.input || 0));
|
|
const safeOutput = Math.max(0, Math.round(tokens.output || 0));
|
|
this.stats.inputTokens += safeInput;
|
|
this.stats.outputTokens += safeOutput;
|
|
this.stats.totalTokens += safeInput + safeOutput;
|
|
}
|
|
this.updateTimestamps();
|
|
this.scheduleSave();
|
|
}
|
|
|
|
public getStatsSummary(): StatsSummary {
|
|
const total = this.stats.totalRequests;
|
|
const wentThrough = this.stats.wentThrough;
|
|
const failed = this.stats.failed;
|
|
const cancelled = this.stats.cancelled;
|
|
const successRate = total > 0 ? Number(((wentThrough / total) * 100).toFixed(1)) : 100.0;
|
|
|
|
const uptimeSeconds = Math.floor((Date.now() - this.serverStartedAt.getTime()) / 1000);
|
|
const uptimeFormatted = this.formatUptime(uptimeSeconds);
|
|
|
|
return {
|
|
requests: {
|
|
total,
|
|
wentThrough,
|
|
failed,
|
|
cancelled,
|
|
successRate
|
|
},
|
|
tokens: {
|
|
total: this.stats.totalTokens,
|
|
input: this.stats.inputTokens,
|
|
output: this.stats.outputTokens
|
|
},
|
|
activeRequests: this.activeRequests,
|
|
uptimeSeconds,
|
|
uptimeFormatted,
|
|
startedAt: this.serverStartedAt.toISOString(),
|
|
lastRequestAt: this.stats.lastRequestAt,
|
|
server: {
|
|
model: config.model,
|
|
configuredKeysCount: config.geminiApiKeys.length
|
|
}
|
|
};
|
|
}
|
|
|
|
private formatUptime(seconds: number): string {
|
|
const d = Math.floor(seconds / 86400);
|
|
const h = Math.floor((seconds % 86400) / 3600);
|
|
const m = Math.floor((seconds % 3600) / 60);
|
|
const s = seconds % 60;
|
|
if (d > 0) return `${d}d ${h}h ${m}m`;
|
|
if (h > 0) return `${h}h ${m}m ${s}s`;
|
|
if (m > 0) return `${m}m ${s}s`;
|
|
return `${s}s`;
|
|
}
|
|
|
|
public renderStatsHtml(summary: StatsSummary): string {
|
|
const { requests, tokens, activeRequests, uptimeFormatted, lastRequestAt, server } = summary;
|
|
|
|
const wentThroughPct = requests.total > 0 ? ((requests.wentThrough / requests.total) * 100).toFixed(1) : '100.0';
|
|
const failedPct = requests.total > 0 ? ((requests.failed / requests.total) * 100).toFixed(1) : '0.0';
|
|
const cancelledPct = requests.total > 0 ? ((requests.cancelled / requests.total) * 100).toFixed(1) : '0.0';
|
|
|
|
const inputTokensPct = tokens.total > 0 ? ((tokens.input / tokens.total) * 100).toFixed(1) : '50.0';
|
|
const outputTokensPct = tokens.total > 0 ? ((tokens.output / tokens.total) * 100).toFixed(1) : '50.0';
|
|
|
|
return `<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>GeminiRevolver — API Telemetry & Statistics</title>
|
|
<link rel="icon" type="image/svg+xml" href="/favicon.ico">
|
|
<link rel="stylesheet" href="https://storage.gsdistance.org/store/icons/css/all.min.css">
|
|
<style>
|
|
:root {
|
|
--primary-color: #bb86fc;
|
|
--primary-hover: #cf9eff;
|
|
--background-dark: #121212;
|
|
--background-light: #ffffff;
|
|
--text-dark: #e0e0e0;
|
|
--text-light: #121212;
|
|
--card-dark: #1f1b24;
|
|
--card-light: #f5f5f5;
|
|
--border-dark: rgba(187, 134, 252, 0.12);
|
|
--border-light: rgba(187, 134, 252, 0.22);
|
|
--muted-dark: #9e9e9e;
|
|
--muted-light: #616161;
|
|
--nav-bg-dark: rgba(18, 18, 18, 0.95);
|
|
--nav-bg-light: rgba(255, 255, 255, 0.95);
|
|
--accent-success: #03dac6;
|
|
--accent-warning: #ffb74d;
|
|
--accent-danger: #cf6679;
|
|
--accent-input: #bb86fc;
|
|
--accent-output: #03dac6;
|
|
}
|
|
|
|
body.light-theme {
|
|
--accent-success: #00897b;
|
|
--accent-warning: #f57c00;
|
|
--accent-danger: #d32f2f;
|
|
--accent-input: #7c4dff;
|
|
--accent-output: #00897b;
|
|
}
|
|
|
|
* {
|
|
box-sizing: border-box;
|
|
margin: 0;
|
|
padding: 0;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
|
|
font-size: 16px;
|
|
line-height: 1.6;
|
|
background-color: var(--background-dark);
|
|
color: var(--text-dark);
|
|
min-height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
transition: background-color 0.3s ease, color 0.3s ease;
|
|
overflow-x: hidden;
|
|
}
|
|
|
|
body.light-theme {
|
|
background-color: var(--background-light);
|
|
color: var(--text-light);
|
|
}
|
|
|
|
/* Navbar */
|
|
.navbar {
|
|
position: sticky;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 1rem 2rem;
|
|
background: var(--nav-bg-dark);
|
|
backdrop-filter: blur(10px);
|
|
-webkit-backdrop-filter: blur(10px);
|
|
border-bottom: 1px solid var(--border-dark);
|
|
z-index: 1000;
|
|
transition: background-color 0.3s ease, border-color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .navbar {
|
|
background: var(--nav-bg-light);
|
|
border-bottom-color: var(--border-light);
|
|
}
|
|
|
|
.brand-wrap {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.brand-link {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.65rem;
|
|
text-decoration: none;
|
|
color: var(--primary-color);
|
|
font-size: 1.3rem;
|
|
font-weight: 700;
|
|
letter-spacing: -0.01em;
|
|
}
|
|
|
|
.brand-link span {
|
|
color: var(--text-dark);
|
|
font-weight: 400;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .brand-link span {
|
|
color: var(--text-light);
|
|
}
|
|
|
|
.brand-icon {
|
|
width: 32px;
|
|
height: 32px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.live-badge {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.4rem;
|
|
padding: 0.25rem 0.65rem;
|
|
border-radius: 20px;
|
|
font-size: 0.72rem;
|
|
font-weight: 600;
|
|
letter-spacing: 0.05em;
|
|
text-transform: uppercase;
|
|
background: rgba(3, 218, 198, 0.12);
|
|
color: var(--accent-success);
|
|
border: 1px solid rgba(3, 218, 198, 0.25);
|
|
}
|
|
|
|
.live-dot {
|
|
width: 7px;
|
|
height: 7px;
|
|
border-radius: 50%;
|
|
background-color: var(--accent-success);
|
|
box-shadow: 0 0 8px var(--accent-success);
|
|
animation: pulse-glow 2s infinite;
|
|
}
|
|
|
|
@keyframes pulse-glow {
|
|
0% { transform: scale(0.95); opacity: 0.8; }
|
|
50% { transform: scale(1.15); opacity: 1; }
|
|
100% { transform: scale(0.95); opacity: 0.8; }
|
|
}
|
|
|
|
.nav-actions {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.85rem;
|
|
}
|
|
|
|
.nav-links {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
.nav-links a {
|
|
color: var(--text-dark);
|
|
text-decoration: none;
|
|
font-size: 0.95rem;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .nav-links a {
|
|
color: var(--text-light);
|
|
}
|
|
|
|
.nav-links a:hover {
|
|
color: var(--primary-color);
|
|
}
|
|
|
|
.action-btn {
|
|
background: var(--card-dark);
|
|
color: var(--text-dark);
|
|
border: 1px solid var(--border-dark);
|
|
padding: 0.45rem 0.85rem;
|
|
border-radius: 20px;
|
|
font-size: 0.8125rem;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
transition: all 0.25s ease;
|
|
}
|
|
|
|
body.light-theme .action-btn {
|
|
background: var(--card-light);
|
|
color: var(--text-light);
|
|
border-color: var(--border-light);
|
|
}
|
|
|
|
.action-btn:hover {
|
|
border-color: var(--primary-color);
|
|
color: var(--primary-color);
|
|
box-shadow: 0 2px 8px rgba(187, 134, 252, 0.15);
|
|
}
|
|
|
|
.action-btn.active {
|
|
background: rgba(187, 134, 252, 0.12);
|
|
border-color: var(--primary-color);
|
|
color: var(--primary-color);
|
|
}
|
|
|
|
.auto-dot {
|
|
width: 6px;
|
|
height: 6px;
|
|
border-radius: 50%;
|
|
background: var(--primary-color);
|
|
animation: pulse-glow 2s infinite;
|
|
}
|
|
|
|
/* GsDistance Theme Toggle Button */
|
|
.theme-toggle {
|
|
background: var(--card-dark);
|
|
border: 2px solid var(--primary-color);
|
|
color: var(--primary-color);
|
|
width: 40px;
|
|
height: 40px;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
box-shadow: 0 0 10px rgba(187, 134, 252, 0.2);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
body.light-theme .theme-toggle {
|
|
background: var(--card-light);
|
|
}
|
|
|
|
.theme-toggle:hover {
|
|
transform: rotate(360deg);
|
|
background: var(--primary-color);
|
|
color: var(--background-dark);
|
|
box-shadow: 0 0 20px rgba(187, 134, 252, 0.4);
|
|
}
|
|
|
|
.theme-toggle i {
|
|
font-size: 1.15rem;
|
|
}
|
|
|
|
/* Hero Section */
|
|
.hero {
|
|
text-align: center;
|
|
padding: 4.5rem 1.5rem 3rem;
|
|
background: linear-gradient(45deg, #18151f, #221c2b);
|
|
border-bottom: 1px solid var(--border-dark);
|
|
transition: background 0.3s ease, border-color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .hero {
|
|
background: linear-gradient(45deg, #f3ebfc, #ece2f7);
|
|
border-bottom-color: var(--border-light);
|
|
}
|
|
|
|
.hero h1 {
|
|
font-size: 2.85rem;
|
|
font-weight: 700;
|
|
color: var(--primary-color);
|
|
margin-bottom: 0.6rem;
|
|
letter-spacing: -0.02em;
|
|
}
|
|
|
|
.hero .subtitle {
|
|
font-size: 1.15rem;
|
|
color: var(--muted-dark);
|
|
max-width: 650px;
|
|
margin: 0 auto 1.75rem;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .hero .subtitle {
|
|
color: var(--muted-light);
|
|
}
|
|
|
|
.hero-meta-row {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
justify-content: center;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.meta-chip {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
padding: 0.4rem 1rem;
|
|
border-radius: 20px;
|
|
background: var(--card-dark);
|
|
border: 1px solid var(--border-dark);
|
|
font-size: 0.85rem;
|
|
color: var(--text-dark);
|
|
transition: all 0.25s ease;
|
|
}
|
|
|
|
body.light-theme .meta-chip {
|
|
background: var(--card-light);
|
|
border-color: var(--border-light);
|
|
color: var(--text-light);
|
|
}
|
|
|
|
.meta-chip i {
|
|
color: var(--primary-color);
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
/* Main Container */
|
|
main {
|
|
max-width: 1140px;
|
|
width: 100%;
|
|
margin: 0 auto;
|
|
padding: 3rem 1.5rem 4rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 2.5rem;
|
|
}
|
|
|
|
/* KPI Metrics Grid */
|
|
.metrics-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
.metric-card {
|
|
background: var(--card-dark);
|
|
border: 1px solid var(--border-dark);
|
|
border-radius: 12px;
|
|
padding: 1.6rem 1.5rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
justify-content: space-between;
|
|
transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease, background-color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .metric-card {
|
|
background: var(--card-light);
|
|
border-color: var(--border-light);
|
|
}
|
|
|
|
.metric-card:hover {
|
|
transform: translateY(-5px);
|
|
border-color: var(--primary-color);
|
|
box-shadow: 0 8px 20px rgba(187, 134, 252, 0.2);
|
|
}
|
|
|
|
.metric-head {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 0.75rem;
|
|
}
|
|
|
|
.metric-title {
|
|
font-size: 0.8rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
color: var(--muted-dark);
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .metric-title {
|
|
color: var(--muted-light);
|
|
}
|
|
|
|
.metric-icon {
|
|
color: var(--primary-color);
|
|
font-size: 1.25rem;
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.metric-value {
|
|
font-size: 2.35rem;
|
|
font-weight: 700;
|
|
line-height: 1.15;
|
|
color: var(--text-dark);
|
|
letter-spacing: -0.02em;
|
|
margin-bottom: 0.75rem;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .metric-value {
|
|
color: var(--text-light);
|
|
}
|
|
|
|
.metric-sub {
|
|
font-size: 0.825rem;
|
|
color: var(--muted-dark);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
flex-wrap: wrap;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .metric-sub {
|
|
color: var(--muted-light);
|
|
}
|
|
|
|
.stat-tag {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.35rem;
|
|
}
|
|
|
|
.indicator-dot {
|
|
width: 7px;
|
|
height: 7px;
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
}
|
|
|
|
.dot-success { background-color: var(--accent-success); }
|
|
.dot-danger { background-color: var(--accent-danger); }
|
|
.dot-warning { background-color: var(--accent-warning); }
|
|
.dot-primary { background-color: var(--primary-color); }
|
|
|
|
/* Breakdown Section (2-Column Grid) */
|
|
.breakdown-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
|
|
gap: 1.75rem;
|
|
}
|
|
|
|
@media (max-width: 600px) {
|
|
.breakdown-grid {
|
|
grid-template-columns: 1fr;
|
|
}
|
|
}
|
|
|
|
.breakdown-card {
|
|
background: var(--card-dark);
|
|
border: 1px solid var(--border-dark);
|
|
border-radius: 12px;
|
|
padding: 1.75rem;
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 1.4rem;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .breakdown-card {
|
|
background: var(--card-light);
|
|
border-color: var(--border-light);
|
|
}
|
|
|
|
.breakdown-card:hover {
|
|
border-color: rgba(187, 134, 252, 0.35);
|
|
box-shadow: 0 6px 18px rgba(187, 134, 252, 0.12);
|
|
}
|
|
|
|
.breakdown-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
}
|
|
|
|
.breakdown-title {
|
|
font-size: 1.15rem;
|
|
font-weight: 600;
|
|
color: var(--primary-color);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.65rem;
|
|
}
|
|
|
|
.pill-counter {
|
|
font-size: 0.78rem;
|
|
font-weight: 600;
|
|
padding: 0.3rem 0.75rem;
|
|
border-radius: 20px;
|
|
background: rgba(187, 134, 252, 0.1);
|
|
color: var(--primary-color);
|
|
border: 1px solid rgba(187, 134, 252, 0.2);
|
|
}
|
|
|
|
/* Segmented Bar */
|
|
.progress-bar-wrap {
|
|
height: 8px;
|
|
width: 100%;
|
|
background-color: rgba(255, 255, 255, 0.06);
|
|
border-radius: 4px;
|
|
overflow: hidden;
|
|
display: flex;
|
|
}
|
|
|
|
body.light-theme .progress-bar-wrap {
|
|
background-color: rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.bar-segment {
|
|
height: 100%;
|
|
transition: width 0.4s ease;
|
|
}
|
|
|
|
.bar-success { background-color: var(--accent-success); }
|
|
.bar-danger { background-color: var(--accent-danger); }
|
|
.bar-warning { background-color: var(--accent-warning); }
|
|
.bar-input { background-color: var(--accent-input); }
|
|
.bar-output { background-color: var(--accent-output); }
|
|
|
|
.breakdown-rows {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.75rem;
|
|
}
|
|
|
|
.breakdown-item {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 0.8rem 1rem;
|
|
background: rgba(255, 255, 255, 0.03);
|
|
border-radius: 8px;
|
|
border: 1px solid rgba(255, 255, 255, 0.05);
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
body.light-theme .breakdown-item {
|
|
background: #ffffff;
|
|
border-color: rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
.breakdown-label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
font-size: 0.88rem;
|
|
font-weight: 500;
|
|
color: var(--text-dark);
|
|
}
|
|
|
|
body.light-theme .breakdown-label {
|
|
color: var(--text-light);
|
|
}
|
|
|
|
.breakdown-values {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.75rem;
|
|
font-weight: 600;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.pct-tag {
|
|
font-size: 0.75rem;
|
|
font-weight: 600;
|
|
color: var(--muted-dark);
|
|
background: rgba(255, 255, 255, 0.06);
|
|
padding: 0.18rem 0.5rem;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
body.light-theme .pct-tag {
|
|
color: var(--muted-light);
|
|
background: rgba(0, 0, 0, 0.06);
|
|
}
|
|
|
|
/* System Details Card */
|
|
.system-card {
|
|
background: var(--card-dark);
|
|
border: 1px solid var(--border-dark);
|
|
border-radius: 12px;
|
|
padding: 1.75rem;
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
|
|
gap: 1.5rem;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .system-card {
|
|
background: var(--card-light);
|
|
border-color: var(--border-light);
|
|
}
|
|
|
|
.system-item {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.35rem;
|
|
}
|
|
|
|
.system-label {
|
|
font-size: 0.75rem;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
color: var(--muted-dark);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
body.light-theme .system-label {
|
|
color: var(--muted-light);
|
|
}
|
|
|
|
.system-label i {
|
|
color: var(--primary-color);
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
.system-val {
|
|
font-size: 1rem;
|
|
font-weight: 600;
|
|
color: var(--text-dark);
|
|
}
|
|
|
|
body.light-theme .system-val {
|
|
color: var(--text-light);
|
|
}
|
|
|
|
/* Privacy Banner */
|
|
.privacy-banner {
|
|
background: var(--card-dark);
|
|
border: 1px solid var(--border-dark);
|
|
border-radius: 12px;
|
|
padding: 1.25rem 1.6rem;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 1.25rem;
|
|
font-size: 0.88rem;
|
|
color: var(--muted-dark);
|
|
line-height: 1.55;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .privacy-banner {
|
|
background: var(--card-light);
|
|
border-color: var(--border-light);
|
|
color: var(--muted-light);
|
|
}
|
|
|
|
.privacy-icon {
|
|
color: var(--primary-color);
|
|
font-size: 1.5rem;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.privacy-text strong {
|
|
color: var(--text-dark);
|
|
}
|
|
|
|
body.light-theme .privacy-text strong {
|
|
color: var(--text-light);
|
|
}
|
|
|
|
/* Footer - GsDistance Theme */
|
|
footer {
|
|
background: var(--card-dark);
|
|
border-top: 1px solid var(--border-dark);
|
|
padding: 2.5rem 1.5rem 2rem;
|
|
margin-top: auto;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
body.light-theme footer {
|
|
background: var(--card-light);
|
|
border-top-color: var(--border-light);
|
|
}
|
|
|
|
.footer-content {
|
|
max-width: 1140px;
|
|
margin: 0 auto;
|
|
text-align: center;
|
|
}
|
|
|
|
.footer-links {
|
|
display: flex;
|
|
justify-content: center;
|
|
gap: 2rem;
|
|
margin-bottom: 1.25rem;
|
|
flex-wrap: wrap;
|
|
}
|
|
|
|
.footer-links a {
|
|
color: var(--text-dark);
|
|
text-decoration: none;
|
|
font-size: 0.95rem;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .footer-links a {
|
|
color: var(--text-light);
|
|
}
|
|
|
|
.footer-links a:hover {
|
|
color: var(--primary-color);
|
|
}
|
|
|
|
.social-links {
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.social-links a {
|
|
color: var(--primary-color);
|
|
font-size: 1.15rem;
|
|
margin: 0 0.75rem;
|
|
text-decoration: none;
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 0.45rem;
|
|
transition: transform 0.3s ease, opacity 0.3s ease;
|
|
}
|
|
|
|
.social-links a:hover {
|
|
transform: translateY(-2px);
|
|
opacity: 0.85;
|
|
}
|
|
|
|
.copyright {
|
|
color: var(--muted-dark);
|
|
font-size: 0.85rem;
|
|
transition: color 0.3s ease;
|
|
}
|
|
|
|
body.light-theme .copyright {
|
|
color: var(--muted-light);
|
|
}
|
|
|
|
/* Responsive */
|
|
@media (max-width: 768px) {
|
|
.navbar {
|
|
padding: 0.85rem 1.25rem;
|
|
}
|
|
.nav-links {
|
|
display: none;
|
|
}
|
|
.hero {
|
|
padding: 3rem 1rem 2rem;
|
|
}
|
|
.hero h1 {
|
|
font-size: 2.15rem;
|
|
}
|
|
main {
|
|
padding: 2rem 1rem 3rem;
|
|
gap: 2rem;
|
|
}
|
|
.footer-links {
|
|
gap: 1.25rem;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Header / Navbar -->
|
|
<header class="navbar">
|
|
<div class="brand-wrap">
|
|
<a href="/" class="brand-link" title="GeminiRevolver Home">
|
|
<div class="brand-icon">
|
|
<svg width="30" height="30" viewBox="0 0 32 32" fill="none">
|
|
<circle cx="16" cy="16" r="14" stroke="var(--primary-color)" stroke-width="2.2"/>
|
|
<circle cx="16" cy="16" r="4" fill="var(--primary-color)"/>
|
|
<circle cx="16" cy="7" r="2.5" fill="var(--primary-color)"/>
|
|
<circle cx="23.8" cy="11.5" r="2.5" fill="var(--primary-color)"/>
|
|
<circle cx="23.8" cy="20.5" r="2.5" fill="var(--primary-color)"/>
|
|
<circle cx="16" cy="25" r="2.5" fill="var(--primary-color)"/>
|
|
<circle cx="8.2" cy="20.5" r="2.5" fill="var(--primary-color)"/>
|
|
<circle cx="8.2" cy="11.5" r="2.5" fill="var(--primary-color)"/>
|
|
</svg>
|
|
</div>
|
|
Gemini<span>Revolver</span>
|
|
</a>
|
|
<span class="live-badge">
|
|
<span class="live-dot"></span>
|
|
Live
|
|
</span>
|
|
</div>
|
|
|
|
<div class="nav-actions">
|
|
<div class="nav-links">
|
|
<a href="/api/stats" target="_blank" title="View raw JSON API">JSON API</a>
|
|
<a href="/health" target="_blank" title="View gateway health status">Health</a>
|
|
</div>
|
|
<button id="refresh-btn" class="action-btn" title="Refresh metrics" aria-label="Refresh metrics">
|
|
<i class="fas fa-sync-alt" id="refresh-icon"></i>
|
|
</button>
|
|
<button id="auto-btn" class="action-btn active" title="Toggle automatic 5s refresh" aria-label="Toggle auto refresh">
|
|
<span class="auto-dot"></span>
|
|
<span id="auto-text">Auto (5s)</span>
|
|
</button>
|
|
<button class="theme-toggle" id="theme-toggle" title="Toggle dark/light theme" aria-label="Toggle theme">
|
|
<i class="fas fa-sun" id="theme-icon"></i>
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
<!-- Hero Section -->
|
|
<section class="hero">
|
|
<h1>GeminiRevolver</h1>
|
|
<p class="subtitle">OpenAI v1 Compatible Gemini Key Rotation Gateway</p>
|
|
<div class="hero-meta-row">
|
|
<div class="meta-chip">
|
|
<i class="fas fa-microchip"></i>
|
|
<span>Model: <strong>${server.model}</strong></span>
|
|
</div>
|
|
<div class="meta-chip">
|
|
<i class="fas fa-key"></i>
|
|
<span>Key Pool: <strong>${server.configuredKeysCount} Keys Rotating</strong></span>
|
|
</div>
|
|
<div class="meta-chip">
|
|
<i class="fas fa-clock"></i>
|
|
<span>Uptime: <strong id="val-uptime-chip">${uptimeFormatted}</strong></span>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<!-- Main Content -->
|
|
<main>
|
|
<!-- KPI Summary Grid -->
|
|
<div class="metrics-grid">
|
|
<!-- Total Requests -->
|
|
<div class="metric-card">
|
|
<div class="metric-head">
|
|
<span class="metric-title">Total Requests</span>
|
|
<i class="fas fa-exchange-alt metric-icon"></i>
|
|
</div>
|
|
<div class="metric-value" id="val-total-reqs">${requests.total.toLocaleString()}</div>
|
|
<div class="metric-sub">
|
|
<span class="stat-tag"><span class="indicator-dot dot-success"></span> <strong id="sub-went">${requests.wentThrough.toLocaleString()}</strong> ok</span>
|
|
<span>•</span>
|
|
<span class="stat-tag"><span class="indicator-dot dot-danger"></span> <strong id="sub-failed">${requests.failed.toLocaleString()}</strong> err</span>
|
|
<span>•</span>
|
|
<span class="stat-tag"><span class="indicator-dot dot-warning"></span> <strong id="sub-cancelled">${requests.cancelled.toLocaleString()}</strong> drop</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Success Rate -->
|
|
<div class="metric-card">
|
|
<div class="metric-head">
|
|
<span class="metric-title">Success Rate</span>
|
|
<i class="fas fa-chart-line metric-icon"></i>
|
|
</div>
|
|
<div class="metric-value" id="val-success-rate">${requests.successRate}%</div>
|
|
<div class="metric-sub">
|
|
<span>Completed vs total incoming calls</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Total Tokens -->
|
|
<div class="metric-card">
|
|
<div class="metric-head">
|
|
<span class="metric-title">Total Tokens</span>
|
|
<i class="fas fa-coins metric-icon"></i>
|
|
</div>
|
|
<div class="metric-value" id="val-total-tokens">${tokens.total.toLocaleString()}</div>
|
|
<div class="metric-sub">
|
|
<span>In: <strong id="sub-input">${tokens.input.toLocaleString()}</strong></span>
|
|
<span>•</span>
|
|
<span>Out: <strong id="sub-output">${tokens.output.toLocaleString()}</strong></span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Active In-Flight -->
|
|
<div class="metric-card">
|
|
<div class="metric-head">
|
|
<span class="metric-title">Active In-Flight</span>
|
|
<i class="fas fa-bolt metric-icon"></i>
|
|
</div>
|
|
<div class="metric-value" id="val-active-reqs">${activeRequests}</div>
|
|
<div class="metric-sub">
|
|
<span id="sub-active-desc">${activeRequests === 0 ? 'Idle • Ready for requests' : 'Processing active completions'}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Detailed Breakdowns -->
|
|
<div class="breakdown-grid">
|
|
<!-- Request Distribution -->
|
|
<div class="breakdown-card">
|
|
<div class="breakdown-header">
|
|
<div class="breakdown-title">
|
|
<i class="fas fa-chart-pie"></i>
|
|
Request Breakdown
|
|
</div>
|
|
<span class="pill-counter" id="detail-total-reqs-badge">${requests.total.toLocaleString()} total</span>
|
|
</div>
|
|
|
|
<div class="progress-bar-wrap">
|
|
<div id="bar-went" class="bar-segment bar-success" style="width: ${wentThroughPct}%;" title="Completed: ${wentThroughPct}%"></div>
|
|
<div id="bar-failed" class="bar-segment bar-danger" style="width: ${failedPct}%;" title="Failed: ${failedPct}%"></div>
|
|
<div id="bar-cancelled" class="bar-segment bar-warning" style="width: ${cancelledPct}%;" title="Cancelled: ${cancelledPct}%"></div>
|
|
</div>
|
|
|
|
<div class="breakdown-rows">
|
|
<div class="breakdown-item">
|
|
<div class="breakdown-label">
|
|
<span class="indicator-dot dot-success"></span>
|
|
<span>Went Through (Completed)</span>
|
|
</div>
|
|
<div class="breakdown-values">
|
|
<span id="detail-went">${requests.wentThrough.toLocaleString()}</span>
|
|
<span class="pct-tag" id="detail-went-pct">${wentThroughPct}%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="breakdown-item">
|
|
<div class="breakdown-label">
|
|
<span class="indicator-dot dot-danger"></span>
|
|
<span>Failed (Error / Rate Limit)</span>
|
|
</div>
|
|
<div class="breakdown-values">
|
|
<span id="detail-failed">${requests.failed.toLocaleString()}</span>
|
|
<span class="pct-tag" id="detail-failed-pct">${failedPct}%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="breakdown-item">
|
|
<div class="breakdown-label">
|
|
<span class="indicator-dot dot-warning"></span>
|
|
<span>Cancelled (Client Disconnected)</span>
|
|
</div>
|
|
<div class="breakdown-values">
|
|
<span id="detail-cancelled">${requests.cancelled.toLocaleString()}</span>
|
|
<span class="pct-tag" id="detail-cancelled-pct">${cancelledPct}%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Token Distribution -->
|
|
<div class="breakdown-card">
|
|
<div class="breakdown-header">
|
|
<div class="breakdown-title">
|
|
<i class="fas fa-layer-group"></i>
|
|
Token Distribution
|
|
</div>
|
|
<span class="pill-counter" id="detail-total-tokens-badge">${tokens.total.toLocaleString()} tokens</span>
|
|
</div>
|
|
|
|
<div class="progress-bar-wrap">
|
|
<div id="bar-input" class="bar-segment bar-input" style="width: ${inputTokensPct}%;" title="Input Tokens: ${inputTokensPct}%"></div>
|
|
<div id="bar-output" class="bar-segment bar-output" style="width: ${outputTokensPct}%;" title="Output Tokens: ${outputTokensPct}%"></div>
|
|
</div>
|
|
|
|
<div class="breakdown-rows">
|
|
<div class="breakdown-item">
|
|
<div class="breakdown-label">
|
|
<span class="indicator-dot dot-primary"></span>
|
|
<span>Input Tokens (Prompt)</span>
|
|
</div>
|
|
<div class="breakdown-values">
|
|
<span id="detail-input">${tokens.input.toLocaleString()}</span>
|
|
<span class="pct-tag" id="detail-input-pct">${inputTokensPct}%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="breakdown-item">
|
|
<div class="breakdown-label">
|
|
<span class="indicator-dot dot-success"></span>
|
|
<span>Output Tokens (Completion)</span>
|
|
</div>
|
|
<div class="breakdown-values">
|
|
<span id="detail-output">${tokens.output.toLocaleString()}</span>
|
|
<span class="pct-tag" id="detail-output-pct">${outputTokensPct}%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="breakdown-item">
|
|
<div class="breakdown-label">
|
|
<span class="indicator-dot" style="background-color: var(--primary-color);"></span>
|
|
<span>Total Combined Tokens</span>
|
|
</div>
|
|
<div class="breakdown-values">
|
|
<span id="detail-combined">${tokens.total.toLocaleString()}</span>
|
|
<span class="pct-tag">100.0%</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- System Telemetry Grid -->
|
|
<div class="system-card">
|
|
<div class="system-item">
|
|
<span class="system-label"><i class="fas fa-server"></i> Active Model Engine</span>
|
|
<span class="system-val" id="val-model">${server.model}</span>
|
|
</div>
|
|
<div class="system-item">
|
|
<span class="system-label"><i class="fas fa-key"></i> Key Rotation Pool</span>
|
|
<span class="system-val" id="val-keys">${server.configuredKeysCount} keys rotating</span>
|
|
</div>
|
|
<div class="system-item">
|
|
<span class="system-label"><i class="fas fa-stopwatch"></i> Gateway Uptime</span>
|
|
<span class="system-val" id="val-uptime">${uptimeFormatted}</span>
|
|
</div>
|
|
<div class="system-item">
|
|
<span class="system-label"><i class="fas fa-history"></i> Last Request</span>
|
|
<span class="system-val" id="val-last-request">${lastRequestAt ? new Date(lastRequestAt).toLocaleTimeString() : 'None yet'}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Privacy Banner -->
|
|
<div class="privacy-banner">
|
|
<i class="fas fa-shield-alt privacy-icon"></i>
|
|
<div class="privacy-text">
|
|
<strong>Zero-Knowledge Privacy:</strong> This public dashboard provides aggregate telemetry counts only. No prompt messages, completion texts, client IPs, user tokens, or Gemini API keys are ever stored or exposed.
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Footer - Matches www.gsdistance.org -->
|
|
<footer>
|
|
<div class="footer-content">
|
|
<div class="footer-links">
|
|
<a href="/api/stats" target="_blank">Raw Stats API</a>
|
|
<a href="/health" target="_blank">Health Check</a>
|
|
<a href="https://stats.uptimerobot.com/g68DVM4aPI" target="_blank">Uptime</a>
|
|
<a href="https://github.com/GsDistance" target="_blank">GitHub</a>
|
|
</div>
|
|
<div class="social-links">
|
|
<a href="https://github.com/GsDistance" target="_blank" title="GsDistance on GitHub"><i class="fab fa-github"></i> GsD</a>
|
|
<a href="https://github.com/tyuXX" target="_blank" title="tyuXX on GitHub"><i class="fab fa-github"></i> tyuXX</a>
|
|
</div>
|
|
<p class="copyright">© 2026 GsDistance. All rights reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script>
|
|
(function() {
|
|
// Theme toggle functionality (matching www.gsdistance.org)
|
|
const themeToggle = document.getElementById('theme-toggle');
|
|
const themeIcon = document.getElementById('theme-icon');
|
|
const body = document.body;
|
|
|
|
function setTheme(theme) {
|
|
const isLight = theme === 'light';
|
|
body.classList.toggle('light-theme', isLight);
|
|
if (themeIcon) {
|
|
themeIcon.className = isLight ? 'fas fa-moon' : 'fas fa-sun';
|
|
}
|
|
try {
|
|
localStorage.setItem('theme', theme);
|
|
} catch (e) {}
|
|
}
|
|
|
|
// Check saved theme
|
|
try {
|
|
const savedTheme = localStorage.getItem('theme');
|
|
if (savedTheme) {
|
|
setTheme(savedTheme);
|
|
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
|
setTheme('light');
|
|
} else {
|
|
setTheme('dark');
|
|
}
|
|
} catch (e) {
|
|
setTheme('dark');
|
|
}
|
|
|
|
if (themeToggle) {
|
|
themeToggle.addEventListener('click', () => {
|
|
const nextTheme = body.classList.contains('light-theme') ? 'dark' : 'light';
|
|
setTheme(nextTheme);
|
|
});
|
|
}
|
|
|
|
// Auto-refresh & Data updater
|
|
let autoRefresh = true;
|
|
let refreshTimer = null;
|
|
const refreshBtn = document.getElementById('refresh-btn');
|
|
const refreshIcon = document.getElementById('refresh-icon');
|
|
const autoBtn = document.getElementById('auto-btn');
|
|
const autoText = document.getElementById('auto-text');
|
|
|
|
function updateDashboard(data) {
|
|
if (!data || !data.requests || !data.tokens) return;
|
|
|
|
// Metric values
|
|
const valTotalReqs = document.getElementById('val-total-reqs');
|
|
if (valTotalReqs) valTotalReqs.textContent = data.requests.total.toLocaleString();
|
|
const subWent = document.getElementById('sub-went');
|
|
if (subWent) subWent.textContent = data.requests.wentThrough.toLocaleString();
|
|
const subFailed = document.getElementById('sub-failed');
|
|
if (subFailed) subFailed.textContent = data.requests.failed.toLocaleString();
|
|
const subCancelled = document.getElementById('sub-cancelled');
|
|
if (subCancelled) subCancelled.textContent = data.requests.cancelled.toLocaleString();
|
|
|
|
const valTotalTokens = document.getElementById('val-total-tokens');
|
|
if (valTotalTokens) valTotalTokens.textContent = data.tokens.total.toLocaleString();
|
|
const subInput = document.getElementById('sub-input');
|
|
if (subInput) subInput.textContent = data.tokens.input.toLocaleString();
|
|
const subOutput = document.getElementById('sub-output');
|
|
if (subOutput) subOutput.textContent = data.tokens.output.toLocaleString();
|
|
|
|
const valSuccessRate = document.getElementById('val-success-rate');
|
|
if (valSuccessRate) valSuccessRate.textContent = data.requests.successRate + '%';
|
|
|
|
const valActiveReqs = document.getElementById('val-active-reqs');
|
|
if (valActiveReqs) valActiveReqs.textContent = data.activeRequests;
|
|
const subActiveDesc = document.getElementById('sub-active-desc');
|
|
if (subActiveDesc) {
|
|
subActiveDesc.textContent = data.activeRequests === 0 ? 'Idle • Ready for requests' : 'Processing active completions';
|
|
}
|
|
|
|
// Request breakdown
|
|
const totalReqs = data.requests.total;
|
|
const wentPct = totalReqs > 0 ? ((data.requests.wentThrough / totalReqs) * 100).toFixed(1) : '100.0';
|
|
const failedPct = totalReqs > 0 ? ((data.requests.failed / totalReqs) * 100).toFixed(1) : '0.0';
|
|
const cancelledPct = totalReqs > 0 ? ((data.requests.cancelled / totalReqs) * 100).toFixed(1) : '0.0';
|
|
|
|
const barWent = document.getElementById('bar-went');
|
|
if (barWent) barWent.style.width = wentPct + '%';
|
|
const barFailed = document.getElementById('bar-failed');
|
|
if (barFailed) barFailed.style.width = failedPct + '%';
|
|
const barCancelled = document.getElementById('bar-cancelled');
|
|
if (barCancelled) barCancelled.style.width = cancelledPct + '%';
|
|
|
|
const badgeTotalReqs = document.getElementById('detail-total-reqs-badge');
|
|
if (badgeTotalReqs) badgeTotalReqs.textContent = totalReqs.toLocaleString() + ' total';
|
|
const detailWent = document.getElementById('detail-went');
|
|
if (detailWent) detailWent.textContent = data.requests.wentThrough.toLocaleString();
|
|
const detailWentPct = document.getElementById('detail-went-pct');
|
|
if (detailWentPct) detailWentPct.textContent = wentPct + '%';
|
|
const detailFailed = document.getElementById('detail-failed');
|
|
if (detailFailed) detailFailed.textContent = data.requests.failed.toLocaleString();
|
|
const detailFailedPct = document.getElementById('detail-failed-pct');
|
|
if (detailFailedPct) detailFailedPct.textContent = failedPct + '%';
|
|
const detailCancelled = document.getElementById('detail-cancelled');
|
|
if (detailCancelled) detailCancelled.textContent = data.requests.cancelled.toLocaleString();
|
|
const detailCancelledPct = document.getElementById('detail-cancelled-pct');
|
|
if (detailCancelledPct) detailCancelledPct.textContent = cancelledPct + '%';
|
|
|
|
// Token breakdown
|
|
const totalToks = data.tokens.total;
|
|
const inputPct = totalToks > 0 ? ((data.tokens.input / totalToks) * 100).toFixed(1) : '50.0';
|
|
const outputPct = totalToks > 0 ? ((data.tokens.output / totalToks) * 100).toFixed(1) : '50.0';
|
|
|
|
const barInput = document.getElementById('bar-input');
|
|
if (barInput) barInput.style.width = inputPct + '%';
|
|
const barOutput = document.getElementById('bar-output');
|
|
if (barOutput) barOutput.style.width = outputPct + '%';
|
|
|
|
const badgeTotalToks = document.getElementById('detail-total-tokens-badge');
|
|
if (badgeTotalToks) badgeTotalToks.textContent = totalToks.toLocaleString() + ' tokens';
|
|
const detailInput = document.getElementById('detail-input');
|
|
if (detailInput) detailInput.textContent = data.tokens.input.toLocaleString();
|
|
const detailInputPct = document.getElementById('detail-input-pct');
|
|
if (detailInputPct) detailInputPct.textContent = inputPct + '%';
|
|
const detailOutput = document.getElementById('detail-output');
|
|
if (detailOutput) detailOutput.textContent = data.tokens.output.toLocaleString();
|
|
const detailOutputPct = document.getElementById('detail-output-pct');
|
|
if (detailOutputPct) detailOutputPct.textContent = outputPct + '%';
|
|
const detailCombined = document.getElementById('detail-combined');
|
|
if (detailCombined) detailCombined.textContent = totalToks.toLocaleString();
|
|
|
|
// System values
|
|
const valUptime = document.getElementById('val-uptime');
|
|
if (valUptime && data.uptimeFormatted) valUptime.textContent = data.uptimeFormatted;
|
|
const valUptimeChip = document.getElementById('val-uptime-chip');
|
|
if (valUptimeChip && data.uptimeFormatted) valUptimeChip.textContent = data.uptimeFormatted;
|
|
const valLastReq = document.getElementById('val-last-request');
|
|
if (valLastReq) {
|
|
valLastReq.textContent = data.lastRequestAt ? new Date(data.lastRequestAt).toLocaleTimeString() : 'None yet';
|
|
}
|
|
}
|
|
|
|
async function fetchStats() {
|
|
if (refreshIcon) refreshIcon.classList.add('fa-spin');
|
|
try {
|
|
const res = await fetch('/api/stats');
|
|
if (!res.ok) throw new Error('HTTP ' + res.status);
|
|
const data = await res.json();
|
|
updateDashboard(data);
|
|
} catch (err) {
|
|
console.debug('Failed to refresh stats:', err);
|
|
} finally {
|
|
if (refreshIcon) {
|
|
setTimeout(() => refreshIcon.classList.remove('fa-spin'), 600);
|
|
}
|
|
}
|
|
}
|
|
|
|
function setupTimer() {
|
|
if (refreshTimer) clearInterval(refreshTimer);
|
|
if (autoRefresh) {
|
|
refreshTimer = setInterval(fetchStats, 5000);
|
|
}
|
|
}
|
|
|
|
if (refreshBtn) {
|
|
refreshBtn.addEventListener('click', () => fetchStats());
|
|
}
|
|
|
|
if (autoBtn) {
|
|
autoBtn.addEventListener('click', () => {
|
|
autoRefresh = !autoRefresh;
|
|
if (autoRefresh) {
|
|
autoBtn.classList.add('active');
|
|
if (autoText) autoText.textContent = 'Auto (5s)';
|
|
setupTimer();
|
|
} else {
|
|
autoBtn.classList.remove('active');
|
|
if (autoText) autoText.textContent = 'Auto (Paused)';
|
|
if (refreshTimer) clearInterval(refreshTimer);
|
|
}
|
|
});
|
|
}
|
|
|
|
setupTimer();
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>`;
|
|
}
|
|
}
|
|
|
|
export const statsTracker = new StatsTracker();
|