ApiListener: Handle zero JSON-RPC WQs gracefully for stats

refs #5266
refs #5133
This commit is contained in:
Michael Friedrich 2017-05-26 17:02:36 +02:00
parent 28395b32f0
commit d0dcb8a658
1 changed files with 8 additions and 3 deletions

View File

@ -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;
}