@hasna/logs 0.3.13 → 0.3.15

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.
@@ -0,0 +1,39 @@
1
+ // @bun
2
+ import {
3
+ __require
4
+ } from "./index-re3ntm60.js";
5
+
6
+ // src/lib/health.ts
7
+ var startTime = Date.now();
8
+ function getHealth(db) {
9
+ const projects = db.prepare("SELECT COUNT(*) as c FROM projects").get().c;
10
+ const total_logs = db.prepare("SELECT COUNT(*) as c FROM logs").get().c;
11
+ const scheduler_jobs = db.prepare("SELECT COUNT(*) as c FROM scan_jobs WHERE enabled = 1").get().c;
12
+ const open_issues = db.prepare("SELECT COUNT(*) as c FROM issues WHERE status = 'open'").get().c;
13
+ const levelRows = db.prepare("SELECT level, COUNT(*) as c FROM logs GROUP BY level").all();
14
+ const logs_by_level = Object.fromEntries(levelRows.map((r) => [r.level, r.c]));
15
+ const oldest = db.prepare("SELECT MIN(timestamp) as t FROM logs").get();
16
+ const newest = db.prepare("SELECT MAX(timestamp) as t FROM logs").get();
17
+ let db_size_bytes = null;
18
+ try {
19
+ const dbPath = process.env.HASNA_LOGS_DB_PATH ?? process.env.LOGS_DB_PATH;
20
+ if (dbPath) {
21
+ const { statSync } = __require("fs");
22
+ db_size_bytes = statSync(dbPath).size;
23
+ }
24
+ } catch {}
25
+ return {
26
+ status: "ok",
27
+ uptime_seconds: Math.floor((Date.now() - startTime) / 1000),
28
+ db_size_bytes,
29
+ projects,
30
+ total_logs,
31
+ logs_by_level,
32
+ oldest_log: oldest.t,
33
+ newest_log: newest.t,
34
+ scheduler_jobs,
35
+ open_issues
36
+ };
37
+ }
38
+
39
+ export { getHealth };