CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/hub/servers/app/stats.ts
Views: 687
1
import { Router } from "express";
2
import { callback2 } from "@cocalc/util/async-utils";
3
import { database_is_working } from "@cocalc/hub/hub_register";
4
import { database } from "../database";
5
6
export default function init(router: Router) {
7
// Return global status information about CoCalc
8
router.get("/stats", async (_req, res) => {
9
if (!database_is_working()) {
10
res.json({ error: "not connected to database" });
11
return;
12
}
13
res.header("Cache-Control", "no-cache, no-store");
14
try {
15
const stats = await callback2(database.get_stats, {
16
update: false, // never update in hub b/c too slow. instead, run $ hub --update_stats via a cronjob every minute
17
ttl: 30,
18
});
19
res.header("Content-Type", "application/json");
20
res.send(JSON.stringify(stats, null, 1));
21
} catch (err) {
22
res.status(500).send(`internal error: ${err}`);
23
}
24
});
25
}
26
27