-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresource_usage_test.pl
More file actions
executable file
·132 lines (116 loc) · 4.72 KB
/
resource_usage_test.pl
File metadata and controls
executable file
·132 lines (116 loc) · 4.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/perl
#
# Resource Monitoring Demo/Test Script
# This script demonstrates the resource monitoring functionality
# without requiring a full database connection.
#
use strict;
use warnings;
use lib '.'; # Use current directory for local modules
use POSIX qw(strftime);
use Digest::MD5 qw(md5_hex);
use File::Find;
# Load the config to verify it works
use Cfg::Config;
print "=== GSP Agent Resource Monitoring Demo ===\n\n";
# Test 1: Configuration Loading
print "1. Testing Configuration Loading:\n";
print " Database Host: " . ($Cfg::Config{stats_db_host} || 'undefined') . "\n";
print " Database User: " . ($Cfg::Config{stats_db_user} || 'undefined') . "\n";
print " Database Name: " . ($Cfg::Config{stats_db_name} || 'undefined') . "\n";
print " Frequency: " . ($Cfg::Config{stats_frequency_minutes} || 'undefined') . " minutes\n";
print " ✓ Configuration loaded successfully\n\n";
# Test 2: Machine ID Generation
print "2. Testing Machine ID Generation:\n";
sub get_machine_id_demo {
my $hostname = `hostname` || 'unknown';
chomp($hostname);
# For demo on Linux, get MAC from ifconfig
my $mac = '';
my $ifconfig_output = `ifconfig 2>/dev/null | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}' | head -1`;
chomp($ifconfig_output);
$mac = $ifconfig_output if $ifconfig_output;
my $machine_id = md5_hex($hostname . '_' . $mac . '_' . './test');
print " Hostname: $hostname\n";
print " MAC Address: $mac\n";
print " Generated Machine ID: $machine_id\n";
print " ✓ Machine ID generated successfully\n\n";
return $machine_id;
}
my $machine_id = get_machine_id_demo();
# Test 3: Timestamp Generation
print "3. Testing Timestamp Generation:\n";
my $timestamp = strftime("%Y-%m-%d %H:%M:%S", localtime());
print " Current timestamp: $timestamp\n";
print " ✓ Timestamp generated successfully\n\n";
# Test 4: Game Server Detection (if startup directory exists)
print "4. Testing Game Server Detection:\n";
my $startup_dir = './startups'; # Relative to script's root
if (-d $startup_dir) {
opendir(my $dir, $startup_dir) or die "Cannot open $startup_dir: $!";
my @startup_files = grep { !/^\./ && -f "$startup_dir/$_" } readdir($dir);
closedir($dir);
if (@startup_files) {
print " Found " . scalar(@startup_files) . " game server startup files:\n";
foreach my $file (@startup_files) {
if ($file =~ /^(.+)-(\d+)$/) {
my ($ip, $port) = ($1, $2);
print " - $ip:$port (file: $file)\n";
# Read server path
if (open(my $fh, '<', "$startup_dir/$file")) {
my $path = <$fh>;
chomp($path) if $path;
print " Path: $path\n" if $path;
close($fh);
}
}
}
} else {
print " No startup files found (startup directory is empty)\n";
print " In production, only processes with startup files are monitored\n";
}
print " ✓ Game server detection working\n\n";
} else {
print " Startup directory not found: $startup_dir\n";
print " ✓ This is expected in a clean installation\n\n";
}
# Test 5: Database Schema
print "5. Checking Database Schema Files:\n";
my $db_dir = './DB'; # Relative to script's root
if (-d $db_dir) {
opendir(my $dir, $db_dir) or die "Cannot open $db_dir: $!";
my @sql_files = grep { /\.sql$/ } readdir($dir);
closedir($dir);
print " Found " . scalar(@sql_files) . " SQL schema files:\n";
foreach my $file (@sql_files) {
print " - $file\n";
}
print " ✓ Database schema files ready\n\n";
}
# Test 6: Windows/Linux Compatibility Check
print "6. Testing Platform Compatibility:\n";
if (-e '/proc/stat') {
print " Platform: Linux (using /proc/stat for CPU monitoring)\n";
} else {
print " Platform: Windows (would use wmic for CPU monitoring)\n";
}
if (-e '/proc/meminfo') {
print " Memory monitoring: Linux /proc/meminfo\n";
} else {
print " Memory monitoring: Windows wmic OS queries\n";
}
if (-e '/bin/df') {
print " Disk monitoring: Linux/Cygwin df command\n";
} else {
print " Disk monitoring: Windows wmic logicaldisk\n";
}
print " ✓ Platform detection working\n\n";
print "=== Demo Complete ===\n";
print "The resource monitoring system is ready for use.\n";
print "To enable it:\n";
print "1. Configure database settings in Cfg/Config.pm\n";
print "2. Import SQL schema files from DB/ directory\n";
print "3. Install DBI and DBD::mysql Perl modules\n";
print "4. Restart the OGP Agent\n";
print "\nThe system will automatically start collecting resource data\n";
print "every " . ($Cfg::Config{stats_frequency_minutes} || '5') . " minutes when enabled.\n";