Commit 1700cf77077937d5f66e793ff4ddded5e7fe4629
Committed by
Andrew Shvayka
1 parent
4d7e5add
Added producer stats to 'transport' services
Showing
22 changed files
with
228 additions
and
111 deletions
@@ -298,18 +298,6 @@ | @@ -298,18 +298,6 @@ | ||
298 | <groupId>com.github.ua-parser</groupId> | 298 | <groupId>com.github.ua-parser</groupId> |
299 | <artifactId>uap-java</artifactId> | 299 | <artifactId>uap-java</artifactId> |
300 | </dependency> | 300 | </dependency> |
301 | - <dependency> | ||
302 | - <groupId>org.springframework.boot</groupId> | ||
303 | - <artifactId>spring-boot-starter-actuator</artifactId> | ||
304 | - </dependency> | ||
305 | - <dependency> | ||
306 | - <groupId>io.micrometer</groupId> | ||
307 | - <artifactId>micrometer-core</artifactId> | ||
308 | - </dependency> | ||
309 | - <dependency> | ||
310 | - <groupId>io.micrometer</groupId> | ||
311 | - <artifactId>micrometer-registry-prometheus</artifactId> | ||
312 | - </dependency> | ||
313 | </dependencies> | 301 | </dependencies> |
314 | 302 | ||
315 | <build> | 303 | <build> |
@@ -31,6 +31,7 @@ import org.thingsboard.server.queue.TbQueueConsumer; | @@ -31,6 +31,7 @@ import org.thingsboard.server.queue.TbQueueConsumer; | ||
31 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 31 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
32 | import org.thingsboard.server.queue.discovery.PartitionChangeEvent; | 32 | import org.thingsboard.server.queue.discovery.PartitionChangeEvent; |
33 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; | 33 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
34 | +import org.thingsboard.server.common.msg.stats.StatsFactory; | ||
34 | import org.thingsboard.server.queue.util.TbCoreComponent; | 35 | import org.thingsboard.server.queue.util.TbCoreComponent; |
35 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; | 36 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; |
36 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; | 37 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; |
@@ -38,7 +39,6 @@ import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | @@ -38,7 +39,6 @@ import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | ||
38 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; | 39 | import org.thingsboard.server.service.rpc.TbCoreDeviceRpcService; |
39 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; | 40 | import org.thingsboard.server.service.rpc.ToDeviceRpcRequestActorMsg; |
40 | import org.thingsboard.server.service.state.DeviceStateService; | 41 | import org.thingsboard.server.service.state.DeviceStateService; |
41 | -import org.thingsboard.server.service.stats.StatsCounterFactory; | ||
42 | import org.thingsboard.server.service.subscription.SubscriptionManagerService; | 42 | import org.thingsboard.server.service.subscription.SubscriptionManagerService; |
43 | import org.thingsboard.server.service.subscription.TbLocalSubscriptionService; | 43 | import org.thingsboard.server.service.subscription.TbLocalSubscriptionService; |
44 | import org.thingsboard.server.service.subscription.TbSubscriptionUtils; | 44 | import org.thingsboard.server.service.subscription.TbSubscriptionUtils; |
@@ -78,14 +78,14 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | @@ -78,14 +78,14 @@ public class DefaultTbCoreConsumerService extends AbstractConsumerService<ToCore | ||
78 | public DefaultTbCoreConsumerService(TbCoreQueueFactory tbCoreQueueFactory, ActorSystemContext actorContext, | 78 | public DefaultTbCoreConsumerService(TbCoreQueueFactory tbCoreQueueFactory, ActorSystemContext actorContext, |
79 | DeviceStateService stateService, TbLocalSubscriptionService localSubscriptionService, | 79 | DeviceStateService stateService, TbLocalSubscriptionService localSubscriptionService, |
80 | SubscriptionManagerService subscriptionManagerService, DataDecodingEncodingService encodingService, | 80 | SubscriptionManagerService subscriptionManagerService, DataDecodingEncodingService encodingService, |
81 | - TbCoreDeviceRpcService tbCoreDeviceRpcService, StatsCounterFactory counterFactory) { | 81 | + TbCoreDeviceRpcService tbCoreDeviceRpcService, StatsFactory statsFactory) { |
82 | super(actorContext, encodingService, tbCoreQueueFactory.createToCoreNotificationsMsgConsumer()); | 82 | super(actorContext, encodingService, tbCoreQueueFactory.createToCoreNotificationsMsgConsumer()); |
83 | this.mainConsumer = tbCoreQueueFactory.createToCoreMsgConsumer(); | 83 | this.mainConsumer = tbCoreQueueFactory.createToCoreMsgConsumer(); |
84 | this.stateService = stateService; | 84 | this.stateService = stateService; |
85 | this.localSubscriptionService = localSubscriptionService; | 85 | this.localSubscriptionService = localSubscriptionService; |
86 | this.subscriptionManagerService = subscriptionManagerService; | 86 | this.subscriptionManagerService = subscriptionManagerService; |
87 | this.tbCoreDeviceRpcService = tbCoreDeviceRpcService; | 87 | this.tbCoreDeviceRpcService = tbCoreDeviceRpcService; |
88 | - this.stats = new TbCoreConsumerStats(counterFactory); | 88 | + this.stats = new TbCoreConsumerStats(statsFactory); |
89 | } | 89 | } |
90 | 90 | ||
91 | @PostConstruct | 91 | @PostConstruct |
@@ -42,6 +42,7 @@ import org.thingsboard.server.queue.discovery.PartitionChangeEvent; | @@ -42,6 +42,7 @@ import org.thingsboard.server.queue.discovery.PartitionChangeEvent; | ||
42 | import org.thingsboard.server.queue.provider.TbRuleEngineQueueFactory; | 42 | import org.thingsboard.server.queue.provider.TbRuleEngineQueueFactory; |
43 | import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; | 43 | import org.thingsboard.server.queue.settings.TbQueueRuleEngineSettings; |
44 | import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; | 44 | import org.thingsboard.server.queue.settings.TbRuleEngineQueueConfiguration; |
45 | +import org.thingsboard.server.common.msg.stats.StatsFactory; | ||
45 | import org.thingsboard.server.queue.util.TbRuleEngineComponent; | 46 | import org.thingsboard.server.queue.util.TbRuleEngineComponent; |
46 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; | 47 | import org.thingsboard.server.service.encoding.DataDecodingEncodingService; |
47 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; | 48 | import org.thingsboard.server.service.queue.processing.AbstractConsumerService; |
@@ -54,7 +55,6 @@ import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrateg | @@ -54,7 +55,6 @@ import org.thingsboard.server.service.queue.processing.TbRuleEngineSubmitStrateg | ||
54 | import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; | 55 | import org.thingsboard.server.service.rpc.FromDeviceRpcResponse; |
55 | import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService; | 56 | import org.thingsboard.server.service.rpc.TbRuleEngineDeviceRpcService; |
56 | import org.thingsboard.server.service.stats.RuleEngineStatisticsService; | 57 | import org.thingsboard.server.service.stats.RuleEngineStatisticsService; |
57 | -import org.thingsboard.server.service.stats.StatsCounterFactory; | ||
58 | 58 | ||
59 | import javax.annotation.PostConstruct; | 59 | import javax.annotation.PostConstruct; |
60 | import javax.annotation.PreDestroy; | 60 | import javax.annotation.PreDestroy; |
@@ -83,7 +83,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -83,7 +83,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
83 | @Value("${queue.rule-engine.stats.enabled:true}") | 83 | @Value("${queue.rule-engine.stats.enabled:true}") |
84 | private boolean statsEnabled; | 84 | private boolean statsEnabled; |
85 | 85 | ||
86 | - private final StatsCounterFactory counterFactory; | 86 | + private final StatsFactory statsFactory; |
87 | private final TbRuleEngineSubmitStrategyFactory submitStrategyFactory; | 87 | private final TbRuleEngineSubmitStrategyFactory submitStrategyFactory; |
88 | private final TbRuleEngineProcessingStrategyFactory processingStrategyFactory; | 88 | private final TbRuleEngineProcessingStrategyFactory processingStrategyFactory; |
89 | private final TbRuleEngineQueueFactory tbRuleEngineQueueFactory; | 89 | private final TbRuleEngineQueueFactory tbRuleEngineQueueFactory; |
@@ -101,7 +101,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -101,7 +101,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
101 | TbRuleEngineQueueFactory tbRuleEngineQueueFactory, RuleEngineStatisticsService statisticsService, | 101 | TbRuleEngineQueueFactory tbRuleEngineQueueFactory, RuleEngineStatisticsService statisticsService, |
102 | ActorSystemContext actorContext, DataDecodingEncodingService encodingService, | 102 | ActorSystemContext actorContext, DataDecodingEncodingService encodingService, |
103 | TbRuleEngineDeviceRpcService tbDeviceRpcService, | 103 | TbRuleEngineDeviceRpcService tbDeviceRpcService, |
104 | - StatsCounterFactory counterFactory) { | 104 | + StatsFactory statsFactory) { |
105 | super(actorContext, encodingService, tbRuleEngineQueueFactory.createToRuleEngineNotificationsMsgConsumer()); | 105 | super(actorContext, encodingService, tbRuleEngineQueueFactory.createToRuleEngineNotificationsMsgConsumer()); |
106 | this.statisticsService = statisticsService; | 106 | this.statisticsService = statisticsService; |
107 | this.ruleEngineSettings = ruleEngineSettings; | 107 | this.ruleEngineSettings = ruleEngineSettings; |
@@ -109,7 +109,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -109,7 +109,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
109 | this.submitStrategyFactory = submitStrategyFactory; | 109 | this.submitStrategyFactory = submitStrategyFactory; |
110 | this.processingStrategyFactory = processingStrategyFactory; | 110 | this.processingStrategyFactory = processingStrategyFactory; |
111 | this.tbDeviceRpcService = tbDeviceRpcService; | 111 | this.tbDeviceRpcService = tbDeviceRpcService; |
112 | - this.counterFactory = counterFactory; | 112 | + this.statsFactory = statsFactory; |
113 | } | 113 | } |
114 | 114 | ||
115 | @PostConstruct | 115 | @PostConstruct |
@@ -118,7 +118,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | @@ -118,7 +118,7 @@ public class DefaultTbRuleEngineConsumerService extends AbstractConsumerService< | ||
118 | for (TbRuleEngineQueueConfiguration configuration : ruleEngineSettings.getQueues()) { | 118 | for (TbRuleEngineQueueConfiguration configuration : ruleEngineSettings.getQueues()) { |
119 | consumerConfigurations.putIfAbsent(configuration.getName(), configuration); | 119 | consumerConfigurations.putIfAbsent(configuration.getName(), configuration); |
120 | consumers.computeIfAbsent(configuration.getName(), queueName -> tbRuleEngineQueueFactory.createToRuleEngineMsgConsumer(configuration)); | 120 | consumers.computeIfAbsent(configuration.getName(), queueName -> tbRuleEngineQueueFactory.createToRuleEngineMsgConsumer(configuration)); |
121 | - consumerStats.put(configuration.getName(), new TbRuleEngineConsumerStats(configuration.getName(), counterFactory)); | 121 | + consumerStats.put(configuration.getName(), new TbRuleEngineConsumerStats(configuration.getName(), statsFactory)); |
122 | } | 122 | } |
123 | submitExecutor = Executors.newSingleThreadExecutor(); | 123 | submitExecutor = Executors.newSingleThreadExecutor(); |
124 | } | 124 | } |
@@ -17,12 +17,11 @@ package org.thingsboard.server.service.queue; | @@ -17,12 +17,11 @@ package org.thingsboard.server.service.queue; | ||
17 | 17 | ||
18 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
19 | import org.thingsboard.server.gen.transport.TransportProtos; | 19 | import org.thingsboard.server.gen.transport.TransportProtos; |
20 | -import org.thingsboard.server.service.stats.StatsCounter; | ||
21 | -import org.thingsboard.server.service.stats.StatsCounterFactory; | ||
22 | -import org.thingsboard.server.service.stats.StatsType; | 20 | +import org.thingsboard.server.common.msg.stats.StatsCounter; |
21 | +import org.thingsboard.server.common.msg.stats.StatsFactory; | ||
22 | +import org.thingsboard.server.common.msg.stats.StatsType; | ||
23 | 23 | ||
24 | import java.util.*; | 24 | import java.util.*; |
25 | -import java.util.concurrent.atomic.AtomicInteger; | ||
26 | 25 | ||
27 | @Slf4j | 26 | @Slf4j |
28 | public class TbCoreConsumerStats { | 27 | public class TbCoreConsumerStats { |
@@ -53,20 +52,20 @@ public class TbCoreConsumerStats { | @@ -53,20 +52,20 @@ public class TbCoreConsumerStats { | ||
53 | 52 | ||
54 | private final List<StatsCounter> counters = new ArrayList<>(); | 53 | private final List<StatsCounter> counters = new ArrayList<>(); |
55 | 54 | ||
56 | - public TbCoreConsumerStats(StatsCounterFactory counterFactory) { | 55 | + public TbCoreConsumerStats(StatsFactory statsFactory) { |
57 | String statsKey = StatsType.CORE.getName(); | 56 | String statsKey = StatsType.CORE.getName(); |
58 | 57 | ||
59 | - this.totalCounter = counterFactory.createStatsCounter(statsKey, TOTAL_MSGS); | ||
60 | - this.sessionEventCounter = counterFactory.createStatsCounter(statsKey, SESSION_EVENTS); | ||
61 | - this.getAttributesCounter = counterFactory.createStatsCounter(statsKey, GET_ATTRIBUTE); | ||
62 | - this.subscribeToAttributesCounter = counterFactory.createStatsCounter(statsKey, ATTRIBUTE_SUBSCRIBES); | ||
63 | - this.subscribeToRPCCounter = counterFactory.createStatsCounter(statsKey, RPC_SUBSCRIBES); | ||
64 | - this.toDeviceRPCCallResponseCounter = counterFactory.createStatsCounter(statsKey, TO_DEVICE_RPC_CALL_RESPONSES); | ||
65 | - this.subscriptionInfoCounter = counterFactory.createStatsCounter(statsKey, SUBSCRIPTION_INFO); | ||
66 | - this.claimDeviceCounter = counterFactory.createStatsCounter(statsKey, DEVICE_CLAIMS); | ||
67 | - this.deviceStateCounter = counterFactory.createStatsCounter(statsKey, DEVICE_STATES); | ||
68 | - this.subscriptionMsgCounter = counterFactory.createStatsCounter(statsKey, SUBSCRIPTION_MSGS); | ||
69 | - this.toCoreNotificationsCounter = counterFactory.createStatsCounter(statsKey, TO_CORE_NOTIFICATIONS); | 58 | + this.totalCounter = statsFactory.createStatsCounter(statsKey, TOTAL_MSGS); |
59 | + this.sessionEventCounter = statsFactory.createStatsCounter(statsKey, SESSION_EVENTS); | ||
60 | + this.getAttributesCounter = statsFactory.createStatsCounter(statsKey, GET_ATTRIBUTE); | ||
61 | + this.subscribeToAttributesCounter = statsFactory.createStatsCounter(statsKey, ATTRIBUTE_SUBSCRIBES); | ||
62 | + this.subscribeToRPCCounter = statsFactory.createStatsCounter(statsKey, RPC_SUBSCRIBES); | ||
63 | + this.toDeviceRPCCallResponseCounter = statsFactory.createStatsCounter(statsKey, TO_DEVICE_RPC_CALL_RESPONSES); | ||
64 | + this.subscriptionInfoCounter = statsFactory.createStatsCounter(statsKey, SUBSCRIPTION_INFO); | ||
65 | + this.claimDeviceCounter = statsFactory.createStatsCounter(statsKey, DEVICE_CLAIMS); | ||
66 | + this.deviceStateCounter = statsFactory.createStatsCounter(statsKey, DEVICE_STATES); | ||
67 | + this.subscriptionMsgCounter = statsFactory.createStatsCounter(statsKey, SUBSCRIPTION_MSGS); | ||
68 | + this.toCoreNotificationsCounter = statsFactory.createStatsCounter(statsKey, TO_CORE_NOTIFICATIONS); | ||
70 | 69 | ||
71 | 70 | ||
72 | counters.add(totalCounter); | 71 | counters.add(totalCounter); |
@@ -15,21 +15,19 @@ | @@ -15,21 +15,19 @@ | ||
15 | */ | 15 | */ |
16 | package org.thingsboard.server.service.queue; | 16 | package org.thingsboard.server.service.queue; |
17 | 17 | ||
18 | -import lombok.Data; | ||
19 | import lombok.extern.slf4j.Slf4j; | 18 | import lombok.extern.slf4j.Slf4j; |
20 | import org.thingsboard.server.common.data.id.TenantId; | 19 | import org.thingsboard.server.common.data.id.TenantId; |
21 | import org.thingsboard.server.common.msg.queue.RuleEngineException; | 20 | import org.thingsboard.server.common.msg.queue.RuleEngineException; |
22 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; | 21 | import org.thingsboard.server.gen.transport.TransportProtos.ToRuleEngineMsg; |
23 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; | 22 | import org.thingsboard.server.queue.common.TbProtoQueueMsg; |
23 | +import org.thingsboard.server.common.msg.stats.StatsFactory; | ||
24 | import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingResult; | 24 | import org.thingsboard.server.service.queue.processing.TbRuleEngineProcessingResult; |
25 | -import org.thingsboard.server.service.stats.StatsCounter; | ||
26 | -import org.thingsboard.server.service.stats.StatsCounterFactory; | ||
27 | -import org.thingsboard.server.service.stats.StatsType; | 25 | +import org.thingsboard.server.common.msg.stats.StatsCounter; |
26 | +import org.thingsboard.server.common.msg.stats.StatsType; | ||
28 | 27 | ||
29 | import java.util.*; | 28 | import java.util.*; |
30 | import java.util.concurrent.ConcurrentHashMap; | 29 | import java.util.concurrent.ConcurrentHashMap; |
31 | import java.util.concurrent.ConcurrentMap; | 30 | import java.util.concurrent.ConcurrentMap; |
32 | -import java.util.concurrent.atomic.AtomicInteger; | ||
33 | 31 | ||
34 | @Slf4j | 32 | @Slf4j |
35 | public class TbRuleEngineConsumerStats { | 33 | public class TbRuleEngineConsumerStats { |
@@ -60,18 +58,18 @@ public class TbRuleEngineConsumerStats { | @@ -60,18 +58,18 @@ public class TbRuleEngineConsumerStats { | ||
60 | 58 | ||
61 | private final String queueName; | 59 | private final String queueName; |
62 | 60 | ||
63 | - public TbRuleEngineConsumerStats(String queueName, StatsCounterFactory counterFactory) { | 61 | + public TbRuleEngineConsumerStats(String queueName, StatsFactory statsFactory) { |
64 | this.queueName = queueName; | 62 | this.queueName = queueName; |
65 | 63 | ||
66 | String statsKey = StatsType.RULE_ENGINE.getName() + "." + queueName; | 64 | String statsKey = StatsType.RULE_ENGINE.getName() + "." + queueName; |
67 | - this.totalMsgCounter = counterFactory.createStatsCounter(statsKey, TOTAL_MSGS); | ||
68 | - this.successMsgCounter = counterFactory.createStatsCounter(statsKey, SUCCESSFUL_MSGS); | ||
69 | - this.timeoutMsgCounter = counterFactory.createStatsCounter(statsKey, TIMEOUT_MSGS); | ||
70 | - this.failedMsgCounter = counterFactory.createStatsCounter(statsKey, FAILED_MSGS); | ||
71 | - this.tmpTimeoutMsgCounter = counterFactory.createStatsCounter(statsKey, TMP_TIMEOUT); | ||
72 | - this.tmpFailedMsgCounter = counterFactory.createStatsCounter(statsKey, TMP_FAILED); | ||
73 | - this.successIterationsCounter = counterFactory.createStatsCounter(statsKey, SUCCESSFUL_ITERATIONS); | ||
74 | - this.failedIterationsCounter = counterFactory.createStatsCounter(statsKey, FAILED_ITERATIONS); | 65 | + this.totalMsgCounter = statsFactory.createStatsCounter(statsKey, TOTAL_MSGS); |
66 | + this.successMsgCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_MSGS); | ||
67 | + this.timeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TIMEOUT_MSGS); | ||
68 | + this.failedMsgCounter = statsFactory.createStatsCounter(statsKey, FAILED_MSGS); | ||
69 | + this.tmpTimeoutMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_TIMEOUT); | ||
70 | + this.tmpFailedMsgCounter = statsFactory.createStatsCounter(statsKey, TMP_FAILED); | ||
71 | + this.successIterationsCounter = statsFactory.createStatsCounter(statsKey, SUCCESSFUL_ITERATIONS); | ||
72 | + this.failedIterationsCounter = statsFactory.createStatsCounter(statsKey, FAILED_ITERATIONS); | ||
75 | 73 | ||
76 | counters.add(totalMsgCounter); | 74 | counters.add(totalMsgCounter); |
77 | counters.add(successMsgCounter); | 75 | counters.add(successMsgCounter); |
@@ -18,6 +18,9 @@ package org.thingsboard.server.service.stats; | @@ -18,6 +18,9 @@ package org.thingsboard.server.service.stats; | ||
18 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | import org.springframework.stereotype.Service; | 19 | import org.springframework.stereotype.Service; |
20 | import org.thingsboard.server.actors.JsInvokeStats; | 20 | import org.thingsboard.server.actors.JsInvokeStats; |
21 | +import org.thingsboard.server.common.msg.stats.StatsCounter; | ||
22 | +import org.thingsboard.server.common.msg.stats.StatsFactory; | ||
23 | +import org.thingsboard.server.common.msg.stats.StatsType; | ||
21 | 24 | ||
22 | import javax.annotation.PostConstruct; | 25 | import javax.annotation.PostConstruct; |
23 | 26 | ||
@@ -32,14 +35,14 @@ public class DefaultJsInvokeStats implements JsInvokeStats { | @@ -32,14 +35,14 @@ public class DefaultJsInvokeStats implements JsInvokeStats { | ||
32 | private StatsCounter failuresCounter; | 35 | private StatsCounter failuresCounter; |
33 | 36 | ||
34 | @Autowired | 37 | @Autowired |
35 | - private StatsCounterFactory counterFactory; | 38 | + private StatsFactory statsFactory; |
36 | 39 | ||
37 | @PostConstruct | 40 | @PostConstruct |
38 | public void init() { | 41 | public void init() { |
39 | String key = StatsType.JS_INVOKE.getName(); | 42 | String key = StatsType.JS_INVOKE.getName(); |
40 | - this.requestsCounter = counterFactory.createStatsCounter(key, REQUESTS); | ||
41 | - this.responsesCounter = counterFactory.createStatsCounter(key, RESPONSES); | ||
42 | - this.failuresCounter = counterFactory.createStatsCounter(key, FAILURES); | 43 | + this.requestsCounter = statsFactory.createStatsCounter(key, REQUESTS); |
44 | + this.responsesCounter = statsFactory.createStatsCounter(key, RESPONSES); | ||
45 | + this.failuresCounter = statsFactory.createStatsCounter(key, FAILURES); | ||
43 | } | 46 | } |
44 | 47 | ||
45 | @Override | 48 | @Override |
@@ -20,6 +20,9 @@ import org.springframework.beans.factory.annotation.Value; | @@ -20,6 +20,9 @@ import org.springframework.beans.factory.annotation.Value; | ||
20 | import org.springframework.boot.context.event.ApplicationReadyEvent; | 20 | import org.springframework.boot.context.event.ApplicationReadyEvent; |
21 | import org.springframework.context.event.EventListener; | 21 | import org.springframework.context.event.EventListener; |
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | +import org.thingsboard.server.common.msg.stats.MessagesStats; | ||
24 | +import org.thingsboard.server.common.msg.stats.StatsFactory; | ||
25 | +import org.thingsboard.server.common.msg.stats.StatsType; | ||
23 | import org.thingsboard.server.queue.TbQueueConsumer; | 26 | import org.thingsboard.server.queue.TbQueueConsumer; |
24 | import org.thingsboard.server.queue.TbQueueProducer; | 27 | import org.thingsboard.server.queue.TbQueueProducer; |
25 | import org.thingsboard.server.queue.TbQueueResponseTemplate; | 28 | import org.thingsboard.server.queue.TbQueueResponseTemplate; |
@@ -29,10 +32,6 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | @@ -29,10 +32,6 @@ import org.thingsboard.server.gen.transport.TransportProtos.TransportApiRequestM | ||
29 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; | 32 | import org.thingsboard.server.gen.transport.TransportProtos.TransportApiResponseMsg; |
30 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; | 33 | import org.thingsboard.server.queue.provider.TbCoreQueueFactory; |
31 | import org.thingsboard.server.queue.util.TbCoreComponent; | 34 | import org.thingsboard.server.queue.util.TbCoreComponent; |
32 | -import org.thingsboard.server.service.stats.DefaultQueueStats; | ||
33 | -import org.thingsboard.server.service.stats.StatsCounter; | ||
34 | -import org.thingsboard.server.service.stats.StatsCounterFactory; | ||
35 | -import org.thingsboard.server.service.stats.StatsType; | ||
36 | 35 | ||
37 | import javax.annotation.PostConstruct; | 36 | import javax.annotation.PostConstruct; |
38 | import javax.annotation.PreDestroy; | 37 | import javax.annotation.PreDestroy; |
@@ -45,13 +44,9 @@ import java.util.concurrent.*; | @@ -45,13 +44,9 @@ import java.util.concurrent.*; | ||
45 | @Service | 44 | @Service |
46 | @TbCoreComponent | 45 | @TbCoreComponent |
47 | public class TbCoreTransportApiService { | 46 | public class TbCoreTransportApiService { |
48 | - private static final String TOTAL_MSGS = "totalMsgs"; | ||
49 | - private static final String SUCCESSFUL_MSGS = "successfulMsgs"; | ||
50 | - private static final String FAILED_MSGS = "failedMsgs"; | ||
51 | - | ||
52 | private final TbCoreQueueFactory tbCoreQueueFactory; | 47 | private final TbCoreQueueFactory tbCoreQueueFactory; |
53 | private final TransportApiService transportApiService; | 48 | private final TransportApiService transportApiService; |
54 | - private final StatsCounterFactory counterFactory; | 49 | + private final StatsFactory statsFactory; |
55 | 50 | ||
56 | @Value("${queue.transport_api.max_pending_requests:10000}") | 51 | @Value("${queue.transport_api.max_pending_requests:10000}") |
57 | private int maxPendingRequests; | 52 | private int maxPendingRequests; |
@@ -66,10 +61,10 @@ public class TbCoreTransportApiService { | @@ -66,10 +61,10 @@ public class TbCoreTransportApiService { | ||
66 | private TbQueueResponseTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, | 61 | private TbQueueResponseTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, |
67 | TbProtoQueueMsg<TransportApiResponseMsg>> transportApiTemplate; | 62 | TbProtoQueueMsg<TransportApiResponseMsg>> transportApiTemplate; |
68 | 63 | ||
69 | - public TbCoreTransportApiService(TbCoreQueueFactory tbCoreQueueFactory, TransportApiService transportApiService, StatsCounterFactory counterFactory) { | 64 | + public TbCoreTransportApiService(TbCoreQueueFactory tbCoreQueueFactory, TransportApiService transportApiService, StatsFactory statsFactory) { |
70 | this.tbCoreQueueFactory = tbCoreQueueFactory; | 65 | this.tbCoreQueueFactory = tbCoreQueueFactory; |
71 | this.transportApiService = transportApiService; | 66 | this.transportApiService = transportApiService; |
72 | - this.counterFactory = counterFactory; | 67 | + this.statsFactory = statsFactory; |
73 | } | 68 | } |
74 | 69 | ||
75 | @PostConstruct | 70 | @PostConstruct |
@@ -79,10 +74,7 @@ public class TbCoreTransportApiService { | @@ -79,10 +74,7 @@ public class TbCoreTransportApiService { | ||
79 | TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> consumer = tbCoreQueueFactory.createTransportApiRequestConsumer(); | 74 | TbQueueConsumer<TbProtoQueueMsg<TransportApiRequestMsg>> consumer = tbCoreQueueFactory.createTransportApiRequestConsumer(); |
80 | 75 | ||
81 | String key = StatsType.TRANSPORT.getName(); | 76 | String key = StatsType.TRANSPORT.getName(); |
82 | - StatsCounter totalCounter = counterFactory.createStatsCounter(key, TOTAL_MSGS); | ||
83 | - StatsCounter successfulCounter = counterFactory.createStatsCounter(key, SUCCESSFUL_MSGS); | ||
84 | - StatsCounter failedCounter = counterFactory.createStatsCounter(key, FAILED_MSGS); | ||
85 | - DefaultQueueStats queueStats = new DefaultQueueStats(totalCounter, successfulCounter, failedCounter); | 77 | + MessagesStats queueStats = statsFactory.createMessagesStats(key); |
86 | 78 | ||
87 | DefaultTbQueueResponseTemplate.DefaultTbQueueResponseTemplateBuilder | 79 | DefaultTbQueueResponseTemplate.DefaultTbQueueResponseTemplateBuilder |
88 | <TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> builder = DefaultTbQueueResponseTemplate.builder(); | 80 | <TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> builder = DefaultTbQueueResponseTemplate.builder(); |
@@ -69,6 +69,21 @@ | @@ -69,6 +69,21 @@ | ||
69 | <artifactId>protobuf-java</artifactId> | 69 | <artifactId>protobuf-java</artifactId> |
70 | <scope>provided</scope> | 70 | <scope>provided</scope> |
71 | </dependency> | 71 | </dependency> |
72 | + | ||
73 | + <!--TODO is this a good idea to put actuator here?--> | ||
74 | + <dependency> | ||
75 | + <groupId>org.springframework.boot</groupId> | ||
76 | + <artifactId>spring-boot-starter-actuator</artifactId> | ||
77 | + </dependency> | ||
78 | + <dependency> | ||
79 | + <groupId>io.micrometer</groupId> | ||
80 | + <artifactId>micrometer-core</artifactId> | ||
81 | + </dependency> | ||
82 | + <dependency> | ||
83 | + <groupId>io.micrometer</groupId> | ||
84 | + <artifactId>micrometer-registry-prometheus</artifactId> | ||
85 | + </dependency> | ||
86 | + | ||
72 | <dependency> | 87 | <dependency> |
73 | <groupId>junit</groupId> | 88 | <groupId>junit</groupId> |
74 | <artifactId>junit</artifactId> | 89 | <artifactId>junit</artifactId> |
common/message/src/main/java/org/thingsboard/server/common/msg/stats/DefaultMessagesStats.java
renamed from
application/src/main/java/org/thingsboard/server/service/stats/DefaultQueueStats.java
@@ -13,16 +13,14 @@ | @@ -13,16 +13,14 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.stats; | 16 | +package org.thingsboard.server.common.msg.stats; |
17 | 17 | ||
18 | -import org.thingsboard.server.queue.stats.QueueStats; | ||
19 | - | ||
20 | -public class DefaultQueueStats implements QueueStats { | 18 | +public class DefaultMessagesStats implements MessagesStats { |
21 | private final StatsCounter totalCounter; | 19 | private final StatsCounter totalCounter; |
22 | private final StatsCounter successfulCounter; | 20 | private final StatsCounter successfulCounter; |
23 | private final StatsCounter failedCounter; | 21 | private final StatsCounter failedCounter; |
24 | 22 | ||
25 | - public DefaultQueueStats(StatsCounter totalCounter, StatsCounter successfulCounter, StatsCounter failedCounter) { | 23 | + public DefaultMessagesStats(StatsCounter totalCounter, StatsCounter successfulCounter, StatsCounter failedCounter) { |
26 | this.totalCounter = totalCounter; | 24 | this.totalCounter = totalCounter; |
27 | this.successfulCounter = successfulCounter; | 25 | this.successfulCounter = successfulCounter; |
28 | this.failedCounter = failedCounter; | 26 | this.failedCounter = failedCounter; |
common/message/src/main/java/org/thingsboard/server/common/msg/stats/DefaultStatsFactory.java
renamed from
application/src/main/java/org/thingsboard/server/service/stats/StatsCounterFactory.java
@@ -13,19 +13,22 @@ | @@ -13,19 +13,22 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.stats; | 16 | +package org.thingsboard.server.common.msg.stats; |
17 | 17 | ||
18 | import io.micrometer.core.instrument.Counter; | 18 | import io.micrometer.core.instrument.Counter; |
19 | import io.micrometer.core.instrument.MeterRegistry; | 19 | import io.micrometer.core.instrument.MeterRegistry; |
20 | import org.springframework.beans.factory.annotation.Autowired; | 20 | import org.springframework.beans.factory.annotation.Autowired; |
21 | import org.springframework.beans.factory.annotation.Value; | 21 | import org.springframework.beans.factory.annotation.Value; |
22 | import org.springframework.stereotype.Service; | 22 | import org.springframework.stereotype.Service; |
23 | -import org.thingsboard.server.service.metrics.StubCounter; | ||
24 | 23 | ||
25 | import java.util.concurrent.atomic.AtomicInteger; | 24 | import java.util.concurrent.atomic.AtomicInteger; |
26 | 25 | ||
27 | @Service | 26 | @Service |
28 | -public class StatsCounterFactory { | 27 | +public class DefaultStatsFactory implements StatsFactory { |
28 | + private static final String TOTAL_MSGS = "totalMsgs"; | ||
29 | + private static final String SUCCESSFUL_MSGS = "successfulMsgs"; | ||
30 | + private static final String FAILED_MSGS = "failedMsgs"; | ||
31 | + | ||
29 | private static final String STATS_NAME_TAG = "statsName"; | 32 | private static final String STATS_NAME_TAG = "statsName"; |
30 | 33 | ||
31 | private static final Counter STUB_COUNTER = new StubCounter(); | 34 | private static final Counter STUB_COUNTER = new StubCounter(); |
@@ -33,9 +36,10 @@ public class StatsCounterFactory { | @@ -33,9 +36,10 @@ public class StatsCounterFactory { | ||
33 | @Autowired | 36 | @Autowired |
34 | private MeterRegistry meterRegistry; | 37 | private MeterRegistry meterRegistry; |
35 | 38 | ||
36 | - @Value("${metrics.enabled}") | 39 | + @Value("${metrics.enabled:false}") |
37 | private Boolean metricsEnabled; | 40 | private Boolean metricsEnabled; |
38 | 41 | ||
42 | + @Override | ||
39 | public StatsCounter createStatsCounter(String key, String statsName) { | 43 | public StatsCounter createStatsCounter(String key, String statsName) { |
40 | return new StatsCounter( | 44 | return new StatsCounter( |
41 | new AtomicInteger(0), | 45 | new AtomicInteger(0), |
@@ -45,4 +49,27 @@ public class StatsCounterFactory { | @@ -45,4 +49,27 @@ public class StatsCounterFactory { | ||
45 | statsName | 49 | statsName |
46 | ); | 50 | ); |
47 | } | 51 | } |
52 | + | ||
53 | + @Override | ||
54 | + public MessagesStats createMessagesStats(String key) { | ||
55 | + StatsCounter totalCounter = createStatsCounter(key, TOTAL_MSGS); | ||
56 | + StatsCounter successfulCounter = createStatsCounter(key, SUCCESSFUL_MSGS); | ||
57 | + StatsCounter failedCounter = createStatsCounter(key, FAILED_MSGS); | ||
58 | + return new DefaultMessagesStats(totalCounter, successfulCounter, failedCounter); | ||
59 | + } | ||
60 | + | ||
61 | + private static class StubCounter implements Counter { | ||
62 | + @Override | ||
63 | + public void increment(double amount) {} | ||
64 | + | ||
65 | + @Override | ||
66 | + public double count() { | ||
67 | + return 0; | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public Id getId() { | ||
72 | + return null; | ||
73 | + } | ||
74 | + } | ||
48 | } | 75 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/stats/MessagesStats.java
renamed from
common/queue/src/main/java/org/thingsboard/server/queue/stats/QueueStats.java
@@ -13,9 +13,9 @@ | @@ -13,9 +13,9 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.queue.stats; | 16 | +package org.thingsboard.server.common.msg.stats; |
17 | 17 | ||
18 | -public interface QueueStats { | 18 | +public interface MessagesStats { |
19 | default void incrementTotal() { | 19 | default void incrementTotal() { |
20 | incrementTotal(1); | 20 | incrementTotal(1); |
21 | } | 21 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/stats/StatsCounter.java
renamed from
application/src/main/java/org/thingsboard/server/service/stats/StatsCounter.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.stats; | 16 | +package org.thingsboard.server.common.msg.stats; |
17 | 17 | ||
18 | import io.micrometer.core.instrument.Counter; | 18 | import io.micrometer.core.instrument.Counter; |
19 | 19 |
common/message/src/main/java/org/thingsboard/server/common/msg/stats/StatsFactory.java
renamed from
application/src/main/java/org/thingsboard/server/service/metrics/StubCounter.java
@@ -13,21 +13,10 @@ | @@ -13,21 +13,10 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.metrics; | 16 | +package org.thingsboard.server.common.msg.stats; |
17 | 17 | ||
18 | -import io.micrometer.core.instrument.Counter; | 18 | +public interface StatsFactory { |
19 | + StatsCounter createStatsCounter(String key, String statsName); | ||
19 | 20 | ||
20 | -public class StubCounter implements Counter { | ||
21 | - @Override | ||
22 | - public void increment(double amount) {} | ||
23 | - | ||
24 | - @Override | ||
25 | - public double count() { | ||
26 | - return 0; | ||
27 | - } | ||
28 | - | ||
29 | - @Override | ||
30 | - public Id getId() { | ||
31 | - return null; | ||
32 | - } | 21 | + MessagesStats createMessagesStats(String key); |
33 | } | 22 | } |
common/message/src/main/java/org/thingsboard/server/common/msg/stats/StatsType.java
renamed from
application/src/main/java/org/thingsboard/server/service/stats/StatsType.java
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. | 14 | * limitations under the License. |
15 | */ | 15 | */ |
16 | -package org.thingsboard.server.service.stats; | 16 | +package org.thingsboard.server.common.msg.stats; |
17 | 17 | ||
18 | public enum StatsType { | 18 | public enum StatsType { |
19 | RULE_ENGINE("ruleEngine"), CORE("core"), TRANSPORT("transport"), JS_INVOKE("jsInvoke"); | 19 | RULE_ENGINE("ruleEngine"), CORE("core"), TRANSPORT("transport"), JS_INVOKE("jsInvoke"); |
@@ -112,6 +112,7 @@ | @@ -112,6 +112,7 @@ | ||
112 | <groupId>org.apache.curator</groupId> | 112 | <groupId>org.apache.curator</groupId> |
113 | <artifactId>curator-recipes</artifactId> | 113 | <artifactId>curator-recipes</artifactId> |
114 | </dependency> | 114 | </dependency> |
115 | + | ||
115 | <dependency> | 116 | <dependency> |
116 | <groupId>junit</groupId> | 117 | <groupId>junit</groupId> |
117 | <artifactId>junit</artifactId> | 118 | <artifactId>junit</artifactId> |
@@ -16,6 +16,7 @@ | @@ -16,6 +16,7 @@ | ||
16 | package org.thingsboard.server.queue; | 16 | package org.thingsboard.server.queue; |
17 | 17 | ||
18 | import com.google.common.util.concurrent.ListenableFuture; | 18 | import com.google.common.util.concurrent.ListenableFuture; |
19 | +import org.thingsboard.server.common.msg.stats.MessagesStats; | ||
19 | 20 | ||
20 | public interface TbQueueRequestTemplate<Request extends TbQueueMsg, Response extends TbQueueMsg> { | 21 | public interface TbQueueRequestTemplate<Request extends TbQueueMsg, Response extends TbQueueMsg> { |
21 | 22 | ||
@@ -25,4 +26,5 @@ public interface TbQueueRequestTemplate<Request extends TbQueueMsg, Response ext | @@ -25,4 +26,5 @@ public interface TbQueueRequestTemplate<Request extends TbQueueMsg, Response ext | ||
25 | 26 | ||
26 | void stop(); | 27 | void stop(); |
27 | 28 | ||
29 | + void setMessagesStats(MessagesStats messagesStats); | ||
28 | } | 30 | } |
@@ -28,6 +28,7 @@ import org.thingsboard.server.queue.TbQueueMsg; | @@ -28,6 +28,7 @@ import org.thingsboard.server.queue.TbQueueMsg; | ||
28 | import org.thingsboard.server.queue.TbQueueMsgMetadata; | 28 | import org.thingsboard.server.queue.TbQueueMsgMetadata; |
29 | import org.thingsboard.server.queue.TbQueueProducer; | 29 | import org.thingsboard.server.queue.TbQueueProducer; |
30 | import org.thingsboard.server.queue.TbQueueRequestTemplate; | 30 | import org.thingsboard.server.queue.TbQueueRequestTemplate; |
31 | +import org.thingsboard.server.common.msg.stats.MessagesStats; | ||
31 | 32 | ||
32 | import java.util.List; | 33 | import java.util.List; |
33 | import java.util.UUID; | 34 | import java.util.UUID; |
@@ -54,6 +55,8 @@ public class DefaultTbQueueRequestTemplate<Request extends TbQueueMsg, Response | @@ -54,6 +55,8 @@ public class DefaultTbQueueRequestTemplate<Request extends TbQueueMsg, Response | ||
54 | private volatile long tickSize = 0L; | 55 | private volatile long tickSize = 0L; |
55 | private volatile boolean stopped = false; | 56 | private volatile boolean stopped = false; |
56 | 57 | ||
58 | + private MessagesStats messagesStats; | ||
59 | + | ||
57 | @Builder | 60 | @Builder |
58 | public DefaultTbQueueRequestTemplate(TbQueueAdmin queueAdmin, | 61 | public DefaultTbQueueRequestTemplate(TbQueueAdmin queueAdmin, |
59 | TbQueueProducer<Request> requestTemplate, | 62 | TbQueueProducer<Request> requestTemplate, |
@@ -154,6 +157,11 @@ public class DefaultTbQueueRequestTemplate<Request extends TbQueueMsg, Response | @@ -154,6 +157,11 @@ public class DefaultTbQueueRequestTemplate<Request extends TbQueueMsg, Response | ||
154 | } | 157 | } |
155 | 158 | ||
156 | @Override | 159 | @Override |
160 | + public void setMessagesStats(MessagesStats messagesStats) { | ||
161 | + this.messagesStats = messagesStats; | ||
162 | + } | ||
163 | + | ||
164 | + @Override | ||
157 | public ListenableFuture<Response> send(Request request) { | 165 | public ListenableFuture<Response> send(Request request) { |
158 | if (tickSize > maxPendingRequests) { | 166 | if (tickSize > maxPendingRequests) { |
159 | return Futures.immediateFailedFuture(new RuntimeException("Pending request map is full!")); | 167 | return Futures.immediateFailedFuture(new RuntimeException("Pending request map is full!")); |
@@ -166,14 +174,17 @@ public class DefaultTbQueueRequestTemplate<Request extends TbQueueMsg, Response | @@ -166,14 +174,17 @@ public class DefaultTbQueueRequestTemplate<Request extends TbQueueMsg, Response | ||
166 | ResponseMetaData<Response> responseMetaData = new ResponseMetaData<>(tickTs + maxRequestTimeout, future); | 174 | ResponseMetaData<Response> responseMetaData = new ResponseMetaData<>(tickTs + maxRequestTimeout, future); |
167 | pendingRequests.putIfAbsent(requestId, responseMetaData); | 175 | pendingRequests.putIfAbsent(requestId, responseMetaData); |
168 | log.trace("[{}] Sending request, key [{}], expTime [{}]", requestId, request.getKey(), responseMetaData.expTime); | 176 | log.trace("[{}] Sending request, key [{}], expTime [{}]", requestId, request.getKey(), responseMetaData.expTime); |
177 | + if (messagesStats != null) messagesStats.incrementTotal(); | ||
169 | requestTemplate.send(TopicPartitionInfo.builder().topic(requestTemplate.getDefaultTopic()).build(), request, new TbQueueCallback() { | 178 | requestTemplate.send(TopicPartitionInfo.builder().topic(requestTemplate.getDefaultTopic()).build(), request, new TbQueueCallback() { |
170 | @Override | 179 | @Override |
171 | public void onSuccess(TbQueueMsgMetadata metadata) { | 180 | public void onSuccess(TbQueueMsgMetadata metadata) { |
181 | + if (messagesStats != null) messagesStats.incrementSuccessful(); | ||
172 | log.trace("[{}] Request sent: {}", requestId, metadata); | 182 | log.trace("[{}] Request sent: {}", requestId, metadata); |
173 | } | 183 | } |
174 | 184 | ||
175 | @Override | 185 | @Override |
176 | public void onFailure(Throwable t) { | 186 | public void onFailure(Throwable t) { |
187 | + if (messagesStats != null) messagesStats.incrementFailed(); | ||
177 | pendingRequests.remove(requestId); | 188 | pendingRequests.remove(requestId); |
178 | future.setException(t); | 189 | future.setException(t); |
179 | } | 190 | } |
@@ -23,7 +23,7 @@ import org.thingsboard.server.queue.TbQueueHandler; | @@ -23,7 +23,7 @@ import org.thingsboard.server.queue.TbQueueHandler; | ||
23 | import org.thingsboard.server.queue.TbQueueMsg; | 23 | import org.thingsboard.server.queue.TbQueueMsg; |
24 | import org.thingsboard.server.queue.TbQueueProducer; | 24 | import org.thingsboard.server.queue.TbQueueProducer; |
25 | import org.thingsboard.server.queue.TbQueueResponseTemplate; | 25 | import org.thingsboard.server.queue.TbQueueResponseTemplate; |
26 | -import org.thingsboard.server.queue.stats.QueueStats; | 26 | +import org.thingsboard.server.common.msg.stats.MessagesStats; |
27 | 27 | ||
28 | import java.util.List; | 28 | import java.util.List; |
29 | import java.util.UUID; | 29 | import java.util.UUID; |
@@ -45,7 +45,7 @@ public class DefaultTbQueueResponseTemplate<Request extends TbQueueMsg, Response | @@ -45,7 +45,7 @@ public class DefaultTbQueueResponseTemplate<Request extends TbQueueMsg, Response | ||
45 | private final ExecutorService loopExecutor; | 45 | private final ExecutorService loopExecutor; |
46 | private final ScheduledExecutorService timeoutExecutor; | 46 | private final ScheduledExecutorService timeoutExecutor; |
47 | private final ExecutorService callbackExecutor; | 47 | private final ExecutorService callbackExecutor; |
48 | - private final QueueStats stats; | 48 | + private final MessagesStats stats; |
49 | private final int maxPendingRequests; | 49 | private final int maxPendingRequests; |
50 | private final long requestTimeout; | 50 | private final long requestTimeout; |
51 | 51 | ||
@@ -61,7 +61,7 @@ public class DefaultTbQueueResponseTemplate<Request extends TbQueueMsg, Response | @@ -61,7 +61,7 @@ public class DefaultTbQueueResponseTemplate<Request extends TbQueueMsg, Response | ||
61 | long requestTimeout, | 61 | long requestTimeout, |
62 | int maxPendingRequests, | 62 | int maxPendingRequests, |
63 | ExecutorService executor, | 63 | ExecutorService executor, |
64 | - QueueStats stats) { | 64 | + MessagesStats stats) { |
65 | this.requestTemplate = requestTemplate; | 65 | this.requestTemplate = requestTemplate; |
66 | this.responseTemplate = responseTemplate; | 66 | this.responseTemplate = responseTemplate; |
67 | this.pendingRequests = new ConcurrentHashMap<>(); | 67 | this.pendingRequests = new ConcurrentHashMap<>(); |
@@ -55,6 +55,9 @@ import org.thingsboard.server.queue.discovery.PartitionService; | @@ -55,6 +55,9 @@ import org.thingsboard.server.queue.discovery.PartitionService; | ||
55 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; | 55 | import org.thingsboard.server.queue.discovery.TbServiceInfoProvider; |
56 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; | 56 | import org.thingsboard.server.queue.provider.TbQueueProducerProvider; |
57 | import org.thingsboard.server.queue.provider.TbTransportQueueFactory; | 57 | import org.thingsboard.server.queue.provider.TbTransportQueueFactory; |
58 | +import org.thingsboard.server.common.msg.stats.MessagesStats; | ||
59 | +import org.thingsboard.server.common.msg.stats.StatsFactory; | ||
60 | +import org.thingsboard.server.common.msg.stats.StatsType; | ||
58 | 61 | ||
59 | import javax.annotation.PostConstruct; | 62 | import javax.annotation.PostConstruct; |
60 | import javax.annotation.PreDestroy; | 63 | import javax.annotation.PreDestroy; |
@@ -101,12 +104,17 @@ public class DefaultTransportService implements TransportService { | @@ -101,12 +104,17 @@ public class DefaultTransportService implements TransportService { | ||
101 | private final TbQueueProducerProvider producerProvider; | 104 | private final TbQueueProducerProvider producerProvider; |
102 | private final PartitionService partitionService; | 105 | private final PartitionService partitionService; |
103 | private final TbServiceInfoProvider serviceInfoProvider; | 106 | private final TbServiceInfoProvider serviceInfoProvider; |
107 | + private final StatsFactory statsFactory; | ||
104 | 108 | ||
105 | protected TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> transportApiRequestTemplate; | 109 | protected TbQueueRequestTemplate<TbProtoQueueMsg<TransportApiRequestMsg>, TbProtoQueueMsg<TransportApiResponseMsg>> transportApiRequestTemplate; |
106 | protected TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> ruleEngineMsgProducer; | 110 | protected TbQueueProducer<TbProtoQueueMsg<ToRuleEngineMsg>> ruleEngineMsgProducer; |
107 | protected TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> tbCoreMsgProducer; | 111 | protected TbQueueProducer<TbProtoQueueMsg<ToCoreMsg>> tbCoreMsgProducer; |
108 | protected TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> transportNotificationsConsumer; | 112 | protected TbQueueConsumer<TbProtoQueueMsg<ToTransportMsg>> transportNotificationsConsumer; |
109 | 113 | ||
114 | + protected MessagesStats ruleEngineProducerStats; | ||
115 | + protected MessagesStats tbCoreProducerStats; | ||
116 | + protected MessagesStats transportApiStats; | ||
117 | + | ||
110 | protected ScheduledExecutorService schedulerExecutor; | 118 | protected ScheduledExecutorService schedulerExecutor; |
111 | protected ExecutorService transportCallbackExecutor; | 119 | protected ExecutorService transportCallbackExecutor; |
112 | 120 | ||
@@ -119,11 +127,12 @@ public class DefaultTransportService implements TransportService { | @@ -119,11 +127,12 @@ public class DefaultTransportService implements TransportService { | ||
119 | private ExecutorService mainConsumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("transport-consumer")); | 127 | private ExecutorService mainConsumerExecutor = Executors.newSingleThreadExecutor(ThingsBoardThreadFactory.forName("transport-consumer")); |
120 | private volatile boolean stopped = false; | 128 | private volatile boolean stopped = false; |
121 | 129 | ||
122 | - public DefaultTransportService(TbServiceInfoProvider serviceInfoProvider, TbTransportQueueFactory queueProvider, TbQueueProducerProvider producerProvider, PartitionService partitionService) { | 130 | + public DefaultTransportService(TbServiceInfoProvider serviceInfoProvider, TbTransportQueueFactory queueProvider, TbQueueProducerProvider producerProvider, PartitionService partitionService, StatsFactory statsFactory) { |
123 | this.serviceInfoProvider = serviceInfoProvider; | 131 | this.serviceInfoProvider = serviceInfoProvider; |
124 | this.queueProvider = queueProvider; | 132 | this.queueProvider = queueProvider; |
125 | this.producerProvider = producerProvider; | 133 | this.producerProvider = producerProvider; |
126 | this.partitionService = partitionService; | 134 | this.partitionService = partitionService; |
135 | + this.statsFactory = statsFactory; | ||
127 | } | 136 | } |
128 | 137 | ||
129 | @PostConstruct | 138 | @PostConstruct |
@@ -133,10 +142,14 @@ public class DefaultTransportService implements TransportService { | @@ -133,10 +142,14 @@ public class DefaultTransportService implements TransportService { | ||
133 | new TbRateLimits(perTenantLimitsConf); | 142 | new TbRateLimits(perTenantLimitsConf); |
134 | new TbRateLimits(perDevicesLimitsConf); | 143 | new TbRateLimits(perDevicesLimitsConf); |
135 | } | 144 | } |
145 | + this.ruleEngineProducerStats = statsFactory.createMessagesStats(StatsType.RULE_ENGINE.getName() + ".producer"); | ||
146 | + this.tbCoreProducerStats = statsFactory.createMessagesStats(StatsType.CORE.getName() + ".producer"); | ||
147 | + this.transportApiStats = statsFactory.createMessagesStats(StatsType.TRANSPORT.getName() + ".producer"); | ||
136 | this.schedulerExecutor = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName("transport-scheduler")); | 148 | this.schedulerExecutor = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName("transport-scheduler")); |
137 | this.transportCallbackExecutor = Executors.newWorkStealingPool(20); | 149 | this.transportCallbackExecutor = Executors.newWorkStealingPool(20); |
138 | this.schedulerExecutor.scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS); | 150 | this.schedulerExecutor.scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) sessionReportTimeout), sessionReportTimeout, TimeUnit.MILLISECONDS); |
139 | transportApiRequestTemplate = queueProvider.createTransportApiRequestTemplate(); | 151 | transportApiRequestTemplate = queueProvider.createTransportApiRequestTemplate(); |
152 | + transportApiRequestTemplate.setMessagesStats(transportApiStats); | ||
140 | ruleEngineMsgProducer = producerProvider.getRuleEngineMsgProducer(); | 153 | ruleEngineMsgProducer = producerProvider.getRuleEngineMsgProducer(); |
141 | tbCoreMsgProducer = producerProvider.getTbCoreMsgProducer(); | 154 | tbCoreMsgProducer = producerProvider.getTbCoreMsgProducer(); |
142 | transportNotificationsConsumer = queueProvider.createTransportNotificationsConsumer(); | 155 | transportNotificationsConsumer = queueProvider.createTransportNotificationsConsumer(); |
@@ -557,10 +570,14 @@ public class DefaultTransportService implements TransportService { | @@ -557,10 +570,14 @@ public class DefaultTransportService implements TransportService { | ||
557 | if (log.isTraceEnabled()) { | 570 | if (log.isTraceEnabled()) { |
558 | log.trace("[{}][{}] Pushing to topic {} message {}", getTenantId(sessionInfo), getDeviceId(sessionInfo), tpi.getFullTopicName(), toDeviceActorMsg); | 571 | log.trace("[{}][{}] Pushing to topic {} message {}", getTenantId(sessionInfo), getDeviceId(sessionInfo), tpi.getFullTopicName(), toDeviceActorMsg); |
559 | } | 572 | } |
573 | + TransportTbQueueCallback transportTbQueueCallback = callback != null ? | ||
574 | + new TransportTbQueueCallback(callback) : null; | ||
575 | + tbCoreProducerStats.incrementTotal(); | ||
576 | + StatsCallback wrappedCallback = new StatsCallback(transportTbQueueCallback, tbCoreProducerStats); | ||
560 | tbCoreMsgProducer.send(tpi, | 577 | tbCoreMsgProducer.send(tpi, |
561 | new TbProtoQueueMsg<>(getRoutingKey(sessionInfo), | 578 | new TbProtoQueueMsg<>(getRoutingKey(sessionInfo), |
562 | - ToCoreMsg.newBuilder().setToDeviceActorMsg(toDeviceActorMsg).build()), callback != null ? | ||
563 | - new TransportTbQueueCallback(callback) : null); | 579 | + ToCoreMsg.newBuilder().setToDeviceActorMsg(toDeviceActorMsg).build()), |
580 | + wrappedCallback); | ||
564 | } | 581 | } |
565 | 582 | ||
566 | protected void sendToRuleEngine(TenantId tenantId, TbMsg tbMsg, TbQueueCallback callback) { | 583 | protected void sendToRuleEngine(TenantId tenantId, TbMsg tbMsg, TbQueueCallback callback) { |
@@ -571,7 +588,9 @@ public class DefaultTransportService implements TransportService { | @@ -571,7 +588,9 @@ public class DefaultTransportService implements TransportService { | ||
571 | ToRuleEngineMsg msg = ToRuleEngineMsg.newBuilder().setTbMsg(TbMsg.toByteString(tbMsg)) | 588 | ToRuleEngineMsg msg = ToRuleEngineMsg.newBuilder().setTbMsg(TbMsg.toByteString(tbMsg)) |
572 | .setTenantIdMSB(tenantId.getId().getMostSignificantBits()) | 589 | .setTenantIdMSB(tenantId.getId().getMostSignificantBits()) |
573 | .setTenantIdLSB(tenantId.getId().getLeastSignificantBits()).build(); | 590 | .setTenantIdLSB(tenantId.getId().getLeastSignificantBits()).build(); |
574 | - ruleEngineMsgProducer.send(tpi, new TbProtoQueueMsg<>(tbMsg.getId(), msg), callback); | 591 | + ruleEngineProducerStats.incrementTotal(); |
592 | + StatsCallback wrappedCallback = new StatsCallback(callback, ruleEngineProducerStats); | ||
593 | + ruleEngineMsgProducer.send(tpi, new TbProtoQueueMsg<>(tbMsg.getId(), msg), wrappedCallback); | ||
575 | } | 594 | } |
576 | 595 | ||
577 | private class TransportTbQueueCallback implements TbQueueCallback { | 596 | private class TransportTbQueueCallback implements TbQueueCallback { |
@@ -592,6 +611,30 @@ public class DefaultTransportService implements TransportService { | @@ -592,6 +611,30 @@ public class DefaultTransportService implements TransportService { | ||
592 | } | 611 | } |
593 | } | 612 | } |
594 | 613 | ||
614 | + private class StatsCallback implements TbQueueCallback { | ||
615 | + private final TbQueueCallback callback; | ||
616 | + private final MessagesStats stats; | ||
617 | + | ||
618 | + private StatsCallback(TbQueueCallback callback, MessagesStats stats) { | ||
619 | + this.callback = callback; | ||
620 | + this.stats = stats; | ||
621 | + } | ||
622 | + | ||
623 | + @Override | ||
624 | + public void onSuccess(TbQueueMsgMetadata metadata) { | ||
625 | + stats.incrementSuccessful(); | ||
626 | + if (callback != null) | ||
627 | + callback.onSuccess(metadata); | ||
628 | + } | ||
629 | + | ||
630 | + @Override | ||
631 | + public void onFailure(Throwable t) { | ||
632 | + stats.incrementFailed(); | ||
633 | + if (callback != null) | ||
634 | + callback.onFailure(t); | ||
635 | + } | ||
636 | + } | ||
637 | + | ||
595 | private class MsgPackCallback implements TbQueueCallback { | 638 | private class MsgPackCallback implements TbQueueCallback { |
596 | private final AtomicInteger msgCount; | 639 | private final AtomicInteger msgCount; |
597 | private final TransportServiceCallback<Void> callback; | 640 | private final TransportServiceCallback<Void> callback; |
@@ -14,8 +14,16 @@ | @@ -14,8 +14,16 @@ | ||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | # | 15 | # |
16 | 16 | ||
17 | -spring.main.web-environment: false | ||
18 | -spring.main.web-application-type: none | 17 | +# If you enabled process metrics you should also enable 'web-environment'. |
18 | +spring.main.web-environment: "${WEB_APPLICATION_ENABLE:false}" | ||
19 | +# If you enabled process metrics you should set 'web-application-type' to 'servlet' value. | ||
20 | +spring.main.web-application-type: "${WEB_APPLICATION_TYPE:none}" | ||
21 | + | ||
22 | +server: | ||
23 | + # Server bind address (has no effect if web-environment is disabled). | ||
24 | + address: "${HTTP_BIND_ADDRESS:0.0.0.0}" | ||
25 | + # Server bind port (has no effect if web-environment is disabled). | ||
26 | + port: "${HTTP_BIND_PORT:8083}" | ||
19 | 27 | ||
20 | # Zookeeper connection parameters. Used for service discovery. | 28 | # Zookeeper connection parameters. Used for service discovery. |
21 | zk: | 29 | zk: |
@@ -211,4 +219,16 @@ service: | @@ -211,4 +219,16 @@ service: | ||
211 | type: "${TB_SERVICE_TYPE:tb-transport}" | 219 | type: "${TB_SERVICE_TYPE:tb-transport}" |
212 | # Unique id for this service (autogenerated if empty) | 220 | # Unique id for this service (autogenerated if empty) |
213 | id: "${TB_SERVICE_ID:}" | 221 | id: "${TB_SERVICE_ID:}" |
214 | - tenant_id: "${TB_SERVICE_TENANT_ID:}" # empty or specific tenant id. | ||
222 | + tenant_id: "${TB_SERVICE_TENANT_ID:}" # empty or specific tenant id. | ||
223 | + | ||
224 | + | ||
225 | +metrics: | ||
226 | + # Enable/disable actuator metrics. | ||
227 | + enabled: "${METRICS_ENABLED:false}" | ||
228 | + | ||
229 | +management: | ||
230 | + endpoints: | ||
231 | + web: | ||
232 | + exposure: | ||
233 | + # Expose metrics endpoint (use value 'prometheus' to enable prometheus metrics). | ||
234 | + include: '${METRICS_ENDPOINTS_EXPOSE:info}' |
@@ -212,4 +212,16 @@ service: | @@ -212,4 +212,16 @@ service: | ||
212 | type: "${TB_SERVICE_TYPE:tb-transport}" | 212 | type: "${TB_SERVICE_TYPE:tb-transport}" |
213 | # Unique id for this service (autogenerated if empty) | 213 | # Unique id for this service (autogenerated if empty) |
214 | id: "${TB_SERVICE_ID:}" | 214 | id: "${TB_SERVICE_ID:}" |
215 | - tenant_id: "${TB_SERVICE_TENANT_ID:}" # empty or specific tenant id. | ||
215 | + tenant_id: "${TB_SERVICE_TENANT_ID:}" # empty or specific tenant id. | ||
216 | + | ||
217 | + | ||
218 | +metrics: | ||
219 | + # Enable/disable actuator metrics. | ||
220 | + enabled: "${METRICS_ENABLED:false}" | ||
221 | + | ||
222 | +management: | ||
223 | + endpoints: | ||
224 | + web: | ||
225 | + exposure: | ||
226 | + # Expose metrics endpoint (use value 'prometheus' to enable prometheus metrics). | ||
227 | + include: '${METRICS_ENDPOINTS_EXPOSE:info}' |
@@ -14,8 +14,16 @@ | @@ -14,8 +14,16 @@ | ||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | # | 15 | # |
16 | 16 | ||
17 | -spring.main.web-environment: false | ||
18 | -spring.main.web-application-type: none | 17 | +# If you enabled process metrics you should also enable 'web-environment'. |
18 | +spring.main.web-environment: "${WEB_APPLICATION_ENABLE:false}" | ||
19 | +# If you enabled process metrics you should set 'web-application-type' to 'servlet' value. | ||
20 | +spring.main.web-application-type: "${WEB_APPLICATION_TYPE:none}" | ||
21 | + | ||
22 | +server: | ||
23 | + # Server bind address (has no effect if web-environment is disabled). | ||
24 | + address: "${HTTP_BIND_ADDRESS:0.0.0.0}" | ||
25 | + # Server bind port (has no effect if web-environment is disabled). | ||
26 | + port: "${HTTP_BIND_PORT:8083}" | ||
19 | 27 | ||
20 | # Zookeeper connection parameters. Used for service discovery. | 28 | # Zookeeper connection parameters. Used for service discovery. |
21 | zk: | 29 | zk: |
@@ -232,4 +240,15 @@ service: | @@ -232,4 +240,15 @@ service: | ||
232 | type: "${TB_SERVICE_TYPE:tb-transport}" | 240 | type: "${TB_SERVICE_TYPE:tb-transport}" |
233 | # Unique id for this service (autogenerated if empty) | 241 | # Unique id for this service (autogenerated if empty) |
234 | id: "${TB_SERVICE_ID:}" | 242 | id: "${TB_SERVICE_ID:}" |
235 | - tenant_id: "${TB_SERVICE_TENANT_ID:}" # empty or specific tenant id. | ||
243 | + tenant_id: "${TB_SERVICE_TENANT_ID:}" # empty or specific tenant id. | ||
244 | + | ||
245 | +metrics: | ||
246 | + # Enable/disable actuator metrics. | ||
247 | + enabled: "${METRICS_ENABLED:false}" | ||
248 | + | ||
249 | +management: | ||
250 | + endpoints: | ||
251 | + web: | ||
252 | + exposure: | ||
253 | + # Expose metrics endpoint (use value 'prometheus' to enable prometheus metrics). | ||
254 | + include: '${METRICS_ENDPOINTS_EXPOSE:info}' |