2012-02-28 Ramon Novoa <rnovoa@artica.es>

* Linux/pandora_agent.conf,
	  pandora_agent: Added support for xml_buffer.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5664 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
Ramon Novoa 2012-02-28 15:48:26 +00:00
parent 8a1382980d
commit 9bf73f9357
3 changed files with 64 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2012-02-28 Ramon Novoa <rnovoa@artica.es>
* Linux/pandora_agent.conf,
pandora_agent: Added support for xml_buffer.
2012-02-23 Ramon Novoa <rnovoa@artica.es>
* pandora_agent: Set the intensive interval before reading modules.

View File

@ -127,6 +127,12 @@ transfer_mode tentacle
# User the agent will run as
#pandora_user root
# Enable or disable XML buffer.
#xml_buffer 0
# Minimum available bytes in the temporal directory to enable the XML buffer
#temporal_min_size 1024
# Secondary server configuration
# ==============================

View File

@ -98,6 +98,16 @@ use constant PART_CMDS => {
aix => 'df -kP | awk \'NR > 1 {print $2, $4, $6}\'',
freebsd => 'df -k | awk \'NR > 1 {print $2, $4, $6}\''
};
# Commands to call df with POSIX output format
use constant DF_CMDS => {
# total, available, mount point
linux => 'df -P',
solaris => 'df -k',
hpux => 'df -P',
aix => 'df -kP',
freebsd => 'df -k'
};
# OS and OS version
my $OS = $^O;
@ -146,6 +156,7 @@ my %Conf = (
'secondary_server_ssl' => 'no',
'secondary_server_opts' => '',
'autotime' => 0,
'temporal_min_size' => 1,
'timezone_offset' => 0,
'pandora_exec' => 'pandora_agent_exec',
'agent_threads' => 1,
@ -157,6 +168,7 @@ my %Conf = (
'proxy_timeout' => 1,
'intensive_interval' => 0,
'timestamp' => 0,
'xml_buffer' => 0,
);
# Modules
@ -673,6 +685,22 @@ sub send_file {
return $rc;
}
################################################################################
# Send buffered XML files.
################################################################################
sub send_buffered_xml_files () {
# Read XML files from the temporal directory
opendir(TEMPORAL, $Conf{'temporal'}) or return;
while (my $xml_file = readdir(TEMPORAL)) {
# Skip non data files
next unless ($xml_file =~ m/\.data$/);
send_file ($xml_file, 1);
}
}
################################################################################
# Swap primary and secondary servers.
################################################################################
@ -1627,6 +1655,23 @@ sub kill_signal_handler (){
exit (0);
}
################################################################################
# Get the free disk space in the temporal directory (in bytes).
################################################################################
sub temporal_freedisk () {
# Call df
return 0 unless defined (DF_CMDS->{$OS});
my $cmd = DF_CMDS->{$OS} . ' ' . $Conf{'temporal'} . ' | awk \'NR > 1 {print $4}\'';
my $temporal_freedisk = `$cmd`;
# Check for errors
return 0 unless ($? eq 0);
# Convert to bytes
return 1024 * int ($temporal_freedisk);
}
################################################################################
# Main.
################################################################################
@ -1893,9 +1938,15 @@ while (1) {
}
# Send the XML data file
send_file ($temp_file, 1);
unlink ($temp_file);
my $rc = send_file ($temp_file, 1);
if ($rc == 0 || $Conf{'xml_buffer'} == 0 || temporal_freedisk () < $Conf{'temporal_min_size'}) {
unlink ($temp_file);
}
# Send buffered XML data files
if ($Conf{'xml_buffer'} == 1) {
send_buffered_xml_files ();
}
}
# Enable signal capture to break the Sleep interval on UDP signal