feat: Implement server and client metrics collection and monitoring
- Added a new PHP script for collecting server metrics every 30 seconds. - Created a ServerMonitoring class to handle metrics collection for CPU, RAM, Disk, and Network. - Introduced database tables for storing server and client metrics. - Updated server view template to display real-time metrics using Chart.js. - Added translations for monitoring UI elements. - Created a new monitoring template for detailed server metrics visualization. - Implemented client speed tracking and display in the monitoring UI.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
-- Add server metrics tables
|
||||
-- This migration adds functionality to store and display server monitoring data
|
||||
|
||||
-- Server metrics (CPU, RAM, Disk, Network)
|
||||
CREATE TABLE IF NOT EXISTS server_metrics (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
server_id INT UNSIGNED NOT NULL,
|
||||
cpu_percent DECIMAL(5,2) NULL COMMENT 'CPU usage percentage',
|
||||
ram_used_mb INT UNSIGNED NULL COMMENT 'RAM used in MB',
|
||||
ram_total_mb INT UNSIGNED NULL COMMENT 'Total RAM in MB',
|
||||
disk_used_gb DECIMAL(10,2) NULL COMMENT 'Disk used in GB',
|
||||
disk_total_gb DECIMAL(10,2) NULL COMMENT 'Total disk in GB',
|
||||
network_rx_mbps DECIMAL(10,2) NULL COMMENT 'Network receive speed in Mbps',
|
||||
network_tx_mbps DECIMAL(10,2) NULL COMMENT 'Network transmit speed in Mbps',
|
||||
collected_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_server_time (server_id, collected_at),
|
||||
FOREIGN KEY (server_id) REFERENCES vpn_servers(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
||||
-- Client traffic metrics (speed tracking)
|
||||
CREATE TABLE IF NOT EXISTS client_metrics (
|
||||
id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
|
||||
client_id INT UNSIGNED NOT NULL,
|
||||
bytes_sent BIGINT UNSIGNED DEFAULT 0 COMMENT 'Bytes sent at this moment',
|
||||
bytes_received BIGINT UNSIGNED DEFAULT 0 COMMENT 'Bytes received at this moment',
|
||||
speed_up_kbps DECIMAL(10,2) NULL COMMENT 'Upload speed in Kbps',
|
||||
speed_down_kbps DECIMAL(10,2) NULL COMMENT 'Download speed in Kbps',
|
||||
collected_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
INDEX idx_client_time (client_id, collected_at),
|
||||
FOREIGN KEY (client_id) REFERENCES vpn_clients(id) ON DELETE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
@@ -0,0 +1,92 @@
|
||||
-- Add translations for monitoring UI elements
|
||||
|
||||
INSERT INTO translations (translation_key, language_code, translation_value) VALUES
|
||||
-- Speed
|
||||
('common.speed', 'en', 'Speed'),
|
||||
('common.speed', 'ru', 'Скорость'),
|
||||
('common.speed', 'es', 'Velocidad'),
|
||||
('common.speed', 'de', 'Geschwindigkeit'),
|
||||
('common.speed', 'fr', 'Vitesse'),
|
||||
('common.speed', 'zh', '速度'),
|
||||
|
||||
-- Metrics
|
||||
('common.metrics', 'en', 'Metrics'),
|
||||
('common.metrics', 'ru', 'Метрики'),
|
||||
('common.metrics', 'es', 'Métricas'),
|
||||
('common.metrics', 'de', 'Metriken'),
|
||||
('common.metrics', 'fr', 'Métriques'),
|
||||
('common.metrics', 'zh', '指标'),
|
||||
|
||||
-- Server Info
|
||||
('servers.server_info', 'en', 'Server Info'),
|
||||
('servers.server_info', 'ru', 'Информация о сервере'),
|
||||
('servers.server_info', 'es', 'Información del servidor'),
|
||||
('servers.server_info', 'de', 'Serverinformationen'),
|
||||
('servers.server_info', 'fr', 'Informations sur le serveur'),
|
||||
('servers.server_info', 'zh', '服务器信息'),
|
||||
|
||||
-- Status
|
||||
('common.status', 'en', 'Status'),
|
||||
('common.status', 'ru', 'Статус'),
|
||||
('common.status', 'es', 'Estado'),
|
||||
('common.status', 'de', 'Status'),
|
||||
('common.status', 'fr', 'Statut'),
|
||||
('common.status', 'zh', '状态'),
|
||||
|
||||
-- Client Configuration
|
||||
('clients.configuration', 'en', 'Client Configuration'),
|
||||
('clients.configuration', 'ru', 'Конфигурация клиента'),
|
||||
('clients.configuration', 'es', 'Configuración del cliente'),
|
||||
('clients.configuration', 'de', 'Client-Konfiguration'),
|
||||
('clients.configuration', 'fr', 'Configuration du client'),
|
||||
('clients.configuration', 'zh', '客户端配置'),
|
||||
|
||||
-- Traffic Statistics
|
||||
('clients.traffic_stats', 'en', 'Traffic Statistics'),
|
||||
('clients.traffic_stats', 'ru', 'Статистика трафика'),
|
||||
('clients.traffic_stats', 'es', 'Estadísticas de tráfico'),
|
||||
('clients.traffic_stats', 'de', 'Traffic-Statistiken'),
|
||||
('clients.traffic_stats', 'fr', 'Statistiques de trafic'),
|
||||
('clients.traffic_stats', 'zh', '流量统计'),
|
||||
|
||||
-- Uploaded
|
||||
('common.uploaded', 'en', 'Uploaded'),
|
||||
('common.uploaded', 'ru', 'Отправлено'),
|
||||
('common.uploaded', 'es', 'Subido'),
|
||||
('common.uploaded', 'de', 'Hochgeladen'),
|
||||
('common.uploaded', 'fr', 'Envoyé'),
|
||||
('common.uploaded', 'zh', '上传'),
|
||||
|
||||
-- Downloaded
|
||||
('common.downloaded', 'en', 'Downloaded'),
|
||||
('common.downloaded', 'ru', 'Получено'),
|
||||
('common.downloaded', 'es', 'Descargado'),
|
||||
('common.downloaded', 'de', 'Heruntergeladen'),
|
||||
('common.downloaded', 'fr', 'Reçu'),
|
||||
('common.downloaded', 'zh', '下载'),
|
||||
|
||||
-- Total
|
||||
('common.total', 'en', 'Total'),
|
||||
('common.total', 'ru', 'Всего'),
|
||||
('common.total', 'es', 'Total'),
|
||||
('common.total', 'de', 'Gesamt'),
|
||||
('common.total', 'fr', 'Total'),
|
||||
('common.total', 'zh', '总计'),
|
||||
|
||||
-- Created
|
||||
('common.created', 'en', 'Created'),
|
||||
('common.created', 'ru', 'Создан'),
|
||||
('common.created', 'es', 'Creado'),
|
||||
('common.created', 'de', 'Erstellt'),
|
||||
('common.created', 'fr', 'Créé'),
|
||||
('common.created', 'zh', '创建时间'),
|
||||
|
||||
-- IP Address
|
||||
('common.ip_address', 'en', 'IP Address'),
|
||||
('common.ip_address', 'ru', 'IP-адрес'),
|
||||
('common.ip_address', 'es', 'Dirección IP'),
|
||||
('common.ip_address', 'de', 'IP-Adresse'),
|
||||
('common.ip_address', 'fr', 'Adresse IP'),
|
||||
('common.ip_address', 'zh', 'IP地址')
|
||||
|
||||
ON DUPLICATE KEY UPDATE translation_value=VALUES(translation_value);
|
||||
Reference in New Issue
Block a user