fix: semantic host stats (#11482)

This commit is contained in:
Rhys Arkins 2021-08-30 17:09:08 +02:00 committed by GitHub
parent 60b3d6d933
commit 59cc317156
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,25 +30,26 @@ export function printRequestStats(): void {
requestHosts[hostname].push(httpRequest);
}
logger.trace({ allRequests, requestHosts }, 'full stats');
const hostStats: string[] = [];
type HostStats = {
requestCount: number;
requestAvgMs: number;
queueAvgMs: number;
};
const hostStats: Record<string, HostStats> = {};
let totalRequests = 0;
for (const [hostname, requests] of Object.entries(requestHosts)) {
const hostRequests = requests.length;
totalRequests += hostRequests;
const requestCount = requests.length;
totalRequests += requestCount;
const requestSum = requests
.map(({ duration }) => duration)
.reduce((a, b) => a + b, 0);
const requestAvg = Math.round(requestSum / hostRequests);
const requestAvgMs = Math.round(requestSum / requestCount);
const queueSum = requests
.map(({ queueDuration }) => queueDuration)
.reduce((a, b) => a + b, 0);
const queueAvg = Math.round(queueSum / hostRequests);
const requestCount =
`${hostRequests} ` + (hostRequests > 1 ? 'requests' : 'request');
hostStats.push(
`${hostname}, ${requestCount}, ${requestAvg}ms request average, ${queueAvg}ms queue average`
);
const queueAvgMs = Math.round(queueSum / requestCount);
hostStats[hostname] = { requestCount, requestAvgMs, queueAvgMs };
}
logger.debug({ hostStats, totalRequests }, 'http statistics');
}