summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Unterkircher <unki@netshadow.at>2008-12-03 22:27:50 +0100
committerAndreas Unterkircher <unki@netshadow.at>2008-12-12 18:37:27 +0100
commitf603da207df24207be8cbb734778ff9e11ec479a (patch)
tree43e1120be4f3dab456666612e51df7fae3e05e05
parent6f71c4ad3b8e28556c2c3d9ae5918f47c09ea519 (diff)
downloadexilog-f603da207df24207be8cbb734778ff9e11ec479a.zip
exilog-f603da207df24207be8cbb734778ff9e11ec479a.tar.gz
exilog-f603da207df24207be8cbb734778ff9e11ec479a.tar.bz2
exilog-agent heartbeats, resolves #115
Signed-off-by: Andreas Unterkircher <unki@netshadow.at>
-rwxr-xr-xagent/exilog_agent.pl2
-rw-r--r--cgi/exilog_cgi_html.pm5
-rw-r--r--cgi/exilog_cgi_servers.pm26
-rw-r--r--doc/mysql-db-script.sql9
-rw-r--r--lib/exilog_sql.pm18
5 files changed, 59 insertions, 1 deletions
diff --git a/agent/exilog_agent.pl b/agent/exilog_agent.pl
index dec5973..e09dce9 100755
--- a/agent/exilog_agent.pl
+++ b/agent/exilog_agent.pl
@@ -120,6 +120,8 @@ sub _queue_actions {
for (;;) {
# conditional reconnect
reconnect(1);
+
+ sql_update_heartbeat;
my $deliver = sql_select('queue',
[ 'message_id' ],
diff --git a/cgi/exilog_cgi_html.pm b/cgi/exilog_cgi_html.pm
index 00f4431..9011369 100644
--- a/cgi/exilog_cgi_html.pm
+++ b/cgi/exilog_cgi_html.pm
@@ -51,6 +51,7 @@ sub render_server {
my $server = shift;
my $num_queued = shift;
my $h24_stats = shift;
+ my $last_update = shift;
$q->div({-class=>"top_spacer"},
$q->table({-class=>"stats", -cellspacing=>1, -cellpadding=>2, -border=>0},
@@ -64,6 +65,10 @@ sub render_server {
$q->td({-class=>"large_text"},
$server
)
+ ),
+ $q->Tr(
+ $q->td('', ''),
+ $q->td('', 'last update: '. $last_update),
)
)
),
diff --git a/cgi/exilog_cgi_servers.pm b/cgi/exilog_cgi_servers.pm
index 424abf1..ffe5357 100644
--- a/cgi/exilog_cgi_servers.pm
+++ b/cgi/exilog_cgi_servers.pm
@@ -90,12 +90,36 @@ sub _get_h24_stats {
return $h;
}
+sub _get_last_update {
+ my $server = shift;
+ my $now = time();
+ my $timestamp;
+
+ my $results = sql_select( 'heartbeats', [ 'timestamp' ], { 'server' => $server } );
+
+ foreach (@{ $results }) {
+
+ $timestamp = $_->{timestamp};
+
+ # if timestamp is older then 5 minutes
+ if($timestamp + 300 < $now) {
+ return "<div style='color: #ff5555;'>". stamp_to_date($timestamp) ."</div>";
+ }
+
+ return "<div>". stamp_to_date($timestamp) ."</div>";
+
+ }
+
+ return "<div style='color: #ff0000;'>no heartbeat signal</div>";
+
+}
+
sub servers {
#print $q->div({-style=>"font-size: 28px; font-weight: bold;"},"Basic statictics for all servers");
foreach my $server (sort {$a cmp $b} keys %{ $config->{servers} }) {
- print render_server($server,_get_num_queued($server),_get_h24_stats($server));
+ print render_server($server,_get_num_queued($server),_get_h24_stats($server),_get_last_update($server));
};
}
diff --git a/doc/mysql-db-script.sql b/doc/mysql-db-script.sql
index 7ed82a6..79cabfb 100644
--- a/doc/mysql-db-script.sql
+++ b/doc/mysql-db-script.sql
@@ -197,3 +197,12 @@ CREATE TABLE `unknown` (
KEY `timestamp` (`timestamp`)
) TYPE=MyISAM;
+--
+-- Table structure for table `heartbeats`
+--
+
+CREATE TABLE IF NOT EXISTS `heartbeats` (
+ `server` varchar(32) NOT NULL,
+ `timestamp` bigint(20) default NULL,
+ PRIMARY KEY (`server`)
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
diff --git a/lib/exilog_sql.pm b/lib/exilog_sql.pm
index fc8bc71..7c116a6 100644
--- a/lib/exilog_sql.pm
+++ b/lib/exilog_sql.pm
@@ -30,6 +30,7 @@ BEGIN {
&sql_delete
&sql_optimize
&sql_count
+ &sql_update_heartbeat
&sql_queue_add
&sql_queue_update
&sql_queue_delete
@@ -94,6 +95,11 @@ sub sql_optimize {
return &{ "_".$config->{sql}->{type}."_sql_optimize" }(@_);
};
+sub sql_update_heartbeat {
+ no strict "refs";
+ return &{ "_".$config->{sql}->{type}."_sql_update_heartbeat" }(@_);
+};
+
sub sql_queue_add {
no strict "refs";
return &{ "_".$config->{sql}->{type}."_sql_queue_add" }(@_);
@@ -143,6 +149,12 @@ sub _pgsql_sql_count {
return @{$tmp}[0];
};
+sub _pgsql_sql_update_heartbeat {
+ my $now = time();
+
+ $dbh->do("REPLACE heartbeats SET server='". $config->{agent}->{server} ."', timestamp='". $now ."'");
+};
+
sub _pgsql_sql_queue_delete {
my $spool_path = shift;
@@ -324,6 +336,12 @@ sub _mysql_sql_count {
return @{$tmp}[0];
};
+sub _mysql_sql_update_heartbeat {
+ my $now = time();
+
+ $dbh->do("REPLACE heartbeats SET server='". $config->{agent}->{server} ."', timestamp='". $now ."'");
+};
+
sub _mysql_sql_queue_delete {
my $spool_path = shift;