2009-06-08 Ramon Novoa <rnovoa@artica.es>

* util/pandora_xml_stress.pl: Let the user specify the maximum number
          of threads.

        * util/pandora_xml_stress.README: Updated the documentation.





git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1739 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
ramonn 2009-06-08 18:36:12 +00:00
parent 2c400b64bb
commit 376bcd83e6
3 changed files with 75 additions and 44 deletions

View File

@ -1,3 +1,10 @@
2009-06-08 Ramon Novoa <rnovoa@artica.es>
* util/pandora_xml_stress.pl: Let the user specify the maximum number
of threads.
* util/pandora_xml_stress.README: Updated the documentation.
2009-06-08 Sancho Leren <slerena@artica.es> 2009-06-08 Sancho Leren <slerena@artica.es>
* Header updates. * Header updates.

View File

@ -18,6 +18,9 @@ Run the script like this:
Sample configuration file Sample configuration file
========================= =========================
# Maximum number of threads, by default 10.
max_threads 10
# File containing a list of agent names (one per line). # File containing a list of agent names (one per line).
agent_file agent_names.txt agent_file agent_names.txt
@ -52,6 +55,12 @@ time_to 2009-06-05 00:00:00
# race conditions when auto-creating the agent, by default 2. # race conditions when auto-creating the agent, by default 2.
startup_delay 2 startup_delay 2
# Address of the Tentacle server where XML files will be sent (optional).
# server_ip 192.168.50.1
# Port of the Tentacle server, by default 41121.
# server_port 41121
# Module definitions. Similar to pandora_agent.conf. # Module definitions. Similar to pandora_agent.conf.
module_begin module_begin

View File

@ -24,7 +24,7 @@ use threads::shared;
use Time::Local; use Time::Local;
use Time::HiRes qw(gettimeofday); use Time::HiRes qw(gettimeofday);
use POSIX qw (strftime); use POSIX qw (strftime ceil);
# Global variables used for statistics # Global variables used for statistics
my $Agents :shared = 0; my $Agents :shared = 0;
@ -78,8 +78,8 @@ sub load_config ($\%\@) {
################################################################################ ################################################################################
# Generate XML files. # Generate XML files.
################################################################################ ################################################################################
sub generate_xml_files ($$$) { sub generate_xml_files ($$$$$) {
my ($agent_name, $conf, $modules) = @_; my ($agents, $start, $step, $conf, $modules) = @_;
# Read agent configuration # Read agent configuration
my $interval = get_conf_token ($conf, 'interval', '300'); my $interval = get_conf_token ($conf, 'interval', '300');
@ -103,7 +103,12 @@ sub generate_xml_files ($$$) {
# Generate data files # Generate data files
my $utimestamp = $utimestamp_from; my $utimestamp = $utimestamp_from;
while ($utimestamp < $utimestamp_to) { while ($utimestamp <= $utimestamp_to) {
for (my $i = $start; $i < $start + $step; $i++) {
# Get the name of the agent
last unless defined ($agents->[$i]);
my $agent_name = $agents->[$i];
# XML header # XML header
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp)); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime ($utimestamp));
@ -141,13 +146,14 @@ sub generate_xml_files ($$$) {
$temporal .= $last_char if ($last_char ne '/'); $temporal .= $last_char if ($last_char ne '/');
# Save the XML data file # Save the XML data file
my $xml_file = $temporal . '/' . $agent_name . $utimestamp . '.data'; my $xml_file = $temporal . '/' . $agent_name . '_' . $utimestamp . '.data';
open (FILE, ">", $xml_file) || die ("[error] Could not write to '$xml_file': $!.\n\n"); open (FILE, ">", $xml_file) || die ("[error] Could not write to '$xml_file': $!.\n\n");
print FILE $xml_data; print FILE $xml_data;
close (FILE); close (FILE);
copy_xml_file ($conf, $xml_file); copy_xml_file ($conf, $xml_file);
$XMLFiles++; $XMLFiles++;
}
# First run, let the server create the new agent before sending more data # First run, let the server create the new agent before sending more data
if ($utimestamp == $utimestamp_from) { if ($utimestamp == $utimestamp_from) {
@ -252,16 +258,25 @@ load_config ($ARGV[0], %conf, @modules);
die ("[error] No agent file specified in configuration file.\n\n") unless defined ($conf{'agent_file'}); die ("[error] No agent file specified in configuration file.\n\n") unless defined ($conf{'agent_file'});
open (FILE, "<", $conf{'agent_file'}) || die ("[error] Could not open agent configuration file '" . $conf{'agent_file'} . "': $!.\n\n"); open (FILE, "<", $conf{'agent_file'}) || die ("[error] Could not open agent configuration file '" . $conf{'agent_file'} . "': $!.\n\n");
my $t0 = gettimeofday (); # Read agent names
my @agents;
# Launch a thread for each agent
while (my $agent_name = <FILE>) { while (my $agent_name = <FILE>) {
chomp ($agent_name); chomp ($agent_name);
threads->create (\&generate_xml_files, $agent_name, \%conf, \@modules); push (@agents, $agent_name);
$Agents++; $Agents++;
} }
close (FILE); close (FILE);
# Get the maximum number of threads and the number of agents per thread
my $max_threads = get_conf_token (\%conf, 'max_threads', '10');
$max_threads = 10 unless ($max_threads > 0);
my $step = ceil ($Agents / $max_threads);
my $t0 = gettimeofday ();
for (my $i = 0; $i < $Agents; $i += $step) {
threads->create (\&generate_xml_files, \@agents, $i, $step, \%conf, \@modules);
}
# Log some information for the user # Log some information for the user
my $time_now = strftime ("%Y-%m-%d %H:%M:%S", localtime ()); my $time_now = strftime ("%Y-%m-%d %H:%M:%S", localtime ());
my $time_from = get_conf_token (\%conf, 'time_from', $time_now); my $time_from = get_conf_token (\%conf, 'time_from', $time_now);