/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.apache.stratos.cartridge.agent.health.publisher;

import java.io.*;
import java.lang.Double;
import java.lang.Integer;
import java.lang.Runtime;
import java.lang.System;
import java.util.HashMap;
import java.util.Map;
import java.lang.management.ManagementFactory;

public class HealthPublisherClient {

    private static final int MB = 1024 * 1024;

    public Object getHealthStats() {

        Runtime runtime = Runtime.getRuntime();

        Map<String, Double> statsMap = new HashMap<String, Double>();

        //statsMap.put("Available Processors", (int)runtime.availableProcessors());
        statsMap.put("total_memory", (double)(runtime.totalMemory() / MB));
        //statsMap.put("max_memory", (int)(runtime.maxMemory() / MB));
        statsMap.put("used_memory", (double)((runtime.totalMemory() - runtime.freeMemory()) / MB));
        //statsMap.put("free_memory", (int)(runtime.freeMemory() / MB));
        statsMap.put("load_average", (double)ManagementFactory.getOperatingSystemMXBean().getSystemLoadAverage());
        //statsMap.put("member_id", Integer.parseInt(memberID));

        Object statObj = (Object)statsMap;

        return statObj;
    }

    public void run() {
        try {
            HealthPublisher publisher = new HealthPublisher();

            while (true) {
                Object healthStatObj = getHealthStats();
                publisher.update(healthStatObj);

                Thread.sleep(10000);
            }
        } catch(InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
    }
}
@@ -1338,120 +1338,28 @@
     
-//statsMap.put(%22Available Processors%22, (int)runtime.availableProcessors());%0A        statsMap.put(%22
+double 
 total
-_m
+M
 emory
-%22,
+ =
  (do
@@ -1383,33 +1383,32 @@
 alMemory() / MB)
-)
 ;%0A        //stat
@@ -1405,42 +1405,52 @@
     
-//statsMap.put(%22max_memory%22, (int)
+double usedMemory = (double)((totalMemory - 
 (run
@@ -1458,11 +1458,12 @@
 ime.
-max
+free
 Memo
@@ -1464,32 +1464,34 @@
 eeMemory() / MB)
+ )
 );%0A        stats
@@ -1489,99 +1489,69 @@
     
-statsMap.put(%22used_memory%22, (double)((runtime.totalMemory() - runtime.freeMemory()) / MB));
+double memoryConsumption = (usedMemory / totalMemory) * 100;%0A
 %0A   
@@ -1547,34 +1547,32 @@
 * 100;%0A%0A        
-//
 statsMap.put(%22fr
@@ -1573,54 +1573,46 @@
 ut(%22
-free_
 memory
-%22, (int)(runtime.freeMemory() / MB)
+_consumption%22, memoryConsumption
 );%0A 
@@ -1728,73 +1728,8 @@
 ());
-%0A        //statsMap.put(%22member_id%22, Integer.parseInt(memberID));
 %0A%0A  

Add memory consumption function to health checker module