Browse Source

TTL for system info

pull/9353/head
ViacheslavKlimov 3 years ago
committed by Andrii Shvaika
parent
commit
69349d5075
  1. 10
      application/src/main/java/org/thingsboard/server/service/system/DefaultSystemInfoService.java
  2. 5
      application/src/main/resources/thingsboard.yml

10
application/src/main/java/org/thingsboard/server/service/system/DefaultSystemInfoService.java

@ -19,6 +19,7 @@ import com.google.common.util.concurrent.FutureCallback;
import com.google.protobuf.ProtocolStringList;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.common.util.ThingsBoardThreadFactory;
@ -93,6 +94,11 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
private final SmsService smsService;
private volatile ScheduledExecutorService scheduler;
@Value("${metrics.system_info.persist_frequency:60}")
private int systemInfoPersistFrequencySeconds;
@Value("#{${metrics.system_info.ttl:7} * 86400}")
private int systemInfoTtlSeconds;
@Override
protected void onTbApplicationEvent(PartitionChangeEvent partitionChangeEvent) {
if (ServiceType.TB_CORE.equals(partitionChangeEvent.getServiceType())) {
@ -101,7 +107,7 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
if (myPartition) {
if (scheduler == null) {
scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName("tb-system-info-scheduler"));
scheduler.scheduleAtFixedRate(this::saveCurrentSystemInfo, 0, 1, TimeUnit.MINUTES);
scheduler.scheduleWithFixedDelay(this::saveCurrentSystemInfo, systemInfoPersistFrequencySeconds, systemInfoPersistFrequencySeconds, TimeUnit.SECONDS);
}
} else {
destroy();
@ -195,7 +201,7 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
private void doSave(List<TsKvEntry> telemetry) {
ApiUsageState apiUsageState = apiUsageStateClient.getApiUsageState(TenantId.SYS_TENANT_ID);
telemetryService.saveAndNotifyInternal(TenantId.SYS_TENANT_ID, apiUsageState.getId(), telemetry, CALLBACK);
telemetryService.saveAndNotifyInternal(TenantId.SYS_TENANT_ID, apiUsageState.getId(), telemetry, systemInfoTtlSeconds, CALLBACK);
}
private List<SystemInfoData> getSystemData(ServiceInfo serviceInfo) {

5
application/src/main/resources/thingsboard.yml

@ -1326,6 +1326,11 @@ metrics:
timer:
# Metrics percentiles returned by actuator for timer metrics. List of double values (divided by ,).
percentiles: "${METRICS_TIMER_PERCENTILES:0.5}"
system_info:
# Persist frequency of system info (CPU, memory usage, etc.) in seconds
persist_frequency: "${METRICS_SYSTEM_INFO_PERSIST_FREQUENCY_SECONDS:60}"
# TTL in days for system info timeseries
ttl: "${METRICS_SYSTEM_INFO_TTL_DAYS:7}"
vc:
# Pool size for handling export tasks

Loading…
Cancel
Save