Ability to log number of active MQTT connections
This commit is contained in:
parent
c52c9a16ed
commit
d40bc48898
@ -702,6 +702,9 @@ transport:
|
||||
parallelism_level: "${SNMP_RESPONSE_PROCESSING_PARALLELISM_LEVEL:20}"
|
||||
# to configure SNMP to work over UDP or TCP
|
||||
underlying_protocol: "${SNMP_UNDERLYING_PROTOCOL:udp}"
|
||||
stats:
|
||||
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
|
||||
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"
|
||||
|
||||
# Edges parameters
|
||||
edges:
|
||||
|
||||
@ -31,6 +31,7 @@ import org.thingsboard.server.transport.mqtt.adaptors.ProtoMqttAdaptor;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 04.10.18.
|
||||
@ -71,4 +72,19 @@ public class MqttTransportContext extends TransportContext {
|
||||
@Getter
|
||||
@Value("${transport.mqtt.timeout:10000}")
|
||||
private long timeout;
|
||||
|
||||
private final AtomicInteger connectionsCounter = new AtomicInteger();
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
transportService.createGaugeStats("openConnections", connectionsCounter);
|
||||
}
|
||||
|
||||
public void channelRegistered() {
|
||||
connectionsCounter.incrementAndGet();
|
||||
}
|
||||
|
||||
public void channelUnregistered() {
|
||||
connectionsCounter.decrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,6 +146,18 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
||||
this.rpcAwaitingAck = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelRegistered(ctx);
|
||||
context.channelRegistered();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelUnregistered(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelUnregistered(ctx);
|
||||
context.channelUnregistered();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||
log.trace("[{}] Processing msg: {}", sessionId, msg);
|
||||
|
||||
@ -39,7 +39,7 @@ public abstract class TransportContext {
|
||||
protected final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Autowired
|
||||
private TransportService transportService;
|
||||
protected TransportService transportService;
|
||||
|
||||
@Autowired
|
||||
private TbServiceInfoProvider serviceInfoProvider;
|
||||
|
||||
@ -58,6 +58,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenR
|
||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 04.10.18.
|
||||
@ -138,4 +139,6 @@ public interface TransportService {
|
||||
ExecutorService getCallbackExecutor();
|
||||
|
||||
boolean hasSession(SessionInfoProto sessionInfo);
|
||||
|
||||
void createGaugeStats(String openConnections, AtomicInteger connectionsCounter);
|
||||
}
|
||||
|
||||
@ -21,9 +21,11 @@ import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.protobuf.ByteString;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||
import org.thingsboard.common.util.ThingsBoardThreadFactory;
|
||||
@ -96,6 +98,7 @@ import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -110,6 +113,7 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by ashvayka on 17.10.18.
|
||||
@ -135,6 +139,10 @@ public class DefaultTransportService implements TransportService {
|
||||
private long clientSideRpcTimeout;
|
||||
@Value("${queue.transport.poll_interval}")
|
||||
private int notificationsPollDuration;
|
||||
@Value("${transport.stats.enabled:false}")
|
||||
private boolean statsEnabled;
|
||||
|
||||
private final Map<String, Number> statsMap = new LinkedHashMap<>();
|
||||
|
||||
private final Gson gson = new Gson();
|
||||
private final TbTransportQueueFactory queueProvider;
|
||||
@ -1167,4 +1175,19 @@ public class DefaultTransportService implements TransportService {
|
||||
public boolean hasSession(TransportProtos.SessionInfoProto sessionInfo) {
|
||||
return sessions.containsKey(toSessionId(sessionInfo));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createGaugeStats(String statsName, AtomicInteger number) {
|
||||
statsFactory.createGauge(StatsType.TRANSPORT + "." + statsName, number);
|
||||
statsMap.put(statsName, number);
|
||||
}
|
||||
|
||||
@Scheduled(fixedDelayString = "${transport.stats.print-interval-ms:60000}")
|
||||
public void printStats() {
|
||||
if (statsEnabled) {
|
||||
String values = statsMap.entrySet().stream()
|
||||
.map(kv -> kv.getKey() + " [" + kv.getValue() + "]").collect(Collectors.joining(", "));
|
||||
log.info("Transport Stats: {}", values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -122,6 +122,9 @@ transport:
|
||||
log:
|
||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
||||
stats:
|
||||
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
|
||||
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"
|
||||
|
||||
queue:
|
||||
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
|
||||
|
||||
@ -94,6 +94,9 @@ transport:
|
||||
log:
|
||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
||||
stats:
|
||||
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
|
||||
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"
|
||||
|
||||
queue:
|
||||
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
|
||||
|
||||
@ -147,6 +147,9 @@ transport:
|
||||
paging_transmission_window: "${LWM2M_PAGING_TRANSMISSION_WINDOW:10000}"
|
||||
# Use redis for Security and Registration stores
|
||||
redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
|
||||
stats:
|
||||
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
|
||||
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"
|
||||
|
||||
queue:
|
||||
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
|
||||
|
||||
@ -127,6 +127,9 @@ transport:
|
||||
log:
|
||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
||||
stats:
|
||||
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
|
||||
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"
|
||||
|
||||
|
||||
queue:
|
||||
|
||||
@ -59,6 +59,9 @@ transport:
|
||||
log:
|
||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
||||
stats:
|
||||
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
|
||||
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"
|
||||
|
||||
queue:
|
||||
type: "${TB_QUEUE_TYPE:kafka}" # kafka (Apache Kafka) or aws-sqs (AWS SQS) or pubsub (PubSub) or service-bus (Azure Service Bus) or rabbitmq (RabbitMQ)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user