Monitor and manage Raspberry Pi system metrics via a Flask server
Project description
RPi Metrics
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.
-
Clone this repository
sudo git -c http.followRedirects=true clone https://github.com/QinCai-rui/RPi-Metrics.git /usr/share/rpi-metrics
-
Navigate to the server directory:
cd /usr/share/rpi-metrics/Server
-
Activate the virtual environment:
source venv/bin/activate
-
Run the server:
sudo python3 rpi_metrics_server.py
-
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.
-
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"
-
Download the client code to your Pi Pico. The code is here.
-
Ensure your Raspberry Pi Pico is connected to the internet.
-
Run the client script (or save it as
main.pyto 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 returnsHTTP 200and 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 401and 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 returnsHTTP 200and 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 401and 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:
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-wetflag will removepython3,python3-pip, andpython3-venvfrom 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rpi_metrics_server-1.0.0.tar.gz.
File metadata
- Download URL: rpi_metrics_server-1.0.0.tar.gz
- Upload date:
- Size: 25.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3253c4dd325f33f907582e989d3a83455594312c32bda91efb954e9357ccb1c3
|
|
| MD5 |
d9404d7633cefecb28985dabea2824a8
|
|
| BLAKE2b-256 |
903a11b9b313a5f97ea615430d5d437606f3b7dba84d9e37758e5731a9967bef
|
Provenance
The following attestation bundles were made for rpi_metrics_server-1.0.0.tar.gz:
Publisher:
publish-pypi.yml on QinCai-rui/RPi-Metrics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rpi_metrics_server-1.0.0.tar.gz -
Subject digest:
3253c4dd325f33f907582e989d3a83455594312c32bda91efb954e9357ccb1c3 - Sigstore transparency entry: 203548117
- Sigstore integration time:
-
Permalink:
QinCai-rui/RPi-Metrics@3ef54336f9e3ef52dfbeedf0ff17f73b9461fb82 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QinCai-rui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3ef54336f9e3ef52dfbeedf0ff17f73b9461fb82 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file rpi_metrics_server-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rpi_metrics_server-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
252a0a99c2758341c80cf682f8ca1ef1b2f22edee1f28e83b1062cedc54095f5
|
|
| MD5 |
f00e26777306fea0b929c3236e518db1
|
|
| BLAKE2b-256 |
fc35e640c8378879a459608abf68d21c07382406b3112bf496f8499c787db5c1
|
Provenance
The following attestation bundles were made for rpi_metrics_server-1.0.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on QinCai-rui/RPi-Metrics
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rpi_metrics_server-1.0.0-py3-none-any.whl -
Subject digest:
252a0a99c2758341c80cf682f8ca1ef1b2f22edee1f28e83b1062cedc54095f5 - Sigstore transparency entry: 203548120
- Sigstore integration time:
-
Permalink:
QinCai-rui/RPi-Metrics@3ef54336f9e3ef52dfbeedf0ff17f73b9461fb82 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QinCai-rui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3ef54336f9e3ef52dfbeedf0ff17f73b9461fb82 -
Trigger Event:
workflow_dispatch
-
Statement type: