From: Jean-Baptiste Lievremont Date: Wed, 27 Aug 2014 15:26:08 +0000 (+0200) Subject: SONAR-5484 Add node address in system info X-Git-Tag: 4.5-RC1~71 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=055ca6aaf138acf489063707df70ec95c9899b86;p=sonarqube.git SONAR-5484 Add node address in system info --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/search/NodeHealth.java b/server/sonar-server/src/main/java/org/sonar/server/search/NodeHealth.java index 1d59e9b65a7..51f727e1b42 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/search/NodeHealth.java +++ b/server/sonar-server/src/main/java/org/sonar/server/search/NodeHealth.java @@ -27,6 +27,7 @@ import java.util.Date; public class NodeHealth { private boolean master; + private String address; private long jvmHeapMax; private long jvmHeapUsed; private long fsAvailable; @@ -44,6 +45,14 @@ public class NodeHealth { this.master = master; } + public String getAddress() { + return address; + } + + void setAddress(String address) { + this.address = address; + } + void setJvmHeapMax(long bytes) { this.jvmHeapMax = bytes; } @@ -122,13 +131,13 @@ public class NodeHealth { // Master/slave setMaster(nodesStats.getNode().isMasterNode()); + // Host IP and port + setAddress(nodesStats.getNode().getAddress().toString()); + // JVM Heap Usage setJvmHeapMax(nodesStats.getJvm().getMem().getHeapMax().bytes()); setJvmHeapUsed(nodesStats.getJvm().getMem().getHeapUsed().bytes()); - // OS Memory Usage ? - // nodesStats.getOs().getMem().freePercent(); - // Disk Usage setFsTotal(nodesStats.getFs().getTotal().getTotal().bytes()); setFsAvailable(nodesStats.getFs().getTotal().getAvailable().bytes()); diff --git a/server/sonar-server/src/test/java/org/sonar/server/search/SearchHealthMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/search/SearchHealthMediumTest.java index 4236b4fc851..05440c82ef9 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/search/SearchHealthMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/search/SearchHealthMediumTest.java @@ -21,6 +21,11 @@ package org.sonar.server.search; import org.junit.ClassRule; import org.junit.Test; +import org.sonar.api.rule.RuleKey; +import org.sonar.core.persistence.DbSession; +import org.sonar.server.db.DbClient; +import org.sonar.server.rule.RuleTesting; +import org.sonar.server.rule.db.RuleDao; import org.sonar.server.tester.ServerTester; import java.util.Date; @@ -35,6 +40,10 @@ public class SearchHealthMediumTest { @Test public void get_search_health(){ + DbSession dbSession = tester.get(DbClient.class).openSession(false); + tester.get(RuleDao.class).insert(dbSession, RuleTesting.newDto(RuleKey.of("javascript", "S001"))); + dbSession.commit(); + SearchHealth health = tester.get(SearchHealth.class); Date now = new Date(); @@ -44,6 +53,8 @@ public class SearchHealthMediumTest { NodeHealth nodeHealth = health.getNodesHealth().values().iterator().next(); assertThat(nodeHealth.isMaster()).isTrue(); + System.out.println(nodeHealth.getAddress()); + assertThat(nodeHealth.getAddress()).contains(":"); assertThat(nodeHealth.getJvmHeapUsedPercent()).contains("%"); assertThat(nodeHealth.getFsUsedPercent()).contains("%"); assertThat(nodeHealth.getJvmThreads()).isGreaterThanOrEqualTo(0L); diff --git a/server/sonar-web/src/main/webapp/WEB-INF/app/models/server.rb b/server/sonar-web/src/main/webapp/WEB-INF/app/models/server.rb index d1116ecf15c..8e8514384f4 100644 --- a/server/sonar-web/src/main/webapp/WEB-INF/app/models/server.rb +++ b/server/sonar-web/src/main/webapp/WEB-INF/app/models/server.rb @@ -99,6 +99,7 @@ class Server node_info=[] add_property(node_info, 'Node Name') { name } add_property(node_info, 'Node Type') { node_health.isMaster() ? 'Master' : 'Slave' } + add_property(node_info, 'Node Address') { node_health.getAddress() } add_property(node_info, 'JVM Heap Usage') { node_health.getJvmHeapUsedPercent() } add_property(node_info, 'JVM Threads') { node_health.getJvmThreads() } add_property(node_info, 'JVM Uptime') { Internal.i18n.ageFromNow(node_health.getJvmUpSince()) }