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 System | Architecture | Versions | Binary Included | ||||
---|---|---|---|---|---|---|---|
Linux | x86 | 2.2, 2.4, 2.6 kernels | 支持 | ||||
Linux | amd64 | 2.6 kernel |
| ||||
Linux | ppc | 2.6 kernel |
| ||||
Linux | ppc64 | 2.6 kernel |
| ||||
Linux | ia64 | 2.6 kernel |
| ||||
Linux | s390 | 2.6 kernel |
| ||||
Linux | s390x | 2.6 kernel |
| ||||
Windows | x86 | NT 4.0, 2000 Pro/Server, 2003 Server, XP, Vista, 2008 Server, 7 |
| ||||
Windows | x64 | 2003 Server, Vista, 2008 Server, 7 |
| ||||
Solaris | sparc-32 | 2.6, 7, 8, 9, 10 |
| ||||
Solaris | sparc-64 | " |
| ||||
Solaris | x86 | 8, 9, 10 |
| ||||
Solaris | x64 | " |
| ||||
AIX | ppc | 4.3, 5.1, 5.2, 5.3, 6.1 |
| ||||
AIX | ppc64 | 5.2,5.3,6.1 |
| ||||
HP-UX | PA-RISC | 11 |
| ||||
HP-UX | ia64 | 11 |
| ||||
FreeBSD | x86 | 4.x | 不支持 | ||||
FreeBSD | x86 | 5.x, 6.x |
| ||||
FreeBSD | x64 | 6.x |
| ||||
FreeBSD | x86,x64 | 7.x,8.x | 不支持 | ||||
OpenBSD | x86 | 4.x,5.x | 不支持 | ||||
NetBSD | x86 | 3.1 | 不支持 | ||||
Mac OS X | PowerPC | 10.3, 10.4 | 支持 | ||||
Mac OS X | x86 | 10.4, 10.5, 10.6 | 支持 | ||||
Mac OS X | x64 | 10.5, 10.6 | 支持 |
While SIGAR only depends on the Linux kernel version, the following distributions have been certified:
Distribution | Versions |
---|---|
Red Hat | 6.2, 7.3, 8.0, 9.0 |
RHEL | 3, 4, 5, 6 |
CentOS | 3, 4, 5 |
Fedora | 2, 3, 4, 5, 6, 7, 8, 9, 10 |
SuSE | 8, 9, 10, 11 |
Ubuntu | 6.06, 8.04, 8.10, 9.04 |
Debian | 2.6, 3.0, 3.1, 3.2, 4.0, 5.0 |
VMware ESX | 2.x, 3.0 |
XenServer | 3.1, 3.2, 4.0, 4.1, 5.0 |
Slackware | 10, 11 |
Mandrake | 10 |
Scientific Linux | 5 |
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
[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