當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。