changeset 2769:6dbace3c1515

Make VmMemoryStatTypeAdapter include resident memory attribute Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2017-October/025252.html
author Miloslav Zezulka <mzezulka@redhat.com>
date Mon, 02 Oct 2017 15:09:26 +0200
parents 13f7923af927
children bde0a709ca30
files plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatTypeAdapter.java plugins/vm-memory/agent/src/test/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatTypeAdapterTest.java
diffstat 2 files changed, 32 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatTypeAdapter.java	Thu Oct 05 10:35:02 2017 -0400
+++ b/plugins/vm-memory/agent/src/main/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatTypeAdapter.java	Mon Oct 02 15:09:26 2017 +0200
@@ -57,6 +57,7 @@
     private static final String METASPACE_MIN_CAPACITY = "metaspaceMinCapacity";
     private static final String METASPACE_CAPACITY = "metaspaceCapacity";
     private static final String METASPACE_USED = "metaspaceUsed";
+    private static final String RESIDENT_MEMORY = "residentMemory";
     private static final String NAME = "name";
     private static final String CAPACITY = "capacity";
     private static final String MAX_CAPACITY = "maxCapacity";
@@ -80,12 +81,12 @@
         out.endArray();
     }
 
-    public void writeStat(JsonWriter out, VmMemoryStat stat) throws IOException {
+    private void writeStat(JsonWriter out, VmMemoryStat stat) throws IOException {
         out.beginObject();
         out.name(AGENT_ID);
-        out.value(stat.getAgentId());
+        writeString(out, stat.getAgentId());
         out.name(JVM_ID);
-        out.value(stat.getJvmId());
+        writeString(out, stat.getJvmId());
         out.name(TIMESTAMP);
         writeLong(out, stat.getTimeStamp());
         out.name(METASPACE_MAX_CAPACITY);
@@ -96,16 +97,18 @@
         writeLong(out, stat.getMetaspaceCapacity());
         out.name(METASPACE_USED);
         writeLong(out, stat.getMetaspaceUsed());
+        out.name(RESIDENT_MEMORY);
+        writeLong(out, stat.getResidentMemory());
         out.name(GENERATIONS);
-        out.beginArray();
-        for (Generation g : stat.getGenerations()) {
-            writeGeneration(out, g);
-        }
-        out.endArray();
+        writeGenerations(out, stat.getGenerations());
         out.endObject();
     }
 
-    public void writeLong(JsonWriter out, long value) throws IOException {
+    private void writeString(JsonWriter out, String value) throws IOException {
+        out.value(value);
+    }
+
+    private void writeLong(JsonWriter out, long value) throws IOException {
         // Write MongoDB representation of a Long
         out.beginObject();
         out.name(TYPE_LONG);
@@ -113,7 +116,15 @@
         out.endObject();
     }
 
-    public void writeGeneration(JsonWriter out, Generation g) throws IOException {
+    private void writeGenerations(JsonWriter out, Generation[] generations) throws IOException {
+        out.beginArray();
+        for (Generation g : generations) {
+            writeGeneration(out, g);
+        }
+        out.endArray();
+    }
+
+    private void writeGeneration(JsonWriter out, Generation g) throws IOException {
         out.beginObject();
         out.name(NAME);
         out.value(g.getName());
@@ -132,7 +143,7 @@
         out.endObject();
     }
 
-    public void writeSpace(JsonWriter out, Space s) throws IOException {
+    private void writeSpace(JsonWriter out, Space s) throws IOException {
         out.beginObject();
         out.name(INDEX);
         out.value(s.getIndex());
--- a/plugins/vm-memory/agent/src/test/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatTypeAdapterTest.java	Thu Oct 05 10:35:02 2017 -0400
+++ b/plugins/vm-memory/agent/src/test/java/com/redhat/thermostat/vm/memory/agent/internal/models/VmMemoryStatTypeAdapterTest.java	Mon Oct 02 15:09:26 2017 +0200
@@ -59,6 +59,7 @@
         stat.setMetaspaceMaxCapacity(4096l);
         stat.setMetaspaceMinCapacity(2048l);
         stat.setMetaspaceUsed(3000l);
+        stat.setResidentMemory(10000l);
         Generation[] gens = new Generation[1];
         Generation gen1 = new Generation();
         gen1.setCapacity(1002l);
@@ -76,6 +77,14 @@
         gen1.setSpaces(spaces);
         gens[0] = gen1;
         stat.setGenerations(gens);
-        assertJsonEquals("[{\"agentId\":\"AGENT-1\",\"jvmId\":\"VM-1\",\"timeStamp\":{\"$numberLong\":\"100\"},\"metaspaceMaxCapacity\":{\"$numberLong\":\"4096\"},\"metaspaceMinCapacity\":{\"$numberLong\":\"2048\"},\"metaspaceCapacity\":{\"$numberLong\":\"2000\"},\"metaspaceUsed\":{\"$numberLong\":\"3000\"},\"generations\":[{\"name\":\"Name\",\"capacity\":{\"$numberLong\":\"1002\"},\"maxCapacity\":{\"$numberLong\":\"2048\"},\"collector\":\"Collector 1\",\"spaces\":[{\"index\":1,\"name\":\"Space Name\",\"capacity\":{\"$numberLong\":\"500\"},\"maxCapacity\":{\"$numberLong\":\"1024\"},\"used\":{\"$numberLong\":\"400\"}}]}]}]", typeAdapter.toJson(Arrays.asList(stat)));
+        assertJsonEquals("[{\"agentId\":\"AGENT-1\",\"jvmId\":\"VM-1\","
+                         + "\"timeStamp\":{\"$numberLong\":\"100\"},"
+                         + "\"metaspaceMaxCapacity\":{\"$numberLong\":\"4096\"},"
+                         + "\"metaspaceMinCapacity\":{\"$numberLong\":\"2048\"},"
+                         + "\"metaspaceCapacity\":{\"$numberLong\":\"2000\"},"
+                         + "\"metaspaceUsed\":{\"$numberLong\":\"3000\"},"
+                         + "\"residentMemory\":{\"$numberLong\":\"10000\"},"
+                         + "\"generations\":[{\"name\":\"Name\",\"capacity\":{\"$numberLong\":\"1002\"},\"maxCapacity\":{\"$numberLong\":\"2048\"},\"collector\":\"Collector 1\",\"spaces\":[{\"index\":1,\"name\":\"Space Name\",\"capacity\":{\"$numberLong\":\"500\"},\"maxCapacity\":{\"$numberLong\":\"1024\"},\"used\":{\"$numberLong\":\"400\"}}]}]}]",
+                typeAdapter.toJson(Arrays.asList(stat)));
     }
 }
\ No newline at end of file