Add comprehensive resource monitoring system - Phase 1: Database schema and agent functions

Co-authored-by: iaretechnician <2749183+iaretechnician@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-09-10 20:10:45 +00:00
parent 88325eaba9
commit 57a34d3a2b
7 changed files with 1329 additions and 1 deletions

View file

@ -1440,6 +1440,105 @@ INSERT INTO `ogp_ticket_settings` (setting_name, setting_value) VALUES ('attachm
INSERT INTO `ogp_ticket_settings` (setting_name, setting_value) VALUES ('attachment_extensions', 'jpg, gif, jpeg, jpg, png, pdf, txt, sql, zip') ON DUPLICATE KEY UPDATE `setting_name` = 'attachment_extensions', `setting_value` = 'jpg, gif, jpeg, jpg, png, pdf, txt, sql, zip';
INSERT INTO `ogp_ticket_settings` (setting_name, setting_value) VALUES ('notifications_enabled', 'true') ON DUPLICATE KEY UPDATE `setting_name` = 'notifications_enabled', `setting_value` = 'true';
-- --------------------------------------------------------
--
-- Table structure for table `ogp_resource_monitoring`
--
CREATE TABLE `ogp_resource_monitoring` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`remote_server_id` int(11) NOT NULL,
`home_id` int(11) DEFAULT NULL COMMENT 'NULL for system-wide metrics',
`timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`cpu_usage` decimal(5,2) DEFAULT NULL COMMENT 'CPU usage percentage (0.00-100.00)',
`memory_usage` decimal(5,2) DEFAULT NULL COMMENT 'Memory usage percentage (0.00-100.00)',
`memory_used_mb` int(11) DEFAULT NULL COMMENT 'Memory used in MB',
`memory_total_mb` int(11) DEFAULT NULL COMMENT 'Total memory in MB',
`disk_usage` decimal(5,2) DEFAULT NULL COMMENT 'Disk usage percentage (0.00-100.00)',
`disk_used_mb` bigint(20) DEFAULT NULL COMMENT 'Disk used in MB',
`disk_total_mb` bigint(20) DEFAULT NULL COMMENT 'Total disk in MB',
`process_count` int(11) DEFAULT NULL COMMENT 'Number of processes (for game servers)',
`network_rx_mb` bigint(20) DEFAULT NULL COMMENT 'Network received in MB',
`network_tx_mb` bigint(20) DEFAULT NULL COMMENT 'Network transmitted in MB',
PRIMARY KEY (`id`),
KEY `idx_server_timestamp` (`remote_server_id`, `timestamp`),
KEY `idx_home_timestamp` (`home_id`, `timestamp`),
KEY `idx_timestamp` (`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Resource monitoring data for servers and game instances';
-- --------------------------------------------------------
--
-- Table structure for table `ogp_resource_alerts`
--
CREATE TABLE `ogp_resource_alerts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`remote_server_id` int(11) NOT NULL,
`home_id` int(11) DEFAULT NULL COMMENT 'NULL for system-wide alerts',
`alert_type` enum('cpu','memory','disk') NOT NULL,
`threshold_percentage` decimal(5,2) NOT NULL DEFAULT 80.00,
`duration_minutes` int(11) NOT NULL DEFAULT 30,
`is_active` tinyint(1) NOT NULL DEFAULT 1,
`discord_webhook_url` varchar(500) DEFAULT NULL,
`last_triggered` timestamp NULL DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_server_active` (`remote_server_id`, `is_active`),
KEY `idx_home_active` (`home_id`, `is_active`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Alert configurations and state for resource monitoring';
-- --------------------------------------------------------
--
-- Table structure for table `ogp_resource_alert_history`
--
CREATE TABLE `ogp_resource_alert_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`alert_id` int(11) NOT NULL,
`remote_server_id` int(11) NOT NULL,
`home_id` int(11) DEFAULT NULL,
`alert_type` enum('cpu','memory','disk') NOT NULL,
`triggered_value` decimal(5,2) NOT NULL,
`threshold_value` decimal(5,2) NOT NULL,
`duration_exceeded` int(11) NOT NULL COMMENT 'Duration in minutes that threshold was exceeded',
`message_sent` tinyint(1) NOT NULL DEFAULT 0,
`discord_response` text DEFAULT NULL,
`triggered_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_alert_triggered` (`alert_id`, `triggered_at`),
KEY `idx_server_triggered` (`remote_server_id`, `triggered_at`),
FOREIGN KEY (`alert_id`) REFERENCES `ogp_resource_alerts`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='History of triggered resource alerts';
-- --------------------------------------------------------
--
-- Table structure for table `ogp_discord_settings`
--
CREATE TABLE `ogp_discord_settings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`setting_name` varchar(100) NOT NULL,
`setting_value` text DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE KEY `unique_setting` (`setting_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='Discord integration settings';
-- Default Discord settings
INSERT INTO `ogp_discord_settings` (setting_name, setting_value, description) VALUES
('default_webhook_url', '', 'Default Discord webhook URL for alerts'),
('alert_enabled', '1', 'Enable/disable Discord alerts (1=enabled, 0=disabled)'),
('alert_format', 'json', 'Format for Discord messages (json or embed)'),
('bot_username', 'OGP Monitor', 'Username displayed for the bot in Discord'),
('alert_cooldown_minutes', '60', 'Minimum minutes between identical alerts');
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;