package com.metamx.druid.http;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;

/**
 */
@Path("/{a:status|health}")
public class StatusResource
{
  @GET
  @Produces("text/plain")
  public Response doGet()
  {
    StringBuffer buf = new StringBuffer();

    Runtime runtime = Runtime.getRuntime();
    long maxMemory = runtime.maxMemory();
    long totalMemory = runtime.totalMemory();
    long freeMemory = runtime.freeMemory();

    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));

    return Response.ok(buf.toString()).build();
  }
}

@@ -1,33 +1,903 @@
-package com.metamx.druid.http
+/*%0A * Druid - a distributed column store.%0A * Copyright (C) 2013  Metamarkets Group Inc.%0A *%0A * This program is free software; you can redistribute it and/or%0A * modify it under the terms of the GNU General Public License%0A * as published by the Free Software Foundation; either version 2%0A * of the License, or (at your option) any later version.%0A *%0A * This program is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU General Public License for more details.%0A *%0A * You should have received a copy of the GNU General Public License%0A * along with this program; if not, write to the Free Software%0A * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.%0A */%0A%0Apackage com.metamx.druid.http;%0A%0Aimport com.fasterxml.jackson.annotation.JsonProperty
 ;%0A%0Ai
@@ -976,42 +976,8 @@
 ces;
-%0Aimport javax.ws.rs.core.Response;
 %0A%0A/*
@@ -1064,147 +1064,756 @@
 es(%22
-text/plain%22)%0A  public Response doGet()%0A  %7B%0A    StringBuffer buf = new StringBuffer();%0A%0A    Runtime runtime = Runtime.getRuntime();
+application/json%22)%0A  public Status doGet()%0A  %7B%0A    return new Status(%0A        StatusResource.class.getPackage().getImplementationVersion(),%0A        new Memory(Runtime.getRuntime())%0A    );%0A  %7D%0A%0A  public static class Status %7B%0A    final String version;%0A    final Memory memory;%0A%0A    public Status(String version, Memory memory)%0A    %7B%0A      this.version = version;%0A      this.memory = memory;%0A    %7D%0A%0A    @JsonProperty%0A    public String getVersion()%0A    %7B%0A      return version;%0A    %7D%0A%0A    @JsonProperty%0A    public Memory getMemory()%0A    %7B%0A      return memory;%0A    %7D%0A  %7D%0A%0A  public static class Memory %7B%0A    final long maxMemory;%0A    final long totalMemory;%0A    final long freeMemory;%0A    final long usedMemory;%0A%0A    public Memory(Runtime runtime) %7B
 %0A    
-long
+ 
  max
@@ -1846,20 +1846,17 @@
 ();%0A    
-long
+ 
  totalMe
@@ -1889,20 +1889,17 @@
 ();%0A    
-long
+ 
  freeMem
@@ -1930,67 +1930,127 @@
 ();%0A
-%0A
+  
     
-buf.append(String.format(%22
+usedMemory = totalMemory - freeMemory;%0A    %7D%0A%0A    @JsonProperty%0A    public long get
 Max
- 
 Memory
-:%5Ct%25,18d%5Ct%251$d%25n%22,
+()%0A    %7B%0A      return
  max
@@ -2059,72 +2059,86 @@
 mory
-))
 ;%0A    
-buf.append(String.format(%22
+%7D%0A%0A    @JsonProperty%0A    public long get
 Total
- 
 Memory
-:%5Ct%25,18d%5Ct%251$d%25n%22,
+()%0A    %7B%0A      return
  tot
@@ -2149,71 +2149,85 @@
 mory
-))
 ;%0A    
-buf.append(String.format(%22
+%7D%0A%0A    @JsonProperty%0A    public long get
 Free
- 
 Memory
-:%5Ct%25,18d%5Ct%251$d%25n%22,
+()%0A    %7B%0A      return
  fre
@@ -2237,148 +2237,103 @@
 mory
-))
 ;%0A    
-buf.append(String.format(%22Used Memory:%5Ct%25,18d%5Ct%251$d%25n%22, totalMemory - freeMemory));%0A%0A
+%7D%0A%0A    @JsonProperty%0A    public long getUsedMemory()%0A    %7B%0A 
     
+ 
 return 
-Response.ok(buf.toString()).build();
+usedMemory;%0A    %7D
 %0A  %7D

add version information to status