UNPKG

agentcrumbs

Version:
72 lines 3.14 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.stats = stats; const node_fs_1 = __importDefault(require("node:fs")); const store_js_1 = require("../../collector/store.js"); const app_store_js_1 = require("../app-store.js"); async function stats(args) { const appCtx = (0, app_store_js_1.parseAppFlags)(args); if (appCtx.allApps) { // Show stats for all apps const apps = store_js_1.CrumbStore.listApps(); if (apps.length === 0) { process.stdout.write("No apps found.\n"); return; } process.stdout.write(`agentcrumbs stats (all apps)\n\n`); for (const app of apps) { const store = store_js_1.CrumbStore.forApp(app); const crumbs = store.readAll(); const namespaces = new Set(crumbs.map((c) => c.ns)); const filePath = store.getFilePath(); let fileSize = "0B"; try { const stat = node_fs_1.default.statSync(filePath); fileSize = formatBytes(stat.size); } catch { // file might not exist } const oneHourAgo = Date.now() - 60 * 60 * 1000; const recentCount = crumbs.filter((c) => new Date(c.ts).getTime() >= oneHourAgo).length; process.stdout.write(` ${app}\n`); process.stdout.write(` Services: ${[...namespaces].join(", ") || "none"}\n`); process.stdout.write(` Total: ${crumbs.length} crumbs\n`); process.stdout.write(` Last hour: ${recentCount} crumbs\n`); process.stdout.write(` File: ${filePath} (${fileSize})\n\n`); } return; } // Single app stats const app = (0, app_store_js_1.resolveApp)(appCtx); const allCrumbs = (0, app_store_js_1.readAllCrumbs)(appCtx); const namespaces = new Set(allCrumbs.map((c) => c.ns)); const filePath = (0, app_store_js_1.getStoreFilePath)(appCtx); let fileSize = "0B"; try { const stat = node_fs_1.default.statSync(filePath); fileSize = formatBytes(stat.size); } catch { // file might not exist } const oneHourAgo = Date.now() - 60 * 60 * 1000; const recentCount = allCrumbs.filter((c) => new Date(c.ts).getTime() >= oneHourAgo).length; process.stdout.write(`agentcrumbs stats (${app})\n`); process.stdout.write(` App: ${app}\n`); process.stdout.write(` Services: ${[...namespaces].join(", ") || "none"}\n`); process.stdout.write(` Total: ${allCrumbs.length} crumbs\n`); process.stdout.write(` Last hour: ${recentCount} crumbs\n`); process.stdout.write(` File: ${filePath} (${fileSize})\n`); } function formatBytes(bytes) { if (bytes < 1024) return `${bytes}B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)}KB`; return `${(bytes / (1024 * 1024)).toFixed(1)}MB`; } //# sourceMappingURL=stats.js.map