Added new server_keepalive column to have individual keepalive TICKETS #3273
This commit is contained in:
parent
368a96222e
commit
f397b657f1
|
@ -3,3 +3,9 @@
|
|||
-- ---------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
|
|
|
@ -3,3 +3,9 @@
|
|||
-- ---------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
|
|
|
@ -30,6 +30,7 @@ if (! check_acl ($config["id_user"], 0, "AW")) {
|
|||
|
||||
global $tiny;
|
||||
global $hidden_toggle;
|
||||
$date = time();
|
||||
|
||||
$servers = servers_get_info();
|
||||
if ($servers === false) {
|
||||
|
@ -84,12 +85,11 @@ foreach ($servers as $server) {
|
|||
$data[0] = '<span title="' . $server['version'] . '">' .
|
||||
$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);
|
||||
}
|
||||
else {
|
||||
$data[1] = ui_print_status_image (STATUS_SERVER_OK, '', true);
|
||||
}
|
||||
|
||||
// Type
|
||||
$data[2] = '<span style="white-space:nowrap;">' . $server["img"];
|
||||
|
|
|
@ -765,19 +765,19 @@ function servers_check_status () {
|
|||
$sql = "SELECT COUNT(id_server)
|
||||
FROM tserver
|
||||
WHERE status = 1
|
||||
AND keepalive > NOW() - INTERVAL 15 MINUTE";
|
||||
AND keepalive > NOW() - INTERVAL server_keepalive*2 SECOND";
|
||||
break;
|
||||
case "postgresql":
|
||||
$sql = "SELECT COUNT(id_server)
|
||||
FROM tserver
|
||||
WHERE status = 1
|
||||
AND keepalive > NOW() - INTERVAL '15 MINUTE'";
|
||||
AND keepalive > NOW() - INTERVAL 'server_keepalive*2 SECOND'";
|
||||
break;
|
||||
case "oracle":
|
||||
$sql = "SELECT COUNT(id_server)
|
||||
FROM tserver
|
||||
WHERE status = 1
|
||||
AND keepalive > systimestamp - INTERVAL '15' MINUTE";
|
||||
AND keepalive > systimestamp - INTERVAL 'server_keepalive*2' SECOND";
|
||||
break;
|
||||
}
|
||||
$status = (int) db_get_sql ($sql); //Cast as int will assure a number value
|
||||
|
|
|
@ -1001,6 +1001,7 @@ CREATE TABLE tserver (
|
|||
lag_modules NUMBER(10, 0) DEFAULT 0,
|
||||
total_modules_running 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
|
||||
);
|
||||
CREATE INDEX tserver_name_idx ON tserver(name);
|
||||
|
|
|
@ -820,6 +820,7 @@ CREATE TABLE "tserver" (
|
|||
"lag_modules" INTEGER NOT NULL default 0,
|
||||
"total_modules_running" 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
|
||||
);
|
||||
CREATE INDEX "tserver_name_idx" ON "tserver"("name");
|
||||
|
|
|
@ -895,6 +895,7 @@ CREATE TABLE IF NOT EXISTS `tserver` (
|
|||
`lag_modules` int(11) NOT NULL default 0,
|
||||
`total_modules_running` 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',
|
||||
PRIMARY KEY (`id_server`),
|
||||
KEY `name` (`name`)
|
||||
|
|
|
@ -606,8 +606,13 @@ sub main() {
|
|||
$server->update();
|
||||
}
|
||||
|
||||
# Update fallen servers
|
||||
db_do ($DBH, "UPDATE tserver SET status = 0 WHERE keepalive < ?", strftime ("%Y-%m-%d %H:%M:%S", localtime(time() - $Config{'keepalive'})));
|
||||
# Update fallen servers
|
||||
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
|
||||
pandora_set_master(\%Config, $DBH);
|
||||
|
|
|
@ -2197,12 +2197,13 @@ Update server status:
|
|||
|
||||
=cut
|
||||
##########################################################################
|
||||
sub pandora_update_server ($$$$$$;$$$) {
|
||||
sub pandora_update_server ($$$$$$;$$$$) {
|
||||
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);
|
||||
$queue_size = 0 unless defined ($queue_size);
|
||||
$keepalive = $pa_config->{'keepalive'} unless defined ($keepalive);
|
||||
|
||||
my $timestamp = strftime ("%Y-%m-%d %H:%M:%S", localtime());
|
||||
$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
|
||||
my $server = get_db_single_row ($dbh, 'SELECT id_server FROM tserver WHERE name = ? AND server_type = ?', $server_name, $server_type);
|
||||
if (! defined ($server)) {
|
||||
$server_id = db_insert ($dbh, 'id_server', 'INSERT INTO tserver (name, server_type, description, version, threads, queued_modules)
|
||||
VALUES (?, ?, ?, ?, ?, ?)', $server_name, $server_type,
|
||||
'Autocreated at startup', $version, $num_threads, $queue_size);
|
||||
$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,
|
||||
'Autocreated at startup', $version, $num_threads, $queue_size, $keepalive);
|
||||
|
||||
$server = get_db_single_row ($dbh, 'SELECT status FROM tserver WHERE id_server = ?', $server_id);
|
||||
if (! defined ($server)) {
|
||||
|
@ -2228,14 +2229,14 @@ sub pandora_update_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 = ?',
|
||||
1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $server_id);
|
||||
1, $timestamp, $master, $timestamp, $version, $num_threads, $queue_size, $keepalive, $server_id);
|
||||
return;
|
||||
}
|
||||
|
||||
db_do ($dbh, 'UPDATE tserver SET status = ?, keepalive = ?, master = ?, version = ?, threads = ?, queued_modules = ?
|
||||
WHERE id_server = ?', $status, $timestamp, $master, $version, $num_threads, $queue_size, $server_id);
|
||||
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, $keepalive, $server_id);
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
|
|
|
@ -817,7 +817,7 @@ sub process_xml_server ($$$$) {
|
|||
$version = '' unless defined($version);
|
||||
|
||||
# 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;
|
||||
|
|
Loading…
Reference in New Issue