Skip to content

Commit

Permalink
Merge pull request #6643 from mlschroe/master
Browse files Browse the repository at this point in the history
[backend] slow request log: log worker requests into a different file
  • Loading branch information
mlschroe committed Dec 17, 2018
2 parents ee4292a + bfbbe3a commit 955a91f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/backend/BSServer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,14 @@ sub parse_error_string {

sub log_slow_requests {
my ($conf, $req) = @_;
return unless $req && $conf->{'slowrequestlog'} && $conf->{'slowrequestthr'} && $req->{'starttime'};
return unless $req && $conf->{'slowrequestthr'} && $req->{'starttime'};
my $log = $req->{'slowrequestlog'} || $conf->{'slowrequestlog'};
return unless $log;
my $duration = time() - $req->{'starttime'};
return unless $duration >= $conf->{'slowrequestthr'};
my $msg = sprintf("%s: %3ds %-7s %-22s %s%s\n", BSUtil::isotime($req->{'starttime'}), $duration, "[$$]",
"$req->{'action'} ($req->{'peer'})", $req->{'path'}, ($req->{'query'}) ? "?$req->{'query'}" : '');
eval { BSUtil::appendstr($conf->{'slowrequestlog'}, $msg) };
eval { BSUtil::appendstr($log, $msg) };
}

sub reply_error {
Expand Down
2 changes: 2 additions & 0 deletions src/backend/BSStdServer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ sub dispatch {
"$req->{'action'} ($peer)", $req->{'path'},
defined($req->{'query'}) ? "?$req->{'query'}" : '',
);
$req->{'slowrequestlog'} = $req->{'group'} ? $conf->{'slowrequestlog2'} : $conf->{'slowrequestlog'};
BSServer::setstatus(2, $msg) if $conf->{'serverstatus'};
BSUtil::printlog($msg);
BSServerEvents::cloneconnect("OK\n", "Content-Type: text/plain") if $isajax;
Expand Down Expand Up @@ -242,6 +243,7 @@ sub server {
$conf->{'setkeepalive'} = 1 unless defined $conf->{'setkeepalive'};
$conf->{'run'} ||= \&BSServer::server;
$conf->{'slowrequestlog'} ||= "$bsdir/log/$name.slow.log" if $conf->{'slowrequestthr'};
$conf->{'slowrequestlog2'} ||= "$bsdir/log/${name}2.slow.log" if $conf->{'slowrequestthr'} && $conf->{'port2'};
$conf->{'name'} = $name;
$conf->{'logfile'} = $logfile if $logfile;
BSDispatch::compile($conf);
Expand Down

0 comments on commit 955a91f

Please sign in to comment.