Index

src/fileSystemInfo.ts

formatBytes
formatBytes(bytes: string)

Helper function to format bytes into human-readable form (e.g., KB, MB, GB). This is mainly for the Windows output since df -h already formats it.

Parameters :
Name Type Optional Description
bytes string No
  • The size in bytes.
Returns : string
  • The size formatted in human-readable form.
getFileSystemInfo
getFileSystemInfo(format)

Retrieves information about the file system, including disk space usage.

  • On Windows, it uses wmic to get the size, free space, and caption of logical disks.
  • On Unix-based systems, it uses the df -h command to display the file system usage in a human-readable format.
Parameters :
Name Optional Default value Description
format No "json"
  • The format of the response. Defaults to "json".
Returns : Promise<[] | string>
  • A promise that resolves to either a parsed JSON array or the raw string output.
parseFileSystemOutput
parseFileSystemOutput(output: string)

Parses the output from the wmic or df -h command into a structured JSON format.

Parameters :
Name Type Optional Description
output string No
  • The raw output from the command.
Returns : FileSystemInfo[]
  • An array of objects representing the file system information.

src/activeConnections.ts

getActiveConnections
getActiveConnections(format)

Retrieves the active network connections on the system.

  • On Windows, it uses the netstat command to get network connections.
  • On Unix-based systems, it uses netstat -tn to list TCP connections in numeric form.
Parameters :
Name Optional Default value Description
format No "json"
  • The format of the response. Defaults to "json".
Returns : Promise<[] | string>
  • A promise that resolves to either a parsed JSON array of network connections or the raw string output.
parseNetstatOutput
parseNetstatOutput(output: string)

Parses the output from the netstat command into a structured JSON format.

Parameters :
Name Type Optional Description
output string No
  • The raw output from the netstat command.
  • An array of objects representing the active connections.

src/cpuUsage.ts

getCpuInfo
getCpuInfo()

Asynchronously retrieves detailed CPU information, including total and per-core statistics. It gathers information like total CPU time, idle time, user/system time, and CPU usage percentages.

The function provides an overall summary of the CPU, as well as core-specific data.

Returns : Promise<CpuInfo>

A promise that resolves to an object containing detailed CPU statistics.

src/diskUsage.ts

getDiskUsage
getDiskUsage()

Retrieves detailed disk usage data by executing a system command. Parses the output of the 'df -k' command to extract information such as filesystem type, total size, used space, available space, usage percentage, and mount point for each partition.

Returns : [] | null

An array of disk usage information for each partition, or null in case of an error.

parseDiskUsage
parseDiskUsage(output: string)

Parses the output of the 'df -k' command to extract disk usage details for each partition.

Parameters :
Name Type Optional Description
output string No
  • The output string from the 'df -k' command.
Returns : EnhancedDiskUsage[]

An array of parsed disk usage information.

src/loadAverage.ts

getLoadAverage
getLoadAverage()

Retrieves the system load averages over 1, 5, and 15 minutes.

The load average represents the average number of processes that are either in a runnable or uninterruptible state. It gives an indication of how busy the system is.

  • load1min: The average number of processes over the last minute.
  • load5min: The average number of processes over the last 5 minutes.
  • load15min: The average number of processes over the last 15 minutes.

These values are useful for determining system load trends:

  • If the value is higher than the number of CPU cores, the system may be overloaded.
  • If it's lower, the system is handling the load well.

Note: On Windows systems, os.loadavg() always returns [0, 0, 0] because load average is a Unix-specific concept and is not supported by Windows.

Returns : LoadAverage

An object containing the system's load averages:

  • load1min (number): System load over the last 1 minute.
  • load5min (number): System load over the last 5 minutes.
  • load15min (number): System load over the last 15 minutes.

src/logs.ts

getLogs
getLogs(path: string, keyword?: string)

Retrieves logs from a specified file and optionally filters them by a keyword.

Parameters :
Name Type Optional Description
path string No
  • The path to the log file.
keyword string Yes
  • An optional keyword to filter logs.
Returns : Promise<string[]>
  • A promise that resolves to an array of log lines, either filtered by the keyword or the complete log data if no keyword is provided.

src/memoryUsage.ts

getMemoryUsage
getMemoryUsage()

Asynchronously retrieves memory usage statistics, including total, free, and used memory.

The function gathers system memory information and calculates the used memory by subtracting the free memory from the total memory available on the system.

Returns : Promise<>

A promise that resolves to an object containing memory usage data with properties for total, free, and used memory.

src/networkInfo.ts

getNetworkInfo
getNetworkInfo()

Asynchronously retrieves network interface information, including details for each network interface available on the system.

The function gathers data such as the IP addresses and netmask for each network interface, facilitating network monitoring and diagnostics.

Returns : Promise<>

A promise that resolves to an object containing network interface data.

src/osInfo.ts

getOSInfo
getOSInfo()

Asynchronously retrieves detailed information about the operating system.

The function gathers various information such as the OS platform, release version, architecture, kernel version, hostname, home directory, uptime, memory statistics, CPU details, network interfaces, and user information.

Returns : OSInfo

An object containing various OS information.

src/processInfo.ts

getProcessInfo
getProcessInfo()

Asynchronously retrieves the CPU and memory usage for the current process.

The function provides detailed information about the CPU time used by the process and the memory footprint, including the Resident Set Size (RSS).

Returns : Promise<>

A promise that resolves to an object containing CPU and memory usage data for the current process.

src/scheduledTasks.ts

getScheduledTasks
getScheduledTasks()

Retrieves a list of scheduled tasks from the system and parses them into an object.

  • On Windows, it uses the schtasks command to list scheduled tasks.
  • On Unix-based systems, it uses crontab -l to list the current user's cron jobs.
Returns : Promise<ScheduledTasksResponse>
  • A promise that resolves to an object containing the list of scheduled tasks.
parseTasks
parseTasks(output: string)

Parses the command output into a structured format.

Parameters :
Name Type Optional Description
output string No
  • The raw command output as a string.
Returns : ScheduledTask[]
  • An array of objects representing the scheduled tasks.

src/serviceStatus.ts

getServiceStatus
getServiceStatus(serviceName: string)

Retrieves the status of a given service.

  • On Windows, it uses the sc query command to check the service status.
  • On Unix-based systems, it uses the systemctl is-active command to determine if the service is active.
Parameters :
Name Type Optional Description
serviceName string No
  • The name of the service whose status is to be checked.
  • A promise that resolves to the service status:
  • 'running' if the service is running,
  • 'inactive' if the service is not running,
  • 'unknown' if the status could not be determined or an error occurred.

src/uptime.ts

getSystemUptime
getSystemUptime()

Asynchronously retrieves the system uptime in seconds.

The function returns the total number of seconds the system has been running since the last boot, providing valuable information for system monitoring and diagnostics.

Returns : Promise<number>

A promise that resolves to the system uptime in seconds.

src/temperature.ts

getTemperature
getTemperature()

Get system temperature based on the platform.

This function retrieves the temperature of the CPU or thermal zone, depending on the operating system:

  • On Linux, it reads from the thermal zone file.
  • On Windows, it uses WMIC to get the temperature.
  • On macOS, temperature retrieval is currently not supported.
Returns : Promise<number | undefined>

Temperature in Celsius or undefined if not supported or an error occurs.

src/userInfo.ts

getUserInfo
getUserInfo()

Retrieves extended user information and system details.

Returns : ExtendedUserInfo
  • Object containing user and system information.
  • username: The name of the current user.
  • homedir: The home directory of the user.
  • shell: The default shell for the user (e.g., /bin/bash, /bin/zsh).
  • hostname: The hostname of the operating system.
  • platform: The platform on which the Node.js process is running (e.g., 'linux', 'win32').
  • architecture: The architecture of the operating system's processor (e.g., 'x64', 'arm').

src/trackTime.ts

logToFile
logToFile(logData: LogData, filePath: string)

Writes log data to a specified file in JSON format.

Parameters :
Name Type Optional Description
logData LogData No
  • Data to log.
filePath string No
  • Path to the log file.
Returns : void
trackTime
trackTime(options: TrackTimeOptions)

Middleware to track request/response time.

This middleware logs the time taken for each request to complete and can store logs either in a file or by invoking a provided callback function to store the log data in a database.

Parameters :
Name Type Optional Description
options TrackTimeOptions No
  • Options to configure logging behavior.

results matching ""

    No results matching ""