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}"
|
parallelism_level: "${SNMP_RESPONSE_PROCESSING_PARALLELISM_LEVEL:20}"
|
||||||
# to configure SNMP to work over UDP or TCP
|
# to configure SNMP to work over UDP or TCP
|
||||||
underlying_protocol: "${SNMP_UNDERLYING_PROTOCOL:udp}"
|
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 parameters
|
||||||
edges:
|
edges:
|
||||||
|
|||||||
@ -31,6 +31,7 @@ import org.thingsboard.server.transport.mqtt.adaptors.ProtoMqttAdaptor;
|
|||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ashvayka on 04.10.18.
|
* Created by ashvayka on 04.10.18.
|
||||||
@ -71,4 +72,19 @@ public class MqttTransportContext extends TransportContext {
|
|||||||
@Getter
|
@Getter
|
||||||
@Value("${transport.mqtt.timeout:10000}")
|
@Value("${transport.mqtt.timeout:10000}")
|
||||||
private long timeout;
|
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<>();
|
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
|
@Override
|
||||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||||
log.trace("[{}] Processing msg: {}", sessionId, msg);
|
log.trace("[{}] Processing msg: {}", sessionId, msg);
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public abstract class TransportContext {
|
|||||||
protected final ObjectMapper mapper = new ObjectMapper();
|
protected final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TransportService transportService;
|
protected TransportService transportService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private TbServiceInfoProvider serviceInfoProvider;
|
private TbServiceInfoProvider serviceInfoProvider;
|
||||||
|
|||||||
@ -58,6 +58,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenR
|
|||||||
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
|
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ashvayka on 04.10.18.
|
* Created by ashvayka on 04.10.18.
|
||||||
@ -138,4 +139,6 @@ public interface TransportService {
|
|||||||
ExecutorService getCallbackExecutor();
|
ExecutorService getCallbackExecutor();
|
||||||
|
|
||||||
boolean hasSession(SessionInfoProto sessionInfo);
|
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.Gson;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.context.ApplicationEventPublisher;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thingsboard.common.util.ThingsBoardExecutors;
|
import org.thingsboard.common.util.ThingsBoardExecutors;
|
||||||
import org.thingsboard.common.util.ThingsBoardThreadFactory;
|
import org.thingsboard.common.util.ThingsBoardThreadFactory;
|
||||||
@ -96,6 +98,7 @@ import javax.annotation.PostConstruct;
|
|||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@ -110,6 +113,7 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.ScheduledFuture;
|
import java.util.concurrent.ScheduledFuture;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by ashvayka on 17.10.18.
|
* Created by ashvayka on 17.10.18.
|
||||||
@ -135,6 +139,10 @@ public class DefaultTransportService implements TransportService {
|
|||||||
private long clientSideRpcTimeout;
|
private long clientSideRpcTimeout;
|
||||||
@Value("${queue.transport.poll_interval}")
|
@Value("${queue.transport.poll_interval}")
|
||||||
private int notificationsPollDuration;
|
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 Gson gson = new Gson();
|
||||||
private final TbTransportQueueFactory queueProvider;
|
private final TbTransportQueueFactory queueProvider;
|
||||||
@ -1167,4 +1175,19 @@ public class DefaultTransportService implements TransportService {
|
|||||||
public boolean hasSession(TransportProtos.SessionInfoProto sessionInfo) {
|
public boolean hasSession(TransportProtos.SessionInfoProto sessionInfo) {
|
||||||
return sessions.containsKey(toSessionId(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:
|
log:
|
||||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
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:
|
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)
|
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:
|
log:
|
||||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
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:
|
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)
|
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}"
|
paging_transmission_window: "${LWM2M_PAGING_TRANSMISSION_WINDOW:10000}"
|
||||||
# Use redis for Security and Registration stores
|
# Use redis for Security and Registration stores
|
||||||
redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
|
redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
|
||||||
|
stats:
|
||||||
|
enabled: "${TB_TRANSPORT_STATS_ENABLED:true}"
|
||||||
|
print-interval-ms: "${TB_TRANSPORT_STATS_PRINT_INTERVAL_MS:60000}"
|
||||||
|
|
||||||
queue:
|
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)
|
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:
|
log:
|
||||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
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:
|
queue:
|
||||||
|
|||||||
@ -59,6 +59,9 @@ transport:
|
|||||||
log:
|
log:
|
||||||
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
enabled: "${TB_TRANSPORT_LOG_ENABLED:true}"
|
||||||
max_length: "${TB_TRANSPORT_LOG_MAX_LENGTH:1024}"
|
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:
|
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)
|
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