Get CPU-related 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 CPU-related information with the SIGAR API:

Package Com.ghj.packageoftest;import Org.hyperic.sigar.cpu;import Org.hyperic.sigar.cpuinfo;import Org.hyperic.sigar.cpuperc;import org.hyperic.sigar.sigar;import org.hyperic.sigar.sigarexception;/** * with SIGAR  API gets CPU-related information * * @author Gaohuanjie */public class Cputool {public static void main (string[] args) throws Sigarexception {SIGAR SIGAR = new SIGAR (); CpuInfo info = sigar.getcpuinfolist () [0]; SYSTEM.OUT.PRINTLN ("CpuInfo MHz:" + Info.getmhz ()); System.out.println ("CpuInfo Vendor:" + Info.getvendor ()); System.out.println ("CpuInfo Model:" + Info.getmodel ()); System.out.println ("CpuInfo cacheSize:" + info.getcachesize ()); System.out.println ("CpuInfo totalcores:" + info.gettotalcores ()); System.out.println ("CpuInfo totalsockets:" + info.gettotalsockets ()); System.out.println ("CpuInfo corespersocket:" + info.getcorespersocket ()); CPU CPU = SIGAR.GETCPU (); System.err.println ("CPU User:" + cpu.getuser ()); SYSTEM.ERR.PRINTLN ("CPU sys:" + cpu.getsys ()); System.err.println ("CPU nice:" + cpu.getnice ()); SYSTEM.ERR.PRINTLN ("CPU idle:" + cpu.getidle ()); System.err.println ("CPU wait:" + cpu.getwait ()); System.err.println ("CPU IRQ:" + CPU.GETIRQ ()); System.err.println ("CPU total:" + cpu.gettotal ()); SYSTEM.ERR.PRINTLN ("CPU Stolen:" + Cpu.getstolen ()); System.err.println ("CPU softIrq:" + CPU.GETSOFTIRQ ()); Cpuperc Cpuperc = Sigar.getcpuperc (); System.out.println ("Cpuperc User:" + cpuperc.getuser ()); SYSTEM.OUT.PRINTLN ("CPUPERC sys:" + cpuperc.getsys ()); System.out.println ("Cpuperc nice:" + cpuperc.getnice ()); SYSTEM.OUT.PRINTLN ("Cpuperc idle:" + cpuperc.getidle ()); System.out.println ("Cpuperc wait:" + cpuperc.getwait ()); SYSTEM.OUT.PRINTLN ("Cpuperc Stolen:" + Cpuperc.getstolen ()); System.out.println ("Cpuperc softIrq:" + CPUPERC.GETSOFTIRQ ()); System.out.println ("Cpuperc Combined:" + cpuperc.getcombined ());}}
0 min Download Instance code

Get CPU-related 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.