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


Java OperatingSystemMXBean.getFreePhysicalMemorySize方法代码示例

本文整理汇总了Java中com.sun.management.OperatingSystemMXBean.getFreePhysicalMemorySize方法的典型用法代码示例。如果您正苦于以下问题:Java OperatingSystemMXBean.getFreePhysicalMemorySize方法的具体用法?Java OperatingSystemMXBean.getFreePhysicalMemorySize怎么用?Java OperatingSystemMXBean.getFreePhysicalMemorySize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.management.OperatingSystemMXBean的用法示例。


在下文中一共展示了OperatingSystemMXBean.getFreePhysicalMemorySize方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

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

示例8: getMemeryRate

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
/**
 * 获取内存使用率  
 * @return
 */
public static String getMemeryRate()  
{  
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean();  
    // 总的物理内存+虚拟内存  
    long totalvirtualMemory = osmxb.getTotalSwapSpaceSize();  
    // 剩余的物理内存  
    long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize();  
    Double compare = (Double)(1 - freePhysicalMemorySize * 1.0 / totalvirtualMemory) * 100;  
    String str = compare.intValue() + "%";  
    return str;  
}
 
开发者ID:binghuo365,项目名称:csustRepo,代码行数:16,代码来源:GetSystemInfo.java

示例9: 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

示例10: VMSummary

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public VMSummary(){
    MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
    MemoryUsage u = bean.getHeapMemoryUsage();
    heapCommitedMemory= (u.getCommitted());
    heapUsedMemory=(u.getUsed());
    heapMaxMemory=(u.getMax());

    u = bean.getNonHeapMemoryUsage();
    nonHeapCommitedMemory=(u.getCommitted());
    nonHeapUsedMemory=(u.getUsed());
    nonHeapMaxMemory=(u.getMax());

    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    currentThreadCount=threadBean.getThreadCount();
    daemonThreadCount= threadBean.getDaemonThreadCount();
    totalStartedThreadCount= threadBean.getTotalStartedThreadCount();
    peakThreadCount = threadBean.getPeakThreadCount();

    ClassLoadingMXBean classLoadingBean = ManagementFactory.getClassLoadingMXBean();
    loadedClassCount=classLoadingBean.getLoadedClassCount();
    totalLoadedClassCount=classLoadingBean.getTotalLoadedClassCount();
    unloadedClassCount=classLoadingBean.getUnloadedClassCount();
    getGCStatus();

    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    classPath = runtimeBean.getClassPath();
    libraryPath = runtimeBean.getLibraryPath();
    vmOptions = TextUtils.join(" ",runtimeBean.getInputArguments());
    bootClassPath = runtimeBean.getBootClassPath();
    upTime = runtimeBean.getUptime();

    vmName=runtimeBean.getVmName();
    vmVendor= runtimeBean.getVmVendor();


    OperatingSystemMXBean osBean= (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();

    processCpuTime = osBean.getProcessCpuTime();

    jdkVersion=System.getProperty("java.version");
    jitCompiler=System.getProperty("java.vm.name");

    os = osBean.getName() + " "+osBean.getVersion();
    osArch = osBean.getArch();
    availableProcessors = osBean.getAvailableProcessors();

     commitedVirtualMemory = osBean.getCommittedVirtualMemorySize();
    freePhysicalMemorySize =(osBean.getFreePhysicalMemorySize());
    totalPhysicalMemorySize =(osBean.getTotalPhysicalMemorySize());

    freeSwapSpaceSize =(osBean.getFreeSwapSpaceSize());
    totalSwapSpaceSize =(osBean.getTotalSwapSpaceSize());

    List<GarbageCollectorMXBean> beans = ManagementFactory.getGarbageCollectorMXBeans();
    gcInfos = new ArrayList<>(beans.size());
    for (GarbageCollectorMXBean b : beans) {
        GCBean gcBean = new GCBean();
        gcBean.name =b.getName();
        gcBean.gcCount = b.getCollectionCount();
        gcBean.gcTime = b.getCollectionTime();
        gcInfos.add(gcBean);
    }

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

示例11: getSystemInfo

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public static SystemMonitorInfo getSystemInfo() {
    // 可使用内存   
    long totalMemory = Runtime.getRuntime().totalMemory() / SIZE;   
    // 剩余内存   
    long freeMemory = Runtime.getRuntime().freeMemory() / SIZE;   
    // 最大可使用内存   
    long maxMemory = Runtime.getRuntime().maxMemory() / SIZE; 
    
    OperatingSystemMXBean osmxb = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();   
    // 操作系统   
    String osName = System.getProperty("os.name");   
    // 总的物理内存   
    long totalMemorySize = osmxb.getTotalPhysicalMemorySize() / SIZE;   
    // 剩余的物理内存   
    long freePhysicalMemorySize = osmxb.getFreePhysicalMemorySize() / SIZE;   
    // 已使用的物理内存   
    long usedMemory = (osmxb.getTotalPhysicalMemorySize() - osmxb   
            .getFreePhysicalMemorySize())   
            / SIZE;   
    // 获得线程总数   
    ThreadGroup parentThread;   
    for (parentThread = Thread.currentThread().getThreadGroup(); parentThread   
            .getParent() != null; parentThread = parentThread.getParent()); 
    int totalThread = parentThread.activeCount();   
  
    int cpuRatio = 0;   
    if (osName.toLowerCase().startsWith("windows")) {   
        cpuRatio = (int)getCpuRatioForWindows();   
    }   
    int memoryRatio = (int) ((1 - usedMemory * 1.0 / totalMemorySize) * 100);
    // 构造返回对象   
    SystemMonitorInfo infoBean = new SystemMonitorInfo();   
    infoBean.setFreeMemory(freeMemory);   
    infoBean.setFreePhysicalMemorySize(freePhysicalMemorySize);   
    infoBean.setMaxMemory(maxMemory);   
    infoBean.setOsName(osName);   
    infoBean.setTotalMemory(totalMemory);   
    infoBean.setTotalMemorySize(totalMemorySize);   
    infoBean.setTotalThread(totalThread);   
    infoBean.setUsedMemory(usedMemory);   
    infoBean.setCpuRatio(cpuRatio);   
    infoBean.setMemoryRatio(memoryRatio);
    return infoBean;   
}
 
开发者ID:Fetax,项目名称:Fetax-AI,代码行数:45,代码来源:SystemMonitorUtil.java

示例12: getLeftMemory

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
/**
 * 获取剩余内存
 * @return
 */
public static Long getLeftMemory(){
 OperatingSystemMXBean osmxb=(OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
 // 剩余的物理内存  
 return osmxb.getFreePhysicalMemorySize();  
}
 
开发者ID:binghuo365,项目名称:csustRepo,代码行数:10,代码来源:GetSystemInfo.java

示例13: backgroudFinishCallback

import com.sun.management.OperatingSystemMXBean; //导入方法依赖的package包/类
private void backgroudFinishCallback() {
	HashMap<String, CpuInfo> cpus = coresManager.getCPUsInfo();
	
	CpuInfo cpuInfo;
	XYChart.Data data;
	
	for (Entry<String, CpuInfo> entry: cpus.entrySet()) {
		Rectangle rect = new Rectangle(0, 0);
		rect.setVisible(false);
	
		cpuInfo = entry.getValue();
		data = new XYChart.Data(currentGraphPosition, cpuInfo.getUsage());
		data.setNode(rect);
		
		if (currentGraphPosition > MAX_DATA_POINTS) {	
			cpuInfo.getSeries().getData().remove(0);
		}
		
		cpuInfo.getSeries().getData().add(data);
		cpuInfo.getLabel().setText(cpuInfo.getName() + ": " + Math.round(cpuInfo.getUsage()) + "%");
	}
	
	
	
	OperatingSystemMXBean os = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
	
	//os.getTotalPhysicalMemorySize()
	
	double usedPercent = 100 * ((double) (1.0 -  ((double) os.getFreePhysicalMemorySize() / (double) os.getTotalPhysicalMemorySize())));
	
	//System.out.println("usedPercent: " + Runtime.getRuntime().freeMemory() / 1024);
	//System.out.println("usedPercent: " + Runtime.getRuntime().totalMemory()/ 1024);
	//System.out.println("        divi: " + ((double)Runtime.getRuntime().freeMemory()/(double)Runtime.getRuntime().totalMemory()));
	//System.out.println("\n\n");
	
	
	
	usedPercent = Math.round(usedPercent > 99.9? 100 : usedPercent);
	
	Rectangle memRect = new Rectangle(0, 0);
	memRect.setVisible(false);
	
	XYChart.Data memoryData = new XYChart.Data(currentGraphPosition, usedPercent);
	memoryData.setNode(memRect);
	
	memoryChart.setTitle("Uso de memória (" + usedPercent + "%)");
	
	if (currentGraphPosition > MAX_DATA_POINTS) {	
		memorySeries.getData().remove(0);
	}
	
	memorySeries.getData().add(memoryData);
	
	if (currentGraphPosition > MAX_DATA_POINTS) {
		xCPUAxis.setLowerBound(currentGraphPosition - MAX_DATA_POINTS);
		xCPUAxis.setUpperBound(currentGraphPosition);
		
		xMemoryAxis.setLowerBound(currentGraphPosition - MAX_DATA_POINTS);
		xMemoryAxis.setUpperBound(currentGraphPosition);
	}
	
	currentGraphPosition ++;
}
 
开发者ID:dhiogoboza,项目名称:SystemMonitorJFX,代码行数:64,代码来源:MainStage.java


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