提交 3f51ef63 编写于 作者: F fjy

Merge branch 'guice' into guice-rt

/*
* 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()
{
return new Status(
StatusResource.class.getPackage().getImplementationVersion(),
new Memory(Runtime.getRuntime())
);
}
public static class Status {
final String version;
final Memory memory;
public Status(String version, Memory memory)
{
StringBuffer buf = new StringBuffer();
this.version = version;
this.memory = memory;
}
@JsonProperty
public String getVersion()
{
return version;
}
Runtime runtime = Runtime.getRuntime();
long maxMemory = runtime.maxMemory();
long totalMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();
@JsonProperty
public Memory getMemory()
{
return 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 static class Memory {
final long maxMemory;
final long totalMemory;
final long freeMemory;
final long usedMemory;
return Response.ok(buf.toString()).build();
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;
}
}
}
......@@ -211,7 +211,7 @@ public class OmniSegmentLoader implements SegmentLoader
private synchronized void addSegment(DataSegment segment)
{
if (! segments.add(segment)) {
if (segments.add(segment)) {
currSize += segment.getSize();
}
}
......
......@@ -210,7 +210,7 @@ public class SingleSegmentLoader implements SegmentLoader
private synchronized void addSegment(DataSegment segment)
{
if (! segments.add(segment)) {
if (segments.add(segment)) {
currSize += segment.getSize();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册