Java Code Examples for org.hyperic.sigar.Mem

The following examples show how to use org.hyperic.sigar.Mem. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sigar-system_runtime   Source File: sigar.java    License: MIT License 6 votes vote down vote up
private static void memory() throws SigarException {
    Sigar sigar = new Sigar();
    Mem mem = sigar.getMem();
    // 内存总量
    System.out.println("内存总量:    " + mem.getTotal() / 1024L + "K av");
    // 当前内存使用量
    System.out.println("当前内存使用量:    " + mem.getUsed() / 1024L + "K used");
    // 当前内存剩余量
    System.out.println("当前内存剩余量:    " + mem.getFree() / 1024L + "K free");
    Swap swap = sigar.getSwap();
    // 交换区总量
    System.out.println("交换区总量:    " + swap.getTotal() / 1024L + "K av");
    // 当前交换区使用量
    System.out.println("当前交换区使用量:    " + swap.getUsed() / 1024L + "K used");
    // 当前交换区剩余量
    System.out.println("当前交换区剩余量:    " + swap.getFree() / 1024L + "K free");
}
 
Example 2
Source Project: kieker   Source File: MemSwapUsageSampler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void sample(final IMonitoringController monitoringCtr) throws SigarException {
	if (!monitoringCtr.isMonitoringEnabled()) {
		return;
	}
	if (!monitoringCtr.isProbeActivated(SignatureFactory.createMemSwapSignature())) {
		return;
	}

	final Mem mem = this.sigar.getMem();
	final Swap swap = this.sigar.getSwap();
	final MemSwapUsageRecord r = new MemSwapUsageRecord(
			monitoringCtr.getTimeSource().getTime(), monitoringCtr.getHostname(),
			mem.getTotal(), mem.getActualUsed(), mem.getActualFree(),
			swap.getTotal(), swap.getUsed(), swap.getFree());
	monitoringCtr.newMonitoringRecord(r);
}
 
Example 3
/**
 * 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;
}
 
Example 4
Source Project: onos   Source File: NodeMetricsManager.java    License: Apache License 2.0 6 votes vote down vote up
private void pollMetrics() {
    try {
        CpuPerc cpu = sigar.getCpuPerc();
        Mem mem = sigar.getMem();
        FileSystemUsage disk = sigar.getFileSystemUsage(SLASH);

        NodeMemoryUsage memoryNode = new NodeMemoryUsage.Builder().free(mem.getFree())
                .used(mem.getUsed()).total(mem.getTotal()).withUnit(Units.BYTES)
                .withNode(localNodeId).build();
        NodeCpuUsage cpuNode = new NodeCpuUsage.Builder().withNode(localNodeId)
                .usage(cpu.getCombined() * PERCENTAGE_MULTIPLIER).build();
        NodeDiskUsage diskNode = new NodeDiskUsage.Builder().withNode(localNodeId)
                .free(disk.getFree()).used(disk.getUsed()).withUnit(Units.KBYTES)
                .total(disk.getTotal()).build();
        diskStore.put(localNodeId, diskNode);
        memoryStore.put(localNodeId, memoryNode);
        cpuStore.put(localNodeId, cpuNode);

    } catch (SigarException e) {
        log.error("Exception occurred ", e);
    }

}
 
Example 5
Source Project: WeBASE-Front   Source File: PerformanceService.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * getConfigInfo.
 * 
 * @return
 */
public Map<String, String> getConfigInfo() throws UnknownHostException, SigarException {
    log.info("getConfigInfo.");
    Map<String, String> configMap = new HashMap<>();
    String ip = getIp();
    log.debug("local ip:    " + ip);
    configMap.put("ip", ip);
    Mem mem = sigar.getMem();
    log.debug("memory total:    " + mem.getTotal() / 1024L + "K av");
    log.debug("memory used now:    " + mem.getUsed() / 1024L + "K used");
    configMap.put("memoryTotalSize", Long.toString(mem.getTotal() / 1024L));
    configMap.put("memoryUsedSize", Long.toString(mem.getUsed() / 1024L));
    CpuPerc cpu = sigar.getCpuPerc();
    CpuInfo[] infos = sigar.getCpuInfoList();
    log.debug("CPU mhz:    " + infos[0].getMhz());
    log.debug("CPU core number:    " + infos.length);
    configMap.put("cpuSize", Integer.toString(infos[0].getMhz()));
    configMap.put("cpuAmount", Integer.toString(infos.length));
    long total;
    long use;
    FileSystem[] fslist = sigar.getFileSystemList();
    log.debug("****fs " + fslist.length);
    use = sigar.getFileSystemUsage(constants.getMonitorDisk()).getUsed();
    total = sigar.getFileSystemUsage(constants.getMonitorDisk()).getTotal();
    log.debug("diskTotalSize:    " + total);
    log.debug("diskUsedSize:    " + use);
    configMap.put("diskTotalSize", Long.toString(total));
    configMap.put("diskUsedSize", Long.toString(use));
    return configMap;
}
 
Example 6
Source Project: sigar-system_runtime   Source File: SystemRuntime.java    License: MIT License 5 votes vote down vote up
public Mem memory() throws SigarException {
        Mem mem = sigar.getMem();
//        // 内存总量
//        System.out.println("内存总量:    " + mem.getTotal() / 1024L + "K av");
//        // 当前内存使用量
//        System.out.println("当前内存使用量:    " + mem.getUsed() / 1024L + "K used");
//        // 当前内存剩余量
//        System.out.println("当前内存剩余量:    " + mem.getFree() / 1024L + "K free");
        return mem;
    }
 
Example 7
/**
 * 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);
}
 
Example 8
Source Project: micro-server   Source File: MachineStatsCheckerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
	sigar = mock(Sigar.class);
	swap = mock(Swap.class);
	cpuPerc = mock(CpuPerc.class);
	cpuInfo = mock(CpuInfo.class);
	mem = mock(Mem.class);
	
	machineStatsChecker = new MachineStatsChecker();		
}
 
Example 9
Source Project: WeBASE-Front   Source File: PerformanceService.java    License: Apache License 2.0 4 votes vote down vote up
private BigDecimal getMemoryRatio() throws SigarException {
    ;
    Mem mem = sigar.getMem();
    // log.info("内存总量: " + mem.getTotal() / 1024L + "K av");
    return BigDecimal.valueOf(mem.getUsedPercent());
}
 
Example 10
Source Project: maintain   Source File: HttpClientTool.java    License: MIT License 4 votes vote down vote up
public static Mem getMemJson(String url) {
	return getJson(url + "memInfo", Mem.class);
}
 
Example 11
Source Project: maintain   Source File: ServerInfo.java    License: MIT License 4 votes vote down vote up
public Mem getMem() {
	return mem;
}
 
Example 12
Source Project: maintain   Source File: ServerInfo.java    License: MIT License 4 votes vote down vote up
public void setMem(Mem mem) {
	this.mem = mem;
}
 
Example 13
Source Project: perfmon-agent   Source File: MemTotalMetric.java    License: Apache License 2.0 4 votes vote down vote up
public void getValue(StringBuffer res) throws SigarException {
    Mem mem = sigarProxy.getMem();
    double val;
    int factor = 1;
    switch (type) {

        case ACTUAL_FREE:
            val = mem.getActualFree();
            factor = dividingFactor;
            break;
        case ACTUAL_USED:
            val = mem.getActualUsed();
            factor = dividingFactor;
            break;
        case FREE:
            val = mem.getFree();
            factor = dividingFactor;
            break;
        case FREE_PERCENT:
            val = mem.getFreePercent();
            break;
        case RAM:
            val = mem.getRam();
            break;
        case TOTAL:
            val = mem.getTotal();
            factor = dividingFactor;
            break;
        case USED:
            val = mem.getUsed();
            factor = dividingFactor;
            break;
        case USED_PERCENT:
            val = mem.getUsedPercent();
            break;
        default:
            throw new SigarException("Unknown total mem type " + type);
    }
    val = val / factor;
    res.append(Double.toString(val));
}