Skip to content

Commit

Permalink
added active ssl sessions count stats
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-landiak committed Jun 21, 2024
1 parent af7f7f1 commit bc3d850
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

@Service
@Slf4j
Expand All @@ -37,9 +38,12 @@ public class ClientSessionCtxServiceImpl implements ClientSessionCtxService {
private final StatsManager statsManager;
private final boolean isTraceEnabled = log.isTraceEnabled();

private AtomicLong sslSessionCounter;

@PostConstruct
public void init() {
statsManager.registerActiveSessionsStats(clientContextMap);
sslSessionCounter = statsManager.registerActiveSslSessionsStats();
}

@Override
Expand All @@ -49,14 +53,20 @@ public void registerSession(ClientSessionCtx clientSessionCtx) throws MqttExcept
log.trace("Executing registerSession: {}. Current size: {}", clientId, clientContextMap.size());
}
clientContextMap.put(clientId, clientSessionCtx);
if (clientSessionCtx.getSslHandler() != null) {
sslSessionCounter.incrementAndGet();
}
}

@Override
public void unregisterSession(String clientId) {
if (isTraceEnabled) {
log.trace("Executing unregisterSession: {}. Current size: {}", clientId, clientContextMap.size());
}
clientContextMap.remove(clientId);
ClientSessionCtx remove = clientContextMap.remove(clientId);
if (remove != null && remove.getSslHandler() != null) {
sslSessionCounter.decrementAndGet();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public interface StatsManager {

void registerActiveSessionsStats(Map<?, ?> sessionsMap);

AtomicLong registerActiveSslSessionsStats();

void registerAllClientSessionsStats(Map<?, ?> clientSessionsMap);

void registerClientSubscriptionsStats(Map<?, ?> clientSubscriptionsMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,22 @@ public void registerLastWillStats(Map<?, ?> lastWillMsgsMap) {
@Override
public void registerActiveSessionsStats(Map<?, ?> sessionsMap) {
if (log.isTraceEnabled()) {
log.trace("Registering SessionsStats.");
log.trace("Registering ActiveSessionsStats.");
}
statsFactory.createGauge(StatsType.CONNECTED_SESSIONS.getPrintName(), sessionsMap, Map::size);
gauges.add(new Gauge(StatsType.CONNECTED_SESSIONS.getPrintName(), sessionsMap::size));
}

@Override
public AtomicLong registerActiveSslSessionsStats() {
if (log.isTraceEnabled()) {
log.trace("Creating ActiveSslSessionsStats.");
}
AtomicLong sizeGauge = statsFactory.createGauge(StatsType.CONNECTED_SSL_SESSIONS.getPrintName(), new AtomicLong(0));
gauges.add(new Gauge(StatsType.CONNECTED_SSL_SESSIONS.getPrintName(), sizeGauge::get));
return sizeGauge;
}

@Override
public void registerAllClientSessionsStats(Map<?, ?> clientSessionsMap) {
if (log.isTraceEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public void registerLastWillStats(Map<?, ?> lastWillMsgsMap) {
public void registerActiveSessionsStats(Map<?, ?> sessionsMap) {
}

@Override
public AtomicLong registerActiveSslSessionsStats() {
return new AtomicLong(0);
}

@Override
public void registerAllClientSessionsStats(Map<?, ?> clientSessionsMap) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum StatsType {
RETAIN_MSG_TRIE_SIZE("retainMsgTrieSize"),
LAST_WILL_CLIENTS("lastWillClients"),
CONNECTED_SESSIONS("connectedSessions"),
CONNECTED_SSL_SESSIONS("connectedSslSessions"),
ALL_CLIENT_SESSIONS("allClientSessions"),
CLIENT_SUBSCRIPTIONS("clientSubscriptions"),
RETAINED_MESSAGES("retainedMessages"),
Expand Down

0 comments on commit bc3d850

Please sign in to comment.