Browse Source

Make notification for microservices

pull/12616/head
Andrii Landiak 2 years ago
parent
commit
a4948891b2
  1. 17
      application/src/main/java/org/thingsboard/server/service/system/DefaultSystemInfoService.java
  2. 2
      common/data/src/main/java/org/thingsboard/server/common/data/notification/info/ResourcesShortageNotificationInfo.java
  3. 2
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/ResourcesShortageTrigger.java

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

@ -184,6 +184,11 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
private void saveCurrentClusterSystemInfo() {
long ts = System.currentTimeMillis();
List<SystemInfoData> clusterSystemData = getSystemData(serviceInfoProvider.getServiceInfo());
clusterSystemData.forEach(data -> {
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.CPU).usage(data.getCpuUsage()).build());
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.RAM).usage(data.getMemoryUsage()).build());
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.STORAGE).usage(data.getDiscUsage()).build());
});
BasicTsKvEntry clusterDataKv = new BasicTsKvEntry(ts, new JsonDataEntry("clusterSystemData", JacksonUtil.toString(clusterSystemData)));
doSave(Arrays.asList(new BasicTsKvEntry(ts, new BooleanDataEntry("clusterMode", true)), clusterDataKv));
}
@ -194,15 +199,17 @@ public class DefaultSystemInfoService extends TbApplicationEventListener<Partiti
tsList.add(new BasicTsKvEntry(ts, new BooleanDataEntry("clusterMode", false)));
getCpuUsage().ifPresent(v -> {
tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("cpuUsage", (long) v)));
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.CPU).usage(v).build());
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.CPU).usage((long) v).build());
});
getMemoryUsage().ifPresent(v -> {
tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("memoryUsage", (long) v)));
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.RAM).usage(v).build());
long value = (long) v;
tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("memoryUsage", value)));
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.RAM).usage(value).build());
});
getDiscSpaceUsage().ifPresent(v -> {
tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("discUsage", (long) v)));
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.STORAGE).usage(v).build());
long value = (long) v;
tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("discUsage", value)));
notificationRule.process(ResourcesShortageTrigger.builder().resource(Resource.STORAGE).usage(value).build());
});
getCpuCount().ifPresent(v -> tsList.add(new BasicTsKvEntry(ts, new LongDataEntry("cpuCount", (long) v))));

2
common/data/src/main/java/org/thingsboard/server/common/data/notification/info/ResourcesShortageNotificationInfo.java

@ -29,7 +29,7 @@ import java.util.Map;
public class ResourcesShortageNotificationInfo implements RuleOriginatedNotificationInfo {
private String resource;
private Integer usage;
private Long usage;
@Override
public Map<String, String> getTemplateData() {

2
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/trigger/ResourcesShortageTrigger.java

@ -32,7 +32,7 @@ public class ResourcesShortageTrigger implements NotificationRuleTrigger {
private static final long serialVersionUID = 6024216015202949570L;
private Resource resource;
private Integer usage;
private Long usage;
@Override
public TenantId getTenantId() {

Loading…
Cancel
Save