remove monitor.php — SSH pull monitoring replaced by push-based agent
This commit is contained in:
@@ -13,7 +13,6 @@ Repo-specific guidance for OpenCode sessions. Verified against code.
|
|||||||
## Commands
|
## Commands
|
||||||
- `composer install` — install deps (no dev deps in `composer.json`)
|
- `composer install` — install deps (no dev deps in `composer.json`)
|
||||||
- `php bin/generate-key.php` — generate master key at `/etc/servermanager/master.key`
|
- `php bin/generate-key.php` — generate master key at `/etc/servermanager/master.key`
|
||||||
- `php bin/monitor.php` — collect server metrics (runs via cron every minute)
|
|
||||||
- `sudo bash install.sh` — full Ubuntu 22.04+/24.04+ install (needs sudo)
|
- `sudo bash install.sh` — full Ubuntu 22.04+/24.04+ install (needs sudo)
|
||||||
- `mysql servermanager < database/migrations/001_initial_schema.sql` — db setup
|
- `mysql servermanager < database/migrations/001_initial_schema.sql` — db setup
|
||||||
- `export ANDROID_HOME=/opt/android-sdk && cd android && ./gradlew assembleDebug` — build APK → `public/sysadmin.apk`
|
- `export ANDROID_HOME=/opt/android-sdk && cd android && ./gradlew assembleDebug` — build APK → `public/sysadmin.apk`
|
||||||
|
|||||||
13
README.md
13
README.md
@@ -116,17 +116,7 @@ server {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5. Cron Job for Monitoring
|
### 5. Start Services
|
||||||
|
|
||||||
```bash
|
|
||||||
# Add to crontab (runs every minute)
|
|
||||||
sudo crontab -u www-data -e
|
|
||||||
|
|
||||||
# Add line:
|
|
||||||
* * * * * php /var/www/servermanager/bin/monitor.php >> /var/www/servermanager/logs/cron.log 2>&1
|
|
||||||
```
|
|
||||||
|
|
||||||
### 6. Start Services
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
sudo systemctl restart php8.3-fpm nginx mysql
|
sudo systemctl restart php8.3-fpm nginx mysql
|
||||||
@@ -171,7 +161,6 @@ All credential accesses are logged:
|
|||||||
```
|
```
|
||||||
ServerManager/
|
ServerManager/
|
||||||
├── bin/
|
├── bin/
|
||||||
│ ├── monitor.php # CLI: collect metrics
|
|
||||||
│ └── generate-key.php # CLI: generate master key
|
│ └── generate-key.php # CLI: generate master key
|
||||||
├── config/
|
├── config/
|
||||||
│ └── config.php # App configuration
|
│ └── config.php # App configuration
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
|
||||||
|
|
||||||
use ServerManager\Core\App;
|
|
||||||
use ServerManager\Services\MonitoringService;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$app = App::getInstance();
|
|
||||||
$app->boot(dirname(__DIR__));
|
|
||||||
|
|
||||||
$monitoring = new MonitoringService();
|
|
||||||
$results = $monitoring->collectAllMetrics();
|
|
||||||
|
|
||||||
$online = count(array_filter($results, fn($r) => $r && ($r['status'] ?? '') === 'online'));
|
|
||||||
$offline = count($results) - $online;
|
|
||||||
|
|
||||||
echo sprintf("[%s] Metrics collected: %d servers (%d online, %d offline)\n",
|
|
||||||
date('Y-m-d H:i:s'), count($results), $online, $offline);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
echo sprintf("[%s] ERROR: %s\n", date('Y-m-d H:i:s'), $e->getMessage());
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
34
install.sh
34
install.sh
@@ -241,11 +241,8 @@ configure_cron() {
|
|||||||
log_step "Configuring Cron Jobs"
|
log_step "Configuring Cron Jobs"
|
||||||
|
|
||||||
cat > /etc/cron.d/servermanager << CRONEOF
|
cat > /etc/cron.d/servermanager << CRONEOF
|
||||||
# ServerManager Monitoring Cron
|
# ServerManager Cron Jobs
|
||||||
# Collect metrics every minute
|
# Logs cleanup — weekly
|
||||||
* * * * * www-data /usr/bin/php ${APP_DIR}/bin/monitor.php >> ${APP_DIR}/logs/cron.log 2>&1
|
|
||||||
|
|
||||||
# Cleanup old logs weekly
|
|
||||||
0 3 * * 0 www-data find ${APP_DIR}/logs/ -name "*.log" -mtime +30 -delete
|
0 3 * * 0 www-data find ${APP_DIR}/logs/ -name "*.log" -mtime +30 -delete
|
||||||
CRONEOF
|
CRONEOF
|
||||||
|
|
||||||
@@ -259,32 +256,6 @@ create_binaries() {
|
|||||||
|
|
||||||
mkdir -p "${APP_DIR}/bin"
|
mkdir -p "${APP_DIR}/bin"
|
||||||
|
|
||||||
cat > "${APP_DIR}/bin/monitor.php" << 'PHPEOF'
|
|
||||||
<?php
|
|
||||||
declare(strict_types=1);
|
|
||||||
require_once __DIR__ . '/../vendor/autoload.php';
|
|
||||||
|
|
||||||
use ServerManager\Core\App;
|
|
||||||
use ServerManager\Services\MonitoringService;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$app = App::getInstance();
|
|
||||||
$app->boot(dirname(__DIR__));
|
|
||||||
|
|
||||||
$monitoring = new MonitoringService();
|
|
||||||
$results = $monitoring->collectAllMetrics();
|
|
||||||
|
|
||||||
$online = count(array_filter($results, fn($r) => $r && ($r['status'] ?? '') === 'online'));
|
|
||||||
$offline = count($results) - $online;
|
|
||||||
|
|
||||||
echo sprintf("[%s] Metrics collected: %d servers (%d online, %d offline)\n",
|
|
||||||
date('Y-m-d H:i:s'), count($results), $online, $offline);
|
|
||||||
} catch (\Throwable $e) {
|
|
||||||
echo sprintf("[%s] ERROR: %s\n", date('Y-m-d H:i:s'), $e->getMessage());
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
PHPEOF
|
|
||||||
|
|
||||||
cat > "${APP_DIR}/bin/generate-key.php" << 'PHPEOF'
|
cat > "${APP_DIR}/bin/generate-key.php" << 'PHPEOF'
|
||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
@@ -307,7 +278,6 @@ echo "Master key generated: {$keyFile}\n";
|
|||||||
echo "IMPORTANT: Store this key securely!\n";
|
echo "IMPORTANT: Store this key securely!\n";
|
||||||
PHPEOF
|
PHPEOF
|
||||||
|
|
||||||
chmod +x "${APP_DIR}/bin/monitor.php"
|
|
||||||
chmod +x "${APP_DIR}/bin/generate-key.php"
|
chmod +x "${APP_DIR}/bin/generate-key.php"
|
||||||
chown -R rafael:rafael "${APP_DIR}/bin"
|
chown -R rafael:rafael "${APP_DIR}/bin"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user