Merge pull request #227 from metamx/version-in-status

Add maven version to status information
This commit is contained in:
cheddar 2013-08-21 13:59:19 -07:00
commit 8980a4ace9
1 changed files with 85 additions and 13 deletions

View File

@ -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;
}
}
}