Skip to content

Releases: sentrychris/psmonitor

v1.2.2.1551

25 Jul 19:19
Compare
Choose a tag to compare

psmonitor

A simple system and network monitoring solution with a built-in server for remote monitoring capabilities.

app

View an example web client dashboard here

Features

  • Asynchronous Data Collection: Efficient, non-blocking data collection.
  • Real-Time Monitoring: Transmits live system and network statistics.
  • System Statistics: Provides CPU, memory, and disk usage, uptime, and top processes.
  • Network Statistics: Monitors data sent and received on network interfaces.
  • Websocket Server: Includes a tornado server for remote monitoring (built-in and standalone).

Desktop application

The desktop application is built with Tkinter, Python's binding to the Tk GUI toolkit, it consists of:

  • Core logic: The collection of modules, scripts and binaries that are used to provide the functionality.
  • The server: Used by the app to receive data to display, but can also be run as its own standalone service.

Server

The server manages the execution of the monitoring scripts, using multiple threads managed through an executor to retrieve data asynchronously and mitigate blocking operations from calls to read system data.

The server is built with tornado, a scalable, non-blocking web server designed to handle a large number of concurrent connections. It's non-blocking nature makes it ideal for building real-time services.

While the server is included in the desktop application, a standalone version is provided for people who want to build their own clients, or for people who want to port-forward and setup remote monitoring.

HTTP

Three standard HTTP endpoints are provided:

GET /system:

Retrieves system monitoring information

  • CPU: Temperature, Frequency, Usage
  • Disk: Used, Free, Total, Usage
  • Mem: Used, Free, Total, Usage
  • User: Logged in user
  • Platform: Distribution, Kernel, Uptime
  • Processes Top 10 processes by memory usage

A small note on CPU temperature monitoring on Windows: reading temperature sensors requires elevated privileges, in order to display your CPU temperature on Windows, you'll need to run PSMonitor as an administrator.

PSMonitor uses a tiny binary executable called libwincputemp, which is part of this project.

GET /network:

Retrieves network monitoring information:

  • Interfaces: Visible network interfaces
  • Wireless: Name, Quality, Channel, Encryption, Address, Signal
  • Statistics: For each interface: MB sent, MB received, packets sent, packets received, errors receiving packets, error sending packets, dropout rate.

GET /:

Renders a simple dashboard to check or test the server.

POST /:

Creates a worker to manage the execution of monitoring scripts. Responds with a worker ID which is then used in the websocket connection endpoint URL (below).

Websocket

A single websocket endpoint is provided.

WS /connect?id={<worker_id>}

  • Creates the websocket connection, data immediately begins being sent through the connection.

Running the server as a managed process

If you would like to run the standalone server as a managed process, you can use the systemd service file provided.

  1. Copy the service file and make any necessary changes:

    sudo cp ./psmonitor.service /etc/systemd/system/
  2. Reload the daemon to recognize the new service:

    sudo systemctl daemon-reload
  3. Start the service:

    sudo systemctl start psmonitor

Alternatively, you could use supervisor or something similar.

Connecting to the server from your own app

To connect to the WebSocket server, you can use any WebSocket client. Here is an example of how to connect using JavaScript:

  1. Retrieve the assigned worker:

    const client = await fetch(`http://<server-address>`, {
        method: 'POST',
        body: { connection: 'monitor' }
    });
    const worker = await client.json()
  2. Open the WebSocket connection and retrieve data:

    const url = `ws://<server-address>:<port>/ws?id=${worker.id}`;
    
    connection = new WebSocket(url);
    connection.onopen = () => {
        log.write('event', 'websocket is connected');
    }
    connection.onmessage = (response) => {
        const data = JSON.parse(response.data);
    }

You can also use WebSocket clients in other programming languages, such as Python:

  1. Retrieve an assigned worker:

    import requests
    
    response = requests.post('http://<server-address>', json={'connection': 'monitor'})
    worker = response.json()
  2. Open the WebSocket connection and retrieve data:

    import asyncio
    import websockets
    
    async def connect():
        uri = f"ws://<server-address>:<port>/ws?id={worker['id']}"
        async with websockets.connect(uri) as websocket:
            async for message in websocket:
                print(message)
    
    asyncio.run(connect())

You can use the quick dashboard located at public/web.html for further testing and exploration.

I hope you like it!

License

This software is open-sourced software licensed under the MIT license.

Credits

This software uses LibreHardwareMonitorLib.dll in order to provide CPU temperature readings on Windows. The DLL forms part of the libwincputemp program which is part of this project. LibreOpenHardwareMonitor is licensed under MPL 2.0, a copy of the license can be found in the third-party licenses file.

v1.2.1.1167

25 Jul 02:02
Compare
Choose a tag to compare

psmonitor

A simple system and network monitoring solution with real-time data transmission via a websocket server.

This project includes psutil scripts for gathering system and network statistics, and a tornado-based websocket server for transmitting these statistics to connected clients.

Psmonitor also includes a desktop application.

app

View an example web client dashboard here

Requirements

  • Python 3

Features

  • Asynchronous Data Collection: Utilizes asyncio and ThreadPoolExecutor for efficient, non-blocking data collection.
  • Real-Time Monitoring: Transmits live system and network statistics to clients via WebSocket.
  • System Statistics: Provides CPU usage, memory usage, disk usage, system uptime, and top processes by memory usage.
  • Network Statistics: Monitors data sent and received on a specified network interface.
  • Websocket Server: Tornado-based server for real-time data transmission.

Quick Start

  1. Clone this repository:

    git clone [email protected]:sentrychris/psmonitor.git
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the server:

    python server.py run --port=<port> --address=<address>

The websocket server comes with a simple dashboard to test the websocket connection.

Output

Here is the example output from the websocket connection:

{
    "cpu": {
        "usage": 0,
        "temp": 50,
        "freq": 2496
    },
    "mem": {
        "total": 15.54,
        "used": 1.61,
        "free": 13.62,
        "percent": 12.2
    },
    "disk": {
        "total": 1006.85,
        "used": 15.67,
        "free": 939.97,
        "percent": 1.6
    },
    "uptime": "18 hours, 43 minutes, 4 seconds",
    "processes": [
        {
            "memory_info": [
                601661440,
                2731663360,
                47755264,
                84582400,
                0,
                611880960,
                0
            ],
            "name": "node",
            "username": "chris",
            "pid": 424191,
            "mem": 573.79
        },
        {
            "memory_info": [
                262885376,
                12823240704,
                55906304,
                84582400,
                0,
                292528128,
                0
            ],
            "name": "node",
            "username": "chris",
            "pid": 423236,
            "mem": 250.71
        },
        ...
    ]
}

Desktop application

A desktop application is provided, everything is self-contained:

  • The websocket server
  • The system monitoring scripts
  • The GUI

Requirements

Linux

  • python3-tk
  • python3-pil.imagetk

To quickly run the desktop application:

python3 main.py

To build a single-file executable for Windows:

./scripts/build-exe

Websocker server

Running the server as a managed process

If you would like to run the server as a managed process, you can use the systemd service file provided.

  1. Copy the service file and make any necessary changes:

    sudo cp ./psmonitor.service /etc/systemd/system/
  2. Reload the daemon to recognize the new service:

    sudo systemctl daemon-reload
  3. Start the service:

    sudo systemctl start psmonitor

Alternatively, you could use supervisor or something similar.

Next steps

To connect to the WebSocket server, you can use any WebSocket client. Here is an example of how to connect using JavaScript:

  1. Retrieve the assigned worker:

    const client = await fetch(`http://<server-address>`, {
        method: 'POST',
        body: { connection: 'monitor' }
    });
    const worker = await client.json()
  2. Open the WebSocket connection and retrieve data:

    const url = `ws://<server-address>:<port>/ws?id=${worker.id}`;
    
    connection = new WebSocket(url);
    connection.onopen = () => {
        log.write('event', 'websocket is connected');
    }
    connection.onmessage = (response) => {
        const data = JSON.parse(response.data);
    }

You can also use WebSocket clients in other programming languages, such as Python, to connect to the server:

  1. Retrieve an assigned worker:

    import requests
    
    response = requests.post('http://<server-address>', json={'connection': 'monitor'})
    worker = response.json()
  2. Open the WebSocket connection and retrieve data:

    import asyncio
    import websockets
    
    async def connect():
        uri = f"ws://<server-address>:<port>/ws?id={worker['id']}"
        async with websockets.connect(uri) as websocket:
            async for message in websocket:
                print(message)
    
    asyncio.run(connect())

You can use the quick dashboard located at public/index.html for further testing and exploration.

If you are using the system monitor web client, there are instructions contained there to help you get setup and connected.

I hope you like it!

License

This software is open-sourced software licensed under the MIT license.

v1.0.0

21 Jul 08:10
Compare
Choose a tag to compare

psmonitor

A simple system and network monitoring solution with real-time data transmission via a websocket server.

This project includes psutil scripts for gathering system and network statistics, and a tornado-based websocket server for transmitting these statistics to connected clients.

Psmonitor also includes a desktop application.

View an example web client dashboard here

Requirements

  • Python 3

Features

  • Asynchronous Data Collection: Utilizes asyncio and ThreadPoolExecutor for efficient, non-blocking data collection.
  • Real-Time Monitoring: Transmits live system and network statistics to clients via WebSocket.
  • System Statistics: Provides CPU usage, memory usage, disk usage, system uptime, and top processes by memory usage.
  • Network Statistics: Monitors data sent and received on a specified network interface.
  • Websocket Server: Tornado-based server for real-time data transmission.

Quick Start

  1. Clone this repository:

    git clone [email protected]:sentrychris/psmonitor.git
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the server:

    python server.py run --port=<port> --address=<address>

The websocket server comes with a simple dashboard to test the websocket connection.

Output

Here is the example output from the websocket connection:

{
    "cpu": {
        "usage": 0,
        "temp": 50,
        "freq": 2496
    },
    "mem": {
        "total": 15.54,
        "used": 1.61,
        "free": 13.62,
        "percent": 12.2
    },
    "disk": {
        "total": 1006.85,
        "used": 15.67,
        "free": 939.97,
        "percent": 1.6
    },
    "uptime": "18 hours, 43 minutes, 4 seconds",
    "processes": [
        {
            "memory_info": [
                601661440,
                2731663360,
                47755264,
                84582400,
                0,
                611880960,
                0
            ],
            "name": "node",
            "username": "chris",
            "pid": 424191,
            "mem": 573.79
        },
        {
            "memory_info": [
                262885376,
                12823240704,
                55906304,
                84582400,
                0,
                292528128,
                0
            ],
            "name": "node",
            "username": "chris",
            "pid": 423236,
            "mem": 250.71
        },
        ...
    ]
}

Desktop application

A desktop application is provided, everything is self-contained:

  • The websocket server
  • The system monitoring scripts
  • The GUI

Requirements

Linux

  • python3-tk
  • python3-pil.imagetk

To quickly run the desktop application:

python3 main.py

To build a single-file executable for Windows:

./scripts/build-exe

Websocker server

Running the server as a managed process

If you would like to run the server as a managed process, you can use the systemd service file provided.

  1. Copy the service file and make any necessary changes:

    sudo cp ./psmonitor.service /etc/systemd/system/
  2. Reload the daemon to recognize the new service:

    sudo systemctl daemon-reload
  3. Start the service:

    sudo systemctl start psmonitor

Alternatively, you could use supervisor or something similar.

Next steps

To connect to the WebSocket server, you can use any WebSocket client. Here is an example of how to connect using JavaScript:

  1. Retrieve the assigned worker:

    const client = await fetch(`http://<server-address>`, {
        method: 'POST',
        body: { connection: 'monitor' }
    });
    const worker = await client.json()
  2. Open the WebSocket connection and retrieve data:

    const url = `ws://<server-address>:<port>/ws?id=${worker.id}`;
    
    connection = new WebSocket(url);
    connection.onopen = () => {
        log.write('event', 'websocket is connected');
    }
    connection.onmessage = (response) => {
        const data = JSON.parse(response.data);
    }

You can also use WebSocket clients in other programming languages, such as Python, to connect to the server:

  1. Retrieve an assigned worker:

    import requests
    
    response = requests.post('http://<server-address>', json={'connection': 'monitor'})
    worker = response.json()
  2. Open the WebSocket connection and retrieve data:

    import asyncio
    import websockets
    
    async def connect():
        uri = f"ws://<server-address>:<port>/ws?id={worker['id']}"
        async with websockets.connect(uri) as websocket:
            async for message in websocket:
                print(message)
    
    asyncio.run(connect())

You can use the quick dashboard located at public/index.html for further testing and exploration.

If you are using the system monitor web client, there are instructions contained there to help you get setup and connected.

I hope you like it!

License

This software is open-sourced software licensed under the MIT license.