当前位置: 首页>>代码示例>>Java>>正文


Java OperatingSystemMXBean.getTotalPhysicalMemorySize方法代码示例

本文整理汇总了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;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:23,代码来源:MemoryUtils.java

示例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));
}
 
开发者ID:apache,项目名称:stratos,代码行数:18,代码来源:HealthStatisticsReader.java

示例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!");
        }
    }

}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:30,代码来源:HostInfo.java

示例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);
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:14,代码来源:SystemUtil.java

示例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);
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:32,代码来源:OSProcessHelper.java

示例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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:30,代码来源:ParallelPrefix.java

示例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();
}
 
开发者ID:MSUNorg,项目名称:luckyBlog,代码行数:8,代码来源:MonitorSer.java

示例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();
}
 
开发者ID:jcalaz,项目名称:jcalaBlog,代码行数:9,代码来源:MonitorSerImpl.java

示例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;
    }
 
开发者ID:niwaniwa,项目名称:WhiteEggCore,代码行数:15,代码来源:WhiteEggSystemCommand.java

示例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)));
	}
}
 
开发者ID:ICIJ,项目名称:extract,代码行数:11,代码来源:SpewTask.java

示例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();
}
 
开发者ID:JingGe,项目名称:dropwizard,代码行数:10,代码来源:SimpleHealthCheck.java

示例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);
}
 
开发者ID:liulhdarks,项目名称:darks-grid,代码行数:9,代码来源:MachineUtils.java

示例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);
}
 
开发者ID:sizhaoliu,项目名称:MemoryManagementBenchmark,代码行数:11,代码来源:test.java

示例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;

}
 
开发者ID:suhuanzheng7784877,项目名称:ParallelExecute,代码行数:17,代码来源:SystemUtil.java

示例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();
}
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:48,代码来源:PerformanceStatus.java


注:本文中的com.sun.management.OperatingSystemMXBean.getTotalPhysicalMemorySize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。