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 process manager that supervises the gateway services.
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 and available serial ports on the gateway hardware. networkInterfaces returns an object keyed by interface name, as Node.js os.networkInterfaces() (addresses, MAC; no link status). To read or change the IP configuration, use the separate network peer; to find which USB device sits behind a serial port, see Peers API: usb.
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([processName], callback)Restarts network, tincProcess, webserver and supervision (and therefore every driver), or only the process given by name. Less invasive than a full machine reboot.
optimizeMemory(enabled, callback)Turns the low-memory mode on (true) or off (false) and saves it in the configuration (OPTIMIZE_MEMORY). It does not free memory on the spot. On Linux gateways, when the value changes, all gateway services restart (the gateway is unreachable for a short time) and then run with reduced memory limits. Check the current value first with getConfig() (OPTIMIZE_MEMORY).
reload(callback)Restarts the supervision process (and every driver) without rebooting the machine.
The gateway distinguishes two upgrade tracks:
getLocalFirmwareRevision(callback) / getLocalSupervisionRevision(callback)Return the currently-installed revision, as an object (with its id and name).
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. Both call back with (err, onlineRevision, localRevision): an upgrade is available when localRevision.id < onlineRevision.id.
upgradeFirmwareRevision(type, callback) / upgradeSupervisionRevision(type, callback)Trigger an upgrade of the firmware or supervision.
type |
Effect |
|---|---|
'update' |
Online upgrade: downloads the latest signed package |
'file' (or 'path', 'offline') |
Offline upgrade: installs the upgrade.zip already uploaded through the web interface |
The gateway stops all drivers and routes, checks the package signature, installs it and reboots (several minutes offline). Follow the progress with the upgrade start, upgrade progress, upgrade end and upgrade installed events. Errors: SYSTEM_ALREADY_UPGRADING; on Windows, UPGRADE_NOT_SUPPORTED_ON_WINDOWS (install the new Windows package instead).
system.upgradeSupervisionRevision('update', function(err){
if(err) console.error('upgrade refused', err)
})
isUpgrading(callback)Tells whether an upgrade is running.
The gateway's process manager (called PM2 in the API) supervises the gateway services: supervision, webserver, tincProcess and, on Linux gateways, network and modem. Drivers, loggers and logics are child processes of supervision.
PM2GetInfos(callback)Returns { processes: [...], files: [...] }. Each process entry has name, pid and process (on Linux: cpu and mem in %).
system.PM2GetInfos(function(err, infos){
infos.processes.forEach(function(p){
console.log(p.name, p.pid, p.process && p.process.cpu + '%')
})
})
PM2subscribe(callback) / PM2unsubscribe(id, callback)PM2subscribe starts the log stream and returns a subscriber id. Log lines arrive as logs events of the system module:
var subId = system.PM2subscribe(function(err){ if(err) console.error(err) })
system.on('logs', function(log){
console.log('[' + log.app_name + ']', log.message)
})
// later
system.PM2unsubscribe(subId)
PM2GetTemporaryLogs(name, callback) returns the last 50 lines kept in memory (name = process name or 'all').
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.
getDate({ detailed: true }, callback) returns { ms, iso, local, timezone }: use local and timezone to display the gateway time.
forceTimeSync(date, callback)Set the system date and write it to the hardware clock.
gps(callback)Returns the licences installed on the gateway: { l: [licences], p: { <productCode>: 1, … }, s: [custom scripts] }. The name stands for get products; it has nothing to do with GPS.
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){ if(err) console.error(err) })
system.on('logs', function(log){
process.stdout.write('[' + log.app_name + '] ' + log.message + '\n')
})
system.setHttpsEnable(true, function(err, changed){
if(err) return console.error(err)
if(changed) console.log('https enabled')
})
setHttpsEnable already restarts the web server when the value changes; do not call restartWebserver afterwards.
| Event | Description |
|---|---|
config updated |
The configuration changed |
cpu state, memory state, disk state, temperature state |
New hardware measurements |
crashLogs |
The list of crash dumps changed |
logs |
Process log line (after PM2subscribe) |
date change |
System date changed |
reload, reboot, stopAllDrivers |
Services are about to restart / drivers are being stopped |
redundancy state change |
Redundancy peer connected (true) or lost (false) |
upgrade start, upgrade progress, upgrade end, upgrade installed |
Upgrade progress |