Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Added HealthStatusProvider functionality and HealthStatusResource endpoint

Rich Turnerd16f05d888f5
diff --git a/client/src/main/java/org/openremote/app/client/assets/attributes/AttributeViewImpl.java b/client/src/main/java/org/openremote/app/client/assets/attributes/AttributeViewImpl.java
index 6ea547e1e..a1ed9990c 100644
--- a/client/src/main/java/org/openremote/app/client/assets/attributes/AttributeViewImpl.java
+++ b/client/src/main/java/org/openremote/app/client/assets/attributes/AttributeViewImpl.java
@@ -227,7 +227,6 @@ public class AttributeViewImpl extends FormGroup implements AttributeView {
if (connectionStatus != null) {
switch (connectionStatus) {
case DISABLED:
- case CLOSED:
addStyleName(environment.getWidgetStyle().BorderDefault());
break;
case CONNECTED:
diff --git a/manager/src/main/java/org/openremote/manager/Main.java b/manager/src/main/java/org/openremote/manager/Main.java
index fcf1b561e..8a8b45a97 100644
--- a/manager/src/main/java/org/openremote/manager/Main.java
+++ b/manager/src/main/java/org/openremote/manager/Main.java
@@ -42,6 +42,7 @@ import org.openremote.manager.rules.RulesetStorageService;
import org.openremote.manager.security.ManagerIdentityService;
import org.openremote.manager.setup.SetupService;
import org.openremote.manager.simulator.SimulatorService;
+import org.openremote.manager.system.HealthStatusService;
import org.openremote.manager.web.ManagerWebService;
import java.util.ArrayList;
@@ -69,7 +70,8 @@ public class Main {
new AssetDatapointService(),
new AssetAttributeLinkingService(),
new AssetProcessingService(),
- new MessageBrokerService()
+ new MessageBrokerService(),
+ new HealthStatusService()
));
ServiceLoader.load(Protocol.class).forEach(this::add);
addAll(Arrays.asList(
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/agent/AgentHealthStatusProvider.java
new file mode 100644
index 000000000..9e9e1b390
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentHealthStatusProvider.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.agent;
+
+import org.openremote.container.Container;
+import org.openremote.container.ContainerService;
+import org.openremote.model.asset.Asset;
+import org.openremote.model.asset.agent.ConnectionStatus;
+import org.openremote.model.asset.agent.ProtocolConfiguration;
+import org.openremote.model.attribute.AttributeRef;
+import org.openremote.model.system.HealthStatusProvider;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.Values;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class AgentHealthStatusProvider implements HealthStatusProvider, ContainerService {
+
+ public static final String NAME = "agents";
+ public static final String VERSION = "1.0";
+ protected AgentService agentService;
+
+ @Override
+ public void init(Container container) throws Exception {
+ agentService = container.getService(AgentService.class);
+ }
+
+ @Override
+ public void start(Container container) throws Exception {
+
+ }
+
+ @Override
+ public void stop(Container container) throws Exception {
+
+ }
+
+ @Override
+ public String getHealthStatusName() {
+ return NAME;
+ }
+
+ @Override
+ public String getHealthStatusVersion() {
+ return VERSION;
+ }
+
+ @Override
+ public Value getHealthStatus() {
+ AtomicInteger connectedCount = new AtomicInteger(0);
+ AtomicInteger disabledCount = new AtomicInteger(0);
+ AtomicInteger errorCount = new AtomicInteger(0);
+ AtomicInteger otherCount = new AtomicInteger(0);
+
+ ObjectValue objectValue = Values.createObject();
+ objectValue.put("agents", agentService.getAgents().size());
+ objectValue.put("protocols", agentService.protocols.size());
+
+ for (Asset agent : agentService.getAgents().values()) {
+ AtomicInteger total = new AtomicInteger(0);
+ AtomicInteger connected = new AtomicInteger(0);
+ AtomicInteger disabled = new AtomicInteger(0);
+ AtomicInteger error = new AtomicInteger(0);
+ AtomicInteger other = new AtomicInteger(0);
+
+ ObjectValue agentValue = Values.createObject();
+ agentValue.put("name", agent.getName());
+
+ // Get protocol configurations for this agent
+ agentService.protocolConfigurations.entrySet()
+ .stream()
+ .filter(protocolConfigInfo -> Objects.equals(agent.getId(), protocolConfigInfo.getKey().getEntityId()))
+ .forEach(protocolConfigInfo -> {
+
+ total.incrementAndGet();
+
+ ConnectionStatus connectionStatus = protocolConfigInfo.getValue().value;
+ if (connectionStatus != null) {
+ switch (connectionStatus) {
+
+ case UNKNOWN:
+ case DISCONNECTED:
+ case CONNECTING:
+ case DISCONNECTING:
+ case WAITING:
+ otherCount.incrementAndGet();
+ other.incrementAndGet();
+ break;
+ case CONNECTED:
+ connectedCount.incrementAndGet();
+ connected.incrementAndGet();
+ break;
+ case DISABLED:
+ disabledCount.incrementAndGet();
+ disabled.incrementAndGet();
+ break;
+ case ERROR_AUTHENTICATION:
+ case ERROR_CONFIGURATION:
+ case ERROR:
+ errorCount.incrementAndGet();
+ error.incrementAndGet();
+ break;
+ }
+ } else {
+ otherCount.incrementAndGet();
+ other.incrementAndGet();
+ }
+
+ ObjectValue protocol = Values.createObject();
+
+ protocol.put(
+ "protocol",
+ ProtocolConfiguration.getProtocolName(protocolConfigInfo.getValue().key).orElse(null));
+
+ protocol.put(
+ "status",
+ protocolConfigInfo.getValue().value == null ? null : protocolConfigInfo.getValue().value.name());
+
+ List<AttributeRef> linkedAttributes = agentService.linkedAttributes.get(protocolConfigInfo.getKey());
+ protocol.put("linkedAttributes", linkedAttributes != null ? linkedAttributes.size() : 0);
+ agentValue.put(protocolConfigInfo.getKey().getAttributeName(), protocol);
+ });
+
+ agentValue.put("totalProtocolConfigs", total.get());
+ agentValue.put("connectedProtocolConfigs", connected.get());
+ agentValue.put("errorProtocolConfigs", error.get());
+ agentValue.put("disabledProtocolConfigs", disabled.get());
+ agentValue.put("otherProtocolConfigs", other.get());
+ objectValue.put(agent.getId(), agentValue);
+ }
+
+ objectValue.put("totalProtocolConfigs", agentService.protocolConfigurations.size());
+ objectValue.put("connectedProtocolConfigs", connectedCount.get());
+ objectValue.put("errorProtocolConfigs", errorCount.get());
+ objectValue.put("disabledProtocolConfigs", disabledCount.get());
+ objectValue.put("otherProtocolConfigs", otherCount.get());
+ objectValue.put("linkedAttributes", agentService.linkedAttributes.values().stream().mapToInt(List::size).sum());
+
+ return objectValue;
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/agent/AgentService.java b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
index f7e8b70fd..dd39fe800 100644
--- a/manager/src/main/java/org/openremote/manager/agent/AgentService.java
+++ b/manager/src/main/java/org/openremote/manager/agent/AgentService.java
@@ -93,7 +93,7 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
protected ClientEventService clientEventService;
protected final Map<AttributeRef, Pair<AssetAttribute, ConnectionStatus>> protocolConfigurations = new HashMap<>();
protected final Map<String, Protocol> protocols = new HashMap<>();
- protected final List<AttributeRef> linkedAttributes = new ArrayList<>();
+ protected final Map<AttributeRef, List<AttributeRef>> linkedAttributes = new HashMap<>();
protected LocalAgentConnector localAgentConnector;
protected Map<String, Asset> agentMap;
@@ -572,8 +572,19 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
return;
}
- attributes.removeIf(attr -> linkedAttributes.contains(attr.getReferenceOrThrow()));
- linkedAttributes.addAll(attributes.stream().map(AssetAttribute::getReferenceOrThrow).collect(Collectors.toList()));
+ attributes.removeIf(attr ->
+ linkedAttributes.values().stream()
+ .anyMatch(linkedAttributes -> linkedAttributes.contains(attr.getReferenceOrThrow())));
+
+ linkedAttributes.compute(
+ protocolConfiguration.getReferenceOrThrow(),
+ (protocolRef, linkedAttrs) -> {
+ if (linkedAttrs == null) {
+ linkedAttrs = new ArrayList<>(attributes.size());
+ }
+ linkedAttrs.addAll(attributes.stream().map(AssetAttribute::getReferenceOrThrow).collect(Collectors.toList()));
+ return linkedAttrs;
+ });
try {
LOG.finest("Linking protocol attributes to: " + protocol.getProtocolName());
@@ -596,8 +607,13 @@ public class AgentService extends RouteBuilder implements ContainerService, Asse
return;
}
- attributes.removeIf(attr -> !linkedAttributes.contains(attr.getReferenceOrThrow()));
- linkedAttributes.removeAll(attributes.stream().map(AssetAttribute::getReferenceOrThrow).collect(Collectors.toList()));
+ linkedAttributes.computeIfPresent(
+ protocolConfiguration.getReferenceOrThrow(),
+ (protocolRef, linkedAttrs) -> {
+ linkedAttrs.removeAll(attributes.stream().map(AssetAttribute::getReferenceOrThrow).collect(Collectors.toList()));
+ return linkedAttrs.isEmpty() ? null : linkedAttrs;
+ }
+ );
try {
LOG.finest("Unlinking protocol attributes from: " + protocol.getProtocolName());
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
index 0b96475a8..ad90905eb 100644
--- a/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesEngine.java
@@ -159,22 +159,24 @@ public class RulesEngine<T extends Ruleset> {
return false;
}
+ public int getExecutionErrorDeploymentCount() {
+ return (int)deployments.values().stream().filter(deployment -> deployment.getStatus() == EXECUTION_ERROR).count();
+ }
+
+ public int getCompilationErrorDeploymentCount() {
+ return (int)deployments.values().stream().filter(deployment -> deployment.getStatus() == COMPILATION_ERROR).count();
+ }
+
public RuntimeException getError() {
- List<RulesetDeployment> deploymentsWithCompilationError = new ArrayList<>();
- List<RulesetDeployment> deploymentsWithExecutionError = new ArrayList<>();
- for (RulesetDeployment deployment : deployments.values()) {
- if (deployment.getStatus() == COMPILATION_ERROR) {
- deploymentsWithCompilationError.add(deployment);
- } else if (deployment.getStatus() == EXECUTION_ERROR) {
- deploymentsWithExecutionError.add(deployment);
- }
- }
- if (deploymentsWithCompilationError.size() > 0 || deploymentsWithExecutionError.size() > 0) {
+ long executionErrorCount = getExecutionErrorDeploymentCount();
+ long compilationErrorCount = getCompilationErrorDeploymentCount();
+
+ if (executionErrorCount > 0 || compilationErrorCount > 0) {
return new RuntimeException(
"Ruleset deployments have errors, failed compilation: "
- + deploymentsWithCompilationError.size()
+ + compilationErrorCount
+ ", failed execution: "
- + deploymentsWithExecutionError.size() + " - on: " + this
+ + executionErrorCount + " - on: " + this
);
}
return null;
diff --git a/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
new file mode 100644
index 000000000..985a7cbcd
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/rules/RulesHealthStatusProvider.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.rules;
+
+import org.openremote.container.Container;
+import org.openremote.container.ContainerService;
+import org.openremote.model.rules.AssetRuleset;
+import org.openremote.model.rules.TenantRuleset;
+import org.openremote.model.system.HealthStatusProvider;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.Values;
+
+public class RulesHealthStatusProvider implements HealthStatusProvider, ContainerService {
+
+ public static final String NAME = "rules";
+ public static final String VERSION = "1.0";
+
+ protected RulesService rulesService;
+
+ @Override
+ public void init(Container container) throws Exception {
+ rulesService = container.getService(RulesService.class);
+ }
+
+ @Override
+ public void start(Container container) throws Exception {
+
+ }
+
+ @Override
+ public void stop(Container container) throws Exception {
+
+ }
+
+ @Override
+ public String getHealthStatusName() {
+ return NAME;
+ }
+
+ @Override
+ public String getHealthStatusVersion() {
+ return VERSION;
+ }
+
+ @Override
+ public Value getHealthStatus() {
+ int totalEngines = rulesService.tenantEngines.size() + rulesService.assetEngines.size();
+ int stoppedEngines = 0;
+ int errorEngines = 0;
+
+ if (rulesService.globalEngine != null) {
+ totalEngines++;
+ if (!rulesService.globalEngine.isRunning()) {
+ stoppedEngines++;
+ }
+ if (rulesService.globalEngine.isError()) {
+ errorEngines++;
+ }
+ }
+
+ ObjectValue tenantEngines = Values.createObject();
+
+ for (RulesEngine<TenantRuleset> tenantEngine : rulesService.tenantEngines.values()) {
+ if (!tenantEngine.isRunning()) {
+ stoppedEngines++;
+ }
+ if (tenantEngine.isError()) {
+ errorEngines++;
+ }
+
+ tenantEngines.put(tenantEngine.getId().getRealmId().orElse(""), getEngineHealthStatus(tenantEngine));
+ }
+
+ ObjectValue assetEngines = Values.createObject();
+
+ for (RulesEngine<AssetRuleset> assetEngine : rulesService.assetEngines.values()) {
+ if (!assetEngine.isRunning()) {
+ stoppedEngines++;
+ }
+
+ if (assetEngine.isError()) {
+ errorEngines++;
+ }
+
+ assetEngines.put(assetEngine.getId().getAssetId().orElse(""), getEngineHealthStatus(assetEngine));
+ }
+
+ ObjectValue objectValue = Values.createObject();
+ objectValue.put("totalEngines", totalEngines);
+ objectValue.put("stoppedEngines", stoppedEngines);
+ objectValue.put("errorEngines", errorEngines);
+ if (rulesService.globalEngine != null) {
+ objectValue.put("global", getEngineHealthStatus(rulesService.globalEngine));
+ }
+ objectValue.put("tenant", tenantEngines);
+ objectValue.put("asset", assetEngines);
+ return objectValue;
+ }
+
+ protected ObjectValue getEngineHealthStatus(RulesEngine rulesEngine) {
+ boolean isError = rulesEngine.isError();
+ int totalDeployments = rulesEngine.deployments.size();
+ int executionErrorDeployments = rulesEngine.getExecutionErrorDeploymentCount();
+ int compilationErrorDeployments = rulesEngine.getExecutionErrorDeploymentCount();
+ ObjectValue val = Values.createObject();
+ val.put("isError", isError);
+ val.put("totalDeployments", totalDeployments);
+ val.put("executionErrorDeployments", executionErrorDeployments);
+ val.put("compilationErrorDeployments", compilationErrorDeployments);
+
+ ObjectValue deployments = Values.createObject();
+
+ for (Object obj : rulesEngine.deployments.values()) {
+ RulesetDeployment deployment = (RulesetDeployment)obj;
+ ObjectValue dVal = Values.createObject();
+ dVal.put("name", deployment.getName());
+ dVal.put("status", deployment.getStatus().name());
+ dVal.put("error", deployment.getError() != null ? deployment.getError().getMessage() : null);
+ deployments.put(Long.toString(deployment.getId()), dVal);
+ }
+
+ val.put("deployments", deployments);
+
+ return val;
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/system/HealthStatusResourceImpl.java b/manager/src/main/java/org/openremote/manager/system/HealthStatusResourceImpl.java
new file mode 100644
index 000000000..efd083924
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/system/HealthStatusResourceImpl.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.system;
+
+import org.openremote.model.system.HealthStatusProvider;
+import org.openremote.model.system.HealthStatusResource;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Values;
+
+import java.util.List;
+
+public class HealthStatusResourceImpl implements HealthStatusResource {
+
+ protected List<HealthStatusProvider> healthStatusProviderList;
+
+ public HealthStatusResourceImpl(List<HealthStatusProvider> healthStatusProviderList) {
+ this.healthStatusProviderList = healthStatusProviderList;
+ }
+
+ @Override
+ public ObjectValue getHealthStatus() {
+ ObjectValue objectValue = Values.createObject();
+
+ healthStatusProviderList.forEach(healthStatusProvider -> {
+ ObjectValue providerValue = Values.createObject();
+ providerValue.put("version", healthStatusProvider.getHealthStatusVersion());
+ providerValue.put("data", healthStatusProvider.getHealthStatus());
+ objectValue.put(healthStatusProvider.getHealthStatusName(), providerValue);
+ }
+ );
+
+ return objectValue;
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/system/HealthStatusService.java b/manager/src/main/java/org/openremote/manager/system/HealthStatusService.java
new file mode 100644
index 000000000..5e01e8f88
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/system/HealthStatusService.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.system;
+
+import org.openremote.container.Container;
+import org.openremote.container.ContainerService;
+import org.openremote.container.web.WebService;
+import org.openremote.model.system.HealthStatusProvider;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ServiceLoader;
+
+/**
+ * This service is here to initialise the {@link org.openremote.model.system.HealthStatusResource}.
+ */
+public class HealthStatusService implements ContainerService {
+
+ protected List<HealthStatusProvider> healthStatusProviderList = new ArrayList<>();
+
+ @Override
+ public void init(Container container) throws Exception {
+
+ ServiceLoader.load(HealthStatusProvider.class).forEach(healthStatusProviderList::add);
+
+ for (HealthStatusProvider healthStatusProvider : healthStatusProviderList) {
+ if (healthStatusProvider instanceof ContainerService) {
+ ((ContainerService) healthStatusProvider).init(container);
+ }
+ }
+
+ container.getService(WebService.class).getApiSingletons().add(
+ new HealthStatusResourceImpl(healthStatusProviderList)
+ );
+ }
+
+ @Override
+ public void start(Container container) throws Exception {
+ for (HealthStatusProvider healthStatusProvider : healthStatusProviderList) {
+ if (healthStatusProvider instanceof ContainerService) {
+ ((ContainerService) healthStatusProvider).start(container);
+ }
+ } }
+
+ @Override
+ public void stop(Container container) throws Exception {
+ for (HealthStatusProvider healthStatusProvider : healthStatusProviderList) {
+ if (healthStatusProvider instanceof ContainerService) {
+ ((ContainerService) healthStatusProvider).stop(container);
+ }
+ }
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/system/JvmHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/system/JvmHealthStatusProvider.java
new file mode 100644
index 000000000..285b2644b
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/system/JvmHealthStatusProvider.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.system;
+
+import org.openremote.model.system.HealthStatusProvider;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.Values;
+
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryMXBean;
+import java.lang.management.RuntimeMXBean;
+import java.lang.management.ThreadMXBean;
+
+public class JvmHealthStatusProvider implements HealthStatusProvider {
+
+ public static final String NAME = "jvm";
+ public static final String VERSION = "1.0";
+
+ @Override
+ public String getHealthStatusName() {
+ return NAME;
+ }
+
+ @Override
+ public String getHealthStatusVersion() {
+ return VERSION;
+ }
+
+ @Override
+ public Value getHealthStatus() {
+ ObjectValue objectValue = Values.createObject();
+ com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
+ RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
+ ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
+ MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
+
+ objectValue.put("startTimeMillis", runtimeMXBean.getStartTime());
+ objectValue.put("upTimeMillis", runtimeMXBean.getUptime());
+ objectValue.put("processLoadPercentage", operatingSystemMXBean.getProcessCpuLoad()*100);
+ objectValue.put("heapMemoryUsageMB", memoryMXBean.getHeapMemoryUsage().getUsed() / (1024F*1024F));
+ objectValue.put("nonHeapMemoryUsageMB", memoryMXBean.getNonHeapMemoryUsage().getUsed() / (1024F*1024F));
+ objectValue.put("peakThreadCount", threadMXBean.getPeakThreadCount());
+ objectValue.put("threadCount", threadMXBean.getThreadCount());
+ objectValue.put("daemonThreadCount", threadMXBean.getDaemonThreadCount());
+
+ return objectValue;
+ }
+}
diff --git a/manager/src/main/java/org/openremote/manager/system/SystemHealthStatusProvider.java b/manager/src/main/java/org/openremote/manager/system/SystemHealthStatusProvider.java
new file mode 100644
index 000000000..2d8df19a7
--- /dev/null
+++ b/manager/src/main/java/org/openremote/manager/system/SystemHealthStatusProvider.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.manager.system;
+
+import org.openremote.model.system.HealthStatusProvider;
+import org.openremote.model.value.ObjectValue;
+import org.openremote.model.value.Value;
+import org.openremote.model.value.Values;
+
+import java.io.File;
+import java.lang.management.ManagementFactory;
+
+public class SystemHealthStatusProvider implements HealthStatusProvider {
+
+ public static final String NAME = "system";
+ public static final String VERSION = "1.0";
+
+ @Override
+ public String getHealthStatusName() {
+ return NAME;
+ }
+
+ @Override
+ public String getHealthStatusVersion() {
+ return VERSION;
+ }
+
+ @Override
+ public Value getHealthStatus() {
+ ObjectValue objectValue = Values.createObject();
+ com.sun.management.OperatingSystemMXBean operatingSystemMXBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
+ File[] roots = File.listRoots();
+
+ objectValue.put("systemLoadPercentage", operatingSystemMXBean.getSystemCpuLoad()*100);
+ objectValue.put("totalPhysicalMemoryMB", operatingSystemMXBean.getTotalPhysicalMemorySize() / (1024F*1024F));
+ objectValue.put("freePhysicalMemoryMB", operatingSystemMXBean.getFreePhysicalMemorySize() / (1024F*1024F));
+ objectValue.put("committedVirtualMemoryMB", operatingSystemMXBean.getCommittedVirtualMemorySize() / (1024F*1024F));
+ objectValue.put("totalSwapSpaceMB", operatingSystemMXBean.getTotalSwapSpaceSize() / (1024F*1024F));
+ objectValue.put("freeSwapSpaceMB", operatingSystemMXBean.getFreeSwapSpaceSize() / (1024F*1024F));
+
+ ObjectValue rootsObj = Values.createObject();
+
+ for (File root : roots) {
+ ObjectValue rootObj = Values.createObject();
+ rootObj.put("totalSpaceMB", root.getTotalSpace() / (1024F*1024F));
+ rootObj.put("freeSpaceMB", root.getFreeSpace() / (1024F*1024F));
+ String name = root.getAbsolutePath();
+ name = name.replace("/","").replace("\\", "").replace(":", "");
+ rootsObj.put(name, rootObj);
+ }
+
+ objectValue.put("filesystem", rootsObj);
+
+ return objectValue;
+ }
+}
diff --git a/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider b/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
new file mode 100644
index 000000000..abd7c1225
--- /dev/null
+++ b/manager/src/main/resources/META-INF/services/org.openremote.model.system.HealthStatusProvider
@@ -0,0 +1,4 @@
+org.openremote.manager.system.JvmHealthStatusProvider
+org.openremote.manager.system.SystemHealthStatusProvider
+org.openremote.manager.rules.RulesHealthStatusProvider
+org.openremote.manager.agent.AgentHealthStatusProvider
\ No newline at end of file
diff --git a/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java b/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java
index 4c709782c..201a64ba2 100644
--- a/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java
+++ b/model/src/main/java/org/openremote/model/asset/agent/ConnectionStatus.java
@@ -66,11 +66,6 @@ public enum ConnectionStatus {
*/
WAITING,
- /**
- * Connection is closed and cannot be re-used.
- */
- CLOSED,
-
/**
* An authentication related error has occurred.
*/
diff --git a/model/src/main/java/org/openremote/model/system/HealthStatusProvider.java b/model/src/main/java/org/openremote/model/system/HealthStatusProvider.java
new file mode 100644
index 000000000..18379ec25
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/system/HealthStatusProvider.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.system;
+
+import org.openremote.model.value.Value;
+
+/**
+ * Allows implementors to provide health status data that is relevant to them.
+ */
+public interface HealthStatusProvider {
+
+ String getHealthStatusName();
+
+ String getHealthStatusVersion();
+
+ Value getHealthStatus();
+}
diff --git a/model/src/main/java/org/openremote/model/system/HealthStatusResource.java b/model/src/main/java/org/openremote/model/system/HealthStatusResource.java
new file mode 100644
index 000000000..1c25e01e8
--- /dev/null
+++ b/model/src/main/java/org/openremote/model/system/HealthStatusResource.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017, OpenRemote Inc.
+ *
+ * See the CONTRIBUTORS.txt file in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.openremote.model.system;
+
+import org.openremote.model.http.SuccessStatusCode;
+import org.openremote.model.value.ObjectValue;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+@Path("health")
+public interface HealthStatusResource {
+
+ @GET
+ @Produces(APPLICATION_JSON)
+ @SuccessStatusCode(200)
+ ObjectValue getHealthStatus();
+}
diff --git a/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy b/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy
index ae41a0024..08307fbb2 100644
--- a/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy
+++ b/test/src/main/groovy/org/openremote/test/ManagerContainerTrait.groovy
@@ -26,6 +26,7 @@ import org.openremote.manager.rules.RulesetStorageService
import org.openremote.manager.security.ManagerIdentityService
import org.openremote.manager.setup.SetupService
import org.openremote.manager.simulator.SimulatorService
+import org.openremote.manager.system.HealthStatusService
import org.openremote.manager.web.ManagerWebService
import spock.util.concurrent.PollingConditions
@@ -74,6 +75,7 @@ trait ManagerContainerTrait extends ContainerTrait {
new NotificationService(),
new ConsoleAppService(),
new ManagerWebService(),
+ new HealthStatusService(),
*additionalServices
] as Iterable<ContainerService>