Get memory information with the SIGAR API

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.