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


Java Mem类代码示例

本文整理汇总了Java中org.hyperic.sigar.Mem的典型用法代码示例。如果您正苦于以下问题:Java Mem类的具体用法?Java Mem怎么用?Java Mem使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: onCommand

import org.hyperic.sigar.Mem; //导入依赖的package包/类
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!isAllowed(sender, command)) {
        sender.sendMessage(org.bukkit.ChatColor.DARK_RED + "Not whitelisted");
        return true;
    }

    if (!plugin.getConfig().getBoolean("native-library")) {
        sender.sendMessage(ChatColor.DARK_RED + "Native support is disabled");
        return true;
    }

    //swap and load is already available in the environment command because MBeans already supports this
    Sigar sigar = plugin.getNativeData().getSigar();
    try {
        int uptime = (int) sigar.getUptime().getUptime();
        sender.sendMessage(PRIMARY_COLOR + "OS Uptime: " + SECONDARY_COLOR + formatUptime(uptime));

        CpuInfo[] cpuInfoList = sigar.getCpuInfoList();
        int mhz = cpuInfoList[0].getMhz();
        sender.sendMessage(PRIMARY_COLOR + "CPU MHZ: " + SECONDARY_COLOR + mhz);

        CpuPerc cpuPerc = sigar.getCpuPerc();
        //IO wait
        double wait = cpuPerc.getWait();
        sender.sendMessage(PRIMARY_COLOR + "CPU Wait (I/O): " + SECONDARY_COLOR + wait + '%');

        Mem mem = sigar.getMem();
        //included cache
        long actualUsed = mem.getActualUsed();
        long used = mem.getUsed();

        long cache = used - actualUsed;
        sender.sendMessage(PRIMARY_COLOR + "Memory Cache: " + SECONDARY_COLOR + Sigar.formatSize(cache));

        printNetworkInfo(sender, sigar);

        //disk read write
        List<String> diskNames = Arrays.stream(sigar.getFileSystemList())
                .map(FileSystem::getDevName)
                .filter(name -> name.startsWith("/dev/sd"))
                .distinct()
                .collect(Collectors.toList());

        Collection<DiskUsage> diskUsages = new ArrayList<>();
        for (String diskName : diskNames) {
            diskUsages.add(sigar.getDiskUsage(diskName));
        }

        long diskReads = diskUsages.stream().mapToLong(DiskUsage::getReadBytes).sum();
        long diskWrites = diskUsages.stream().mapToLong(DiskUsage::getWriteBytes).sum();


        String diskReadBytes = Sigar.formatSize(diskReads);
        String diskWriteBytes = Sigar.formatSize(diskWrites);

        sender.sendMessage(PRIMARY_COLOR + "Disk read bytes: " + SECONDARY_COLOR + diskReadBytes);
        sender.sendMessage(PRIMARY_COLOR + "Disk write bytes: " + SECONDARY_COLOR + diskWriteBytes);

        sender.sendMessage(PRIMARY_COLOR + "Filesystems:");
        for (FileSystem fileSystem : sigar.getFileSystemList()) {
            String dirName = fileSystem.getDirName();
            String typeName = fileSystem.getSysTypeName();
            sender.sendMessage(PRIMARY_COLOR + dirName + " - " + SECONDARY_COLOR + typeName);
        }
    } catch (SigarException sigarException) {
        plugin.getLogger().log(Level.SEVERE, null, sigarException);
    }

    return true;
}
 
开发者ID:games647,项目名称:LagMonitor,代码行数:72,代码来源:NativeCommand.java

示例2: getCurrentWorkerStat

import org.hyperic.sigar.Mem; //导入依赖的package包/类
public WorkerStat getCurrentWorkerStat(){
	try {
		CpuPerc cpp=sigar.getCpuPerc();
		Mem mem=sigar.getMem();			
		workerStat.cpuUsage=cpp.getCombined();
		workerStat.memUsed=mem.getActualUsed();
		workerStat.memFree=mem.getActualFree();
		workerStat.timestampMS=System.currentTimeMillis();
		workerStat.instanceCount=worker.insMap.size();
		return workerStat;
	}
	catch (SigarException e) {
		e.printStackTrace();
		return workerStat;
	}
}
 
开发者ID:HoratiusTang,项目名称:EsperDist,代码行数:17,代码来源:WorkerStatCollector.java

示例3: updateMachineInfo

import org.hyperic.sigar.Mem; //导入依赖的package包/类
@Override
public MachineInfo updateMachineInfo(MachineInfo info)
{
    Sigar sigar = new Sigar();
	long maxMemory = Runtime.getRuntime().maxMemory();
	long totalMemory = Runtime.getRuntime().totalMemory();
	long freeMemory = Runtime.getRuntime().freeMemory();
	info.setUsedMaxMemoryUsage((float) ((double) (maxMemory - freeMemory) / (double) maxMemory));
	info.setUsedTotalMemoryUsage((float) ((double) (totalMemory - freeMemory) / (double) totalMemory));
       Mem memory = null;
       try {
           memory = sigar.getMem();
           info.setUsedPhysicalMemoryUsage((float)((double) memory.getUsed() / (double)memory.getTotal()));
       } catch (SigarException e) {
           log.error(e.getMessage(), e);
       }
	updateProcessCpuUsage(sigar, info);
	updateSystemCpuUsage(sigar, info);
	info.setHealthyScore(NodeHealth.evaluateLocal(info));
	return info;
}
 
开发者ID:liulhdarks,项目名称:darks-grid,代码行数:22,代码来源:SigarMachineInfoFactory.java

示例4: calculateStats

import org.hyperic.sigar.Mem; //导入依赖的package包/类
public void calculateStats() {
    numCores = Runtime.getRuntime().availableProcessors();
    Sigar sigar = new Sigar();
    try {
        CpuInfo[] cpuInfo = sigar.getCpuInfoList();
        cpuFreq = cpuInfo[0].getMhz();
        Mem memInfo = sigar.getMem();
        freeRAM = memInfo.getFreePercent();
        cpuLoad = sigar.getLoadAverage();
        for (int i = 0; i < getCpuLoad().length; i++) {
            cpuLoad[i] /= numCores;
        }
    } catch (SigarException ex) {
        ex.printStackTrace();
    }
}
 
开发者ID:adityashah30,项目名称:dcs,代码行数:17,代码来源:StatsCalculator.java

示例5: getNodeMemoryInfo

import org.hyperic.sigar.Mem; //导入依赖的package包/类
/**
 * Method getNodeMemoryInfo.
 * 
 * @return Map<Object,Object>
 */
public Map<Object, Object> getNodeMemoryInfo() {
	Map<Object, Object> nodeMemoryInfo = new HashMap<Object, Object>();
	Mem mem = null;

	try {
		mem = sigar.getMem();
	} catch (Exception e) {
		LOGGER.error(e.getMessage(), e);
	}

	nodeMemoryInfo.put("total", mem.getTotal());
	nodeMemoryInfo.put("free", mem.getFree());
	nodeMemoryInfo.put("used", mem.getUsed());
	nodeMemoryInfo.put("actualFree", mem.getActualFree());
	nodeMemoryInfo.put("actualUsed", mem.getActualUsed());
	nodeMemoryInfo.put("freePercentage", mem.getFreePercent());
	nodeMemoryInfo.put("usedPercentage", mem.getUsedPercent());

	return nodeMemoryInfo;
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:26,代码来源:SigarNodeInfoProvider.java

示例6: executeCommand

import org.hyperic.sigar.Mem; //导入依赖的package包/类
@Override
public String executeCommand(final SigarProxy sigar) throws SigarException {
	StrBuilder sb = new StrBuilder(200);

	Mem mem = sigar.getMem();

	sb.append(TYPE_MEM);
	sb.append(separator);
	sb.append(mem.getTotal() / 1024L);
	sb.append(separator);
	sb.append(mem.getUsed() / 1024L);
	sb.append(separator);
	sb.append(mem.getFree() / 1024L);
	sb.append(separator);
	sb.append(mem.getActualUsed() / 1024L);
	sb.append(separator);
	sb.append(mem.getActualFree() / 1024L);

	return sb.toString();
}
 
开发者ID:mgm-tp,项目名称:perfload-perfmon,代码行数:21,代码来源:PerfMonMem.java

示例7: output

import org.hyperic.sigar.Mem; //导入依赖的package包/类
public void output(String[] args) throws SigarException {
    Mem mem   = this.sigar.getMem();
    Swap swap = this.sigar.getSwap();

    Object[] header = new Object[] { "total", "used", "free" };

    Object[] memRow = new Object[] {
        format(mem.getTotal()),
        format(mem.getUsed()),
        format(mem.getFree())
    };

    Object[] actualRow = new Object[] {
        format(mem.getActualUsed()),
        format(mem.getActualFree())
    };

    Object[] swapRow = new Object[] {
        format(swap.getTotal()),
        format(swap.getUsed()),
        format(swap.getFree())
    };

    printf("%18s %10s %10s", header);

    printf("Mem:    %10ld %10ld %10ld", memRow);

    //e.g. linux
    if ((mem.getUsed() != mem.getActualUsed()) ||
        (mem.getFree() != mem.getActualFree()))
    {
        printf("-/+ buffers/cache: " + "%10ld %10d", actualRow);
    }

    printf("Swap:   %10ld %10ld %10ld", swapRow);

    printf("RAM:    %10ls", new Object[] { mem.getRam() + "MB" });
}
 
开发者ID:EnFlexIT,项目名称:AgentWorkbench,代码行数:39,代码来源:Free.java

示例8: getPhysicalMemory

import org.hyperic.sigar.Mem; //导入依赖的package包/类
/**
 * 2.内存资源信息
 */

public void getPhysicalMemory() {
	// a)物理内存信息
	DecimalFormat df = new DecimalFormat("#0.00");
	Sigar sigar = new Sigar();
	Mem mem;
	try {
		mem = sigar.getMem();
		// 内存总量
		System.out.println("内存总量:" + df.format((float) mem.getTotal() / 1024 / 1024 / 1024) + "G");
		// 当前内存使用量
		System.out.println("当前内存使用量:" + df.format((float) mem.getUsed() / 1024 / 1024 / 1024) + "G");
		// 当前内存剩余量
		System.out.println("当前内存剩余量:" + df.format((float) mem.getFree() / 1024 / 1024 / 1024) + "G");
		// b)系统页面文件交换区信息
		Swap swap = sigar.getSwap();
		// 交换区总量
		System.out.println("交换区总量:" + df.format((float) swap.getTotal() / 1024 / 1024 / 1024) + "G");
		// 当前交换区使用量
		System.out.println("当前交换区使用量:" + df.format((float) swap.getUsed() / 1024 / 1024 / 1024) + "G");
		// 当前交换区剩余量
		System.out.println("当前交换区剩余量:" + df.format((float) swap.getFree() / 1024 / 1024 / 1024) + "G");
	} catch (SigarException e) {
		e.printStackTrace();
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:30,代码来源:SysInfo.java

示例9: getMemoryUsage

import org.hyperic.sigar.Mem; //导入依赖的package包/类
/**
 * @desc 获取内存使用率
 *
 * @author liuliang
 *
 * @return Double 比例(保留2位小数)
 */
public static Double getMemoryUsage() {
	double memoryUsage = 0;
	try {
		Mem mem = getInstance().getMem();
		memoryUsage = NumberUtil.format(mem.getUsedPercent());
	} catch (SigarException e) {
		e.printStackTrace();
	}
	return memoryUsage;
}
 
开发者ID:yunjiweidian,项目名称:TITAN,代码行数:18,代码来源:SigarUtil.java

示例10: totalMem

import org.hyperic.sigar.Mem; //导入依赖的package包/类
/**
 * 获取总内存
 */
public static long totalMem() throws SigarException{
	if(staticResource.totalMem == null){
		Mem mem = sigar.getMem();
		staticResource.totalMem = (long)(mem.getTotal()/1048576);
	}
	return staticResource.totalMem;
}
 
开发者ID:yanfanvip,项目名称:RedisClusterManager,代码行数:11,代码来源:MonitorUtil.java

示例11: getTotalRam

import org.hyperic.sigar.Mem; //导入依赖的package包/类
/**
 * Gets the total RAM memory available on the device.
 *
 * @return the total RAM memory in MBs.
 */
public static long getTotalRam() {
    try {
        Mem memory = sigar.getMem();
        long totalMemory = memory.getTotal();

        // Convert the total memory from bytes to MBs.
        totalMemory /= 1024 * 1024;
        return totalMemory;
    } catch (SigarException e) {
        LOGGER.warn("Could not get total RAM memory.", e);
    }

    return FALLBACK_TOTAL_RAM;
}
 
开发者ID:MusalaSoft,项目名称:atmosphere-agent,代码行数:20,代码来源:SystemInformation.java

示例12: getFreeRam

import org.hyperic.sigar.Mem; //导入依赖的package包/类
/**
 * Gets the free RAM memory available on the device.
 *
 * @return the free RAM memory in MBs.
 */
public static long getFreeRam() {
    try {
        Mem memory = sigar.getMem();
        long freeMemory = memory.getFree();

        // Convert the free memory from bytes to MBs.
        freeMemory /= 1024 * 1024;
        return freeMemory;
    } catch (SigarException e) {
        LOGGER.warn("Could not get the free RAM memory.", e);
    }

    return FALLBACK_FREE_RAM;
}
 
开发者ID:MusalaSoft,项目名称:atmosphere-agent,代码行数:20,代码来源:SystemInformation.java

示例13: osMemStats

import org.hyperic.sigar.Mem; //导入依赖的package包/类
/**
 * Generate memory statistics
 * http://casidiablo.net/capturar-informacion-sistema-operativo-java/
 */
public JFreeChart osMemStats() throws IOException, ServletException {
	DefaultPieDataset dataset = new DefaultPieDataset();
	Sigar sigar = new Sigar();
	String title = null;

	try {
		Mem mem = sigar.getMem();
		long max = mem.getRam();
		long available = mem.getFree();
		long total = mem.getTotal();
		long used = mem.getUsed();
		long free = mem.getFree();
		title = "OS memory: " + FormatUtil.formatSize(total);

		log.debug("OS maximun memory: {}", FormatUtil.formatSize(max));
		log.debug("OS available memory: {}", FormatUtil.formatSize(available));
		log.debug("OS free memory: {}", FormatUtil.formatSize(free));
		log.debug("OS used memory: {}", FormatUtil.formatSize(used));
		log.debug("OS total memory: {}", FormatUtil.formatSize(total));

		dataset.setValue("Available (" + FormatUtil.formatSize(free) + ")", free * 100 / total);
		dataset.setValue("Used (" + FormatUtil.formatSize(used) + ")", used * 100 / total);
	} catch (SigarException se) {
		title = "OS memory: " + se.getMessage();
	} catch (UnsatisfiedLinkError ule) {
		title = "OS memory: (missing native libraries)";
	}

	return ChartFactory.createPieChart(title, dataset, true, false, false);
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:35,代码来源:StatsGraphServlet.java

示例14: getTotalMemory

import org.hyperic.sigar.Mem; //导入依赖的package包/类
public long getTotalMemory() {
    if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
        com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
        return nativeOsBean.getTotalPhysicalMemorySize();
    } else if (sigar != null) {
        try {
            Mem mem = sigar.getMem();
            return mem.getTotal();
        } catch (SigarException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }

    return -1;
}
 
开发者ID:games647,项目名称:LagMonitor,代码行数:16,代码来源:NativeData.java

示例15: getFreeMemory

import org.hyperic.sigar.Mem; //导入依赖的package包/类
public long getFreeMemory() {
    if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
        com.sun.management.OperatingSystemMXBean nativeOsBean = (com.sun.management.OperatingSystemMXBean) osBean;
        return nativeOsBean.getFreePhysicalMemorySize();
    } else if (sigar != null) {
        try {
            Mem mem = sigar.getMem();
            return mem.getFree();
        } catch (SigarException ex) {
            logger.log(Level.SEVERE, null, ex);
        }
    }

    return -1;
}
 
开发者ID:games647,项目名称:LagMonitor,代码行数:16,代码来源:NativeData.java


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