Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/airhacks/ping/boundary/HealthResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ public JsonObject osInfo() {
return this.watch.osInfo();
}

@GET
@Path("/hostname")
public String hostname() {
return this.watch.getHostname();
}
}
17 changes: 16 additions & 1 deletion src/main/java/com/airhacks/ping/control/ServerWatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.lang.management.OperatingSystemMXBean;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.time.ZonedDateTime;
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
Expand All @@ -22,19 +24,32 @@ public class ServerWatch {
private ZonedDateTime startTime;
private MemoryUsage heapUsageAtStartTime;
private MemoryMXBean memoryMxBean;
private String hostname;

@PostConstruct
public void initialize() {
this.initializeStartTime();
this.memoryMxBean = ManagementFactory.getMemoryMXBean();
this.heapUsageAtStartTime = this.memoryMxBean.getHeapMemoryUsage();

this.lookupHostname();
}

void initializeStartTime() {
this.startTime = ZonedDateTime.now();
}

void lookupHostname() {
try {
this.hostname = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ex) {
this.hostname = "<unknown> : " + ex.getMessage();
}
}

public String getHostname() {
return hostname;
}

public ZonedDateTime getDateTime() {
return this.startTime;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ <h2>Health</h2>
<article>
<a href="./resources/health/os-info">Operating System Info</a>
</article>
<article>
<a href="./resources/health/hostname">Hostname</a>
</article>
</section>
</body>
</html>