Beszel Server Monitoring Platform
repository·main·Indexed 12 days ago
https://github.com/henrygd/beszelA lightweight server monitoring platform for tracking host and container metrics (Docker/Podman) with low resource usage. It utilizes a client-server architecture consisting of a central Hub for dashboards and management, and lightweight Agents installed on monitored systems to collect CPU, memory, disk, network, GPU, and S.M.A.R.T. data.
What's inside Beszel
- Beszel is a lightweight server monitoring platform designed for simplicity and low resource consumption. It provides a web interface to monitor host systems and Docker/Podman containers, offering historical data, Docker statistics, and configurable alerts. Key features include multi-user support, OAuth/OIDC authentication, automatic backups (to disk or S3), and a REST API for external integration.
How Beszel architecture works
mainBeszel operates using a client-server model consisting of two primary components:
- Hub: The central web application (built on PocketBase) that serves as the dashboard for viewing metrics and managing connected systems.
- Agent: A lightweight component installed on every system you wish to monitor. The agent collects system metrics and communicates them back to the Hub.
Getting started with Beszel
mainTo set up Beszel, you need to deploy both the Hub and the Agent. Detailed installation steps and a quick start guide are available at the official documentation site: beszel.dev.Manually configure Beszel Hub systemd service
mainIf you prefer not to use the install script, you can manually create a systemd service file at
/etc/systemd/system/beszel.service.Ensure you replace the placeholders in curly braces with your actual paths and username. After creating the file, reload the daemon, enable the service for boot, and start it.
# /etc/systemd/system/beszel.service [Unit] Description=Beszel Hub Service After=network.target [Service] ExecStart={/path/to/working/directory}/beszel serve WorkingDirectory={/path/to/working/directory} User={YOUR_USERNAME} Restart=always [Install] WantedBy=multi-user.targetsudo systemctl daemon-reload sudo systemctl enable beszel.service sudo systemctl start beszel.serviceInstall Beszel Agent as a systemd service using the install script
mainThe recommended way to run the Beszel Agent in the background is via the provided install script. This script creates a dedicated
beszeluser, downloads the latest release, and sets up the systemd service.You can optionally provide an SSH key and port as arguments. If using the
-kflag for a key, ensure the key is enclosed in quotes.# Download the script curl -sL https://raw.githubusercontent.com/henrygd/beszel/main/supplemental/scripts/install-agent.sh -o install-agent.sh && chmod +x install-agent.sh # Install ./install-agent.sh # View help for arguments ./install-agent.sh -hUninstall or Update Beszel Hub
mainTo remove the Beszel Hub service, run the install script with the
-uflag. To update the Hub, use the internal update command and restart the systemd service.# Uninstall ./install-hub.sh -u # Update sudo /opt/beszel/beszel update && sudo systemctl restart beszel-hubUninstall or Update Beszel Agent
mainTo remove the Beszel Agent service, run the install script with the
-uflag. To update the Agent, use the internal update command and restart the systemd service.# Uninstall ./install-agent.sh -u # Update sudo /opt/beszel-agent/beszel-agent update && sudo systemctl restart beszel-agentInstall Beszel Hub as a systemd service using the install script
mainThe recommended way to run the Beszel Hub in the background is via the provided install script. This script creates a dedicated
beszeluser, downloads the latest release, and sets up the systemd service. You must have system administrator privileges.To install, download the script, make it executable, and run it. You can optionally specify a custom port using the
-pflag (default is8090).# Download the script curl -sL https://raw.githubusercontent.com/henrygd/beszel/main/supplemental/scripts/install-hub.sh -o install-hub.sh && chmod +x install-hub.sh # Install (default port 8090) ./install-hub.sh # Install with a custom port ./install-hub.sh -p 9000Manually configure Beszel Agent systemd service
mainTo manually install the Beszel Agent, create a service file at
/etc/systemd/system/beszel-agent.service.You can use
Environmentvariables to configure the agent:PORT: The port to run on.KEY: The authentication key.EXTRA_FILESYSTEMS: (Optional) Specify additional filesystems to monitor (e.g.,Environment="EXTRA_FILESYSTEMS={sdb}").
Replace all
{}placeholders with your actual configuration values. After creation, reload, enable, and start the service.# /etc/systemd/system/beszel-agent.service [Unit] Description=Beszel Agent Service After=network.target [Service] Environment="PORT={PASTE_YOUR_PORT_HERE}" Environment="KEY={PASTE_YOUR_KEY_HERE}" # Environment="EXTRA_FILESYSTEMS={sdb}" ExecStart={/path/to/directory}/beszel-agent User={YOUR_USERNAME} Restart=always [Install] WantedBy=multi-user.targetsudo systemctl daemon-reload sudo systemctl enable beszel-agent.service sudo systemctl start beszel-agent.serviceWebSocketClient message routing and decoding
mainThe
WebSocketClientimplements thegws.BuiltinEventHandlerinterface to process incoming traffic:- Binary Messages: The client expects
gws.OpcodeBinary. Incoming data is unmarshaled from CBOR into acommon.HubRequest[cbor.RawMessage]structure. - Routing: Once decoded, the request is passed to
handleHubRequest, which uses the agent'shandlerRegistryto find the appropriate logic to execute based on the message content. - Pings: The client automatically responds to
OnPingframes with a pong to maintain the connection and resets thewsDeadline.
- Binary Messages: The client expects
How WebSocketClient handles authentication and verification
mainThe
WebSocketClientuses a two-step process for secure communication:- Token Authentication: During the initial WebSocket handshake, the client includes the registration token in the
X-TokenHTTP header. - Hub Verification: Upon connection, the hub may issue an authentication challenge. The client verifies the hub's signature using the agent's configured public keys (
client.agent.keys). Once verified,client.hubVerifiedis set totrue, allowing the agent to proceed with sending sensitive system information.
- Token Authentication: During the initial WebSocket handshake, the client includes the registration token in the
Deploy Beszel Hub using Docker Compose
mainTo run the Beszel Hub (the central dashboard) on the same system as your agent, use the
henrygd/beszel:latestimage. The Hub requires a persistent volume for data and a socket for communication.Key configuration:
- Ports: Maps host port
8090to container port8090. - Environment Variables: Set
APP_URLto the public or local URL where the dashboard is accessible. - Volumes: Requires
./beszel_datafor application data and./beszel_socketfor the socket file.
services: beszel: image: henrygd/beszel:latest container_name: beszel restart: unless-stopped environment: APP_URL: http://localhost:8090 ports: - 8090:8090 volumes: - ./beszel_data:/beszel_data - ./beszel_socket:/beszel_socket- Ports: Maps host port