Search in sources :

Example 1 with TbRuleEngineConsumerStats

use of org.thingsboard.server.service.queue.TbRuleEngineConsumerStats in project thingsboard by thingsboard.

the class DefaultRuleEngineStatisticsService method reportQueueStats.

@Override
public void reportQueueStats(long ts, TbRuleEngineConsumerStats ruleEngineStats) {
    String queueName = ruleEngineStats.getQueueName();
    ruleEngineStats.getTenantStats().forEach((id, stats) -> {
        TenantId tenantId = TenantId.fromUUID(id);
        try {
            AssetId serviceAssetId = getServiceAssetId(tenantId, queueName);
            if (stats.getTotalMsgCounter().get() > 0) {
                List<TsKvEntry> tsList = stats.getCounters().entrySet().stream().map(kv -> new BasicTsKvEntry(ts, new LongDataEntry(kv.getKey(), (long) kv.getValue().get()))).collect(Collectors.toList());
                if (!tsList.isEmpty()) {
                    tsService.saveAndNotifyInternal(tenantId, serviceAssetId, tsList, CALLBACK);
                }
            }
        } catch (DataValidationException e) {
            if (!e.getMessage().equalsIgnoreCase("Asset is referencing to non-existent tenant!")) {
                throw e;
            }
        }
    });
    ruleEngineStats.getTenantExceptions().forEach((tenantId, e) -> {
        TsKvEntry tsKv = new BasicTsKvEntry(e.getTs(), new JsonDataEntry("ruleEngineException", e.toJsonString()));
        try {
            tsService.saveAndNotifyInternal(tenantId, getServiceAssetId(tenantId, queueName), Collections.singletonList(tsKv), CALLBACK);
        } catch (DataValidationException e2) {
            if (!e2.getMessage().equalsIgnoreCase("Asset is referencing to non-existent tenant!")) {
                throw e2;
            }
        }
    });
}
Also used : JacksonUtil(org.thingsboard.common.util.JacksonUtil) AssetId(org.thingsboard.server.common.data.id.AssetId) TelemetrySubscriptionService(org.thingsboard.server.service.telemetry.TelemetrySubscriptionService) TenantId(org.thingsboard.server.common.data.id.TenantId) ConcurrentMap(java.util.concurrent.ConcurrentMap) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) Service(org.springframework.stereotype.Service) TbRuleEngineComponent(org.thingsboard.server.queue.util.TbRuleEngineComponent) TbRuleEngineConsumerStats(org.thingsboard.server.service.queue.TbRuleEngineConsumerStats) TbServiceInfoProvider(org.thingsboard.server.queue.discovery.TbServiceInfoProvider) Nullable(javax.annotation.Nullable) AssetService(org.thingsboard.server.dao.asset.AssetService) ReentrantLock(java.util.concurrent.locks.ReentrantLock) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) FutureCallback(com.google.common.util.concurrent.FutureCallback) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Lock(java.util.concurrent.locks.Lock) JsonDataEntry(org.thingsboard.server.common.data.kv.JsonDataEntry) Data(lombok.Data) Collections(java.util.Collections) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) Asset(org.thingsboard.server.common.data.asset.Asset) TenantId(org.thingsboard.server.common.data.id.TenantId) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) LongDataEntry(org.thingsboard.server.common.data.kv.LongDataEntry) AssetId(org.thingsboard.server.common.data.id.AssetId) JsonDataEntry(org.thingsboard.server.common.data.kv.JsonDataEntry)

Aggregations

FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Collections (java.util.Collections)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Lock (java.util.concurrent.locks.Lock)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Data (lombok.Data)1 Slf4j (lombok.extern.slf4j.Slf4j)1 Service (org.springframework.stereotype.Service)1 JacksonUtil (org.thingsboard.common.util.JacksonUtil)1 Asset (org.thingsboard.server.common.data.asset.Asset)1 AssetId (org.thingsboard.server.common.data.id.AssetId)1 TenantId (org.thingsboard.server.common.data.id.TenantId)1 BasicTsKvEntry (org.thingsboard.server.common.data.kv.BasicTsKvEntry)1 JsonDataEntry (org.thingsboard.server.common.data.kv.JsonDataEntry)1 LongDataEntry (org.thingsboard.server.common.data.kv.LongDataEntry)1 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)1