5.9 KiB
OGP Agent Resource Stats Collection
This document describes the integrated resource statistics collection system in the OGP agents that replaces the standalone Python collector.py script.
Overview
The OGP agents now include built-in resource monitoring that collects:
- Machine-wide statistics: CPU usage, memory, disk space, network activity, load averages
- Per-server process statistics: Memory usage, CPU usage, I/O statistics, listening ports, folder sizes
Data is automatically inserted into the same MySQL database tables used by the web panel for display.
Configuration
Database Configuration
Update the agent configuration files with your database connection details:
Linux Agent: _agent-linux/Cfg/Config.pm
Windows Agent: _agent-windows/Cfg/Config.pm
# Resource stats database configuration
stats_db_host => '127.0.0.1', # Database server hostname/IP
stats_db_user => 'panel_user', # Database username
stats_db_pass => 'your_password_here', # Database password
stats_db_name => 'panel_database', # Database name (same as your web panel)
stats_table_prefix => 'gsp_', # Table prefix (must match collector.py)
stats_frequency_minutes => '5', # Collection frequency in minutes
Database Tables
The system uses the same database tables as the original collector.py:
-- Machine catalog
gsp_machines
-- Machine-wide samples (CPU, memory, disk, network)
gsp_machine_samples
-- Per-process/per-server samples
gsp_process_samples
Run the SQL schema from modules/resource_stats/mysql_query.sql to create these tables if they don't exist.
Required Perl Modules
The agents require these Perl modules for database connectivity:
# Ubuntu/Debian
sudo apt-get install libdbi-perl libdbd-mysql-perl
# CentOS/RHEL
sudo yum install perl-DBI perl-DBD-MySQL
# Or via CPAN
cpan DBI DBD::mysql
Features
Automatic Integration
- Runs automatically as part of the agent scheduler
- No separate cron jobs required
- Starts when the agent starts
- Stops when the agent stops
Platform Support
Linux Agent:
- Uses
/procfilesystem for system stats - Native command-line tools (
df,netstat, etc.) - Full CPU, memory, disk, and network monitoring
- Process association via working directory and command line analysis
Windows Agent:
- Uses
wmicfor system information - Native Windows commands (
dir,netstat) - CPU, memory, disk monitoring (no load averages on Windows)
- Process association via executable path and command line analysis
Process Detection
The system automatically detects game server processes by:
- Scanning for subdirectories in the agent directory
- Finding processes whose working directory, executable path, or command line references these directories
- Collecting detailed metrics for each associated process
Data Collection
Machine-wide metrics:
- Load averages (Linux only)
- CPU percentage
- Memory usage (used/total/percentage)
- Swap usage
- Disk usage for agent directory
- Network interface statistics
- Network throughput
Process-specific metrics:
- Process ID and name
- Command line
- CPU percentage
- Memory usage (RSS/VMS)
- I/O statistics (read/write bytes)
- Open file descriptors
- Listening network ports
- Server directory size
Monitoring and Troubleshooting
Log Messages
The agent logs resource collection activity:
Starting resource stats collection
Resource stats collection completed
Error Handling
If database modules are not available:
DBD::mysql not available - resource stats collection disabled
If database connection fails:
Failed to connect to stats database: [error details]
Verification
To verify the system is working:
- Check agent logs for collection messages
- Query the database tables:
SELECT COUNT(*) FROM gsp_machine_samples WHERE ts >= NOW() - INTERVAL 1 HOUR; SELECT COUNT(*) FROM gsp_process_samples WHERE ts >= NOW() - INTERVAL 1 HOUR;
Performance Impact
- Collection runs every 5 minutes by default (configurable)
- Minimal performance overhead during collection
- Uses native system tools for maximum efficiency
- Database operations are optimized with prepared statements
Migration from collector.py
To migrate from the standalone Python collector:
- Stop the cron job running collector.py
- Install Perl database modules on agent machines
- Update agent configuration with database details
- Restart OGP agents to enable collection
- Verify data collection is working
- Remove collector.py and Python dependencies
The new system produces identical data to collector.py and uses the same database schema, so existing dashboards and reports will continue to work without changes.
Frequency Configuration
The collection frequency can be adjusted by changing stats_frequency_minutes in the config:
stats_frequency_minutes => '1'- Every minute (high frequency)stats_frequency_minutes => '5'- Every 5 minutes (default)stats_frequency_minutes => '15'- Every 15 minutes (low frequency)
Note: Very high frequencies (every minute) may impact performance on busy servers.
Security Considerations
- Database credentials are stored in agent configuration files
- Use dedicated database user with minimal privileges
- Consider firewall rules if database is on separate server
- Monitor database connections and prevent connection leaks
Troubleshooting Common Issues
Collection not working:
- Check if DBD::mysql is installed
- Verify database connection details
- Check database user permissions
- Review agent logs for error messages
Missing process data:
- Verify game servers are running from subdirectories
- Check process detection logic matches your server layout
- Review process association in agent logs
Performance issues:
- Reduce collection frequency
- Check database performance
- Monitor agent resource usage during collection