Add support for thread status logging.

Ref pandora_enterprise#1551.
This commit is contained in:
Ramon Novoa 2017-12-05 11:13:37 +01:00
parent 4d4cee2251
commit e495afe5ed
4 changed files with 29 additions and 0 deletions

View File

@ -149,6 +149,10 @@ network_timeout 4
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 5

View File

@ -468,6 +468,8 @@ sub pandora_load_config {
# Enable (1) or disable (0) events related to the unknown status.
$pa_config->{"unknown_events"} = 1; # > 6.0SP4
$pa_config->{"thread_log"} = 0; # 7.0.717
# Check for UID0
if ($pa_config->{"quiet"} != 0){
if ($> == 0){
@ -1076,6 +1078,9 @@ sub pandora_load_config {
elsif ($parametro =~ m/^syslog_threads\s+([0-9]*)/i) {
$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 #
# Set to RDBMS' standard port

View File

@ -118,6 +118,7 @@ sub data_producer ($$$$$) {
while ($RUN == 1) {
# Get pending tasks
$self->logThread('[PRODUCER] Queuing tasks.');
my @tasks = &{$self->{'_producer'}}($self);
foreach my $task (@tasks) {
@ -169,6 +170,7 @@ sub data_consumer ($$$$$) {
while ($RUN == 1) {
# Wait for data
$self->logThread('[CONSUMER] Waiting for data.');
$task_sem->down;
$sem->down;
@ -179,6 +181,7 @@ sub data_consumer ($$$$$) {
last if ($RUN == 0);
# Execute task
$self->logThread("[CONSUMER] Executing task: $task");
&{$self->{'_consumer'}}($self, $task);
# Update task status

View File

@ -20,6 +20,7 @@ package PandoraFMS::Server;
use strict;
use warnings;
use POSIX 'strftime';
use threads;
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.
########################################################################################