Refactoring for monitoring service
This commit is contained in:
parent
7a30cc1b68
commit
df16a6a310
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
Copyright © 2016-2022 The Thingsboard Authors
|
Copyright © 2016-2023 The Thingsboard Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.thingsboard</groupId>
|
<groupId>org.thingsboard</groupId>
|
||||||
<version>3.4.3-SNAPSHOT</version>
|
<version>3.5.0-SNAPSHOT</version>
|
||||||
<artifactId>thingsboard</artifactId>
|
<artifactId>thingsboard</artifactId>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -59,28 +59,16 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.californium</groupId>
|
<groupId>org.eclipse.californium</groupId>
|
||||||
<artifactId>californium-core</artifactId>
|
<artifactId>californium-core</artifactId>
|
||||||
<version>2.6.1</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.californium</groupId>
|
<groupId>org.eclipse.californium</groupId>
|
||||||
<artifactId>scandium</artifactId>
|
<artifactId>scandium</artifactId>
|
||||||
<version>2.6.1</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.leshan</groupId>
|
|
||||||
<artifactId>leshan-client-cf</artifactId>
|
|
||||||
<version>2.0.0-M4</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.leshan</groupId>
|
|
||||||
<artifactId>leshan-core</artifactId>
|
|
||||||
<version>2.0.0-M4</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.eclipse.paho</groupId>
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
Copyright © 2016-2022 The Thingsboard Authors
|
Copyright © 2016-2023 The Thingsboard Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright © 2016-2022 The Thingsboard Authors
|
# Copyright © 2016-2023 The Thingsboard Authors
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -28,13 +28,13 @@ import java.time.Duration;
|
|||||||
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||||
public class TbClient extends RestClient {
|
public class TbClient extends RestClient {
|
||||||
|
|
||||||
@Value("${monitoring.auth.username}")
|
@Value("${monitoring.rest.username}")
|
||||||
private String username;
|
private String username;
|
||||||
@Value("${monitoring.auth.password}")
|
@Value("${monitoring.rest.password}")
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
public TbClient(@Value("${monitoring.auth.base_url}") String baseUrl,
|
public TbClient(@Value("${monitoring.rest.base_url}") String baseUrl,
|
||||||
@Value("${monitoring.rest_request_timeout_ms}") int requestTimeoutMs) {
|
@Value("${monitoring.rest.request_timeout_ms}") int requestTimeoutMs) {
|
||||||
super(new RestTemplateBuilder()
|
super(new RestTemplateBuilder()
|
||||||
.setConnectTimeout(Duration.ofMillis(requestTimeoutMs))
|
.setConnectTimeout(Duration.ofMillis(requestTimeoutMs))
|
||||||
.setReadTimeout(Duration.ofMillis(requestTimeoutMs))
|
.setReadTimeout(Duration.ofMillis(requestTimeoutMs))
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -30,12 +30,12 @@ import org.thingsboard.monitoring.data.notification.HighLatencyNotification;
|
|||||||
import org.thingsboard.monitoring.data.notification.ServiceFailureNotification;
|
import org.thingsboard.monitoring.data.notification.ServiceFailureNotification;
|
||||||
import org.thingsboard.monitoring.data.notification.ServiceRecoveryNotification;
|
import org.thingsboard.monitoring.data.notification.ServiceRecoveryNotification;
|
||||||
import org.thingsboard.monitoring.notification.NotificationService;
|
import org.thingsboard.monitoring.notification.NotificationService;
|
||||||
import org.thingsboard.server.common.data.EntityType;
|
import org.thingsboard.server.common.data.asset.Asset;
|
||||||
import org.thingsboard.server.common.data.id.EntityId;
|
import org.thingsboard.server.common.data.id.AssetId;
|
||||||
import org.thingsboard.server.common.data.id.EntityIdFactory;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -52,14 +52,15 @@ public class MonitoringReporter {
|
|||||||
|
|
||||||
@Value("${monitoring.failures_threshold}")
|
@Value("${monitoring.failures_threshold}")
|
||||||
private int failuresThreshold;
|
private int failuresThreshold;
|
||||||
@Value("${monitoring.latency.threshold_ms}")
|
|
||||||
private int latencyThresholdMs;
|
|
||||||
@Value("${monitoring.send_repeated_failure_notification}")
|
@Value("${monitoring.send_repeated_failure_notification}")
|
||||||
private boolean sendRepeatedFailureNotification;
|
private boolean sendRepeatedFailureNotification;
|
||||||
@Value("${monitoring.latency.reporting_entity_type}")
|
|
||||||
private EntityType reportingEntityType;
|
@Value("${monitoring.latency.enabled}")
|
||||||
@Value("${monitoring.latency.reporting_entity_id}")
|
private boolean latencyReportingEnabled;
|
||||||
private String reportingEntityId;
|
@Value("${monitoring.latency.threshold_ms}")
|
||||||
|
private int latencyThresholdMs;
|
||||||
|
@Value("${monitoring.latency.reporting_asset_id}")
|
||||||
|
private String reportingAssetId;
|
||||||
|
|
||||||
public void reportLatencies(TbClient tbClient) {
|
public void reportLatencies(TbClient tbClient) {
|
||||||
List<Latency> latencies = this.latencies.values().stream()
|
List<Latency> latencies = this.latencies.values().stream()
|
||||||
@ -75,27 +76,35 @@ public class MonitoringReporter {
|
|||||||
}
|
}
|
||||||
log.info("Latencies:\n{}", latencies.stream().map(latency -> latency.getKey() + ": " + latency.getAvg() + " ms")
|
log.info("Latencies:\n{}", latencies.stream().map(latency -> latency.getKey() + ": " + latency.getAvg() + " ms")
|
||||||
.collect(Collectors.joining("\n")));
|
.collect(Collectors.joining("\n")));
|
||||||
|
|
||||||
|
if (!latencyReportingEnabled) return;
|
||||||
|
|
||||||
if (latencies.stream().anyMatch(latency -> latency.getAvg() >= (double) latencyThresholdMs)) {
|
if (latencies.stream().anyMatch(latency -> latency.getAvg() >= (double) latencyThresholdMs)) {
|
||||||
HighLatencyNotification highLatencyNotification = new HighLatencyNotification(latencies, latencyThresholdMs);
|
HighLatencyNotification highLatencyNotification = new HighLatencyNotification(latencies, latencyThresholdMs);
|
||||||
notificationService.sendNotification(highLatencyNotification);
|
notificationService.sendNotification(highLatencyNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (reportingEntityType != null && StringUtils.isNotBlank(reportingEntityId)) {
|
try {
|
||||||
try {
|
if (StringUtils.isBlank(reportingAssetId)) {
|
||||||
EntityId entityId;
|
String assetName = "Monitoring";
|
||||||
try {
|
Asset monitoringAsset = tbClient.findAsset(assetName).orElseGet(() -> {
|
||||||
entityId = EntityIdFactory.getByTypeAndUuid(reportingEntityType, reportingEntityId);
|
Asset asset = new Asset();
|
||||||
} catch (Exception e) {
|
asset.setType("Monitoring");
|
||||||
return;
|
asset.setName(assetName);
|
||||||
}
|
asset = tbClient.saveAsset(asset);
|
||||||
ObjectNode msg = JacksonUtil.newObjectNode();
|
log.info("Created monitoring asset {}", asset.getId());
|
||||||
latencies.forEach(latency -> {
|
return asset;
|
||||||
msg.set(latency.getKey(), new DoubleNode(latency.getAvg()));
|
|
||||||
});
|
});
|
||||||
tbClient.saveEntityTelemetry(entityId, "time", msg);
|
reportingAssetId = monitoringAsset.getId().toString();
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Failed to report latencies: {}", e.getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ObjectNode msg = JacksonUtil.newObjectNode();
|
||||||
|
latencies.forEach(latency -> {
|
||||||
|
msg.set(latency.getKey(), new DoubleNode(latency.getAvg()));
|
||||||
|
});
|
||||||
|
tbClient.saveEntityTelemetry(new AssetId(UUID.fromString(reportingAssetId)), "time", msg);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed to report latencies: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -134,7 +134,7 @@ public final class TransportMonitoringService {
|
|||||||
deviceId = new DeviceId(deviceConfig.getId());
|
deviceId = new DeviceId(deviceConfig.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Loading credentials for device {}", deviceId);
|
log.info("Loading credentials for device {}", deviceId);
|
||||||
DeviceCredentials credentials = tbClient.getDeviceCredentialsByDeviceId(deviceId)
|
DeviceCredentials credentials = tbClient.getDeviceCredentialsByDeviceId(deviceId)
|
||||||
.orElseThrow(() -> new IllegalArgumentException("No credentials found for device " + deviceId));
|
.orElseThrow(() -> new IllegalArgumentException("No credentials found for device " + deviceId));
|
||||||
target.getDevice().setCredentials(credentials);
|
target.getDevice().setCredentials(credentials);
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* Copyright © 2016-2022 The Thingsboard Authors
|
* Copyright © 2016-2023 The Thingsboard Authors
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
Copyright © 2016-2022 The Thingsboard Authors
|
Copyright © 2016-2023 The Thingsboard Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
<logger name="org" level="WARN"/>
|
<logger name="org" level="WARN"/>
|
||||||
<logger name="org.thingsboard.server" level="INFO"/>
|
<logger name="org.thingsboard.server" level="INFO"/>
|
||||||
<logger name="org.thingsboard.monitoring" level="DEBUG"/>
|
<logger name="org.thingsboard.monitoring" level="INFO"/>
|
||||||
<logger name="org.thingsboard.monitoring.client" level="WARN"/>
|
<logger name="org.thingsboard.monitoring.client" level="WARN"/>
|
||||||
|
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# Copyright © 2016-2022 The Thingsboard Authors
|
# Copyright © 2016-2023 The Thingsboard Authors
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
# you may not use this file except in compliance with the License.
|
# you may not use this file except in compliance with the License.
|
||||||
@ -14,57 +14,93 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
server:
|
|
||||||
port: '${SERVER_PORT:8990}'
|
|
||||||
|
|
||||||
monitoring:
|
monitoring:
|
||||||
auth:
|
# Monitored server domain
|
||||||
base_url: '${AUTH_BASE_URL:http://localhost:8080}'
|
domain: "${DOMAIN:localhost}"
|
||||||
username: '${AUTH_USERNAME:tenant@thingsboard.org}'
|
rest:
|
||||||
password: '${AUTH_PASSWORD:tenant}'
|
# Base REST API url, https://DOMAIN by default
|
||||||
|
base_url: '${REST_BASE_URL:https://${monitoring.domain}}'
|
||||||
|
# Authentication username
|
||||||
|
username: '${REST_AUTH_USERNAME:tenant@thingsboard.org}'
|
||||||
|
# Authentication password
|
||||||
|
password: '${REST_AUTH_PASSWORD:tenant}'
|
||||||
|
# REST request timeout in milliseconds
|
||||||
|
request_timeout_ms: '${REST_REQUEST_TIMEOUT_MS:5000}'
|
||||||
ws:
|
ws:
|
||||||
base_url: '${WS_BASE_URL:ws://localhost:8080}'
|
# WebSocket url, wss://DOMAIN by default
|
||||||
|
base_url: '${WS_BASE_URL:wss://${monitoring.domain}}'
|
||||||
|
# Maximum time between request to transport and WebSocket update
|
||||||
check_timeout_ms: '${WS_CHECK_TIMEOUT_MS:5000}'
|
check_timeout_ms: '${WS_CHECK_TIMEOUT_MS:5000}'
|
||||||
|
# WebSocket request timeout
|
||||||
request_timeout_ms: '${WS_REQUEST_TIMEOUT_MS:3000}'
|
request_timeout_ms: '${WS_REQUEST_TIMEOUT_MS:3000}'
|
||||||
rest_request_timeout_ms: '${REST_REQUEST_TIMEOUT_MS:5000}'
|
|
||||||
|
|
||||||
|
# Failures threshold for notifying
|
||||||
failures_threshold: '${FAILURES_THRESHOLD:2}'
|
failures_threshold: '${FAILURES_THRESHOLD:2}'
|
||||||
|
# Whether to notify about next failures after first notification (will notify after each FAILURES_THRESHOLD failures)
|
||||||
send_repeated_failure_notification: '${SEND_REPEATED_FAILURE_NOTIFICATION:true}'
|
send_repeated_failure_notification: '${SEND_REPEATED_FAILURE_NOTIFICATION:true}'
|
||||||
|
|
||||||
transports:
|
transports:
|
||||||
|
# Transports check frequency in milliseconds
|
||||||
monitoring_rate_ms: '${TRANSPORTS_MONITORING_RATE_MS:10000}'
|
monitoring_rate_ms: '${TRANSPORTS_MONITORING_RATE_MS:10000}'
|
||||||
|
|
||||||
mqtt:
|
mqtt:
|
||||||
enabled: '${MQTT_TRANSPORT_MONITORING_ENABLED:false}'
|
# Enable MQTT checks
|
||||||
|
enabled: '${MQTT_TRANSPORT_MONITORING_ENABLED:true}'
|
||||||
|
# MQTT request timeout in milliseconds
|
||||||
request_timeout_ms: '${MQTT_REQUEST_TIMEOUT_MS:4000}'
|
request_timeout_ms: '${MQTT_REQUEST_TIMEOUT_MS:4000}'
|
||||||
|
# MQTT QoS
|
||||||
qos: '${MQTT_QOS_LEVEL:1}'
|
qos: '${MQTT_QOS_LEVEL:1}'
|
||||||
targets:
|
targets:
|
||||||
- base_url: '${MQTT_TRANSPORT_BASE_URL:tcp://localhost:1883}'
|
# MQTT base url, tcp://DOMAIN:1883 by default
|
||||||
|
- base_url: '${MQTT_TRANSPORT_BASE_URL:tcp://${monitoring.domain}:1883}'
|
||||||
device:
|
device:
|
||||||
|
# MQTT device to push telemetry for. If not set - device will be found or created automatically
|
||||||
id: '${MQTT_TRANSPORT_TARGET_DEVICE_ID:}'
|
id: '${MQTT_TRANSPORT_TARGET_DEVICE_ID:}'
|
||||||
|
# To add more targets, use following environment variables:
|
||||||
|
# monitoring.transports.mqtt.targets[1].base_url, monitoring.transports.mqtt.targets[1].device.id,
|
||||||
|
# monitoring.transports.mqtt.targets[2].base_url, monitoring.transports.mqtt.targets[2].device.id, etc.
|
||||||
|
|
||||||
coap:
|
coap:
|
||||||
enabled: '${COAP_TRANSPORT_MONITORING_ENABLED:false}'
|
# Enable CoAP checks
|
||||||
|
enabled: '${COAP_TRANSPORT_MONITORING_ENABLED:true}'
|
||||||
|
# CoAP request timeout in milliseconds
|
||||||
request_timeout_ms: '${COAP_REQUEST_TIMEOUT_MS:4000}'
|
request_timeout_ms: '${COAP_REQUEST_TIMEOUT_MS:4000}'
|
||||||
targets:
|
targets:
|
||||||
- base_url: '${COAP_TRANSPORT_BASE_URL:coap://localhost}'
|
# CoAP base url, coap://DOMAIN by default
|
||||||
|
- base_url: '${COAP_TRANSPORT_BASE_URL:coap://${monitoring.domain}}'
|
||||||
|
# CoAP device to push telemetry for. If not set - device will be found or created automatically
|
||||||
device:
|
device:
|
||||||
id: '${COAP_TRANSPORT_TARGET_DEVICE_ID:}'
|
id: '${COAP_TRANSPORT_TARGET_DEVICE_ID:}'
|
||||||
|
# To add more targets, use following environment variables:
|
||||||
|
# monitoring.transports.coap.targets[1].base_url, monitoring.transports.coap.targets[1].device.id,
|
||||||
|
# monitoring.transports.coap.targets[2].base_url, monitoring.transports.coap.targets[2].device.id, etc.
|
||||||
|
|
||||||
http:
|
http:
|
||||||
enabled: '${HTTP_TRANSPORT_MONITORING_ENABLED:false}'
|
# Enable HTTP checks
|
||||||
|
enabled: '${HTTP_TRANSPORT_MONITORING_ENABLED:true}'
|
||||||
|
# HTTP request timeout in milliseconds
|
||||||
request_timeout_ms: '${HTTP_REQUEST_TIMEOUT_MS:4000}'
|
request_timeout_ms: '${HTTP_REQUEST_TIMEOUT_MS:4000}'
|
||||||
targets:
|
targets:
|
||||||
- base_url: '${HTTP_TRANSPORT_BASE_URL:http://localhost:8080}'
|
# HTTP base url, https://DOMAIN by default
|
||||||
|
- base_url: '${HTTP_TRANSPORT_BASE_URL:https://${monitoring.domain}}'
|
||||||
device:
|
device:
|
||||||
|
# HTTP device to push telemetry for. If not set - device will be found or created automatically
|
||||||
id: '${HTTP_TRANSPORT_TARGET_DEVICE_ID:}'
|
id: '${HTTP_TRANSPORT_TARGET_DEVICE_ID:}'
|
||||||
|
# To add more targets, use following environment variables:
|
||||||
|
# monitoring.transports.http.targets[1].base_url, monitoring.transports.http.targets[1].device.id,
|
||||||
|
# monitoring.transports.http.targets[2].base_url, monitoring.transports.http.targets[2].device.id, etc.
|
||||||
|
|
||||||
notification_channels:
|
notification_channels:
|
||||||
slack:
|
slack:
|
||||||
|
# Enable notifying via Slack
|
||||||
enabled: '${SLACK_NOTIFICATION_CHANNEL_ENABLED:false}'
|
enabled: '${SLACK_NOTIFICATION_CHANNEL_ENABLED:false}'
|
||||||
|
# Slack webhook url
|
||||||
webhook_url: '${SLACK_WEBHOOK_URL:}'
|
webhook_url: '${SLACK_WEBHOOK_URL:}'
|
||||||
|
|
||||||
latency:
|
latency:
|
||||||
|
# Enable latencies reporting
|
||||||
|
enabled: "${LATENCY_REPORTING_ENABLED:true}"
|
||||||
|
# Latency threshold for notifying
|
||||||
threshold_ms: '${LATENCY_THRESHOLD:2000}'
|
threshold_ms: '${LATENCY_THRESHOLD:2000}'
|
||||||
reporting_entity_type: '${LATENCY_REPORTING_ENTITY_TYPE:ASSET}'
|
# ID of the asset to save latencies to. If not set and latencies reporting is enabled - asset will be found or created automatically
|
||||||
reporting_entity_id: '${LATENCY_REPORTING_ENTITY_ID:}'
|
reporting_asset_id: '${LATENCY_REPORTING_ASSET_ID:}'
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.thingsboard</groupId>
|
<groupId>org.thingsboard</groupId>
|
||||||
<version>3.4.3-SNAPSHOT</version>
|
<version>3.5.0-SNAPSHOT</version>
|
||||||
<artifactId>msa</artifactId>
|
<artifactId>msa</artifactId>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
5
pom.xml
5
pom.xml
@ -1085,6 +1085,11 @@
|
|||||||
<artifactId>jaxb-runtime</artifactId>
|
<artifactId>jaxb-runtime</artifactId>
|
||||||
<version>${jaxb-runtime.version}</version>
|
<version>${jaxb-runtime.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>${spring-boot.version}</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-security</artifactId>
|
<artifactId>spring-boot-starter-security</artifactId>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user