The system module exposes gateway-level information and control: hardware metrics (memory, CPU, uptime, load), network configuration toggles, firmware/supervision upgrades, reboot, and access to the underlying PM2 process manager that supervises every running driver.
Load it with:
peer('supervision').require('system', function(err, system){
// system.totalmem(...), system.reboot(...), system.PM2GetInfos(...)
})
These methods return live hardware information about the gateway machine.
totalmem(callback) / freemem(callback)Total and free memory, in bytes.
system.totalmem(function(err, bytes){ console.log('total:', bytes) })
system.freemem(function(err, bytes){ console.log('free:', bytes) })
uptime(callback)System uptime in seconds.
loadavg(callback)Returns the standard 1, 5, and 15 minute load averages as an array of three numbers.
system.loadavg(function(err, loads){
console.log('1m =', loads[0], '5m =', loads[1], '15m =', loads[2])
})
cpus(callback)Per-CPU information including utilization. Each entry has a percent field with the current CPU usage.
system.cpus(function(err, cpus){
cpus.forEach(function(c, i){
console.log('cpu' + i, c.model, c.percent + '%')
})
})
getInformations(callback)Return live system information: cpus, disks, memory, temperature and diskStats. The hardware model is the property system.baseDevice.
networkInterfaces(callback) / getSerialPorts(callback)List network interfaces (with IP, MAC, status) and available serial ports on the gateway hardware.
getDiskStats(callback)Disk activity and database statistics.
getBuildInfo(callback)Device, platform, architecture, revision and Node.js version.
getConfig(callback)Return the full system configuration object — the persisted settings used by every subsystem.
system.getConfig(function(err, config){
console.log(config.SUPERVISION_NAME, config.HTTP_ENABLE, config.HTTPS_ENABLE)
})
writeConfig(obj, callback) / readConfig(callback)Write a partial configuration update or re-read the configuration file from disk.
system.writeConfig({ SUPERVISION_NAME: 'Boiler Room Gateway' }, function(err){
if(err) console.error(err)
})
Enable or disable individual services. Each setter takes a boolean and a callback that returns (err, hasChanged).
| Method | Service |
|---|---|
setHttpEnable(enabled, callback) |
HTTP server |
setHttpsEnable(enabled, callback) |
HTTPS server |
setModemEnable(enabled, callback) |
4G/LTE modem |
setTincEnable(enabled, callback) |
Tinc VPN mesh |
system.setHttpsEnable(true, function(err, changed){
if(changed) console.log('HTTPS toggled')
})
reboot(callback)Reboot the gateway machine. Use with care — every running driver will be killed and restarted.
restartWebserver(callback)Restart only the web server process, leaving drivers and routes untouched. Useful after changing certificates or webserver-only configuration.
rebootPM2(callback)Restart the PM2 process manager and every process it supervises (drivers, loggers, logics, webserver). Less invasive than a full machine reboot.
optimizeMemory(optMem, callback)Trigger a memory optimization pass — flushes caches and forces garbage collection.
The gateway distinguishes two upgrade tracks:
getLocalFirmwareRevision(callback) / getLocalSupervisionRevision(callback)Return the currently-installed revision strings.
compareFirmwareRevision(callback) / compareSupervisionRevision(callback)Compare the local revision against the available release on the upgrade server. Use this to know whether an upgrade is available.
upgradeFirmwareRevision(type, callback) / upgradeSupervisionRevision(type, callback)Trigger an upgrade of the firmware or supervision. The gateway downloads the new version, stops all drivers cleanly, applies the upgrade, and reboots.
system.upgradeSupervisionRevision('latest', function(err){
if(err) console.error('upgrade failed', err)
})
isUpgrading(callback)Tells whether an upgrade is running.
PM2 supervises every driver process running on the gateway. The system module proxies a few PM2 methods so you can introspect and tail logs without touching the local PM2 daemon directly.
PM2GetInfos(callback)Return per-process information for everything PM2 is currently supervising — CPU, memory, restart count, uptime, and current state.
system.PM2GetInfos(function(err, infos){
infos.forEach(function(p){
console.log(p.name, p.status, p.cpu + '%', p.memory)
})
})
PM2subscribe(callback)Subscribe to the live PM2 log stream. The callback fires for every log line emitted by any process.
system.PM2subscribe(function(err, log){
if(err) return console.error(err)
console.log('[' + log.process + ']', log.line)
})
The function returns an opaque subscriber id that you can pass to PM2listen to detach later.
PM2listen(peersId, callback)Lower-level subscription used internally by PM2subscribe. Most clients should use PM2subscribe.
getCrashLogs(callback)Return the list of all crash dumps currently stored on the gateway.
getCrashLog(moduleName, driverKey, callback)Return the contents of a specific crash dump.
system.getCrashLog('gateways', 12, function(err, log){
console.log(log)
})
deleteCrashLog(name, callback)Remove a crash dump from disk.
getDate(emitter, callback) / initializeDate(callback)Return the current system date or initialize it from the configured time source. Used internally by gateways during boot synchronization.
forceTimeSync(date, callback)Set the system date and write it to the hardware clock.
gps(callback)Return the latest GPS coordinates if a GPS receiver is attached.
crl(callback)Return the certificate revocation list known to the gateway.
showDriver(driverName, callback)Return the driver source code — used by the UI for inspection and debugging.
system.totalmem(function(err, total){
system.freemem(function(err, free){
system.loadavg(function(err, loads){
system.uptime(function(err, up){
console.log('memory:', Math.round((1 - free/total) * 100) + '% used')
console.log('load: ', loads.join(' / '))
console.log('uptime:', Math.round(up / 86400) + ' days')
})
})
})
})
system.PM2subscribe(function(err, log){
if(err) return console.error(err)
process.stdout.write('[' + log.process + '] ' + log.line + '\n')
})
system.setHttpsEnable(true, function(err, changed){
if(err) return console.error(err)
if(changed) system.restartWebserver(function(){ console.log('https enabled') })
})