本文整理汇总了Java中com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize方法的典型用法代码示例。如果您正苦于以下问题:Java OperatingSystemMXBean.getTotalPhysicalMemorySize方法的具体用法?Java OperatingSystemMXBean.getTotalPhysicalMemorySize怎么用?Java OperatingSystemMXBean.getTotalPhysicalMemorySize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.management.OperatingSystemMXBean
的用法示例。
在下文中一共展示了OperatingSystemMXBean.getTotalPhysicalMemorySize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPhysicalMemory
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
/**
* Gets the amount of physical memory (RAM) in this machine, in bytes.
*
* @return the amount of RAM, in bytes; or -1 if the amount of RAM
* cannot be queried.
*/
public static long getPhysicalMemory() {
final Object o = ManagementFactory.getOperatingSystemMXBean();
try {
if (o instanceof OperatingSystemMXBean) {
final OperatingSystemMXBean osb = (OperatingSystemMXBean) o;
return osb.getTotalPhysicalMemorySize();
}
}
catch (NoClassDefFoundError e) {
// com.sun.management.OperatingSystemMXBean doesn't exist in this JVM
}
// We didn't get a com.sun.management.OperatingSystemMXBean.
return -1;
}
示例2: getCartridgeStatistics
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public CartridgeStatistics getCartridgeStatistics() throws IOException {
OperatingSystemMXBean osBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
double totalMemory = (double) (osBean.getTotalPhysicalMemorySize() / MB);
double usedMemory = (double) ((totalMemory - (osBean.getFreePhysicalMemorySize() / MB)));
double loadAvg = (double) osBean.getSystemLoadAverage();
// assume system cores = available cores to JVM
int cores = osBean.getAvailableProcessors();
double memoryConsumption = (usedMemory / totalMemory) * 100;
double loadAvgPercentage = (loadAvg / cores) * 100;
if (log.isDebugEnabled()) {
log.debug("Memory consumption: [totalMemory] " + totalMemory + "Mb [usedMemory] " + usedMemory + "Mb: " + memoryConsumption + "%");
log.debug("Processor consumption: [loadAverage] " + loadAvg + " [cores] " + cores + ": " + loadAvgPercentage + "%");
}
return (new CartridgeStatistics(memoryConsumption, loadAvgPercentage));
}
示例3: refresh
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
public void refresh() {
OperatingSystemMXBean bean= (OperatingSystemMXBean ) ManagementFactory.getOperatingSystemMXBean();
maxFileDescriptorCount = invoke(bean,"getMaxFileDescriptorCount");
openFileDescriptorCount = invoke(bean, "getOpenFileDescriptorCount");
PhysicalMemoryAvaliable = bean.getFreePhysicalMemorySize();
PhysicalMemoryTotal = bean.getTotalPhysicalMemorySize();
systemCpuLoad = (float) bean.getSystemCpuLoad();
processCpuTime = bean.getProcessCpuTime();
processCpuLoad = bean.getProcessCpuLoad();
File[] roots = File.listRoots();
long diskAvaliable=0,diskTotal=0;
for(File file:roots){
diskAvaliable += file.getFreeSpace();
diskTotal += file.getTotalSpace();
}
DiskAvaliable = diskAvaliable;
DiskTotal = diskTotal;
if(isLinux()) {
try {
availableMem =(LinuxInfoUtil.getAvailableMemKB()*1024l);
cpuLoadAverages = LinuxInfoUtil.getCpuLoadAverage();
} catch (Throwable e) {
logger.warn("get linux info failed!");
}
}
}
示例4: getCurrentRamUsage
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
/**
* Gets the current ram usage of this system
*
* @return The current usage in per cent
*/
public static int getCurrentRamUsage() {
OperatingSystemMXBean bean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long total = bean.getTotalPhysicalMemorySize() / 1024;
long used = total - (bean.getFreePhysicalMemorySize() / 1024);
return (int) (100D / (double)total * (double)used);
}
示例5: analyseWinMem
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
private static void analyseWinMem(String resultString, Map<String, Map<String, String>> resultMap,
Map<String, List<Long>> timeRecord) {
long sysTime = System.currentTimeMillis() * 10000;
OperatingSystemMXBean osmb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long totalMem = osmb.getTotalPhysicalMemorySize();
String[] lines = resultString.split("\n");
int beginline = 3; // data begin at line 3
for (int i = beginline; i < lines.length; i++) {
if (lines[i].length() == 0) {
continue;
}
String statusArgs[] = lines[i].split("\\s+");
String pid = statusArgs[1];
Map<String, String> statusMap = resultMap.get(pid);
long mem = Long.parseLong(statusArgs[3]);
DecimalFormat decimalFormat = new DecimalFormat("0.00");
float memrate = (float) mem / (float) totalMem;
String memRate = decimalFormat.format(memrate * 100);
statusMap.put(MEM, String.valueOf(mem / 1024));
statusMap.put(MEMRATE, memRate);
String kernelmodetime = statusArgs[0];
String usermodetime = statusArgs[2];
long nt = Long.parseLong(kernelmodetime) + Long.parseLong(usermodetime);
List<Long> otList;
otList = new ArrayList<Long>(2);
otList.add(nt);
otList.add(sysTime);
timeRecord.put(pid, otList);
}
}
示例6: setup
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@BeforeSuite
public static void setup() {
java.lang.management.OperatingSystemMXBean bean =
ManagementFactory.getOperatingSystemMXBean();
if (bean instanceof OperatingSystemMXBean) {
OperatingSystemMXBean os = (OperatingSystemMXBean)bean;
long physicalMemorySize = os.getTotalPhysicalMemorySize() / (1024 * 1024);
System.out.println("System memory size: " + physicalMemorySize + "M");
// when we can get system memory size, and it's larger than 2G,
// then we enable large array size test below,
// else disable large array size test below.
if (physicalMemorySize > (2 * 1024)) {
arraySizeCollection = new int[]{
SMALL_ARRAY_SIZE,
THRESHOLD_ARRAY_SIZE,
MEDIUM_ARRAY_SIZE,
LARGE_ARRAY_SIZE
};
System.out.println("System memory is large enough, add large array size test");
return;
}
}
arraySizeCollection = new int[]{
SMALL_ARRAY_SIZE,
THRESHOLD_ARRAY_SIZE,
MEDIUM_ARRAY_SIZE
};
System.out.println("System memory is not large enough, remove large array size test");
}
示例7: getFreeMemory
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public int getFreeMemory() {
OperatingSystemMXBean osmxb = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
long totalVirtualMemory = osmxb.getTotalPhysicalMemorySize();
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
Double compare = (freePhysicalMemorySize * 1.0 / totalVirtualMemory) * 100;
return compare.intValue();
}
示例8: getFreeMemory
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
public int getFreeMemory(){
OperatingSystemMXBean osmxb = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
long totalVirtualMemory = osmxb.getTotalPhysicalMemorySize();
long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();
Double compare = (freePhysicalMemorySize * 1.0 / totalVirtualMemory) * 100;
return compare.intValue();
}
示例9: onCommand
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
public boolean onCommand(WhiteCommandSender sender, Command command, String label, String[] args) {
OperatingSystemMXBean systemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
long totalPhysicalMemorySize = systemMXBean.getTotalPhysicalMemorySize();
long usedMemory = (totalPhysicalMemorySize - systemMXBean.getFreePhysicalMemorySize());
// int kb = 1000;
int kbi = 1024;
System.out.println(systemMXBean.getFreePhysicalMemorySize() / kbi);
System.out.println(totalPhysicalMemorySize / kbi);
sender.sendMessage("&7----- &6SYSTEM -----");
sender.sendMessage("&7CPU Usage : &6" + new BigDecimal(systemMXBean.getSystemCpuLoad() * 100.0D).setScale(1, 4).doubleValue() + "&f%");
sender.sendMessage("&7Use Memory : &6" + ((usedMemory / kbi) / kbi) + "&7MB ( " + (100 * systemMXBean.getFreePhysicalMemorySize() / totalPhysicalMemorySize) + "% )");
return true;
}
示例10: checkMemory
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
private void checkMemory() {
final OperatingSystemMXBean os = (com.sun.management.OperatingSystemMXBean)
ManagementFactory.getOperatingSystemMXBean();
final long maxMemory = Runtime.getRuntime().maxMemory();
if (maxMemory < (os.getTotalPhysicalMemorySize() / 4)) {
logger.warn(String.format("Memory available to JVM (%s) is less than 25%% of available system memory. " +
"You should probably increase it.", FileUtils.byteCountToDisplaySize(maxMemory)));
}
}
示例11: check
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
protected Result check() throws Exception {
OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
long pmSize = osBean.getTotalPhysicalMemorySize() / 1000000000;
System.out.println(pmSize);
return pmSize < minMemory ? Result.unhealthy("At least " + minMemory + "G RAM is required to make this application stable") : Result.healthy();
}
示例12: getPhysicalMemoryUsage
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@SuppressWarnings("restriction")
public static float getPhysicalMemoryUsage()
{
OperatingSystemMXBean osmxb = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();
long totalMemorySize = osmxb.getTotalPhysicalMemorySize();
long usedMemorySize = (osmxb.getTotalPhysicalMemorySize() - osmxb.getFreePhysicalMemorySize());
return (float)((double)usedMemorySize / (double)totalMemorySize);
}
示例13: main
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public static void main(String strs[]){
OperatingSystemMXBean bean =
(OperatingSystemMXBean)
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
long max = bean.getTotalPhysicalMemorySize();
double formatMemoryInGB=max/1024.0/1024.0/1024.0;
String OS = System.getProperty( "sun.arch.data.model") ;
System.out.println(OS);
}
示例14: getPhysicalTotal
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
/**
* 获取剩余内存
*
* @return
*/
public static long getPhysicalTotal() {
OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory
.getOperatingSystemMXBean();
// 系统总物理内存
long physicalTotal = osmxb.getTotalPhysicalMemorySize() / mb;
// 单位是mb
return physicalTotal;
}
示例15: PerformanceStatus
import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public PerformanceStatus() {
OperatingSystemMXBean bean= (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
heapMemoryUsage= memBean.getHeapMemoryUsage();
nonHeapMemoryUsage = memBean.getNonHeapMemoryUsage();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
currentThreadCount=threadBean.getThreadCount();
daemonThreadCount= threadBean.getDaemonThreadCount();
beanCreatedThreadCount= threadBean.getTotalStartedThreadCount();
peakThreadCount = threadBean.getPeakThreadCount();
ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
loadedClassCount=classLoadingBean.getLoadedClassCount();
totalLoadedClassCount=classLoadingBean.getTotalLoadedClassCount();
unloadedClassCount=classLoadingBean.getUnloadedClassCount();
committedVirtualMemorySize = (bean.getCommittedVirtualMemorySize());
freePhysicalMemorySize =(bean.getFreePhysicalMemorySize());
totalPhysicalMemorySize =(bean.getTotalPhysicalMemorySize());
freeSwapSpaceSize =(bean.getFreeSwapSpaceSize());
totalSwapSpaceSize =(bean.getTotalSwapSpaceSize());
processCpuTime =(bean.getProcessCpuTime());
availableProcessors =bean.getAvailableProcessors();
processCpuLoad =bean.getProcessCpuLoad();
systemCpuLoad =bean.getSystemCpuLoad();
systemLoadAverage =bean.getSystemLoadAverage();
appStartUpTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(runtimeBean.getStartTime()));
runtime = (new Date().getTime() - runtimeBean.getStartTime())/1000;
os = bean.getName()+" "+bean.getVersion();
if(HostInfo.isLinux()){
try {
availableMemory = (LinuxInfoUtil.getAvailableMemKB()*1024l);
} catch (Throwable ignored) {
}
}
File[] roots = File.listRoots();
for(File file:roots){
rootFiles.add(new RootFile(file.getAbsolutePath(),file.getTotalSpace(),file.getFreeSpace()));
}
getGCStatus();
}