Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

permissions:
contents: read

jobs:
lint:
name: PHP Lint ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php:
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- uses: actions/checkout@v4

- name: Setup PHP ${{ matrix.php }}
uses: shivammathur/setup-php@v4
with:
php-version: ${{ matrix.php }}
coverage: none

- name: Lint all PHP files
run: find app -name '*.php' -print0 | xargs -0 -n1 php -l 1>/dev/null
54 changes: 46 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
![PHP](https://img.shields.io/badge/PHP-%3E%3D7.4-777BB4.svg)
[![CI](https://github.com/GLOBUS-studio/SimpleServerStat/actions/workflows/ci.yml/badge.svg)](https://github.com/GLOBUS-studio/SimpleServerStat/actions/workflows/ci.yml)

Simple, dependency-light server dashboard that shows live **CPU** and **RAM**
usage (plus basic host info) in the browser. Backend is plain PHP, frontend is
Expand All @@ -10,19 +11,20 @@ a single HTML page driven by [Chart.js](https://www.chartjs.org/).
## Features

- Live CPU and RAM chart, refreshed every 2 seconds.
- **Non-blocking** metric collection: CPU usage is computed from a cached
`/proc/stat` snapshot and memory from `/proc/meminfo` — no slow `top`,
`mpstat` or `iostat` sampling per request.
- Graceful fallback to load-average when `/proc` is unavailable.
- **Non-blocking** metric collection: no slow `top`, `mpstat` or `iostat`
sampling. Linux uses `/proc`; Windows uses WMI (`wmic`, with PowerShell CIM
fallback).
- Cross-platform: accurate data on Linux and Windows; graceful fallback to
load average when detailed sources are unavailable.
- Optional shared-secret token to gate the JSON API.
- No build step and no server-side framework required.

## Requirements

- PHP 7.4+ served by any web server (Apache, Nginx + PHP-FPM, or `php -S`).
- Linux for full CPU/RAM metrics (reads `/proc/stat`, `/proc/meminfo`,
`/proc/cpuinfo`). On other platforms the page still loads but live metrics
may be unavailable.
- Linux for the most precise metrics (reads `/proc`). On Windows the page and
chart work fully via WMI; on other platforms the page loads but live charts
may be empty.

## Project layout

Expand All @@ -37,14 +39,17 @@ app/

## Running

Serve the `app/` directory with PHP, for example:
Serve the `app/` directory with PHP:

```bash
php -S 0.0.0.0:8080 -t app
```

Then open <http://localhost:8080/>.

On Windows you can double-click **`start.bat`** — it starts the server and
opens the browser in one step.

## Configuration

Copy the template and edit it (the real file is gitignored):
Expand All @@ -68,6 +73,39 @@ the dashboard injects it automatically.
| `loader.php?action=system_info` | `{ load, memory_usage }` (live) |
| `loader.php?action=general` | `{ cpu_count, php_ver, os_data }` |

## Limitations / Caveats

- On Linux the first poll after server start returns a **load-average**
approximation; subsequent polls (every 2s) show the true `/proc/stat` delta.
- On Windows `wmic` is preferred; if it is unavailable (Windows 11 24H2 has
it as an optional feature) the PowerShell CIM fallback is transparently used.
- The built-in PHP server is single-threaded. For production with multiple
concurrent viewers, serve behind Nginx or Apache.
- The shared-secret token is a basic safeguard only — because `index.php`
exposes it client-side, protect the whole `app/` directory at the web-server
level for real privacy.

## Development

```bash
# Start the built-in server
php -S 127.0.0.1:8080 -t app

# Windows: one-click launcher
start.bat

# Lint all PHP files
find app -name '*.php' -print0 | xargs -0 -n1 php -l 2>&1 | grep -v '^No syntax'
```

All PHP files are linted on every push and pull request via GitHub Actions
(see `.github/workflows/ci.yml`).

## Credits

- [Chart.js](https://www.chartjs.org/) — charting library (MIT)
- [Bootstrap](https://getbootstrap.com/) — CSS framework (MIT)

## License

Released under the [MIT License](LICENSE).
13 changes: 13 additions & 0 deletions start.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@echo off
setlocal

echo ========================================
echo SimpleServerStat [GLOBUS.studio]
echo ========================================
echo.
echo Starting built-in PHP server...
start http://127.0.0.1:8080/
php -S 127.0.0.1:8080 -t app

endlocal
pause
Loading