系统信息收集API : Java Sigar

Sigar简介

开源工具包 SIGAR - System Information Gatherer And Reporter,即 系统信息收集和报告。

官方站点:

https://support.hyperic.com/display/SIGAR/Home

考虑到官网的不稳定,把相关系摘录如下:

简单的说,他能收集的信息包括:

  • System memory, swap, cpu, load average, uptime, logins
  • Per-process memory, cpu, credential info, state, arguments, environment, open files
  • File system detection and metrics
  • Network interface detection, configuration info and metrics
  • TCP and UDP connection tables
  • Network route table

几乎所有的硬件信息、网络情况都可以得到。

1, CPU信息,包括基本信息(vendor、model、mhz、cacheSize)和统计信息(user、sys、idle、nice、wait)

2, 文件系统信息,包括Filesystem、Size、Used、Avail、Use%、Type

3, 事件信息,类似Service Control Manager

4, 内存信息,物理内存和交换内存的总数、使用数、剩余数;RAM的大小

5, 网络信息,包括网络接口信息和网络路由信息

6, 进程信息,包括每个进程的内存、CPU占用数、状态、参数、句柄

7, IO信息,包括IO的状态,读写大小等

8, 服务状态信息

9, 系统信息,包括操作系统版本,系统资源限制情况,系统运行时间以及负载,JAVA的版本信息等.

 

This information is available in most operating systems, but each OS has their own way(s) providing it.
SIGAR provides developers with one API to access this information regardless of the underlying platform.
The core API is implemented in pure C with bindings currently implemented for Java, Perl, Ruby, Python, Erlang, PHP and C#.

支持的操作系统平台:

Operating SystemArchitectureVersionsBinary Included
Linuxx862.2, 2.4, 2.6 kernels    支持
Linuxamd642.6 kernel
支持
Linuxppc2.6 kernel
支持
Linuxppc642.6 kernel
支持
Linuxia642.6 kernel
支持
Linuxs3902.6 kernel
不支持
Linuxs390x2.6 kernel
支持
Windowsx86NT 4.0, 2000 Pro/Server, 2003 Server, XP, Vista, 2008 Server, 7
支持
Windowsx642003 Server, Vista, 2008 Server, 7
支持
Solarissparc-322.6, 7, 8, 9, 10
支持
Solarissparc-64"
支持
Solarisx868, 9, 10
支持
 支持
Solarisx64"
支持
AIXppc4.3, 5.1, 5.2, 5.3, 6.1
支持
AIXppc645.2,5.3,6.1
支持
HP-UXPA-RISC11
支持
HP-UXia6411
支持
FreeBSDx864.x不支持
FreeBSDx865.x, 6.x
支持
FreeBSDx646.x
支持
FreeBSDx86,x647.x,8.x不支持
OpenBSDx864.x,5.x不支持
NetBSDx863.1不支持
Mac OS XPowerPC10.3, 10.4支持
Mac OS Xx8610.4, 10.5, 10.6支持
Mac OS Xx6410.5, 10.6支持

While SIGAR only depends on the Linux kernel version, the following distributions have been certified:

DistributionVersions
Red Hat6.2, 7.3, 8.0, 9.0
RHEL3, 4, 5, 6
CentOS3, 4, 5
Fedora2, 3, 4, 5, 6, 7, 8, 9, 10
SuSE8, 9, 10, 11
Ubuntu6.06, 8.04, 8.10, 9.04
Debian2.6, 3.0, 3.1, 3.2, 4.0, 5.0
VMware ESX2.x, 3.0
XenServer3.1, 3.2, 4.0, 4.1, 5.0
Slackware10, 11
Mandrake10
Scientific Linux5
Gentoo

To test drive run the following command:

?
% java -jar sigar-bin/lib/sigar.jar
sigar> help
Linux下Sigar的安装步骤

wget http://downloads.sourceforge.net/project/sigar/sigar/1.6/hyperic-sigar-1.6.4-src.tar.gz

tar zxf hyperic-sigar-1.6.4-src.tar.gz

cd hyperic-sigar-1.6.4-src

cd src

cd bindings

cd java

ant

Sigar提供的命令行工具

它还提供了一个命令行的使用方式,如下所示:

[root@node16 java]# java -jar sigar-bin/lib/sigar.jar

Loaded rc file: ./.sigar_shellrc

sigar> help

Available commands:

        alias          - Create alias command

        cpuinfo        - Display cpu information

        df             - Report filesystem disk space usage

        du             - Display usage for a directory recursively

        free           - Display information about free and used memory

        get            - Get system properties

        help           - Gives help on shell commands

        ifconfig       - Network interface information

        iostat         - Report filesystem disk i/o

        kill           - Send signal to a process

ls - simple FileInfo test at the moment (like ls -l)

        mps            - Show multi process status

        netinfo        - Display network info

        netstat        - Display network connections

        nfsstat        - Display nfs stats

        pargs          - Show process command line arguments

        penv           - Show process environment

        pfile          - Display process file info

        pidof          - Find the process ID of a running program

        pinfo          - Display all process info

        pmodules       - Display process module info

        ps             - Show process status

        quit           - Terminate the shell

        route          - Kernel IP routing table

        set            - Set system properties

        sleep          - Delay execution for the a number of seconds

        source         - Read a file, executing the contents

        sysinfo        - Display system information

        time           - Time command

        ulimit         - Display system resource limits

        uptime         - Display how long the system has been running

        version        - Display sigar and system version info

        who            - Show who is logged on

 sigar> df

Filesystem      Size Used Avail Use% Mounted on      Type

/dev/mapper/VolGroup00-LogVol00  29G  24G  4.3G  85% /               ext3/local

proc              0    0     0     - /proc           proc/none

sysfs             0    0     0     - /sys            sysfs/none

devpts            0    0     0     - /dev/pts        devpts/none

/dev/sda1        99M  12M   82M  13% /boot           ext3/local

tmpfs           378M   0   378M    - /dev/shm        tmpfs/none

none              0    0     0     - /proc/sys/fs/binfmt_misc binfmt_misc/none

sigar> cpuinfo

Vendor.........Intel

Model..........Core(TM)2 Duo CPU     E8400  @ 3.00GHz

Mhz............2993

Total CPUs.....1

Cache size....6144

CPU 0.........

User Time.....0.0%

Sys Time......0.0%

Idle Time.....100.0%

Wait Time.....0.0%

Nice Time.....0.0%

Combined......0.0%

Irq Time......0.0%

SoftIrq Time..0.0%

Stolen Time....0.0%

Totals........

User Time.....0.0%

--More-- (Page 1 of 2)

Sys Time......0.0%

Idle Time.....100.0%

Wait Time.....0.0%

Nice Time.....0.0%

Combined......0.0%

Irq Time......0.0%

SoftIrq Time..0.0%

Stolen Time....0.0%

sigar> quit

Goodbye.

[root@node16 java]#

 

 

The shell and commands are implemented in Java, the source code is located in
bindings/java/src/org/hyperic/sigar/cmd/.
Including implementations of well-known commands such as:

  • df
  • du
  • free
  • ifconfig
  • iostat
  • netstat
  • ps
  • route
  • top
  • ulimit
  • uptime
  • who

Perl, Ruby, Python, Erlang, PHP and C# interfaces are still a work in progress.

To try the Perl examples:

?
% cd bindings/perl
% perl Makefile.PL && make

\

 
PTQL (Process Table Query Language) 

这是sigar的内部查询语言(类似于数据库的 SQL)

http://support.hyperic.com/display/SIGAR/PTQL

SIGAR 官方站点 写道
Hyperic SIGAR provides a mechanism to identify processes called Process Table Query Language. All operating systems assign a unique id (PID) to each running process. However, the PID is a random number that may also change at any point in time when a process is restarted. PTQL uses process attributes that will persist over time to identify a process.

[root@node16 java]# java -jar sigar-bin/lib/sigar.jar

Loaded rc file: ./.sigar_shellrc

sigar> ps "State.Name.eq=java"

4338    root    15:02   402M    144M    6.7M    S       0:52    java:org.apache.catalina.startup.Bootstrap

4775    root    16:16   309M     16M    5.7M    S       0:0     java:org.hyperic.sigar.cmd.Runner

sigar>

在 java 中如何使用

由于时间关系,只列出一些很好的网络资料:

sigar官方javadoc

http://www.hyperic.com/support/docs/sigar/

评论:用sigar写程序的时候肯定用得着

snmp采集服务器信息(sigar.jar实现)

http://blog.csdn.net/ocelight/article/details/4147278

评论:列举了获取常用系统信息的java代码

Sigar系统监控 的最佳实践产品

http://blog.csdn.net/fred_lzy/article/details/8512624

评论:重点介绍了Hyperic 平台,这个平台又有开源版和企业版。

http://blog.csdn.net/fred_lzy/article/details/12273699

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值