From b95d9498ca59300da02ae7b5c15977d023aa6864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20L=C3=A9aut=C3=A9?= Date: Wed, 21 Aug 2013 13:37:56 -0700 Subject: [PATCH] add version information to status --- .../com/metamx/druid/http/StatusResource.java | 98 ++++++++++++++++--- 1 file changed, 85 insertions(+), 13 deletions(-) diff --git a/client/src/main/java/com/metamx/druid/http/StatusResource.java b/client/src/main/java/com/metamx/druid/http/StatusResource.java index 2c4aed29614..ebe2f0e855a 100644 --- a/client/src/main/java/com/metamx/druid/http/StatusResource.java +++ b/client/src/main/java/com/metamx/druid/http/StatusResource.java @@ -1,9 +1,29 @@ +/* + * Druid - a distributed column store. + * Copyright (C) 2013 Metamarkets Group Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + package com.metamx.druid.http; +import com.fasterxml.jackson.annotation.JsonProperty; + import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.core.Response; /** */ @@ -11,21 +31,73 @@ import javax.ws.rs.core.Response; public class StatusResource { @GET - @Produces("text/plain") - public Response doGet() + @Produces("application/json") + public Status doGet() { - StringBuffer buf = new StringBuffer(); + return new Status( + StatusResource.class.getPackage().getImplementationVersion(), + new Memory(Runtime.getRuntime()) + ); + } - Runtime runtime = Runtime.getRuntime(); - long maxMemory = runtime.maxMemory(); - long totalMemory = runtime.totalMemory(); - long freeMemory = runtime.freeMemory(); + public static class Status { + final String version; + final Memory memory; - buf.append(String.format("Max Memory:\t%,18d\t%1$d%n", maxMemory)); - buf.append(String.format("Total Memory:\t%,18d\t%1$d%n", totalMemory)); - buf.append(String.format("Free Memory:\t%,18d\t%1$d%n", freeMemory)); - buf.append(String.format("Used Memory:\t%,18d\t%1$d%n", totalMemory - freeMemory)); + public Status(String version, Memory memory) + { + this.version = version; + this.memory = memory; + } - return Response.ok(buf.toString()).build(); + @JsonProperty + public String getVersion() + { + return version; + } + + @JsonProperty + public Memory getMemory() + { + return memory; + } + } + + public static class Memory { + final long maxMemory; + final long totalMemory; + final long freeMemory; + final long usedMemory; + + public Memory(Runtime runtime) { + maxMemory = runtime.maxMemory(); + totalMemory = runtime.totalMemory(); + freeMemory = runtime.freeMemory(); + usedMemory = totalMemory - freeMemory; + } + + @JsonProperty + public long getMaxMemory() + { + return maxMemory; + } + + @JsonProperty + public long getTotalMemory() + { + return totalMemory; + } + + @JsonProperty + public long getFreeMemory() + { + return freeMemory; + } + + @JsonProperty + public long getUsedMemory() + { + return usedMemory; + } } }