Added new server_keepalive column to have individual keepalive TICKETS #3273

This commit is contained in:
fermin831 2016-03-15 16:02:27 +01:00
parent 368a96222e
commit f397b657f1
10 changed files with 40 additions and 19 deletions

View File

@ -3,3 +3,9 @@
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
ALTER TABLE talert_templates ADD COLUMN `min_alerts_reset_counter` tinyint(1) DEFAULT 0; ALTER TABLE talert_templates ADD COLUMN `min_alerts_reset_counter` tinyint(1) DEFAULT 0;
-- ----------------------------------------------------------------------
-- Table `tserver`
-- ----------------------------------------------------------------------
ALTER TABLE tserver ADD COLUMN `server_keepalive` int(11) DEFAULT 0;

View File

@ -3,3 +3,9 @@
-- --------------------------------------------------------------------- -- ---------------------------------------------------------------------
ALTER TABLE talert_templates ADD COLUMN min_alerts_reset_counter NUMBER(5, 0) DEFAULT 0; ALTER TABLE talert_templates ADD COLUMN min_alerts_reset_counter NUMBER(5, 0) DEFAULT 0;
-- ----------------------------------------------------------------------
-- Table `tserver`
-- ----------------------------------------------------------------------
ALTER TABLE tserver ADD COLUMN server_keepalive NUMBER(10, 0) DEFAULT 0;

View File

@ -30,6 +30,7 @@ if (! check_acl ($config["id_user"], 0, "AW")) {
global $tiny; global $tiny;
global $hidden_toggle; global $hidden_toggle;
$date = time();
$servers = servers_get_info(); $servers = servers_get_info();
if ($servers === false) { if ($servers === false) {
@ -84,12 +85,11 @@ foreach ($servers as $server) {
$data[0] = '<span title="' . $server['version'] . '">' . $data[0] = '<span title="' . $server['version'] . '">' .
$server['name'] . '</span>'; $server['name'] . '</span>';
if ($server['status'] == 0) { //Status
$data[1] = ui_print_status_image (STATUS_SERVER_OK, '', true);
if (($server['status'] == 0) || (($date - strtotime($server['keepalive'])) > ($server['server_keepalive'])*2)) {
$data[1] = ui_print_status_image (STATUS_SERVER_DOWN, '', true); $data[1] = ui_print_status_image (STATUS_SERVER_DOWN, '', true);
} }
else {
$data[1] = ui_print_status_image (STATUS_SERVER_OK, '', true);
}
// Type // Type
$data[2] = '<span style="white-space:nowrap;">' . $server["img"]; $data[2] = '<span style="white-space:nowrap;">' . $server["img"];

View File

@ -765,19 +765,19 @@ function servers_check_status () {
$sql = "SELECT COUNT(id_server) $sql = "SELECT COUNT(id_server)
FROM tserver FROM tserver
WHERE status = 1 WHERE status = 1
AND keepalive > NOW() - INTERVAL 15 MINUTE"; AND keepalive > NOW() - INTERVAL server_keepalive*2 SECOND";
break; break;
case "postgresql": case "postgresql":
$sql = "SELECT COUNT(id_server) $sql = "SELECT COUNT(id_server)
FROM tserver FROM tserver
WHERE status = 1 WHERE status = 1
AND keepalive > NOW() - INTERVAL '15 MINUTE'"; AND keepalive > NOW() - INTERVAL 'server_keepalive*2 SECOND'";
break; break;
case "oracle": case "oracle":
$sql = "SELECT COUNT(id_server) $sql = "SELECT COUNT(id_server)
FROM tserver FROM tserver
WHERE status = 1 WHERE status = 1
AND keepalive > systimestamp - INTERVAL '15' MINUTE"; AND keepalive > systimestamp - INTERVAL 'server_keepalive*2' SECOND";
break; break;
} }
$status = (int) db_get_sql ($sql); //Cast as int will assure a number value $status = (int) db_get_sql ($sql); //Cast as int will assure a number value

View File

@ -1001,6 +1001,7 @@ CREATE TABLE tserver (
lag_modules NUMBER(10, 0) DEFAULT 0, lag_modules NUMBER(10, 0) DEFAULT 0,
total_modules_running NUMBER(10, 0) DEFAULT 0, total_modules_running NUMBER(10, 0) DEFAULT 0,
my_modules NUMBER(10, 0) DEFAULT 0, my_modules NUMBER(10, 0) DEFAULT 0,
server_keepalive NUMBER(10, 0) DEFAULT 0,
stat_utimestamp NUMBER(19, 0) DEFAULT 0 stat_utimestamp NUMBER(19, 0) DEFAULT 0
); );
CREATE INDEX tserver_name_idx ON tserver(name); CREATE INDEX tserver_name_idx ON tserver(name);

View File

@ -820,6 +820,7 @@ CREATE TABLE "tserver" (
"lag_modules" INTEGER NOT NULL default 0, "lag_modules" INTEGER NOT NULL default 0,
"total_modules_running" INTEGER NOT NULL default 0, "total_modules_running" INTEGER NOT NULL default 0,
"my_modules" INTEGER NOT NULL default 0, "my_modules" INTEGER NOT NULL default 0,
"server_keepalive" INTEGER NOT NULL default 0,
"stat_utimestamp" BIGINT NOT NULL default 0 "stat_utimestamp" BIGINT NOT NULL default 0
); );
CREATE INDEX "tserver_name_idx" ON "tserver"("name"); CREATE INDEX "tserver_name_idx" ON "tserver"("name");

View File

@ -895,6 +895,7 @@ CREATE TABLE IF NOT EXISTS `tserver` (
`lag_modules` int(11) NOT NULL default 0, `lag_modules` int(11) NOT NULL default 0,
`total_modules_running` int(11) NOT NULL default 0, `total_modules_running` int(11) NOT NULL default 0,
`my_modules` int(11) NOT NULL default 0, `my_modules` int(11) NOT NULL default 0,
`server_keepalive` int(11) NOT NULL default 0,
`stat_utimestamp` bigint(20) NOT NULL default '0', `stat_utimestamp` bigint(20) NOT NULL default '0',
PRIMARY KEY (`id_server`), PRIMARY KEY (`id_server`),
KEY `name` (`name`) KEY `name` (`name`)

View File

@ -607,7 +607,12 @@ sub main() {
} }
# Update fallen servers # Update fallen servers
db_do ($DBH, "UPDATE tserver SET status = 0 WHERE keepalive < ?", strftime ("%Y-%m-%d %H:%M:%S", localtime(time() - $Config{'keepalive'}))); my @servers_db = get_db_rows ($DBH, "SELECT id_server, server_keepalive FROM tserver");
for (@servers_db) {
my %server_db = %$_;
my $expected_update = strftime ("%Y-%m-%d %H:%M:%S", localtime(time() - $server_db{'server_keepalive'} * 2));
db_do ($DBH, "UPDATE tserver SET status = 0 WHERE keepalive < ? AND id_server = ?", $expected_update, $server_db{'id_server'});
}
# Set the master server # Set the master server
pandora_set_master(\%Config, $DBH); pandora_set_master(\%Config, $DBH);

View File

@ -2197,12 +2197,13 @@ Update server status:
=cut =cut
########################################################################## ##########################################################################
sub pandora_update_server ($$$$$$;$$$) { sub pandora_update_server ($$$$$$;$$$$) {
my ($pa_config, $dbh, $server_name, $server_id, $status, my ($pa_config, $dbh, $server_name, $server_id, $status,
$server_type, $num_threads, $queue_size, $version) = @_; $server_type, $num_threads, $queue_size, $version, $keepalive) = @_;
$num_threads = 0 unless defined ($num_threads); $num_threads = 0 unless defined ($num_threads);
$queue_size = 0 unless defined ($queue_size); $queue_size = 0 unless defined ($queue_size);
$keepalive = $pa_config->{'keepalive'} unless defined ($keepalive);
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime()); my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime());
$version = $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'} unless defined($version); $version = $pa_config->{'version'} . ' (P) ' . $pa_config->{'build'} unless defined($version);
@ -2215,9 +2216,9 @@ sub pandora_update_server ($$$$$$;$$$) {
# Create an entry in tserver if needed # Create an entry in tserver if needed
my $server = get_db_single_row ($dbh, 'SELECT id_server FROM tserver WHERE name = ? AND server_type = ?', $server_name, $server_type); my $server = get_db_single_row ($dbh, 'SELECT id_server FROM tserver WHERE name = ? AND server_type = ?', $server_name, $server_type);
if (! defined ($server)) { if (! defined ($server)) {
$server_id = db_insert ($dbh, 'id_server', 'INSERT INTO tserver (name, server_type, description, version, threads, queued_modules) $server_id = db_insert ($dbh, 'id_server', 'INSERT INTO tserver (name, server_type, description, version, threads, queued_modules, server_keepalive)
VALUES (?, ?, ?, ?, ?, ?)', $server_name, $server_type, VALUES (?, ?, ?, ?, ?, ?, ?)', $server_name, $server_type,
'Autocreated at startup', $version, $num_threads, $queue_size); 'Autocreated at startup', $version, $num_threads, $queue_size, $keepalive);
$server = get_db_single_row ($dbh, 'SELECT status FROM tserver WHERE id_server = ?', $server_id); $server = get_db_single_row ($dbh, 'SELECT status FROM tserver WHERE id_server = ?', $server_id);
if (! defined ($server)) { if (! defined ($server)) {
@ -2228,14 +2229,14 @@ sub pandora_update_server ($$$$$$;$$$) {
$server_id = $server->{'id_server'}; $server_id = $server->{'id_server'};
} }
db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ? db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, laststart = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ?
WHERE id_server = ?', WHERE id_server = ?',
1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $server_id); 1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $keepalive, $server_id);
return; return;
} }
db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, version = ?, threads = ?, queued_modules = ? db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, version = ?, threads = ?, queued_modules = ?, server_keepalive = ?
WHERE id_server = ?', $status, $timestamp, $master, $version, $num_threads, $queue_size, $server_id); WHERE id_server = ?', $status, $timestamp, $master, $version, $num_threads, $queue_size, $keepalive, $server_id);
} }
########################################################################## ##########################################################################

View File

@ -817,7 +817,7 @@ sub process_xml_server ($$$$) {
$version = '' unless defined($version); $version = '' unless defined($version);
# Update server information # Update server information
pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version); pandora_update_server ($pa_config, $dbh, $data->{'server_name'}, 0, 1, $server_type, $threads, $modules, $version, $data->{'keepalive'});
} }
1; 1;