import { sqlite } from './database/init.js' let globStats = { startup: Date.now(), updatingDB: false, lastDBUpdate: Date.now() } /** * This function returns current server stats. * * @returns {object} Stats for server. * @author BurnyLlama */ export function getStats() { const uptimeMillis = Date.now() - globStats.startup const uptimeSeconds = `${uptimeMillis / 1000} s` const dbBytes = sqlite.prepare("SELECT page_count * page_size as size FROM pragma_page_count(), pragma_page_size()").get().size const db = { size: { bytes: dbBytes, kbytes: dbBytes / 1024, mbytes: dbBytes / 1024 ** 2, gbytes: dbBytes / 1024 ** 3, }, currentlyUpdating: globStats.updatingDB, lastUpdate: new Date(globStats.lastDBUpdate).toLocaleString() } return { uptimeMillis, uptimeSeconds, db } } /** * This sets a "global" stat... * * @param {string} stat The stat you want to set. * @param {*} value The calue you want 'stat' to have. * * @author BurnyLlama */ export function setStat(stat, value) { globStats[stat] = value }