SIGAR (full Name System Information Gatherer and Reporter, which is the Systems information Collection Report), provides an open source, cross-platform API for collecting computer hardware and operating system information (the API's underlying interface is written in C). This article shows you how to get memory information with the SIGAR API:
Package Com.ghj.packageoftest;import Org.hyperic.sigar.mem;import Org.hyperic.sigar.sigar;import Org.hyperic.sigar.sigarexception;import org.hyperic.sigar.swap;/** * Get memory information with SIGAR API * * @author Gaohuanjie */publi C class Memorytool {public static void main (string[] args) throws Sigarexception {SIGAR SIGAR = new SIGAR ();//Physical Memory information Mem MEM = Sigar.getmem (); System.out.println ("Mem total:" + mem.gettotal () + "B"); SYSTEM.OUT.PRINTLN ("Mem RAM:" + mem.getram () + "B"); System.out.println ("Mem used:" + mem.getused () + "B"); System.out.println ("Mem free:" + mem.getfree () + "B"); System.out.println ("Mem actualused:" + mem.getactualused () + "B"); System.out.println ("Mem actualfree:" + mem.getactualfree () + "B"); System.out.println ("Mem usedpercent:" + mem.getusedpercent () + "%"); System.out.println ("Mem freepercent:" + mem.getfreepercent () + "%");//swap area Information swap = Sigar.getswap (); System.err.println ("Swap total:" + swap.gettotal () + "B"); SYSTEM.ERR.PRINTLN ("Swap used:" + swap.getused ()+ "B"); System.err.println ("Swap free:" + swap.getfree () + "B"); System.err.println ("Swap Pagein:" + Swap.getpagein ()); System.err.println ("Swap pageout:" + swap.getpageout ());}}
【
0 min Download Engineering code】
Get memory information with the SIGAR API