/** * Project: dubbo.registry.server-1.1.0-SNAPSHOT * * File Created at 2009-12-27 * $Id: MemoryStatusChecker.java 181192 2012-06-21 05:05:47Z tony.chenl $ * * Copyright 2008 Alibaba.com Croporation Limited. * All rights reserved. * * This software is the confidential and proprietary information of * Alibaba Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with Alibaba.com. */ package com.alibaba.dubbo.governance.status; import com.alibaba.dubbo.common.status.Status; import com.alibaba.dubbo.common.status.StatusChecker; /** * MemoryStatus * * @author william.liangf */ public class MemoryStatusChecker implements StatusChecker { public Status check() { Runtime runtime = Runtime.getRuntime(); long freeMemory = runtime.freeMemory(); long totalMemory = runtime.totalMemory(); long maxMemory = runtime.maxMemory(); boolean ok = (maxMemory - (totalMemory - freeMemory) > 2048); // 剩余空间小于2M报警 String msg = "Max:" + (maxMemory / 1024 / 1024) + "M, Total:" + (totalMemory / 1024 / 1024) + "M, Free:" + (freeMemory / 1024 / 1024) + "M, Use:" + ((totalMemory / 1024 / 1024) - (freeMemory / 1024 / 1024)) + "M"; return new Status(ok ? Status.Level.OK : Status.Level.WARN, msg); } }