Merge branch 'thread_log' into 'develop'
Add support for thread status logging. See merge request artica/pandorafms!1161
This commit is contained in:
commit
b1090f2c03
|
@ -149,6 +149,10 @@ network_timeout 4
|
||||||
|
|
||||||
server_keepalive 45
|
server_keepalive 45
|
||||||
|
|
||||||
|
# Log server thread status to disk (always set to 0, except when debugging).
|
||||||
|
|
||||||
|
thread_log 0
|
||||||
|
|
||||||
# Server Threshold: defines number of seconds of main loop (in sec)
|
# Server Threshold: defines number of seconds of main loop (in sec)
|
||||||
|
|
||||||
server_threshold 5
|
server_threshold 5
|
||||||
|
|
|
@ -468,6 +468,8 @@ sub pandora_load_config {
|
||||||
# Enable (1) or disable (0) events related to the unknown status.
|
# Enable (1) or disable (0) events related to the unknown status.
|
||||||
$pa_config->{"unknown_events"} = 1; # > 6.0SP4
|
$pa_config->{"unknown_events"} = 1; # > 6.0SP4
|
||||||
|
|
||||||
|
$pa_config->{"thread_log"} = 0; # 7.0.717
|
||||||
|
|
||||||
# Check for UID0
|
# Check for UID0
|
||||||
if ($pa_config->{"quiet"} != 0){
|
if ($pa_config->{"quiet"} != 0){
|
||||||
if ($> == 0){
|
if ($> == 0){
|
||||||
|
@ -1076,6 +1078,9 @@ sub pandora_load_config {
|
||||||
elsif ($parametro =~ m/^syslog_threads\s+([0-9]*)/i) {
|
elsif ($parametro =~ m/^syslog_threads\s+([0-9]*)/i) {
|
||||||
$pa_config->{'syslog_threads'}= clean_blank($1);
|
$pa_config->{'syslog_threads'}= clean_blank($1);
|
||||||
}
|
}
|
||||||
|
elsif ($parametro =~ m/^thread_log\s+([0-1])/i) {
|
||||||
|
$pa_config->{'thread_log'}= clean_blank($1);
|
||||||
|
}
|
||||||
} # end of loop for parameter #
|
} # end of loop for parameter #
|
||||||
|
|
||||||
# Set to RDBMS' standard port
|
# Set to RDBMS' standard port
|
||||||
|
|
|
@ -118,6 +118,7 @@ sub data_producer ($$$$$) {
|
||||||
while ($RUN == 1) {
|
while ($RUN == 1) {
|
||||||
|
|
||||||
# Get pending tasks
|
# Get pending tasks
|
||||||
|
$self->logThread('[PRODUCER] Queuing tasks.');
|
||||||
my @tasks = &{$self->{'_producer'}}($self);
|
my @tasks = &{$self->{'_producer'}}($self);
|
||||||
|
|
||||||
foreach my $task (@tasks) {
|
foreach my $task (@tasks) {
|
||||||
|
@ -169,6 +170,7 @@ sub data_consumer ($$$$$) {
|
||||||
while ($RUN == 1) {
|
while ($RUN == 1) {
|
||||||
|
|
||||||
# Wait for data
|
# Wait for data
|
||||||
|
$self->logThread('[CONSUMER] Waiting for data.');
|
||||||
$task_sem->down;
|
$task_sem->down;
|
||||||
|
|
||||||
$sem->down;
|
$sem->down;
|
||||||
|
@ -179,6 +181,7 @@ sub data_consumer ($$$$$) {
|
||||||
last if ($RUN == 0);
|
last if ($RUN == 0);
|
||||||
|
|
||||||
# Execute task
|
# Execute task
|
||||||
|
$self->logThread("[CONSUMER] Executing task: $task");
|
||||||
&{$self->{'_consumer'}}($self, $task);
|
&{$self->{'_consumer'}}($self, $task);
|
||||||
|
|
||||||
# Update task status
|
# Update task status
|
||||||
|
|
|
@ -20,6 +20,7 @@ package PandoraFMS::Server;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
|
use POSIX 'strftime';
|
||||||
use threads;
|
use threads;
|
||||||
use threads::shared;
|
use threads::shared;
|
||||||
|
|
||||||
|
@ -272,6 +273,22 @@ sub update ($) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
########################################################################################
|
||||||
|
# Log a message for the current thread.
|
||||||
|
########################################################################################
|
||||||
|
sub logThread ($$) {
|
||||||
|
my ($self, $msg) = @_;
|
||||||
|
|
||||||
|
return unless ($self->{'_pa_config'}->{'thread_log'} == 1);
|
||||||
|
|
||||||
|
eval {
|
||||||
|
open(my $fh, '>', $self->{'_pa_config'}->{'temporal'} . '/' . $self->{'_pa_config'}->{'servername'} .'.'. $ServerTypes[$self->{'_server_type'}] . '.' . threads->tid() . '.log');
|
||||||
|
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime());
|
||||||
|
print $fh $timestamp . ' ' . $self->{'_pa_config'}->{'servername'} . ' ' . $ServerTypes[$self->{'_server_type'}] . ' (thread ' . threads->tid() . '):' . $msg . "\n";
|
||||||
|
close($fh);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
########################################################################################
|
########################################################################################
|
||||||
# Stop the server, killing all server threads.
|
# Stop the server, killing all server threads.
|
||||||
########################################################################################
|
########################################################################################
|
||||||
|
|
Loading…
Reference in New Issue