You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2013/07/11 07:18:15 UTC

[24/27] aplying 0001-Refactor-usage-module-to-apache-stratos.patch

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/clients/UsageServiceClient.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/clients/UsageServiceClient.java b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/clients/UsageServiceClient.java
new file mode 100644
index 0000000..350fb82
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/clients/UsageServiceClient.java
@@ -0,0 +1,116 @@
+/*
+ *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.usage.ui.clients;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.CarbonConstants;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.ui.CarbonUIUtil;
+import org.wso2.carbon.usage.stub.beans.xsd.InstanceUsageStatics;
+import org.wso2.carbon.usage.stub.beans.xsd.PaginatedInstanceUsage;
+import org.wso2.carbon.usage.stub.beans.xsd.PaginatedTenantUsageInfo;
+import org.wso2.carbon.usage.stub.beans.xsd.TenantUsage;
+import org.wso2.carbon.usage.stub.services.UsageServiceStub;
+import org.wso2.carbon.utils.ServerConstants;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpSession;
+
+public class UsageServiceClient {
+    private static final Log log = LogFactory.getLog(UsageServiceClient.class);
+
+    private UsageServiceStub stub;
+    private String epr;
+
+    public UsageServiceClient(
+            String cookie, String backendServerURL, ConfigurationContext configContext)
+            throws RegistryException {
+
+        epr = backendServerURL + "UsageService";
+
+        try {
+            stub = new UsageServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate UsageService service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public UsageServiceClient(ServletConfig config, HttpSession session)
+            throws RegistryException {
+
+        String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
+        String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
+        ConfigurationContext configContext = (ConfigurationContext) config.
+                getServletContext().getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
+        epr = backendServerURL + "UsageService";
+
+        try {
+            stub = new UsageServiceStub(configContext, epr);
+
+            ServiceClient client = stub._getServiceClient();
+            Options option = client.getOptions();
+            option.setManageSession(true);
+            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);
+
+        } catch (AxisFault axisFault) {
+            String msg = "Failed to initiate UsageService service client. " + axisFault.getMessage();
+            log.error(msg, axisFault);
+            throw new RegistryException(msg, axisFault);
+        }
+    }
+
+    public TenantUsage retrieveCurrentTenantUsage(String yearMonth) throws Exception {
+        return stub.retrieveCurrentTenantUsage(yearMonth);
+    }
+
+    public TenantUsage[] retrieveTenantUsages(String yearMonth) throws Exception {
+        return stub.retrieveTenantUsages(yearMonth);
+    }
+
+    public PaginatedTenantUsageInfo retrievePaginatedTenantUsages(String yearMonth, int pageNumber,
+                                                                  int entriesPerPage) throws Exception {
+        return stub.retrievePaginatedTenantUsages(yearMonth, pageNumber, entriesPerPage);
+    }
+
+    public TenantUsage retrieveTenantUsage(String yearMonth, int tenantId) throws Exception {
+        return stub.retrieveTenantUsage(yearMonth, tenantId);
+    }
+
+    public InstanceUsageStatics[] retrieveInstanceUsage() throws Exception{
+            return stub.retrieveInstanceUsage();
+    }
+
+    public PaginatedInstanceUsage retrievePaginatedInstanceUsage (
+            String yearMonth, int pageNumber, int numbersPerPage) throws Exception {
+            return stub.retrievePaginatedInstanceUsage(yearMonth, pageNumber, numbersPerPage);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageData.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageData.java b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageData.java
new file mode 100755
index 0000000..c959dca
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageData.java
@@ -0,0 +1,96 @@
+/*
+ *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.usage.ui.report;
+
+public class AllTenantUsageData {
+
+	public AllTenantUsageData() {
+	}
+
+	String yearMonth;
+	
+	String tenantName;
+	
+	String numberOfUsers;
+	
+	String currentDataStorage;
+	
+	String regBandwidth;
+	
+	String svcBandwidth;
+	
+	String svcTotalRequest;
+
+	public String getYearMonth() {
+		return yearMonth;
+	}
+
+	public void setYearMonth(String yearMonth) {
+		this.yearMonth = yearMonth;
+	}
+
+	public String getTenantName() {
+		return tenantName;
+	}
+
+	public void setTenantName(String tenantName) {
+		this.tenantName = tenantName;
+	}
+
+	public String getNumberOfUsers() {
+		return numberOfUsers;
+	}
+
+	public void setNumberOfUsers(String numberOfUsers) {
+		this.numberOfUsers = numberOfUsers;
+	}
+
+	public String getCurrentDataStorage() {
+		return currentDataStorage;
+	}
+
+	public void setCurrentDataStorage(String currentDataStorage) {
+		this.currentDataStorage = currentDataStorage;
+	}
+
+	public String getRegBandwidth() {
+		return regBandwidth;
+	}
+
+	public void setRegBandwidth(String regBandwidth) {
+		this.regBandwidth = regBandwidth;
+	}
+
+	public String getSvcBandwidth() {
+		return svcBandwidth;
+	}
+
+	public void setSvcBandwidth(String svcBandwidth) {
+		this.svcBandwidth = svcBandwidth;
+	}
+
+	public String getSvcTotalRequest() {
+		return svcTotalRequest;
+	}
+
+	public void setSvcTotalRequest(String svcTotalRequest) {
+		this.svcTotalRequest = svcTotalRequest;
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageReport.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageReport.java b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageReport.java
new file mode 100644
index 0000000..fb5b0a4
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/AllTenantUsageReport.java
@@ -0,0 +1,110 @@
+/*
+ *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.usage.ui.report;
+
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.usage.stub.beans.xsd.TenantUsage;
+import org.apache.stratos.usage.ui.utils.UsageUtil;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * this class is used to generate reports of all tenant usages
+ */
+public class AllTenantUsageReport {
+
+    private TenantUsage[] tenantUsages;
+    private String yearMonth;
+
+    /**
+     * @param config
+     * @param session
+     * @param request
+     * @throws Exception
+     */
+    private static final Log log = LogFactory.getLog(AllTenantUsageReport.class);
+
+    public AllTenantUsageReport(ServletConfig config, HttpSession session, HttpServletRequest request)
+            throws Exception {
+    	tenantUsages = UsageUtil.retrieveTenantUsages(request, config, session);
+     
+ 
+        yearMonth = (String) request.getSession().getAttribute("year-month");
+    }
+
+    public List<AllTenantUsageData> getUsageReportData() {
+
+        List<AllTenantUsageData> reportData = new ArrayList<AllTenantUsageData>();   // all the strings need to be passed to
+        //  generate the report are added to this list
+
+        if (yearMonth == null) {
+            //  get the current year month
+            yearMonth = UsageUtil.getCurrentYearMonth();
+        }
+        String currentYearMonth = UsageUtil.getCurrentYearMonth();
+
+        //  add all the usage data to the list
+        try {
+            for (TenantUsage usage : tenantUsages) {
+                AllTenantUsageData usageData = new AllTenantUsageData();
+                usageData.setYearMonth(yearMonth);
+                String currentDataStorage = UsageUtil.getTotalDataStorage(usage);
+                String regBandwidth = UsageUtil.getTotalBandwidth(usage.getTotalRegistryBandwidth());
+                String svcBandwidth = UsageUtil.getTotalBandwidth(usage.getTotalServiceBandwidth());
+                long svcTotalRequest = usage.getTotalRequestStatistics().getRequestCount();
+                int numberOfUsers = usage.getNumberOfUsers();
+
+                //  String username = (String) request.getSession().getAttribute("logged-user");
+                String tenantName = usage.getDomain();
+                int tenantId = usage.getTenantId();
+                String fullReportLink = "any_tenant_usage.jsp?tenant-id=" + tenantId + "&year-month=" + yearMonth;
+
+                usageData.setTenantName(tenantName);
+                if (yearMonth.equals(currentYearMonth)) {
+                    usageData.setNumberOfUsers(Integer.toString(numberOfUsers));
+                    usageData.setCurrentDataStorage(currentDataStorage);
+                }
+                // if the yearMonth is not current, number of users coloumn and storage usage coloumn are empty
+                else {
+                    usageData.setNumberOfUsers("-");
+                    usageData.setCurrentDataStorage("-");
+                }
+                usageData.setRegBandwidth(regBandwidth);
+                usageData.setSvcBandwidth(svcBandwidth);
+                usageData.setSvcTotalRequest(Long.toString(svcTotalRequest));
+                reportData.add(usageData);
+            }
+        }
+        catch (Exception e) {
+            String msg = "Error while retrieving tenant usages for month : " + yearMonth;
+            log.error(msg, e);
+        }
+        return reportData;         // return as an array
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/UsageReport.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/UsageReport.java b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/UsageReport.java
new file mode 100644
index 0000000..264266d
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/report/UsageReport.java
@@ -0,0 +1,195 @@
+/*
+ *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.usage.ui.report;
+
+import org.wso2.carbon.usage.stub.beans.xsd.BandwidthStatistics;
+import org.wso2.carbon.usage.stub.beans.xsd.RequestStatistics;
+import org.wso2.carbon.usage.stub.beans.xsd.TenantUsage;
+import org.apache.stratos.usage.ui.utils.UsageUtil;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This class is used to generate tenant usage report
+ */
+public class UsageReport {
+    private TenantUsage usage;
+    private String yearMonth;
+
+    public UsageReport(ServletConfig config, HttpSession session, HttpServletRequest request)
+            throws Exception {
+        usage = UsageUtil.retrieveCurrentTenantUsage(request, config, session);
+        yearMonth = (String) request.getSession().getAttribute("year-month");
+
+    }
+
+
+    public List<String> getUsageReportData() {
+
+        int numberOfUsers = usage.getNumberOfUsers();
+        if (yearMonth == null) {
+
+            yearMonth = UsageUtil.getCurrentYearMonth();
+        }
+
+        String tenantName = usage.getDomain();
+        String currentYearMonth = UsageUtil.getCurrentYearMonth();
+        List<String> reportData = new ArrayList<String>();
+        reportData.add("Basic Tenant Details");
+        reportData.add("");
+        reportData.add("Duration");
+        reportData.add("Tenant Name");
+        reportData.add("Number of users");
+        reportData.add("Basic Tenant Details");
+        reportData.add("");
+        reportData.add(yearMonth);
+        reportData.add(tenantName);
+        reportData.add(String.valueOf(numberOfUsers));
+
+
+        if (currentYearMonth.equals(yearMonth)) {
+            reportData.add("Storage Usage");
+            reportData.add("Data Storage");
+            reportData.add("Current Data Storage");
+            reportData.add("Historical Data Storage");
+            reportData.add("Total Data Storage");
+            String totalDataStorage = UsageUtil.getTotalDataStorage(usage);
+            String currentDataStorage = UsageUtil.getCurrentDataStorage(usage);
+            String historyDataStorage = UsageUtil.getHistoryDataStorage(usage);
+            reportData.add("Storage Usage");
+            reportData.add("Registry Content");
+            reportData.add(totalDataStorage);
+            reportData.add(currentDataStorage);
+            reportData.add(historyDataStorage);
+        }
+
+        String totRegInBandwidth = UsageUtil.getIncomingBandwidth(usage.getTotalRegistryBandwidth());
+        String totRegOutBandwidth = UsageUtil.getOutgoingBandwidth(usage.getTotalRegistryBandwidth());
+        String totRegBandwidth = UsageUtil.getTotalBandwidth(usage.getTotalRegistryBandwidth());
+        reportData.add("Registry Bandwidth Usage");
+        reportData.add("Server Name");
+        reportData.add("Incoming Bandwidth");
+        reportData.add("Outgoing Bandwidth");
+        reportData.add("Total Bandwidth");
+        BandwidthStatistics[] regBWStats = usage.getRegistryBandwidthStatistics();
+        if (regBWStats != null) {
+            for (BandwidthStatistics stat : regBWStats) {
+                String regInBandwidth = UsageUtil.getIncomingBandwidth(stat);
+                String regOutBandwidth = UsageUtil.getOutgoingBandwidth(stat);
+                String regBandwidth = UsageUtil.getTotalBandwidth(stat);
+                reportData.add("Server Name****");
+                reportData.add(regInBandwidth);
+                reportData.add(regOutBandwidth);
+                reportData.add(regBandwidth);
+
+            }
+        }
+        reportData.add("Registry Bandwidth Usage");
+        reportData.add("All Server Total");
+        reportData.add(totRegInBandwidth);
+        reportData.add(totRegOutBandwidth);
+        reportData.add(totRegBandwidth);
+
+        String totSvcInBandwidth = UsageUtil.getIncomingBandwidth(usage.getTotalServiceBandwidth());
+        String totSvcOutBandwidth = UsageUtil.getOutgoingBandwidth(usage.getTotalServiceBandwidth());
+        String totSvcBandwidth = UsageUtil.getTotalBandwidth(usage.getTotalServiceBandwidth());
+        reportData.add("Service Bandwidth Usage");
+        reportData.add("Server Name");
+        reportData.add("Incoming Bandwidth");
+        reportData.add("Outgoing Bandwidth");
+        reportData.add("Total Bandwidth");
+        BandwidthStatistics[] svcBWStats = usage.getServiceBandwidthStatistics();
+        if (svcBWStats != null) {
+            for (BandwidthStatistics stat : svcBWStats) {
+                String svcInBandwidth = UsageUtil.getIncomingBandwidth(stat);
+                String svcOutBandwidth = UsageUtil.getOutgoingBandwidth(stat);
+                String svcBandwidth = UsageUtil.getTotalBandwidth(stat);
+                reportData.add("Server Name****");
+                reportData.add(svcInBandwidth);
+                reportData.add(svcOutBandwidth);
+                reportData.add(svcBandwidth);
+
+            }
+        }
+        reportData.add("Service Bandwidth Usage");
+        reportData.add("All Server Total");
+        reportData.add(totSvcInBandwidth);
+        reportData.add(totSvcOutBandwidth);
+        reportData.add(totSvcBandwidth);
+
+        String totWebappInBandwidth = UsageUtil.getIncomingBandwidth(usage.getTotalWebappBandwidth());
+        String totWebappOutBandwidth = UsageUtil.getOutgoingBandwidth(usage.getTotalWebappBandwidth());
+        String totWebappBandwidth = UsageUtil.getTotalBandwidth(usage.getTotalWebappBandwidth());
+        BandwidthStatistics[] webappBWStats = usage.getWebappBandwidthStatistics();
+        reportData.add("Webapp Bandwidth Usage");
+        reportData.add("Server Name");
+        reportData.add("Incoming Bandwidth");
+        reportData.add("Outgoing Bandwidth");
+        reportData.add("Total Bandwidth");
+        if (webappBWStats != null) {
+            for (BandwidthStatistics stat : webappBWStats) {
+                String webappInBandwidth = UsageUtil.getIncomingBandwidth(stat);
+                String webappOutBandwidth = UsageUtil.getOutgoingBandwidth(stat);
+                String webappBandwidth = UsageUtil.getTotalBandwidth(stat);
+                reportData.add("Server Name****");
+                reportData.add(webappInBandwidth);
+                reportData.add(webappOutBandwidth);
+                reportData.add(webappBandwidth);
+            }
+        }
+        reportData.add("Webapp Bandwidth Usage");
+        reportData.add("All Server Total");
+        reportData.add(totWebappInBandwidth);
+        reportData.add(totWebappOutBandwidth);
+        reportData.add(totWebappBandwidth);
+
+
+        long totSvcReqCount = usage.getTotalRequestStatistics().getRequestCount();
+        long totSvcRespCount = usage.getTotalRequestStatistics().getResponseCount();
+        long totSvcFaultCount = usage.getTotalRequestStatistics().getFaultCount();
+        RequestStatistics[] svcStats = usage.getRequestStatistics();
+        reportData.add("Service Usage Statistic");
+        reportData.add("Server Name");
+        reportData.add("Request Count");
+        reportData.add("Response Count");
+        reportData.add("Fault Count");
+        if (svcStats != null && svcStats.length>0 && svcStats[0]!=null) {
+            for (RequestStatistics stat : svcStats) {
+                long svcReqCount = stat.getRequestCount();
+                long svcResCount = stat.getResponseCount();
+                long svcFaultCount = stat.getFaultCount();
+                reportData.add("Server Name****");
+                reportData.add(String.valueOf(svcReqCount));
+                reportData.add(String.valueOf(svcResCount));
+                reportData.add(String.valueOf(svcFaultCount));
+            }
+        }
+        reportData.add("Service Usage Statistic");
+        reportData.add("All Server Total");
+        reportData.add(String.valueOf(totSvcReqCount));
+        reportData.add(String.valueOf(totSvcRespCount));
+        reportData.add(String.valueOf(totSvcFaultCount));
+
+        return reportData;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/utils/UsageUtil.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/utils/UsageUtil.java b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/utils/UsageUtil.java
new file mode 100644
index 0000000..0b7089f
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/java/org/apache/stratos/usage/ui/utils/UsageUtil.java
@@ -0,0 +1,251 @@
+/*
+ *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.usage.ui.utils;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.util.CommonUtil;
+import org.wso2.carbon.registry.common.ui.UIException;
+import org.wso2.carbon.usage.stub.beans.xsd.*;
+import org.apache.stratos.usage.ui.clients.UsageServiceClient;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpSession;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+
+public class UsageUtil {
+    private static final Log log = LogFactory.getLog(UsageUtil.class);
+
+    private static long KB_LIMIT = 1024;
+    private static long MB_LIMIT = 1024 * 1024;
+    private static long GB_LIMIT = 1024 * 1024 * 1024;
+    private static long TB_LIMIT = (long) 1024 * 1024 * 1024 * 1024;
+
+    public static TenantUsage retrieveCurrentTenantUsage(ServletRequest request,
+                                                         ServletConfig config, HttpSession session) throws Exception {
+        try {
+            UsageServiceClient serviceClient = new UsageServiceClient(config, session);
+            String yearMonth = request.getParameter("year-month");
+            if (yearMonth == null) {
+                // get the current year month
+                yearMonth = getCurrentYearMonth();
+            }
+            return serviceClient.retrieveCurrentTenantUsage(yearMonth);
+        } catch (Exception e) {
+            String msg = "Failed to get current tenant usage.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    public static TenantUsage[] retrieveTenantUsages(ServletRequest request,
+                                                     ServletConfig config, HttpSession session) throws Exception {
+        try {
+            UsageServiceClient serviceClient = new UsageServiceClient(config, session);
+            String yearMonth = request.getParameter("year-month");
+            if (yearMonth == null) {
+                // get the current year month
+                yearMonth = getCurrentYearMonth();
+            }
+            return serviceClient.retrieveTenantUsages(yearMonth);
+        } catch (Exception e) {
+            String msg = "Failed to get all tenants usages.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    public static PaginatedTenantUsageInfo retrievePaginatedTenantUsages(ServletRequest request,
+                                                                         ServletConfig config, HttpSession session) throws Exception {
+        String requestedPage = request.getParameter("requestedPage");
+        int pageNumber = 1;
+        int numberOfPages = 1;
+        int entriesPerPage = 15;
+        if (requestedPage != null && requestedPage.length() > 0) {
+            pageNumber = new Integer(requestedPage);
+        }
+
+        try {
+            UsageServiceClient serviceClient = new UsageServiceClient(config, session);
+            String yearMonth = request.getParameter("year-month");
+            if (yearMonth == null) {
+                // get the current year month
+                yearMonth = getCurrentYearMonth();
+            }
+            return serviceClient.retrievePaginatedTenantUsages(yearMonth, pageNumber, entriesPerPage);
+        } catch (Exception e) {
+            String msg = "Failed to get all tenants usages.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    public static TenantUsage retrieveTenantUsage(ServletRequest request,
+                                                  ServletConfig config, HttpSession session) throws Exception {
+        try {
+            UsageServiceClient serviceClient = new UsageServiceClient(config, session);
+            String yearMonth = request.getParameter("year-month");
+            if (yearMonth == null) {
+                // get the current year month
+                yearMonth = getCurrentYearMonth();
+            }
+            String tenantIdStr = request.getParameter("tenant-id");
+            if (tenantIdStr == null) {
+                tenantIdStr = "0";
+            }
+            return serviceClient.retrieveTenantUsage(yearMonth, Integer.parseInt(tenantIdStr));
+        } catch (Exception e) {
+            String msg = "Failed to get tenant usages.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+
+    public static String convertBytesToString(long storage) {
+        if (storage < KB_LIMIT) {
+            return storage + " Byte(s)";
+        } else if (storage < MB_LIMIT) {
+            return storage / KB_LIMIT + " KByte(s)";
+        } else if (storage < GB_LIMIT) {
+            return storage / MB_LIMIT + " MByte(s)";
+        } else if (storage < TB_LIMIT) {
+            return storage / GB_LIMIT + " GByte(s)";
+        } else {
+            return storage / TB_LIMIT + " TByte(s)";
+        }
+    }
+
+    public static String getCurrentYearMonth() {
+        Calendar calendar = Calendar.getInstance();
+        return CommonUtil.getMonthString(calendar);
+    }
+
+    public static String[] getYearMonths() {
+        // we will list 100 months for now
+        List<String> yearMonths = new ArrayList<String>();
+        for (int i = 0; i > -100; i--) {
+            String yearMonth = CommonUtil.getMonthString(i);
+            yearMonths.add(yearMonth);
+        }
+        return yearMonths.toArray(new String[yearMonths.size()]);
+    }
+
+    public static String getCurrentDataStorage(TenantUsage usage) {
+        TenantDataCapacity regData = usage.getRegistryCapacity();
+        long currentData = 0;
+        if (regData != null) {
+            currentData = regData.getRegistryContentCapacity();
+        }
+        return convertBytesToString(currentData);
+    }
+
+    public static String getHistoryDataStorage(TenantUsage usage) {
+        TenantDataCapacity historyData = usage.getRegistryCapacity();
+        long currentData = 0;
+        if (historyData != null) {
+            currentData = historyData.getRegistryContentHistoryCapacity();
+        }
+        return convertBytesToString(currentData);
+    }
+
+    public static String getTotalDataStorage(TenantUsage usage) {
+        TenantDataCapacity regData = usage.getRegistryCapacity();
+        long totalDataStorage = 0;
+        if (regData != null) {
+            totalDataStorage =
+                    regData.getRegistryContentCapacity() + regData.getRegistryContentHistoryCapacity();
+        }
+        return convertBytesToString(totalDataStorage);
+    }
+
+    public static String getIncomingBandwidth(BandwidthStatistics bandwidth) {
+        long totalBW = 0;
+        if (bandwidth != null) {
+            totalBW = bandwidth.getIncomingBandwidth();
+        }
+        return convertBytesToString(totalBW);
+    }
+
+    public static String getOutgoingBandwidth(BandwidthStatistics bandwidth) {
+        long totalBW = 0;
+        if (bandwidth != null) {
+            totalBW = bandwidth.getOutgoingBandwidth();
+        }
+        return convertBytesToString(totalBW);
+    }
+
+    public static String getTotalBandwidth(BandwidthStatistics bandwidth) {
+        long totalBW = 0;
+        if (bandwidth != null) {
+            totalBW = bandwidth.getIncomingBandwidth() + bandwidth.getOutgoingBandwidth();
+        }
+        return convertBytesToString(totalBW);
+    }
+
+    public static InstanceUsageStatics[] retrieveInstanceUsage(ServletRequest request,
+                                                               ServletConfig config, HttpSession session)
+            throws Exception {
+
+        try {
+            UsageServiceClient serviceClient = new UsageServiceClient(config, session);
+            InstanceUsageStatics[] returnInstanceUsage = serviceClient.retrieveInstanceUsage();
+            return returnInstanceUsage;
+        } catch (Exception e) {
+            String msg = "Failed to get current instance usage.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+
+    public static PaginatedInstanceUsage retrievePaginatedInstanceUsages(ServletRequest request,
+                                                                         ServletConfig config, HttpSession session) throws Exception {
+        String requestedPage = request.getParameter("requestedPage");
+        int pageNumber = 1;
+        int numberOfPages = 1;
+        int entriesPerPage = 15;
+        if (requestedPage != null && requestedPage.length() > 0) {
+            pageNumber = new Integer(requestedPage);
+        }
+        try {
+            UsageServiceClient serviceClient = new UsageServiceClient(config, session);
+            String yearMonth = request.getParameter("year-month");
+            if (yearMonth == null) {
+                // get the current year month
+                yearMonth = getCurrentYearMonth();
+            }
+            return serviceClient.retrievePaginatedInstanceUsage(yearMonth, pageNumber, entriesPerPage);
+        } catch (Exception e) {
+            String msg = "Failed to get paginated instance usages.";
+            log.error(msg, e);
+            throw new UIException(msg, e);
+        }
+    }
+    public static String getAPIUsage(TenantUsage usage) {
+        long count = 0;
+
+        if (usage.getApiManagerUsageStats() != null) {
+            count =usage.getApiManagerUsageStats()[0].getRequestCount();
+        }
+        return Long.toString(count);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/resources/META-INF/component.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.usage.ui/src/main/resources/META-INF/component.xml
new file mode 100644
index 0000000..d4ba371
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/resources/META-INF/component.xml
@@ -0,0 +1,74 @@
+<!--
+  ~  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.
+  -->
+<component xmlns="http://products.wso2.org/carbon">
+    <!-- sample menu configuration -->
+    <menus>
+        <menu>
+            <id>usage_monitoring_menu</id>
+            <i18n-key>usage.monitoring</i18n-key>
+            <i18n-bundle>org.wso2.carbon.usage.ui.i18n.Resources</i18n-bundle>
+            <parent-menu></parent-menu>
+            <link>#</link>
+            <region>region4</region>
+            <style-class>home</style-class>
+            <order>22</order>
+            <icon>../services/images/services.gif</icon>
+        </menu>
+        <menu>
+            <id>tenant_usage_menu</id>
+            <i18n-key>tenant.usage.report</i18n-key>
+            <i18n-bundle>org.wso2.carbon.usage.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>monitor_menu</parent-menu>
+            <link>../tenant-usage/tenant_usage.jsp</link>
+            <region>region4</region>
+            <order>51</order>
+            <style-class>manage</style-class>
+            <icon>../tenant-usage/images/user-usage-report.gif</icon>
+            <require-permission>/permission/admin/monitor/tenantUsage</require-permission>
+            <require-not-super-tenant>true</require-not-super-tenant>
+        </menu>
+        <!--menu>
+            <id>all_tenant_instance_usage_menu</id>
+            <i18n-key>instance.usage.report</i18n-key>
+            <i18n-bundle>org.wso2.carbon.usage.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>monitor_menu</parent-menu>
+            <link>../tenant-usage/all_tenant_instance_usage.jsp</link>
+            <region>region4</region>
+            <order>50</order>
+            <style-class>manage</style-class>
+            <icon>../tenant-usage/images/instance-usage-report.gif</icon>
+            <require-permission>/permission/protected/monitor/userUsage</require-permission>
+            <require-super-tenant>true</require-super-tenant>
+        </menu-->
+        <menu>
+            <id>all_tenant_usage_menu</id>
+            <i18n-key>all.tenant.usage.report</i18n-key>
+            <i18n-bundle>org.wso2.carbon.usage.ui.i18n.Resources</i18n-bundle>
+            <parent-menu>monitor_menu</parent-menu>
+            <link>../tenant-usage/all_tenant_usage.jsp</link>
+            <region>region4</region>
+            <order>50</order>
+            <style-class>manage</style-class>
+            <icon>../tenant-usage/images/tenant-usage-report.gif</icon>
+            <require-permission>/permission/protected/monitor/userUsage</require-permission>
+            <require-super-tenant>true</require-super-tenant>
+        </menu>
+    </menus>
+
+</component>

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/resources/UsageService.wsdl
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/resources/UsageService.wsdl b/components/org.apache.stratos.usage.ui/src/main/resources/UsageService.wsdl
new file mode 100644
index 0000000..b14c186
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/resources/UsageService.wsdl
@@ -0,0 +1,605 @@
+<!--
+  ~  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.
+  -->
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+                  xmlns:ns1="http://org.apache.axis2/xsd"
+                  xmlns:ns="http://services.usage.carbon.wso2.org"
+                  xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
+                  xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
+                  xmlns:xs="http://www.w3.org/2001/XMLSchema"
+                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+                  xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
+                  xmlns:ax2249="http://beans.usage.carbon.wso2.org/xsd"
+                  xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
+                  targetNamespace="http://services.usage.carbon.wso2.org">
+    <wsdl:documentation>UsageService</wsdl:documentation>
+    <wsdl:types>
+        <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified"
+                   targetNamespace="http://beans.usage.carbon.wso2.org/xsd">
+            <xs:complexType name="TenantUsage">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="domain" nillable="true" type="xs:string"/>
+                    <xs:element minOccurs="0" name="numberOfUsers" type="xs:int"/>
+                    <xs:element maxOccurs="unbounded" minOccurs="0"
+                                name="registryBandwidthStatistics" nillable="true"
+                                type="ax2249:BandwidthStatistics"/>
+
+                    <xs:element minOccurs="0" name="registryCapacity" nillable="true"
+                                type="ax2249:TenantDataCapacity"/>
+                    <xs:element minOccurs="0" name="registryContentCapacity" type="xs:long"/>
+                    <xs:element minOccurs="0" name="registryContentHistoryCapacity" type="xs:long"/>
+                    <xs:element maxOccurs="unbounded" minOccurs="0" name="requestStatistics"
+                                nillable="true" type="ax2249:RequestStatistics"/>
+                    <xs:element maxOccurs="unbounded" minOccurs="0"
+                                name="serviceBandwidthStatistics" nillable="true"
+                                type="ax2249:BandwidthStatistics"/>
+                    <xs:element minOccurs="0" name="tenantId" type="xs:int"/>
+                    <xs:element minOccurs="0" name="totalIncomingBandwidth" type="xs:long"/>
+                    <xs:element minOccurs="0" name="totalOutgoingBandwidth" type="xs:long"/>
+                    <xs:element minOccurs="0" name="totalRegistryBandwidth" nillable="true"
+                                type="ax2249:BandwidthStatistics"/>
+
+                    <xs:element minOccurs="0" name="totalRequestStatistics" nillable="true"
+                                type="ax2249:RequestStatistics"/>
+                    <xs:element minOccurs="0" name="totalServiceBandwidth" nillable="true"
+                                type="ax2249:BandwidthStatistics"/>
+                    <xs:element minOccurs="0" name="totalWebappBandwidth" nillable="true"
+                                type="ax2249:BandwidthStatistics"/>
+                    <xs:element maxOccurs="unbounded" minOccurs="0" name="usageEntries"
+                                nillable="true" type="ax2249:UsageEntry"/>
+                    <xs:element maxOccurs="unbounded" minOccurs="0" name="webappBandwidthStatistics"
+                                nillable="true" type="ax2249:BandwidthStatistics"/>
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="BandwidthStatistics">
+                <xs:sequence>
+
+                    <xs:element minOccurs="0" name="incomingBandwidth" type="xs:long"/>
+                    <xs:element minOccurs="0" name="key" nillable="true" type="xs:string"/>
+                    <xs:element minOccurs="0" name="outgoingBandwidth" type="xs:long"/>
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="TenantDataCapacity">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="registryContentCapacity" type="xs:long"/>
+                    <xs:element minOccurs="0" name="registryContentHistoryCapacity" type="xs:long"/>
+
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="RequestStatistics">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="faultCount" type="xs:long"/>
+                    <xs:element minOccurs="0" name="key" nillable="true" type="xs:string"/>
+                    <xs:element minOccurs="0" name="requestCount" type="xs:long"/>
+                    <xs:element minOccurs="0" name="responseCount" type="xs:long"/>
+                </xs:sequence>
+
+            </xs:complexType>
+            <xs:complexType name="UsageEntry">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="key" nillable="true" type="xs:string"/>
+                    <xs:element minOccurs="0" name="value" nillable="true" type="xs:string"/>
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="PaginatedTenantUsageInfo">
+                <xs:sequence>
+
+                    <xs:element minOccurs="0" name="numberOfPages" type="xs:int"/>
+                    <xs:element minOccurs="0" name="pageNumber" type="xs:int"/>
+                    <xs:element maxOccurs="unbounded" minOccurs="0" name="tenantUsages"
+                                nillable="true" type="ax2249:TenantUsage"/>
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="PaginatedInstanceUsage">
+                <xs:sequence>
+                    <xs:element maxOccurs="unbounded" minOccurs="0" name="instanceUsages"
+                                nillable="true" type="ax2249:InstanceUsageStatics"/>
+                    <xs:element minOccurs="0" name="numberOfPages" type="xs:int"/>
+
+                    <xs:element minOccurs="0" name="pageNumber" type="xs:int"/>
+                </xs:sequence>
+            </xs:complexType>
+            <xs:complexType name="InstanceUsageStatics">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="instanceID" nillable="true" type="xs:int"/>
+                    <xs:element minOccurs="0" name="instanceURL" nillable="true" type="xs:string"/>
+                    <xs:element minOccurs="0" name="running" type="xs:boolean"/>
+                    <xs:element minOccurs="0" name="startTime" nillable="true" type="xs:dateTime"/>
+
+                    <xs:element minOccurs="0" name="stopTime" nillable="true" type="xs:dateTime"/>
+                    <xs:element minOccurs="0" name="usedTimeInSeconds" type="xs:long"/>
+                </xs:sequence>
+            </xs:complexType>
+        </xs:schema>
+        <xs:schema xmlns:ax2250="http://beans.usage.carbon.wso2.org/xsd"
+                   attributeFormDefault="qualified" elementFormDefault="qualified"
+                   targetNamespace="http://services.usage.carbon.wso2.org">
+            <xs:import namespace="http://beans.usage.carbon.wso2.org/xsd"/>
+            <xs:element name="Exception">
+                <xs:complexType>
+
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="Exception" nillable="true"
+                                    type="ns:Exception"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:complexType name="Exception">
+                <xs:sequence>
+                    <xs:element minOccurs="0" name="Message" nillable="true" type="xs:string"/>
+                </xs:sequence>
+
+            </xs:complexType>
+            <xs:element name="retrieveTenantUsages">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="yearMonth" nillable="true"
+                                    type="xs:string"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrieveTenantUsagesResponse">
+
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return"
+                                    nillable="true" type="ax2250:TenantUsage"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrieveTenantUsage">
+                <xs:complexType>
+                    <xs:sequence>
+
+                        <xs:element minOccurs="0" name="yearMonth" nillable="true"
+                                    type="xs:string"/>
+                        <xs:element minOccurs="0" name="tenantId" type="xs:int"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrieveTenantUsageResponse">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="return" nillable="true"
+                                    type="ax2250:TenantUsage"/>
+
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrievePaginatedTenantUsages">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="yearMonth" nillable="true"
+                                    type="xs:string"/>
+                        <xs:element minOccurs="0" name="pageNumber" type="xs:int"/>
+                        <xs:element minOccurs="0" name="entriesPerPage" type="xs:int"/>
+
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrievePaginatedTenantUsagesResponse">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="return" nillable="true"
+                                    type="ax2250:PaginatedTenantUsageInfo"/>
+                    </xs:sequence>
+                </xs:complexType>
+
+            </xs:element>
+            <xs:element name="retrievePaginatedInstanceUsage">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="yearMonth" nillable="true"
+                                    type="xs:string"/>
+                        <xs:element minOccurs="0" name="pageNumber" type="xs:int"/>
+                        <xs:element minOccurs="0" name="entriesPerPage" type="xs:int"/>
+                    </xs:sequence>
+                </xs:complexType>
+
+            </xs:element>
+            <xs:element name="retrievePaginatedInstanceUsageResponse">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="return" nillable="true"
+                                    type="ax2250:PaginatedInstanceUsage"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrieveInstanceUsageResponse">
+
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element maxOccurs="unbounded" minOccurs="0" name="return"
+                                    nillable="true" type="ax2250:InstanceUsageStatics"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrieveCurrentTenantUsage">
+                <xs:complexType>
+                    <xs:sequence>
+
+                        <xs:element minOccurs="0" name="yearMonth" nillable="true"
+                                    type="xs:string"/>
+                    </xs:sequence>
+                </xs:complexType>
+            </xs:element>
+            <xs:element name="retrieveCurrentTenantUsageResponse">
+                <xs:complexType>
+                    <xs:sequence>
+                        <xs:element minOccurs="0" name="return" nillable="true"
+                                    type="ax2250:TenantUsage"/>
+                    </xs:sequence>
+
+                </xs:complexType>
+            </xs:element>
+        </xs:schema>
+    </wsdl:types>
+    <wsdl:message name="retrievePaginatedTenantUsagesRequest">
+        <wsdl:part name="parameters" element="ns:retrievePaginatedTenantUsages"/>
+    </wsdl:message>
+    <wsdl:message name="retrievePaginatedTenantUsagesResponse">
+        <wsdl:part name="parameters" element="ns:retrievePaginatedTenantUsagesResponse"/>
+
+    </wsdl:message>
+    <wsdl:message name="Exception">
+        <wsdl:part name="parameters" element="ns:Exception"/>
+    </wsdl:message>
+    <wsdl:message name="retrieveCurrentTenantUsageRequest">
+        <wsdl:part name="parameters" element="ns:retrieveCurrentTenantUsage"/>
+    </wsdl:message>
+    <wsdl:message name="retrieveCurrentTenantUsageResponse">
+        <wsdl:part name="parameters" element="ns:retrieveCurrentTenantUsageResponse"/>
+
+    </wsdl:message>
+    <wsdl:message name="retrieveTenantUsagesRequest">
+        <wsdl:part name="parameters" element="ns:retrieveTenantUsages"/>
+    </wsdl:message>
+    <wsdl:message name="retrieveTenantUsagesResponse">
+        <wsdl:part name="parameters" element="ns:retrieveTenantUsagesResponse"/>
+    </wsdl:message>
+    <wsdl:message name="retrieveTenantUsageRequest">
+        <wsdl:part name="parameters" element="ns:retrieveTenantUsage"/>
+
+    </wsdl:message>
+    <wsdl:message name="retrieveTenantUsageResponse">
+        <wsdl:part name="parameters" element="ns:retrieveTenantUsageResponse"/>
+    </wsdl:message>
+    <wsdl:message name="retrieveInstanceUsageRequest"/>
+    <wsdl:message name="retrieveInstanceUsageResponse">
+        <wsdl:part name="parameters" element="ns:retrieveInstanceUsageResponse"/>
+    </wsdl:message>
+    <wsdl:message name="retrievePaginatedInstanceUsageRequest">
+
+        <wsdl:part name="parameters" element="ns:retrievePaginatedInstanceUsage"/>
+    </wsdl:message>
+    <wsdl:message name="retrievePaginatedInstanceUsageResponse">
+        <wsdl:part name="parameters" element="ns:retrievePaginatedInstanceUsageResponse"/>
+    </wsdl:message>
+    <wsdl:portType name="UsageServicePortType">
+        <wsdl:operation name="retrievePaginatedTenantUsages">
+            <wsdl:input message="ns:retrievePaginatedTenantUsagesRequest"
+                        wsaw:Action="urn:retrievePaginatedTenantUsages"/>
+            <wsdl:output message="ns:retrievePaginatedTenantUsagesResponse"
+                         wsaw:Action="urn:retrievePaginatedTenantUsagesResponse"/>
+
+            <wsdl:fault message="ns:Exception" name="Exception"
+                        wsaw:Action="urn:retrievePaginatedTenantUsagesException"/>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveCurrentTenantUsage">
+            <wsdl:input message="ns:retrieveCurrentTenantUsageRequest"
+                        wsaw:Action="urn:retrieveCurrentTenantUsage"/>
+            <wsdl:output message="ns:retrieveCurrentTenantUsageResponse"
+                         wsaw:Action="urn:retrieveCurrentTenantUsageResponse"/>
+            <wsdl:fault message="ns:Exception" name="Exception"
+                        wsaw:Action="urn:retrieveCurrentTenantUsageException"/>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveTenantUsages">
+            <wsdl:input message="ns:retrieveTenantUsagesRequest"
+                        wsaw:Action="urn:retrieveTenantUsages"/>
+
+            <wsdl:output message="ns:retrieveTenantUsagesResponse"
+                         wsaw:Action="urn:retrieveTenantUsagesResponse"/>
+            <wsdl:fault message="ns:Exception" name="Exception"
+                        wsaw:Action="urn:retrieveTenantUsagesException"/>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveTenantUsage">
+            <wsdl:input message="ns:retrieveTenantUsageRequest"
+                        wsaw:Action="urn:retrieveTenantUsage"/>
+            <wsdl:output message="ns:retrieveTenantUsageResponse"
+                         wsaw:Action="urn:retrieveTenantUsageResponse"/>
+            <wsdl:fault message="ns:Exception" name="Exception"
+                        wsaw:Action="urn:retrieveTenantUsageException"/>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveInstanceUsage">
+
+            <wsdl:input message="ns:retrieveInstanceUsageRequest"
+                        wsaw:Action="urn:retrieveInstanceUsage"/>
+            <wsdl:output message="ns:retrieveInstanceUsageResponse"
+                         wsaw:Action="urn:retrieveInstanceUsageResponse"/>
+            <wsdl:fault message="ns:Exception" name="Exception"
+                        wsaw:Action="urn:retrieveInstanceUsageException"/>
+        </wsdl:operation>
+        <wsdl:operation name="retrievePaginatedInstanceUsage">
+            <wsdl:input message="ns:retrievePaginatedInstanceUsageRequest"
+                        wsaw:Action="urn:retrievePaginatedInstanceUsage"/>
+            <wsdl:output message="ns:retrievePaginatedInstanceUsageResponse"
+                         wsaw:Action="urn:retrievePaginatedInstanceUsageResponse"/>
+            <wsdl:fault message="ns:Exception" name="Exception"
+                        wsaw:Action="urn:retrievePaginatedInstanceUsageException"/>
+        </wsdl:operation>
+
+    </wsdl:portType>
+    <wsdl:binding name="UsageServiceSoap11Binding" type="ns:UsageServicePortType">
+        <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
+        <wsdl:operation name="retrievePaginatedTenantUsages">
+            <soap:operation soapAction="urn:retrievePaginatedTenantUsages" style="document"/>
+            <wsdl:input>
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+
+                <soap:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveCurrentTenantUsage">
+            <soap:operation soapAction="urn:retrieveCurrentTenantUsage" style="document"/>
+            <wsdl:input>
+
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrieveTenantUsages">
+            <soap:operation soapAction="urn:retrieveTenantUsages" style="document"/>
+            <wsdl:input>
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+
+                <soap:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveTenantUsage">
+            <soap:operation soapAction="urn:retrieveTenantUsage" style="document"/>
+            <wsdl:input>
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+
+                <soap:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveInstanceUsage">
+            <soap:operation soapAction="urn:retrieveInstanceUsage" style="document"/>
+            <wsdl:input>
+
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrievePaginatedInstanceUsage">
+            <soap:operation soapAction="urn:retrievePaginatedInstanceUsage" style="document"/>
+            <wsdl:input>
+                <soap:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+
+                <soap:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:binding name="UsageServiceSoap12Binding" type="ns:UsageServicePortType">
+        <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
+        <wsdl:operation name="retrievePaginatedTenantUsages">
+            <soap12:operation soapAction="urn:retrievePaginatedTenantUsages" style="document"/>
+            <wsdl:input>
+
+                <soap12:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap12:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap12:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrieveCurrentTenantUsage">
+            <soap12:operation soapAction="urn:retrieveCurrentTenantUsage" style="document"/>
+            <wsdl:input>
+                <soap12:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap12:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+
+                <soap12:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveTenantUsages">
+            <soap12:operation soapAction="urn:retrieveTenantUsages" style="document"/>
+            <wsdl:input>
+                <soap12:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+
+                <soap12:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap12:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+        <wsdl:operation name="retrieveTenantUsage">
+            <soap12:operation soapAction="urn:retrieveTenantUsage" style="document"/>
+            <wsdl:input>
+
+                <soap12:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap12:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap12:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrieveInstanceUsage">
+            <soap12:operation soapAction="urn:retrieveInstanceUsage" style="document"/>
+            <wsdl:input>
+                <soap12:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap12:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+
+                <soap12:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+        <wsdl:operation name="retrievePaginatedInstanceUsage">
+            <soap12:operation soapAction="urn:retrievePaginatedInstanceUsage" style="document"/>
+            <wsdl:input>
+                <soap12:body use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+
+                <soap12:body use="literal"/>
+            </wsdl:output>
+            <wsdl:fault name="Exception">
+                <soap12:fault use="literal" name="Exception"/>
+            </wsdl:fault>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:binding name="UsageServiceHttpBinding" type="ns:UsageServicePortType">
+        <http:binding verb="POST"/>
+
+        <wsdl:operation name="retrievePaginatedTenantUsages">
+            <http:operation location="retrievePaginatedTenantUsages"/>
+            <wsdl:input>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:input>
+            <wsdl:output>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:output>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrieveCurrentTenantUsage">
+            <http:operation location="retrieveCurrentTenantUsage"/>
+            <wsdl:input>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:input>
+            <wsdl:output>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:output>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrieveTenantUsages">
+            <http:operation location="retrieveTenantUsages"/>
+            <wsdl:input>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:input>
+            <wsdl:output>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:output>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrieveTenantUsage">
+            <http:operation location="retrieveTenantUsage"/>
+            <wsdl:input>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:input>
+            <wsdl:output>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:output>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrieveInstanceUsage">
+            <http:operation location="retrieveInstanceUsage"/>
+            <wsdl:input>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:input>
+            <wsdl:output>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:output>
+        </wsdl:operation>
+
+        <wsdl:operation name="retrievePaginatedInstanceUsage">
+            <http:operation location="retrievePaginatedInstanceUsage"/>
+            <wsdl:input>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:input>
+            <wsdl:output>
+                <mime:content type="text/xml" part="parameters"/>
+            </wsdl:output>
+        </wsdl:operation>
+
+    </wsdl:binding>
+    <wsdl:service name="UsageService">
+        <wsdl:port name="UsageServiceHttpsSoap11Endpoint" binding="ns:UsageServiceSoap11Binding">
+            <soap:address
+                    location="https://10.100.0.19:9446/services/UsageService.UsageServiceHttpsSoap11Endpoint/"/>
+        </wsdl:port>
+        <wsdl:port name="UsageServiceHttpSoap11Endpoint" binding="ns:UsageServiceSoap11Binding">
+            <soap:address
+                    location="http://10.100.0.19:9765/services/UsageService.UsageServiceHttpSoap11Endpoint/"/>
+        </wsdl:port>
+        <wsdl:port name="UsageServiceHttpSoap12Endpoint" binding="ns:UsageServiceSoap12Binding">
+
+            <soap12:address
+                    location="http://10.100.0.19:9765/services/UsageService.UsageServiceHttpSoap12Endpoint/"/>
+        </wsdl:port>
+        <wsdl:port name="UsageServiceHttpsSoap12Endpoint" binding="ns:UsageServiceSoap12Binding">
+            <soap12:address
+                    location="https://10.100.0.19:9446/services/UsageService.UsageServiceHttpsSoap12Endpoint/"/>
+        </wsdl:port>
+        <wsdl:port name="UsageServiceHttpEndpoint" binding="ns:UsageServiceHttpBinding">
+            <http:address
+                    location="http://10.100.0.19:9765/services/UsageService.UsageServiceHttpEndpoint/"/>
+        </wsdl:port>
+        <wsdl:port name="UsageServiceHttpsEndpoint" binding="ns:UsageServiceHttpBinding">
+
+            <http:address
+                    location="https://10.100.0.19:9446/services/UsageService.UsageServiceHttpsEndpoint/"/>
+        </wsdl:port>
+    </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/JSResources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/JSResources.properties b/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/JSResources.properties
new file mode 100644
index 0000000..e7490b0
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/JSResources.properties
@@ -0,0 +1,2 @@
+empty=To make sure the js properties file is not empty
+session.timed.out=Session timed out. Please login again
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/Resources.properties
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/Resources.properties b/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/Resources.properties
new file mode 100644
index 0000000..d7eda93
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/resources/org/apache/carbon/usage/ui/i18n/Resources.properties
@@ -0,0 +1,57 @@
+usage.menu=User Usage
+user.usage.report=User Usage Report
+tenant.menu=Tenant Usage
+tenants.usage.report=Tenant Usage Report
+tenant.usage.report=Usage Report
+data.storage.name=Data Storage
+current.data.storage=Current Data Storage
+history.data.storage=Historical Data Storage
+total.data.storage=Total Data Storage
+registry.content.storage.name=Registry Content
+registry.bandwidth.usage=Registry Bandwidth Usage
+service.bandwidth.usage=Service Bandwidth Usage
+webapp.bandwidth.usage=Webapp Bandwidth Usage
+server.name=Server Name
+all.server.name=All Server Total
+incoming.bandwidth=Incoming Bandwidth
+outgoing.bandwidth=Outgoing Bandwidth
+total.bandwidth=Total Bandwidth
+storage.usage=Storage Usage
+number.of.users=Number of Users
+users=Users
+usage.monitoring=Usage Monitoring
+all.tenant.usage.report=All Tenant Usage
+tenant.domain=Domain
+tenant.id=Id
+full.report=Full Report
+report.duration=Report Duration
+year.month=Year-Month
+back=Back
+page.x.to.y=Page {0}
+prev=Prev
+next=Next
+service.usage.stat=Service Usage Statistics
+service.usage.request=Request Count
+service.usage.response=Response Count
+service.usage.fault=Fault Count
+service.total.request=Service Requests
+registry.total.bandwidth=Total Registry Bandwidth
+service.total.bandwidth=Total Service Bandwidth
+instance.usage.report=Instance Usage Report
+instance.server.url=Instance Server URL
+instance.id=Instance ID
+start.time=Start Time
+stop.time=Stop Time
+used.time.in.hours=Used Time In Hours
+instances.data=Instances Data
+failed.to.get.instance.data=Failed To Get Instance Data
+empty.instance.data=Instance Data Not Found
+usage.data.not.available=Usage Data not available
+empty.usage.data=Usage Data Not Found
+webapp.total.bandwidth=Total WebApp Bandwidth
+number.of.api.calls= Number of API Calls
+api.usage=API Usage
+cartridge.stat=Cartridge Usage
+cartridge.type=Cartridge Type
+image.id=Image ID
+cartridge.hours=Hours
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/df3475cc/components/org.apache.stratos.usage.ui/src/main/resources/web/tenant-usage/all_tenant_instance_usage.jsp
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.usage.ui/src/main/resources/web/tenant-usage/all_tenant_instance_usage.jsp b/components/org.apache.stratos.usage.ui/src/main/resources/web/tenant-usage/all_tenant_instance_usage.jsp
new file mode 100644
index 0000000..32e03ba
--- /dev/null
+++ b/components/org.apache.stratos.usage.ui/src/main/resources/web/tenant-usage/all_tenant_instance_usage.jsp
@@ -0,0 +1,217 @@
+<!--
+  ~  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.
+  -->
+<%@ page import="org.wso2.carbon.usage.stub.beans.xsd.InstanceUsageStatics" %>
+<%@ page import="org.wso2.carbon.usage.stub.beans.xsd.PaginatedInstanceUsage" %>
+<%@ page import="org.wso2.carbon.usage.ui.utils.UsageUtil" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+<%@ taglib uri="http://wso2.org/projects/carbon/taglibs/carbontags.jar" prefix="carbon" %>
+
+<carbon:jsi18n
+        resourceBundle="org.wso2.carbon.usage.ui.i18n.JSResources"
+        request="<%=request%>"/>
+
+
+<fmt:bundle basename="org.wso2.carbon.usage.ui.i18n.Resources">
+    <carbon:breadcrumb
+            label="tenants.usage.report"
+            resourceBundle="org.wso2.carbon.usage.ui.i18n.Resources"
+            topPage="true"
+            request="<%=request%>"/>
+    <jsp:include page="../registry_common/registry_common-i18n-ajaxprocessor.jsp"/>
+    <script type="text/javascript" src="../registry_common/js/registry_validation.js"></script>
+    <script type="text/javascript" src="../registry_common/js/registry_common.js"></script>
+    <script type="text/javascript" src="../ajax/js/prototype.js"></script>
+    <script type="text/javascript" src="../tenant-usage/js/tenant-usage.js"></script>
+    <script type="text/javascript" src="js/all-tenant-usage-report.js"></script>
+    <link rel="stylesheet" type="text/css" href="../tenant-usage/css/tenant-usage.css"/>
+
+
+    <%
+        String yearMonth = request.getParameter("year-month");
+        session.setAttribute("year-month", yearMonth);
+        int pageNumber=0;
+        int rowCount = 5;
+        int numberOfPages=0;
+        InstanceUsageStatics[] instanceUsages=null;
+        if (yearMonth == null) {
+            // get the current year month
+            yearMonth = UsageUtil.getCurrentYearMonth();
+        }
+        try{
+        PaginatedInstanceUsage instanceInfo =
+                UsageUtil.retrievePaginatedInstanceUsages(request, config, session);
+        instanceUsages = instanceInfo.getInstanceUsages();
+        pageNumber = instanceInfo.getPageNumber();
+        numberOfPages = instanceInfo.getNumberOfPages();
+
+        String currentYearMonth = UsageUtil.getCurrentYearMonth();
+
+        if (yearMonth.equals(currentYearMonth)) {
+            rowCount = 7;
+        }
+        }
+        catch (Exception e){
+        //No need to handle here it here.Error will show in next try block
+        //To avoid dead page
+        }
+    %>
+
+    <div id="middle">
+
+        <h2><fmt:message key="instance.usage.report"/> for the Month - <%=yearMonth%> (With All
+            Running Instances)</h2>
+
+        <div id="report_ui">
+            <carbon:reportNew
+                    component="org.wso2.carbon.usage"
+                    template="all_tenant_usage_report"
+                    pdfReport="true"
+                    htmlReport="true"
+                    excelReport="true"
+                    reportDataSession="all_tenant_usage_data"
+                    jsFunction="getUsageReportData()"/>
+        </div>
+
+        <div id="workArea">
+
+            <form id="usageForm" action="all_tenant_instance_usage.jsp" method="post">
+
+
+                <table class="styledLeft">
+                    <thead>
+                    <tr>
+                        <th>
+                            <fmt:message key="report.duration"/>
+                        </th>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <tr>
+                        <td class="nopadding">
+                            <table class="normal-nopadding" cellspacing="0">
+                                <tbody>
+                                <tr>
+                                    <td><fmt:message key="year.month"/></td>
+                                    <td colspan="2">
+                                        <select onchange="this.form.submit()" name="year-month"
+                                                id="year-month" style="width:400px">
+                                            <%
+                                                for (String ym : UsageUtil.getYearMonths()) {
+                                                    String selectedStr = "";
+                                                    if (ym.equals(yearMonth)) {
+                                                        selectedStr = "selected=\"true\" ";
+                                                    }
+                                            %>
+                                            <option <%=selectedStr%> value="<%=ym%>"><%=ym%>
+                                            </option>
+                                            <%
+                                                }
+                                            %>
+                                        </select>
+                                        <input type="hidden" name="requestedPage" id="requestedPage"
+                                               value="<%=pageNumber%>"/>
+                                    </td>
+                                </tr>
+
+                                <tr>
+                                    <td colspan="<%=rowCount%>" class="middle-header"><fmt:message
+                                            key="instances.data"/></td>
+                                </tr>
+                                <tr>
+                                    <th><fmt:message key="instance.id"/></th>
+                                    <th><fmt:message key="server.name"/></th>
+                                    <th><fmt:message key="start.time"/></th>
+                                    <th><fmt:message key="stop.time"/></th>
+                                    <th><fmt:message key="used.time.in.hours"/></th>
+                                </tr>
+                                <%                
+                                    try{
+                                    InstanceUsageStatics[] iu = UsageUtil.retrieveInstanceUsage(request, config, session);
+                                    java.text.SimpleDateFormat dateFormatter = new java.text.SimpleDateFormat("yyyy.MM.dd 'at' hh:mm:ss a zzz");
+                                    if (!iu.equals(null)) {
+                                        for (InstanceUsageStatics usage : instanceUsages) {
+                                            String endDate;
+                                            if (usage.getRunning() == true) {
+                                                endDate="Instance Still Running";
+                                            }
+                                            else{
+                                                endDate=dateFormatter.format(usage.getStopTime().getTime());
+                                            }
+                                            String startDate=dateFormatter.format(usage.getStartTime().getTime());
+                                            long usedHours;
+                                            long usedTimeInSeconds=usage.getUsedTimeInSeconds();
+                                            if(usedTimeInSeconds%3600==0){
+                                                usedHours=usedTimeInSeconds/3600;
+                                            }
+                                            else{
+                                                usedHours=(usedTimeInSeconds/3600)+1;
+                                            }
+                                %>
+                                <tr>
+                                    <td>
+                                        <%=usage.getInstanceID()%>
+                                    </td>
+                                    <td>
+                                        <%=usage.getInstanceURL().toString()%>
+                                    </td>
+                                    <td>
+                                        <%=startDate%>
+                                    </td>
+                                    <td>
+                                        <%=endDate%>
+                                    </td>
+                                    <td>
+
+                                        <%=usedHours%>
+                                    </td>
+                                </tr>
+                                <%
+
+                                        }
+                                    }
+                                    else{
+                                      %>
+                                     <td><fmt:message key="empty.instance.data"/></td>
+                                <%
+                                 }
+                                    }
+                                    catch (Exception e){ %>
+                                      <td><fmt:message key="failed.to.get.instance.data"/></td>
+                                   <% }
+                                %>
+                                <carbon:resourcePaginator pageNumber="<%=pageNumber%>"
+                                                          numberOfPages="<%=numberOfPages%>"
+                                                          resourceBundle="org.wso2.carbon.usage.ui.i18n.Resources"
+                                                          nextKey="next" prevKey="prev"
+                                                          tdColSpan="6"
+                                                          paginationFunction="submitAllTenantPaginatedUsage({0})"/>
+                                </tbody>
+                            </table>
+                        </td>
+                    </tr>
+                    </tbody>
+                </table>
+            </form>
+            <br/>
+        </div>
+    </div>
+</fmt:bundle>
+
+