Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,10 @@ exports.register = function(server, options, next) {
if (options.logRequests) {
// server.log request info:
// track % of requests that were not HTTP OK:
if (data.requests[port] !== undefined && data.requests[port].total !== 0) {
if (data.requests[port] && data.requests[port].total !== 0) {
let totalRequestsProcessed = 0;
let totalErrorRequests = 0;
const requestData = data.requests[port];
requestData.avgResponseTime = data.responseTimes[port].avg;
requestData.maxResponseTime = data.responseTimes[port].max;
if (options.logRequests === 'info') {
server.log(['ops', 'requests'], requestData);
}
Expand All @@ -75,8 +73,14 @@ exports.register = function(server, options, next) {
if (failedRequestPercent > options.failedRequestThreshold) {
server.log(['ops', 'requests', 'threshold', 'warning'], `${failedRequestPercent}% of http requests have returned a non-200 code`);
}
if (requestData.avgResponseTime > options.avgResponseTimeThreshold) {
server.log(['ops', 'memory', 'warning', 'threshold'], `Average response time is ${requestData.avgResponseTime}ms. Exceeds threshold of ${options.avgResponseTimeThreshold}ms`);
if (data.responseTimes && data.responseTimes[port]) {
requestData.avgResponseTime = data.responseTimes[port].avg;
requestData.maxResponseTime = data.responseTimes[port].max;
if (requestData.avgResponseTime > options.avgResponseTimeThreshold) {
server.log(['ops', 'memory', 'warning', 'threshold'], `Average response time is ${requestData.avgResponseTime}ms. Exceeds threshold of ${options.avgResponseTimeThreshold}ms`);
}
} else {
server.log(['ops', 'requests', 'error'], `Unable to get response time data for port ${port}`);
}
}
}
Expand Down