Skip to main content

RPi Metrics

Github top language Github language count Repository size License

Welcome to the RPi Metrics project! This project allows you to monitor and manage your Raspberry Pi's system metrics such as CPU usage, memory usage, and more via a Flask server and a client application (optional but highly recommended).

[!TIP] You can also remote poweroff, remote reboot, and remote update your Pi, from anywhere in the world, provided that the server is reachable from the wider internet. (Check out https://pi5-monitor.qincai.xyz to see it yourself!)

Prerequisites

Ensure you have the following installed on your Raspberry Pi: If you don't have everything, no worries! Just use the installation script below! It will handle everything for you!

  • Python 3
  • Pip
  • Git
  • Curl

However, ensure that curl is already installed on your system before using the Quick Installer.

Quick Installation

Use the installation script by running:

sudo su
bash <(curl -sSL https://qincai.xyz/rpi-metrics-installer.sh)

Alternatively, you can run:

curl -sSL https://qincai.xyz/rpi-metrics-installer.sh | sudo bash -s - -y

to accept all defaults.

Or:

curl -sSL https://qincai.xyz/rpi-metrics-installer.sh | bash -s - --no-check-root

to bypass root check.

Setting Up the Server

[!NOTE] You can skip this if you used the Quick Installer script.

  1. Clone this repository

    sudo git -c http.followRedirects=true clone https://github.com/QinCai-rui/RPi-Metrics.git /usr/share/rpi-metrics
    
  2. Navigate to the server directory:

    cd /usr/share/rpi-metrics/Server
    
  3. Activate the virtual environment:

    source venv/bin/activate
    
  4. Run the server:

    sudo python3 rpi_metrics_server.py
    
  5. Alternatively, start it as a systemd service (Recommended):

    sudo cp /usr/share/rpi-metrics/Server/rpi-metricsd.service /etc/systemd/system/
    sudo systemctl enable --now rpi-metricsd
    

Setting Up the Client

The client should be a Raspberry Pi Pico W or Pico 2 W with 2 buttons and an SSD1306 128x64 screen. The Pico is optional. You can use this API on any device.

  1. Create a .env file in the client directory with the following content:

    SSID = "your_wifi_ssid"
    PSK = "your_wifi_password"
    SERVER_URL = "http://your_server_url"
    API_KEY = "your_api_key_here"
    
  2. Download the client code to your Pi Pico. The code is here.

  3. Ensure your Raspberry Pi Pico is connected to the internet.

  4. Run the client script (or save it as main.py to run at startup).

Available API Endpoints

  • GET /api/time: Retrieve the current system time. Example Output:

    {
      "Current Time":"Jan 01 00:00:00"
    }
    

  • GET /api/mem: Retrieve memory statistics. Example Output:

    {
      "Total RAM": "465MiB",
      "Total Swap": "2048MiB",
      "Used RAM": "244",
      "Used Swap": "72"
    }
    

  • GET /api/cpu: Retrieve CPU usage. Example Output:

    {
      "CPU Usage": "31%",
      "SoC Temperature": "48.9C"
    }
    

  • GET /api/disk: Retrieve disk usage statistics. Example Output:

    {
      "Total Space": "32G",
      "Used Space": "12G",
      "Available Space": "18G",
      "Usage Percentage": "41%"
    }
    

  • GET /api/system: Retrieve detailed system information. Example Output:

    {
      "Model": "Raspberry Pi 5 Model B Rev 1.0",
      "Kernel Version": "6.6.74+rpt-rpi-2712",
      "OS": "Debian GNU/Linux trixie/sid"
    }
    

  • POST /api/shutdown: Shutdown the system (requires API key in the header). Header name should be x-api-key. The server returns HTTP 200 and the following if a valid API key is provided:

    {
        "message": "System shutting down"
    }
    

    If a valid API key is not provided, the server returns HTTP 401 and the following:

    {
        "error": "Unauthorized"
    }   
    

    Example Usage:

    curl -L -X POST http://your_server_url/api/shutdown -H "x-api-key: your_api_key_here"
    

  • POST /api/reboot: Reboot the system (requires API key in the header). The server returns HTTP 200 and the following if a valid API key is provided:

    {
        "message": "System rebooting now"
    }
    

    If a valid API key is not provided, the server returns HTTP 401.

    Example Usage:

    curl -L -X POST http://your_server_url/api/reboot -H "x-api-key: your_api_key_here"
    

  • POST /api/update: Update the system (requires API key in the header). Header name should be x-api-key. The server returns HTTP 200 and the following if a valid API key is provided, after a update:

    {
        "message": "System update complete!"
    }
    

    If a valid API key is not provided, the server returns HTTP 401 and the following:

    {
        "error": "Unauthorized"
    }   
    

    Example Usage:

    curl -L -X POST http://your_server_url/api/update -H "x-api-key: your_api_key_here"
    

  • GET /api/all: Retrieve comprehensive system statistics. Example Output:

    {
      "CPU Usage": "31%",
      "Current Time": "Jan 1 00:00:00",
      "IP Address": "192.168.2.123 100.93.81.48 fd7a:115c:a1e0::8c01:5130",
      "SoC Temperature": "48.9C",
      "Total RAM": "465MiB",
      "Total Swap": "2048MiB",
      "Used RAM": "244",
      "Used Swap": "72"
    }
    

  • GET /: Access the user-friendly GUI. Example Output: root GUI output image

Uninstallation

If for any reason, you want to uninstall the RPi Metrics server from your Raspberry Pi, use rpi-metrics-uninstall to uninstall it. If that command is not found, try this if you only want to uninstall this project, Python excluded:

curl -sSL https://qincai.xyz/rpi-metrics-uninstaller.sh | sudo bash -s - -wet

Use this if you want to remove Python and other packages installed as well:

curl -sSL https://qincai.xyz/rpi-metrics-uninstaller.sh | sudo bash -s - -extra-wet

[!WARNING] Passing the --extra-wet flag will remove python3, python3-pip, and python3-venv from your system. USE WITH CAUTION!!

Contributing

Contributions are welcome! Please create an issue or fork the repository and submit a pull request for review.

License

This project is licensed under the GPLv3 License. See the LICENSE file for details.

Metadata

Release files for rpi-metrics-server 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rpi-metrics-server 1.0.0
File Size Uploaded
rpi_metrics_server-1.0.0.tar.gz 25.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rpi-metrics-server 1.0.0
File Interpreter ABI Platform
rpi_metrics_server-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 49.2 kB

Release files / rpi_metrics_server-1.0.0.tar.gz

Download URL rpi_metrics_server-1.0.0.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3253c4dd325f33f907582e989d3a83455594312c32bda91efb954e9357ccb1c3
BLAKE2b-256 checksum
How to use checksums
903a11b9b313a5f97ea615430d5d437606f3b7dba84d9e37758e5731a9967bef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2025.

Transparency log

Release files / rpi_metrics_server-1.0.0-py3-none-any.whl

Download URL rpi_metrics_server-1.0.0-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
252a0a99c2758341c80cf682f8ca1ef1b2f22edee1f28e83b1062cedc54095f5
BLAKE2b-256 checksum
How to use checksums
fc35e640c8378879a459608abf68d21c07382406b3112bf496f8499c787db5c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page