diff --git a/monitoring/pom.xml b/monitoring/pom.xml
new file mode 100644
index 0000000000..59fdd5f1df
--- /dev/null
+++ b/monitoring/pom.xml
@@ -0,0 +1,132 @@
+
+
+
+ 4.0.0
+
+ org.thingsboard
+ 3.4.2-SNAPSHOT
+ thingsboard
+
+ monitoring
+ 3.4.2-SNAPSHOT
+ Monitoring service
+ jar
+
+
+ UTF-8
+ ${basedir}/..
+ monitoring-service
+
+
+
+
+ org.thingsboard.common
+ data
+
+
+ org.thingsboard.common
+ util
+
+
+ org.thingsboard
+ rest-client
+ provided
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+ org.eclipse.californium
+ californium-core
+ 2.6.1
+
+
+ org.eclipse.californium
+ scandium
+ 2.6.1
+
+
+ org.eclipse.leshan
+ leshan-client-cf
+ 2.0.0-M4
+
+
+ org.eclipse.leshan
+ leshan-core
+ 2.0.0-M4
+
+
+ org.eclipse.paho
+ org.eclipse.paho.client.mqttv3
+
+
+ org.apache.httpcomponents
+ httpclient
+
+
+ org.java-websocket
+ Java-WebSocket
+ compile
+
+
+ org.apache.commons
+ commons-lang3
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ log4j-over-slf4j
+
+
+ ch.qos.logback
+ logback-core
+
+
+ ch.qos.logback
+ logback-classic
+
+
+
+
+ ${pkg.name}-${project.version}
+
+
+ ${project.basedir}/src/main/resources
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+
+
+
+
diff --git a/monitoring/src/main/java/org/thingsboard/aba/LatencyMsg.java b/monitoring/src/main/java/org/thingsboard/aba/LatencyMsg.java
new file mode 100644
index 0000000000..8c49ee8b27
--- /dev/null
+++ b/monitoring/src/main/java/org/thingsboard/aba/LatencyMsg.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright © 2016-2022 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.aba;
+
+import lombok.Data;
+
+@Data
+public class LatencyMsg {
+
+ private long restClientLoginLatency;
+ private long deviceCredLatency;
+ private long getDeviceLatency;
+
+ private long wsSubInitLatency;
+
+ private long mqttConnectLatency;
+ private long mqttSendLatency;
+ private long mqttTotalLatency;
+
+ private long httpSendLatency;
+ private long httpTotalLatency;
+
+ private long mqttErrors;
+ private long mqttReconnects;
+
+
+ public boolean hasLongLatency(long threshold) {
+ return restClientLoginLatency > threshold
+ || deviceCredLatency > threshold
+ || getDeviceLatency > threshold
+ || wsSubInitLatency > threshold
+ || mqttConnectLatency > threshold
+ || mqttSendLatency > threshold
+ || mqttTotalLatency > threshold
+ || httpSendLatency > threshold
+ || httpTotalLatency > threshold;
+ }
+}
diff --git a/monitoring/src/main/java/org/thingsboard/aba/SaasApi.java b/monitoring/src/main/java/org/thingsboard/aba/SaasApi.java
new file mode 100644
index 0000000000..17d196a5aa
--- /dev/null
+++ b/monitoring/src/main/java/org/thingsboard/aba/SaasApi.java
@@ -0,0 +1,234 @@
+/**
+ * Copyright © 2016-2022 The Thingsboard Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.thingsboard.aba;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.apache.http.ssl.SSLContexts;
+import org.apache.http.ssl.TrustStrategy;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.http.HttpRequest;
+import org.springframework.http.client.support.HttpRequestWrapper;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.client.RestTemplate;
+import org.thingsboard.rest.client.RestClient;
+import org.thingsboard.server.common.data.Device;
+import org.thingsboard.server.common.data.EntityType;
+import org.thingsboard.server.common.data.id.DeviceId;
+import org.thingsboard.server.common.data.security.DeviceCredentials;
+
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.atomic.AtomicLong;
+
+@Component
+@Slf4j
+public class SaasApi {
+
+ private static final long wsResponseWaitSec = 300;
+
+
+ @Value("${saas.host}")
+ private String host;
+
+ private AtomicLong counter = new AtomicLong();
+ private SampleMqttClient mqttClient;
+ private AtomicLong mqttErrors = new AtomicLong();
+ private AtomicLong mqttReconnects = new AtomicLong();
+
+ public void checkMqtt(Device device, DeviceCredentials deviceCredentials, RestClient restClient, LatencyMsg latency) {
+ try {
+ WsClient wsClient = subscribeToWebSocket(device.getId(), "tsSubCmds", restClient, latency);
+
+ long msgTs = System.currentTimeMillis();
+ long submittedValue = counter.incrementAndGet();
+ sendMqtt(deviceCredentials, submittedValue, msgTs, latency);
+
+ WsTelemetryResponse actualLatestTelemetry = wsClient.getLastMessage(wsResponseWaitSec);
+ if(actualLatestTelemetry == null) {
+ latency.setMqttTotalLatency(-1*wsResponseWaitSec);
+ } else {
+ validateWsResponse(actualLatestTelemetry, msgTs, submittedValue);
+ long responseReadyTs = System.currentTimeMillis();
+ latency.setMqttTotalLatency(responseReadyTs - msgTs);
+
+ }
+ wsClient.closeBlocking();
+ latency.setMqttErrors(mqttErrors.getAndSet(0L));
+ latency.setMqttReconnects(mqttReconnects.getAndSet(0L));
+ } catch (Exception ex) {
+ throw new IllegalStateException("Could not check mqtt: " + ex.getMessage(), ex);
+ }
+ }
+
+ public void checkHttp(Device device, DeviceCredentials deviceCredentials, RestClient restClient, LatencyMsg latency) {
+ try {
+ WsClient wsClient = subscribeToWebSocket(device.getId(), "tsSubCmds", restClient, latency);
+ long msgTs = System.currentTimeMillis();
+ long submittedValue = counter.incrementAndGet();
+ sendHttp(restClient, deviceCredentials, submittedValue, msgTs, latency);
+ WsTelemetryResponse actualLatestTelemetry = wsClient.getLastMessage(wsResponseWaitSec);
+ if(actualLatestTelemetry == null) {
+ latency.setHttpTotalLatency(-1*wsResponseWaitSec);
+ } else {
+ validateWsResponse(actualLatestTelemetry, msgTs, submittedValue);
+ long responseReadyTs = System.currentTimeMillis();
+ latency.setHttpTotalLatency(responseReadyTs - msgTs);
+ }
+ wsClient.closeBlocking();
+ } catch (Exception ex) {
+ throw new IllegalStateException("Could not check http: " + ex.getMessage(), ex);
+ }
+ }
+
+
+ private void validateWsResponse(WsTelemetryResponse response, long expectedTs, long expectedVal) {
+ try {
+ List