[Phoenix-pm] greetings
Artful
ahenry-pm at artful2099.com
Wed Jul 28 12:40:56 CDT 2004
> Hmmm...these all sound interesting so maybe I should ask a pointed
> question now. I do a lot of net admin stuff involving SNMP polling and
> currently most of my tools are "single-threaded", i.e. I poll one device
> at a time. Based on the options presented, what would be the easiest
> means of changing to a setup of polling say 10 devices at the same time
> with the main script retaining control and reporting responsibilities?
I would highly suggest Parallel::ForkManager for this task. A real
threaded solution would probably be way overkill for what you are doing.
I use Parallel::ForkManager all the time, it works very well. The
following code will run 3 child processes in parallel. The module handles
all of the forking and keeping track of how many children have been
forked. The wait_all_children() will block until all of the child
processes have finished, so you don't print out the stats until all of the
processes have completed.
#!/usr/bin/perl
use strict;
use Parallel::ForkManager;
my $MAX_PROCESSES = 3;
my @hosts = ('dopey', 'grumpy', 'doc', 'happy', 'bashful', 'sneezy',
'sleepy');
$pm = new Parallel::ForkManager($MAX_PROCESSES);
my %snmp_info;
foreach my $host (@hosts) {
$pm->start and next;
$snmp_info{$host} = &get_snmp_info($host);
$pm->finish;
}
$pm->wait_all_children;
foreach my $host (sort @hosts) {
print "$host: $snmp_info{$host}\n";
}
More information about the Phoenix-pm
mailing list