1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-09-11 18:27:21 +03:00

feat: add free RAM check

This commit is contained in:
louistiti 2023-05-03 14:54:23 +08:00
parent 2e3796642d
commit 8f5bd3a9a5
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669
4 changed files with 20 additions and 7 deletions

View File

@ -145,14 +145,17 @@ dotenv.config()
distro: null
}
const totalRAMInGB = SystemHelper.getTotalRAM()
const freeRAMInGB = SystemHelper.getFreeRAM()
if (Math.round(totalRAMInGB) < MINIMUM_REQUIRED_RAM) {
if (Math.round(freeRAMInGB) < MINIMUM_REQUIRED_RAM) {
report.can_run.v = false
LogHelper.error(
`Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM`
`Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM`
)
} else {
LogHelper.success(`Total RAM: ${totalRAMInGB} GB`)
LogHelper.success(
`Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB`
)
}
if (osInfo.platform === 'linux') {
@ -166,6 +169,7 @@ dotenv.config()
reportDataInput.environment.osDetails = osInfo
reportDataInput.environment.totalRAMInGB = totalRAMInGB
reportDataInput.environment.freeRAMInGB = freeRAMInGB
;(
await Promise.all([
command('node --version', { shell: true }),

View File

@ -119,6 +119,14 @@ export class SystemHelper {
return Number((os.totalmem() / (1_024 * 1_024 * 1_024)).toFixed(2))
}
/**
* Get the amount of free memory (in GB) on your machine
* @example getFreeRAM() // 6
*/
public static getFreeRAM(): number {
return Number((os.freemem() / (1_024 * 1_024 * 1_024)).toFixed(2))
}
/**
* Get the Node.js version of the current process
* @example getNodeJSVersion() // '18.15.0'

View File

@ -97,14 +97,15 @@ const GLOBAL_DATA_SCHEMAS = {
LogHelper.info('Checking system requirements...')
const totalRAMInGB = Math.round(SystemHelper.getTotalRAM())
const freeRAMInGB = Math.round(SystemHelper.getFreeRAM())
if (totalRAMInGB < MINIMUM_REQUIRED_RAM) {
if (freeRAMInGB < MINIMUM_REQUIRED_RAM) {
LogHelper.warning(
`Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM. It may not work as expected.`
`Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB. Leon needs at least ${MINIMUM_REQUIRED_RAM} GB of RAM. It may not work as expected.`
)
} else {
LogHelper.success(
`Minimum required RAM: ${MINIMUM_REQUIRED_RAM} GB | Total RAM: ${totalRAMInGB} GB`
`Minimum required RAM: ${MINIMUM_REQUIRED_RAM} GB | Free RAM: ${freeRAMInGB} | Total RAM: ${totalRAMInGB} GB`
)
}

View File

@ -68,7 +68,6 @@ export class Telemetry {
const data = {
isProduction: IS_PRODUCTION_ENV,
isGitpod: IS_GITPOD,
isOnline: true,
language: LANG,
sttProvider: STT_PROVIDER,
ttsProvider: TTS_PROVIDER,
@ -87,6 +86,7 @@ export class Telemetry {
distro: null as Os | null
},
totalRAMInGB: SystemHelper.getTotalRAM(),
freeRAMInGB: SystemHelper.getFreeRAM(),
nodeVersion: SystemHelper.getNodeJSVersion(),
npmVersion: SystemHelper.getNPMVersion()
}