Skip to content

Commit

Permalink
Add a 'STATUS' command to the locking server, gives information about…
Browse files Browse the repository at this point in the history
… times, how many requests have been served successfully and have failed. Use for monitoring.

git-svn-id: http://code.sixapart.com/svn/ddlockd/trunk@41 75bc8fc0-0210-0410-8e5e-a32055405bc5
  • Loading branch information
hachi committed Jun 5, 2007
1 parent 6d3c0b7 commit d5c020d
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion ddlockd
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Getopt::Long::GetOptions(
'T|table=s' => \$table,
);

# Statistics counters
my $lock_successes = 0;
my $lock_failures = 0;

my $client_class;
my @client_options;
if ($lock_type eq 'internal') {
Expand Down Expand Up @@ -218,14 +222,35 @@ sub close {
sub event_err { my $self = shift; $self->close; }
sub event_hup { my $self = shift; $self->close; }

sub cmd_status {
my Client $self = shift;

my $runtime = time - $^T;

$self->write("STATUS: OK\n");
$self->write("SUCCESSES: $lock_successes\n");
$self->write("FAILURES: $lock_failures\n");
$self->write("RUNTIME: $runtime\n");
$self->write("\n");

return 1;
}

# gets a lock or fails with 'taken'
sub cmd_trylock {
my Client $self = shift;
my $args = shift;

my $lock = $args->{lock};
return $self->_trylock( $lock );
my $lockstate = $self->_trylock( $lock );

if ($lockstate) {
$lock_successes++;
} else {
$lock_failures++;
}

return $lockstate;
}

# releases a lock or fails with 'didnthave'
Expand All @@ -248,6 +273,7 @@ sub cmd_locks {

$self->write("LOCKS:\n");
$self->write( join( "\n", $self->_get_locks ) );
$self->write("\n");

return 1;
}
Expand Down

0 comments on commit d5c020d

Please sign in to comment.