usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [32/50] [abbrv] usergrid git commit: Add status/memory endpoint to get heap usage, max heap, and free heap.
Date Mon, 02 May 2016 17:55:03 GMT
Add status/memory endpoint to get heap usage, max heap, and free heap.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/fa5b19f6
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/fa5b19f6
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/fa5b19f6

Branch: refs/heads/USERGRID-1246-MASTER
Commit: fa5b19f6d51a43dbe6046084a20d83e67ee70056
Parents: 8da7334
Author: Mike Dunker <mdunker@apigee.com>
Authored: Thu Apr 21 10:08:25 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Mon May 2 10:49:34 2016 -0700

----------------------------------------------------------------------
 .../org/apache/usergrid/utils/StringUtils.java  |  8 +++++++
 .../org/apache/usergrid/rest/RootResource.java  | 23 ++++++++++++++++++++
 2 files changed, 31 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/fa5b19f6/stack/core/src/main/java/org/apache/usergrid/utils/StringUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/utils/StringUtils.java b/stack/core/src/main/java/org/apache/usergrid/utils/StringUtils.java
index b91b866..6bb44d8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/utils/StringUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/utils/StringUtils.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.utils;
 
 
+import java.text.DecimalFormat;
 import java.util.Arrays;
 
 import org.apache.commons.io.IOUtils;
@@ -169,4 +170,11 @@ public class StringUtils extends org.apache.commons.lang.StringUtils
{
         }
         return null;
     }
+
+    public static String readableByteSize(long size) {
+        if(size <= 0) return "0";
+        final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" };
+        int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
+        return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + "
" + units[digitGroups];
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/fa5b19f6/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
index 75ed567..9701105 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
@@ -248,6 +248,29 @@ public class RootResource extends AbstractContextResource implements
MetricProce
 
     }
 
+    @GET
+    @Path("/status/memory")
+    @JSONP
+    @Produces({MediaType.APPLICATION_JSON, "application/javascript"})
+    public ApiResponse getMemoryStats(){
+
+        ApiResponse response = createApiResponse();
+
+        ObjectNode node = JsonNodeFactory.instance.objectNode();
+
+        long heapSize = Runtime.getRuntime().totalMemory();
+        long heapMaxSize = Runtime.getRuntime().maxMemory();
+        long heapFreeSize = Runtime.getRuntime().freeMemory();
+
+        node.put( "currentHeap", org.apache.usergrid.utils.StringUtils.readableByteSize(heapSize)
);
+        node.put( "maxHeap", org.apache.usergrid.utils.StringUtils.readableByteSize(heapMaxSize)
);
+        node.put( "freeHeap", org.apache.usergrid.utils.StringUtils.readableByteSize(heapFreeSize)
);
+
+        response.setProperty( "status", node );
+        return response;
+
+    }
+
 
 
     private void dumpMetrics( ObjectNode node ) {


Mime
View raw message