@hasna/logs 0.3.9 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +45 -2
- package/dist/index-2sbhn1ye.js +1241 -0
- package/dist/index-t97ttm0a.js +543 -0
- package/dist/mcp/index.js +30 -5
- package/dist/server/index.js +2 -2
- package/package.json +1 -1
- package/src/cli/index.ts +57 -0
- package/src/lib/ingest.ts +5 -1
- package/src/mcp/index.ts +30 -3
package/dist/cli/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// @bun
|
|
3
3
|
import {
|
|
4
4
|
runJob
|
|
5
|
-
} from "../index-
|
|
5
|
+
} from "../index-2sbhn1ye.js";
|
|
6
6
|
import {
|
|
7
7
|
createPage,
|
|
8
8
|
createProject,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
listProjects,
|
|
13
13
|
resolveProjectId,
|
|
14
14
|
summarizeLogs
|
|
15
|
-
} from "../index-
|
|
15
|
+
} from "../index-t97ttm0a.js";
|
|
16
16
|
import {
|
|
17
17
|
createJob,
|
|
18
18
|
listJobs
|
|
@@ -2430,6 +2430,49 @@ Exported ${count} log(s)
|
|
|
2430
2430
|
`);
|
|
2431
2431
|
}
|
|
2432
2432
|
});
|
|
2433
|
+
program2.command("stats").description("Volume overview: count, DB size, timeline, top services, error rate").option("--project <name|id>", "Scope to a project").action((opts) => {
|
|
2434
|
+
const db = getDb();
|
|
2435
|
+
const projectId = resolveProject(opts.project);
|
|
2436
|
+
const pFilter = projectId ? `WHERE project_id = '${projectId.replace(/'/g, "''")}'` : "";
|
|
2437
|
+
const pAnd = projectId ? `AND project_id = '${projectId.replace(/'/g, "''")}'` : "";
|
|
2438
|
+
const total = db.query(`SELECT COUNT(*) as c FROM logs ${pFilter}`).get().c;
|
|
2439
|
+
const oldest = db.query(`SELECT MIN(timestamp) as t FROM logs ${pFilter}`).get().t;
|
|
2440
|
+
const newest = db.query(`SELECT MAX(timestamp) as t FROM logs ${pFilter}`).get().t;
|
|
2441
|
+
const byLevel = db.query(`SELECT level, COUNT(*) as c FROM logs ${pFilter} GROUP BY level ORDER BY c DESC`).all();
|
|
2442
|
+
const topServices = db.query(`SELECT COALESCE(service, '-') as service, COUNT(*) as c FROM logs ${pFilter} GROUP BY service ORDER BY c DESC LIMIT 5`).all();
|
|
2443
|
+
const days = db.query(`SELECT strftime('%Y-%m-%d', timestamp) as day, COUNT(*) as c FROM logs WHERE timestamp >= datetime('now', '-7 days') ${pAnd} GROUP BY day ORDER BY day`).all();
|
|
2444
|
+
const errors = byLevel.find((r) => r.level === "error")?.c ?? 0;
|
|
2445
|
+
const fatals = byLevel.find((r) => r.level === "fatal")?.c ?? 0;
|
|
2446
|
+
const errorRate = total > 0 ? ((errors + fatals) / total * 100).toFixed(2) : "0.00";
|
|
2447
|
+
console.log(`
|
|
2448
|
+
${C.bold}Log Volume Stats${C.reset}${projectId ? ` [${opts.project}]` : ""}`);
|
|
2449
|
+
console.log(` Total: ${total.toLocaleString()}`);
|
|
2450
|
+
console.log(` Oldest: ${oldest?.slice(0, 19) ?? "-"}`);
|
|
2451
|
+
console.log(` Newest: ${newest?.slice(0, 19) ?? "-"}`);
|
|
2452
|
+
console.log(` Error rate: ${errorRate}% (${errors} errors, ${fatals} fatals)`);
|
|
2453
|
+
if (byLevel.length) {
|
|
2454
|
+
console.log(`
|
|
2455
|
+
${C.bold}By Level:${C.reset}`);
|
|
2456
|
+
for (const r of byLevel)
|
|
2457
|
+
console.log(` ${colorLevel(r.level)} ${r.c.toLocaleString()}`);
|
|
2458
|
+
}
|
|
2459
|
+
if (topServices.length) {
|
|
2460
|
+
console.log(`
|
|
2461
|
+
${C.bold}Top Services:${C.reset}`);
|
|
2462
|
+
for (const r of topServices)
|
|
2463
|
+
console.log(` ${C.cyan}${pad(r.service, 20)}${C.reset} ${r.c.toLocaleString()}`);
|
|
2464
|
+
}
|
|
2465
|
+
if (days.length) {
|
|
2466
|
+
const maxC = Math.max(...days.map((d) => d.c));
|
|
2467
|
+
console.log(`
|
|
2468
|
+
${C.bold}Last 7 Days:${C.reset}`);
|
|
2469
|
+
for (const d of days) {
|
|
2470
|
+
const bar = "\u2588".repeat(Math.max(1, Math.round(d.c / maxC * 20)));
|
|
2471
|
+
console.log(` ${d.day} ${C.cyan}${bar}${C.reset} ${d.c.toLocaleString()}`);
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
console.log("");
|
|
2475
|
+
});
|
|
2433
2476
|
program2.command("health").description("Show server health and DB stats").action(async () => {
|
|
2434
2477
|
const { getHealth } = await import("../health-9792c1rc.js");
|
|
2435
2478
|
const h = getHealth(getDb());
|