Code Monkey home page Code Monkey logo

system-status's Introduction

Language : ๐Ÿ‡บ๐Ÿ‡ธ English | ๐Ÿ‡จ๐Ÿ‡ณ ็ฎ€ไฝ“ไธญๆ–‡

system-status

NPM Version NPM Downloads Bundle Size

GitHub Actions CI License

Overview

system-status is a NodeJS lib for statistical system data such as cpu, mem, network, disk.

Features

  • CPU load
  • load average
  • memory usage
  • uptime / boot time
  • battery life
  • filesystem mounts (and disk usage)
  • disk I/O statistics
  • network interfaces
  • network traffic statistics
  • CPU temperature

Table of Contents

Getting Started

Prerequisites

  • Node.js (>= 10.4.0 required, LTS preferred)

Support Operating Systems

API Supported platforms (roughly ordered by completeness of support):

  1. FreeBSD
  2. Linux
  3. OpenBSD
  4. Windows
  5. macOS
  6. NetBSD
  7. more coming soon

NPM Package Supported platforms

node12 node14 node16 node18
Windows x64 โœ“ โœ“ โœ“ โœ“
Windows x86 โœ“ โœ“ โœ“ โœ“
Windows arm64 โœ“ โœ“ โœ“ โœ“
macOS x64 โœ“ โœ“ โœ“ โœ“
macOS aarch64 โœ“ โœ“ โœ“ โœ“
Linux x64 gnu โœ“ โœ“ โœ“ โœ“
Linux x64 musl โœ“ โœ“ โœ“ โœ“
Linux aarch64 gnu โœ“ โœ“ โœ“ โœ“
Linux aarch64 musl โœ“ โœ“ โœ“ โœ“
FreeBSD x64 โœ“ โœ“ โœ“ โœ“

Installation

npm install system-status
# or
yarn add system-status
# or
pnpm i system-status

Documentation

Create Stat class instance in first

const stat = new Stat()

mounts (Stat class instance method)

Get filesystem mount information.

mounts(): Array<FileSystem>

mountAt (Stat class instance method)

Get a filesystem mount information for the filesystem at a given path.

mountAt(at: string): FileSystem

blockDeviceStatistics (Stat class instance method)

Get block device statistics objects.

blockDeviceStatistics(): Array<BlockDeviceStats>

networks (Stat class instance method)

Get network intefrace information.

networks(): Array<Network>

networkStats (Stat class instance method)

Get statistics for a given interface name (bytes/packets sent/received).

networkStats(interface: string): NetworkStats

batteryLife (Stat class instance method)

Get a battery life information object.

batteryLife(): BatteryLife

isAcPower (Stat class instance method)

Get whether AC power is plugged in.

isAcPower(): boolean

memory (Stat class instance method)

Get memory information.

memory(): Memory

swap (Stat class instance method)

Get swap memory information.

swap(): Memory

loadAverage (Stat class instance method)

Get load average.

loadAverage(): LoadAverage

uptime (Stat class instance method)

Get the system uptime.

uptime(): bigint

bootTime (Stat class instance method)

Get the system boot time.

bootTime(): Date

cpuLoadAggregate (Stat class instance method)

Get CPU load statistics, average over all CPUs (cores).

cpuLoadAggregate(): CPULoad

cpuTemp (Stat class instance method)

Get the current CPU temperature in degrees Celsius. Depending on the platform, this might be core 0, package, etc.

cpuTemp(): number

socketStats (Stat class instance method)

Get information about the number of sockets in use

socketStats(): SocketStats

format (Function)

Format the source by ConvertOption

The default of ConvertOption is taking 1024 as the advancement, retain one decimal place

function format(source: bigint, option?: ConvertOption | undefined | null): ConvertResult

FileSystem (Type)

interface FileSystem {
  /** Used file nodes in filesystem */
  files: bigint
  /** Total file nodes in filesystem */
  filesTotal: bigint
  /** Free nodes available to non-superuser */
  filesAvail: bigint
  /** Free bytes in filesystem */
  free: bigint
  /** Free bytes available to non-superuser */
  avail: bigint
  /** Total bytes in filesystem */
  total: bigint
  /** Maximum filename length */
  nameMax: bigint
  fsType: string
  fsMountedFrom: string
  fsMountedOn: string
}

BlockDeviceStats (Type)

interface BlockDeviceStats {
  name: string
  readIos: bigint
  readMerges: bigint
  readSectors: bigint
  readTicks: bigint
  writeIos: bigint
  writeMerges: bigint
  writeSectors: bigint
  writeTicks: bigint
  inFlight: bigint
  ioTicks: bigint
  timeInQueue: bigint
}

Network (Type)

interface Network {
  name: string
  addrs: Array<NetworkAddrs>
}
interface NetworkAddrs {
  addr: string
  netmask: string
  addrType: AddrType
}
const enum AddrType {
  Ipv4 = 0,
  IPv6 = 1,
}

NetworkStats (Type)

interface NetworkStats {
  rxBytes: bigint
  txBytes: bigint
  rxPackets: bigint
  txPackets: bigint
  rxErrors: bigint
  txErrors: bigint
}

BatteryLife (Type)

interface BatteryLife {
  remainingCapacity: number
  remainingTime: bigint
}

Memory (Type)

interface Memory {
  free: bigint
  total: bigint
  used: bigint
}

LoadAverage (Type)

interface LoadAverage {
  one: number
  five: number
  fifteen: number
}

CPULoad (Type)

interface CPULoad {
  user: number
  nice: number
  system: number
  interrupt: number
  idle: number
}

ConvertResult (Type)

interface ConvertResult {
  value: string
  unit: string
}

ConvertOption (Type)

interface ConvertOption {
  advance: Advance
  /** Decimal point */
  precision: number
}
/**
 * unit enum for stat option
 * B -> KB, 1000 bytes
 * B -> KIB, 1024 bytes
 */
export const enum Advance {
  /** 1000 */
  Kilobase = 1000,
  /** 1024 */
  Binary = 1024,
}

How to Develop

Development requirements

  • Install the latest Rust
  • Install Node.js@10+ which fully supported Node-API
  • Install [email protected]

Test in local

  • yarn
  • yarn build
  • yarn test

Found an issue or have a proposal

Create an issue

Release Notes

SEE CHANGELOG

Thanks

systemstat

napi-rs

system-status's People

Contributors

zingerlittlebee avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.