DownloadSystem Monitoring and Backup
This case study demonstrates how Ascoos OS performs system resource monitoring, automated backup creation, encryption, and real-time alerts via Telegram. It showcases the integration of multiple handlers to ensure system stability and data protection.
Purpose
This example highlights the use of the following Ascoos OS components:
- TCoreSystemHandler: Monitors CPU load, memory usage, and system uptime.
- TFilesHandler: Manages file operations, including folder creation, quota checks, and encryption.
- TTelegramAPIHandler: Sends real-time alerts via Telegram.
- TEventHandler: Registers and triggers custom system events.
Structure
The case study is implemented in a single PHP file:
- system_monitoring_backup.php: Monitors system load, creates encrypted snapshots, and sends alerts.
Prerequisites
-
Ensure Ascoos OS is installed (see the main repository). If using
AWES 26, Ascoos OS is preloaded.
-
A valid Telegram bot token and chat ID are required for `TTelegramAPIHandler`.
-
Write permissions for the directories defined in `$AOS_LOGS_PATH` and `$AOS_BACKUP_PATH`.
-
The global variables (`$conf`, `$AOS_LOGS_PATH`, `$AOS_BACKUP_PATH`) are automatically set by Ascoos OS during initialization.
-
The
phpBCL8 library is preinstalled and loaded automatically.
Getting Started
-
Configure the `$properties` array in the script with your Telegram bot token and chat ID.
-
Execute the script via a web server, e.g.:
https://localhost/aos/examples/case-studies/system/monitoring/system_monitoring_backup.php
Example Usage
use ASCOOS\OS\Kernel\Systems\TCoreSystemHandler;
use ASCOOS\OS\Kernel\Files\TFilesHandler;
use ASCOOS\OS\Kernel\API\TTelegramAPIHandler;
use ASCOOS\OS\Kernel\Arrays\Events\TEventHandler;
global $AOS_LOGS_PATH, $AOS_BACKUP_PATH;
// Initialize configuration
$properties = [
'file' => [
'dataDir' => $AOS_BACKUP_PATH . '/system_backups',
'quotaSize' => 1000000
],
'telegram' => [
'url' => 'https://api.telegram.org',
'bot_token' => 'your_bot_token_here'
],
'logs' => [
'useLogger' => true,
'dir' => $AOS_LOGS_PATH . '/ascoos',
'file' => 'system_monitor.log'
]
];
Expected Output
The script generates an encrypted system snapshot and sends a Telegram alert if CPU load exceeds 80%. Example JSON snapshot: {
"cpu_load_percent": 85,
"memory_stats": {
"total": 8192,
"used": 6144,
"free": 2048
},
"uptime_seconds": 36000,
"timestamp": "2025-08-28 15:35:00"
}
Resources
Contributing
Want to contribute to this case study? Fork the repository, modify or add new features to system_monitoring_backup.php, and submit a pull request. See CONTRIBUTING.md for guidelines.
License
This case study is licensed under the Ascoos General License (AGL). See LICENSE.
|