Add RPS logging for all requests
This commit is contained in:
parent
dbd4d2dd9d
commit
f7c0f6e7b3
@ -20,7 +20,6 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -64,8 +63,11 @@ public class IntervalRegistryLogger {
|
||||
}
|
||||
|
||||
public void logStatistic() {
|
||||
Map<String, Long> top = getTopElements(intervalRegistry.getContent());
|
||||
log(top);
|
||||
Map<String, Long> registryContent = intervalRegistry.getContent();
|
||||
int uniqHosts = registryContent.size();
|
||||
long requestsCount = registryContent.values().stream().mapToLong(i -> i).sum();
|
||||
Map<String, Long> top = getTopElements(registryContent);
|
||||
log(top, uniqHosts, requestsCount);
|
||||
}
|
||||
|
||||
protected Map<String, Long> getTopElements(Map<String, Long> countMap) {
|
||||
@ -77,10 +79,15 @@ public class IntervalRegistryLogger {
|
||||
return topQueue.stream().collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||
}
|
||||
|
||||
private void log(Map<String, Long> top) {
|
||||
private void log(Map<String, Long> top, int uniqHosts, long requestsCount) {
|
||||
long rps = requestsCount / TimeUnit.MINUTES.toSeconds(logIntervalMin);
|
||||
StringBuilder builder = new StringBuilder("Quota Statistic : ");
|
||||
builder.append("uniqHosts : ").append(uniqHosts).append("; ");
|
||||
builder.append("requestsCount : ").append(requestsCount).append("; ");
|
||||
builder.append("RPS : ").append(rps).append(" ");
|
||||
builder.append("top -> ");
|
||||
for (Map.Entry<String, Long> host : top.entrySet()) {
|
||||
builder.append(host.getKey()).append(" : ").append(host.getValue()).append(" ; ");
|
||||
builder.append(host.getKey()).append(" : ").append(host.getValue()).append("; ");
|
||||
}
|
||||
|
||||
log.info(builder.toString());
|
||||
|
||||
@ -19,12 +19,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.californium.core.CoapResource;
|
||||
import org.eclipse.californium.core.CoapServer;
|
||||
import org.eclipse.californium.core.network.CoapEndpoint;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.thingsboard.server.common.transport.SessionMsgProcessor;
|
||||
import org.thingsboard.server.common.transport.auth.DeviceAuthService;
|
||||
import org.thingsboard.server.transport.coap.adaptors.CoapTransportAdaptor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.transport.SessionMsgProcessor;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user