mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-29 16:55:05 +02:00
2013-04-18 Sancho Lerena <slerena@artica.es>
* util/pandora_db.pl: Added a usleep() inside loops to aliviate SQL transactions. This should help to improve performance and avoid lockings. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8014 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
1a41b942b8
commit
267d26ac02
@ -1,3 +1,9 @@
|
|||||||
|
2013-04-18 Sancho Lerena <slerena@artica.es>
|
||||||
|
|
||||||
|
* util/pandora_db.pl: Added a usleep() inside loops to aliviate
|
||||||
|
SQL transactions. This should help to improve performance and
|
||||||
|
avoid lockings.
|
||||||
|
|
||||||
2013-04-18 Miguel de Dios <miguel.dedios@artica.es>
|
2013-04-18 Miguel de Dios <miguel.dedios@artica.es>
|
||||||
|
|
||||||
* lib/PandoraFMS/Core.pm: cleaned source code style.
|
* lib/PandoraFMS/Core.pm: cleaned source code style.
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
# Pandora FMS DB Management
|
# Pandora FMS DB Management
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Copyright (c) 2005-2012 Artica Soluciones Tecnologicas S.L
|
# Copyright (c) 2005-2013 Artica Soluciones Tecnologicas S.L
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@ -23,6 +23,7 @@ use Time::Local; # DateTime basic manipulation
|
|||||||
use DBI; # DB interface with MySQL
|
use DBI; # DB interface with MySQL
|
||||||
use POSIX qw(strftime);
|
use POSIX qw(strftime);
|
||||||
use File::Path qw (rmtree);
|
use File::Path qw (rmtree);
|
||||||
|
use Time::HiRes qw/usleep/;
|
||||||
|
|
||||||
# Default lib dir for RPM and DEB packages
|
# Default lib dir for RPM and DEB packages
|
||||||
use lib '/usr/lib/perl5';
|
use lib '/usr/lib/perl5';
|
||||||
@ -31,7 +32,7 @@ use PandoraFMS::Tools;
|
|||||||
use PandoraFMS::DB;
|
use PandoraFMS::DB;
|
||||||
|
|
||||||
# version: define current version
|
# version: define current version
|
||||||
my $version = "5.0dev PS130228";
|
my $version = "5.0dev PS130418";
|
||||||
|
|
||||||
# Pandora server configuration
|
# Pandora server configuration
|
||||||
my %conf;
|
my %conf;
|
||||||
@ -105,6 +106,9 @@ sub pandora_purgedb ($$) {
|
|||||||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||||
db_do ($dbh, "DELETE FROM tagente_datos WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
db_do ($dbh, "DELETE FROM tagente_datos WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
||||||
print "[PURGE] Data deletion Progress %$ax .. \r";
|
print "[PURGE] Data deletion Progress %$ax .. \r";
|
||||||
|
|
||||||
|
# Do a nanosleep here for 0,01 sec
|
||||||
|
usleep (10000);
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
} else {
|
} else {
|
||||||
@ -138,6 +142,8 @@ sub pandora_purgedb ($$) {
|
|||||||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||||
db_do ($dbh, "DELETE FROM tagente_datos_inventory WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
db_do ($dbh, "DELETE FROM tagente_datos_inventory WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
||||||
print "[PURGE] Inventory data deletion Progress %$ax .. \r";
|
print "[PURGE] Inventory data deletion Progress %$ax .. \r";
|
||||||
|
# Do a nanosleep here for 0,01 sec
|
||||||
|
usleep (10000);
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
} else {
|
} else {
|
||||||
@ -157,6 +163,8 @@ sub pandora_purgedb ($$) {
|
|||||||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||||
db_do ($dbh, "DELETE FROM tagente_datos_log4x WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
db_do ($dbh, "DELETE FROM tagente_datos_log4x WHERE utimestamp < ". ($first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark );
|
||||||
print "[PURGE] Log4x data deletion progress %$ax .. \r";
|
print "[PURGE] Log4x data deletion progress %$ax .. \r";
|
||||||
|
# Do a nanosleep here for 0,01 sec
|
||||||
|
usleep (10000);
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
} else {
|
} else {
|
||||||
@ -302,6 +310,8 @@ sub pandora_purgedb ($$) {
|
|||||||
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
for (my $ax = 1; $ax <= $BIG_OPERATION_STEP; $ax++){
|
||||||
db_do ($dbh, "DELETE FROM tagent_access WHERE utimestamp < ". ( $first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark);
|
db_do ($dbh, "DELETE FROM tagent_access WHERE utimestamp < ". ( $first_mark + ($purge_steps * $ax)) . " AND utimestamp >= ". $first_mark);
|
||||||
print "[PURGE] Agent access deletion progress %$ax .. \r";
|
print "[PURGE] Agent access deletion progress %$ax .. \r";
|
||||||
|
# Do a nanosleep here for 0,01 sec
|
||||||
|
usleep (10000);
|
||||||
}
|
}
|
||||||
print "\n";
|
print "\n";
|
||||||
} else {
|
} else {
|
||||||
@ -471,6 +481,7 @@ sub pandora_compactdb ($$) {
|
|||||||
delete($count_hash{$key});
|
delete($count_hash{$key});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
usleep (1000); # Very small usleep, just to don't burn the DB
|
||||||
# Move to the next interval
|
# Move to the next interval
|
||||||
$start_utime = $stop_utime;
|
$start_utime = $stop_utime;
|
||||||
}
|
}
|
||||||
@ -587,6 +598,9 @@ sub pandora_checkdb_integrity {
|
|||||||
# Delete all non-used IP addresses from taddress
|
# Delete all non-used IP addresses from taddress
|
||||||
db_do ($dbh, 'DELETE FROM taddress WHERE id_a NOT IN (SELECT id_a FROM taddress_agent)');
|
db_do ($dbh, 'DELETE FROM taddress WHERE id_a NOT IN (SELECT id_a FROM taddress_agent)');
|
||||||
|
|
||||||
|
# Do a nanosleep here for 0,01 sec
|
||||||
|
usleep (10000);
|
||||||
|
|
||||||
print "[INTEGRITY] Deleting orphan alerts \n";
|
print "[INTEGRITY] Deleting orphan alerts \n";
|
||||||
|
|
||||||
# Delete alerts assigned to inexistant modules
|
# Delete alerts assigned to inexistant modules
|
||||||
@ -603,9 +617,6 @@ sub pandora_checkdb_integrity {
|
|||||||
# Delete orphan data_inc reference records
|
# Delete orphan data_inc reference records
|
||||||
db_do ($dbh, 'DELETE FROM tagente_datos_inc WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM tagente_modulo)');
|
db_do ($dbh, 'DELETE FROM tagente_datos_inc WHERE id_agente_modulo NOT IN (SELECT id_agente_modulo FROM tagente_modulo)');
|
||||||
|
|
||||||
# Delete all non-used IP addresses from taddress
|
|
||||||
db_do ($dbh, 'DELETE FROM taddress WHERE id_a NOT IN (SELECT id_a FROM taddress_agent)');
|
|
||||||
|
|
||||||
# Check enterprise tables
|
# Check enterprise tables
|
||||||
enterprise_hook ('pandora_checkdb_integrity_enterprise', [$dbh]);
|
enterprise_hook ('pandora_checkdb_integrity_enterprise', [$dbh]);
|
||||||
}
|
}
|
||||||
@ -638,6 +649,9 @@ sub pandora_checkdb_consistency {
|
|||||||
# Delete the module
|
# Delete the module
|
||||||
db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agente_modulo);
|
db_do ($dbh, 'DELETE FROM tagente_modulo WHERE id_agente_modulo = ?', $id_agente_modulo);
|
||||||
|
|
||||||
|
# Do a nanosleep here for 0,001 sec
|
||||||
|
usleep (100000);
|
||||||
|
|
||||||
# Delete any alerts associated to the module
|
# Delete any alerts associated to the module
|
||||||
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ?', $id_agente_modulo);
|
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ?', $id_agente_modulo);
|
||||||
}
|
}
|
||||||
@ -657,6 +671,9 @@ sub pandora_checkdb_consistency {
|
|||||||
|
|
||||||
# Delete any alerts associated to the module
|
# Delete any alerts associated to the module
|
||||||
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ? AND NOT EXISTS (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente_modulo = ?)', $id_agente_modulo, $id_agente_modulo);
|
db_do ($dbh, 'DELETE FROM talert_template_modules WHERE id_agent_module = ? AND NOT EXISTS (SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente_modulo = ?)', $id_agente_modulo, $id_agente_modulo);
|
||||||
|
|
||||||
|
# Do a nanosleep here for 0,001 sec
|
||||||
|
usleep (100000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
print "[CHECKDB] Checking database consistency (Missing status)... \n";
|
print "[CHECKDB] Checking database consistency (Missing status)... \n";
|
||||||
@ -686,6 +703,10 @@ sub pandora_checkdb_consistency {
|
|||||||
next if (defined ($count) && $count > 0);
|
next if (defined ($count) && $count > 0);
|
||||||
|
|
||||||
db_do ($dbh, 'DELETE FROM tagente_estado WHERE id_agente_modulo = ?', $id_agente_modulo);
|
db_do ($dbh, 'DELETE FROM tagente_estado WHERE id_agente_modulo = ?', $id_agente_modulo);
|
||||||
|
|
||||||
|
# Do a nanosleep here for 0,001 sec
|
||||||
|
usleep (100000);
|
||||||
|
|
||||||
print "[CHECKDB] Deleting non-existing module $id_agente_modulo in state table \n";
|
print "[CHECKDB] Deleting non-existing module $id_agente_modulo in state table \n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user