systeminformation

repository·master·Indexed 25 days ago

https://github.com/sebhildebrandt/systeminformation

An advanced, lightweight system and OS information library (version 5.33.1) used to retrieve low-level hardware and system data across Linux, macOS, Windows, FreeBSD, OpenBSD, and NetBSD. It provides methods to fetch static and dynamic system data, monitor metrics via observe(), and interact with the Docker engine via the DockerSocket class. The library includes a CLI for generating summary reports and full static data snapshots in JSON format.

Tokens
1.4K
Snippets
0
Records
14
Agent score
79%

What's inside systeminformation

  1. Configure Docker socket connection via environment variables

    master

    The DockerSocket client determines the connection path and timeout using the following environment variables:

    • DOCKER_SOCKET: The path to the Docker socket. Defaults to //./pipe/docker_engine on Windows or /var/run/docker.sock on Unix-like systems.
    • DOCKER_SOCKET_TIMEOUT: The connection timeout in milliseconds. Defaults to 30000 (30 seconds).
  2. Retrieve all dynamic system data

    master

    Use getDynamicData(srv, iface, callback) to retrieve real-time metrics suitable for monitoring agents. This includes data like cpuCurrentSpeed, users, processes, currentLoad, temp, networkStats, networkConnections, mem, battery, services, fsSize, wifiNetworks, and inetLatency.

    Parameters:

    • srv: A comma-separated string of services to monitor (e.g., "mysql, apache, postgresql").
    • iface: The network interface to monitor for network speed (e.g., "eth0"). If not provided, the default interface is used.

    The function returns a Promise and can optionally accept a callback.

  3. Get battery information

    master
    The battery module provides a function that returns detailed information about the system's battery status and health. It supports multiple platforms including Linux, macOS (Darwin), Windows, FreeBSD, OpenBSD, and NetBSD. The function returns a Promise that resolves to a battery information object, or accepts a callback function.
  4. Retrieve all static system data

    master

    Use getStaticData() to retrieve hardware and OS information that typically remains constant until a system restart. This includes data for system, bios, baseboard, chassis, os, uuid, versions, cpu (including flags), graphics, net, memLayout, diskLayout, audio, bluetooth, usb, and printer.

    The function returns a Promise that resolves to the data object and can optionally accept a callback.

  5. Use the DockerSocket class to query Docker engine information

    master
    The DockerSocket class provides methods to interact with the Docker engine via its Unix/Named Pipe socket. All methods follow a callback pattern (error, data) => void. If a request fails, times out, or returns a non-2xx status, the callback is invoked with an empty object {}.
  6. Fetch specific data subsets using `get()`

    master

    The get(valueObject, callback) method allows you to request only specific pieces of information using a mapping object. This is highly efficient for targeted data retrieval.

    Value Object Syntax:

    • The keys in the object must match exported function names.
    • The values can be:
      • '*': Returns the full result of the function.
      • 'all': Returns the full result.
      • 'key1, key2': Returns an object containing only the specified keys from the result.
      • 'key1, key2 | filter': Returns an object with specified keys, filtered by a condition (e.g., key:value).

    Filtering Syntax:

    • Use the pipe | to separate keys from a filter.
    • Filters support exact matches for strings (case-insensitive) or exact matches for numbers (e.g., cpu: 4).

    Example of a value object: { cpu: 'manufacturer, brand', mem: '*' }

  7. Retrieve all system data (Static + Dynamic)

    master

    Use getAllData(srv, iface, callback) to get a complete snapshot of the system by combining both static and dynamic data. This is the most comprehensive method but may take several seconds to complete.

    Parameters:

    • srv: A comma-separated string of services to monitor.
    • iface: The network interface to monitor.

    The function returns a Promise and can optionally accept a callback.

  8. Observe system changes with `observe()`

    master

    Use observe(valueObject, interval, callback) to monitor specific system metrics over time. It will trigger the callback only when the retrieved data changes (compared to the previous poll).

    Parameters:

    • valueObject: The same query object used in get().
    • interval: The polling interval in milliseconds.
    • callback: A function called with the new data when a change is detected.

    Returns: The interval ID from setInterval, which can be used to stop the observation.

  9. Battery information data structure

    master

    The battery information object contains the following fields:

    FieldTypeDescription
    hasBatterybooleanWhether a battery was detected
    cycleCountnumberNumber of battery charge cycles
    isChargingbooleanWhether the battery is currently charging
    designedCapacitynumberThe original design capacity
    maxCapacitynumberThe current maximum capacity
    currentCapacitynumberThe current available capacity
    voltagenumberCurrent battery voltage
    capacityUnitstringUnit of capacity (e.g., 'mWh', 'mAh', or 'unknown')
    percentnumberBattery charge percentage (0-100)
    timeRemainingnumberEstimated time remaining in minutes (null if unavailable)
    acConnectedbooleanWhether the system is connected to AC power
    typestringBattery technology type (e.g., 'Li-ion')
    modelstringBattery model name
    manufacturerstringBattery manufacturer
    serialstringBattery serial number
    additionalBatteriesArray<Object> (Windows only)A list of secondary battery objects if multiple are present