Skip to main content
Version: 8.2.2

os

The sos.management.os API groups together methods for retrieving information about the system.

OS Management Capabilities
CapabilityDescription
SYSTEM_CPUIf device supports collecting CPU usage information
SYSTEM_MEMORYIf device supports collecting memory usage information

If you want to check if the device supports those capabilities, use sos.management.supports().

Methods

getCpuUsage()

The getCpuUsage() method returns the current total CPU usage (ranging from 0 to 100%).

getCpuUsage(): Promise<number>;

Return value

Resolves to the current CPU usage percentage.

Possible errors

If the CPU usage is not supported.

Example

const cpuUsage = await sos.management.os.getCpuUsage();
console.log(`Current CPU usage is: ${cpuUsage}%`);

getInfo()

The getInfo() method returns info about the system of the device, such as what current version of it is installed on the device. Major version of the current operating system. It's usually 1 or 2 digits, including or excluding dot notation.

getInfo(): Promise<IOSInfo>;

Return value

Resolves to an object containing information about the operating system.

Example

const osInfo = await sos.management.os.getInfo();
console.log(`Current OS version is: ${osInfo.version}`);

getMemoryUsage()

The getMemoryUsage() method returns the total memory amount in bytes, the currently used memory, and the remaining free memory.

getMemoryUsage(): Promise<SystemMemoryInfo>;

Return value

Resolves to an object containing total, used, and free memory in bytes.

Possible errors

If the memory usage is not supported.

Example

const memoryUsage = await sos.management.os.getMemoryUsage();
console.log(`Memory usage: ${((memoryUsage.used / memoryUsage.total) * 100).toFixed(2)}%`);