From d0dcb8a6586893424b93b6575bb4635e4729b25b Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 26 May 2017 17:02:36 +0200 Subject: [PATCH] ApiListener: Handle zero JSON-RPC WQs gracefully for stats refs #5266 refs #5133 --- lib/remote/jsonrpcconnection.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/remote/jsonrpcconnection.cpp b/lib/remote/jsonrpcconnection.cpp index dae89eb4c..ef8ef0d89 100644 --- a/lib/remote/jsonrpcconnection.cpp +++ b/lib/remote/jsonrpcconnection.cpp @@ -349,7 +349,7 @@ int JsonRpcConnection::GetWorkQueueLength(void) { size_t itemCount = 0; - for (size_t i = 0; i < l_JsonRpcConnectionWorkQueueCount; i++) { + for (size_t i = 0; i < GetWorkQueueCount(); i++) { itemCount += l_JsonRpcConnectionWorkQueues[i].GetLength(); } @@ -359,11 +359,16 @@ int JsonRpcConnection::GetWorkQueueLength(void) double JsonRpcConnection::GetWorkQueueRate(void) { double rate = 0.0; + int count = GetWorkQueueCount(); - for (size_t i = 0; i < l_JsonRpcConnectionWorkQueueCount; i++) { + /* If this is a standalone environment, we don't have any queues. */ + if (count == 0) + return 0.0; + + for (size_t i = 0; i < count; i++) { rate += l_JsonRpcConnectionWorkQueues[i].GetTaskCount(60) / 60.0; } - return rate / l_JsonRpcConnectionWorkQueueCount; + return rate / count; }