主机系统监控指标获取方法
2014-08-09 21:41
232 查看
最近项目需要根据不同主机相关监控指标下发任务,由于考虑到尽量减少很多第三方软件依赖给系统部署及运维带来的问题,不打算安装ganglia来做。经过一天时间的调研发现了Sigar这个功能强大的开源项目。Sigar本身是C语言开发完成的,通过本地方法调用获取系统指标:
1、操作系统信息;
2、CPU信息;
3、内存信息;
4、进程信息;
5、文件系统信息;
6、网络接口信息;
7、网络路由和链接表信息。
项目中提供一个简单工厂类,获取Sigar对象。同时需要将链接库文件放入src/resources/lib目录下,最终这些链接文件会通过maven打包放入classes/lib。需要注意的是要对这些链接文件打包的时候设置resouce filter进行处理,防止maven打包的时候修改这些文件内容。
<build>
<!-- 通过设置两个resource解决maven编译打包的时候对依赖的二进制链接文件修改的问题 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</resource>
</resources>
</build>
简单工厂类:
sigar依赖的本地库下载地址:http://url.cn/PSyCnF
1、操作系统信息;
2、CPU信息;
3、内存信息;
4、进程信息;
5、文件系统信息;
6、网络接口信息;
7、网络路由和链接表信息。
项目中提供一个简单工厂类,获取Sigar对象。同时需要将链接库文件放入src/resources/lib目录下,最终这些链接文件会通过maven打包放入classes/lib。需要注意的是要对这些链接文件打包的时候设置resouce filter进行处理,防止maven打包的时候修改这些文件内容。
<build>
<!-- 通过设置两个resource解决maven编译打包的时候对依赖的二进制链接文件修改的问题 -->
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
</resource>
</resources>
</build>
简单工厂类:
public class SigarFactory { private static final Logger LOG = LoggerFactory.getLogger(SigarFactory.class); private static String LIB_PATH = SigarFactory.class.getProtectionDomain().getCodeSource().getLocation().getFile(); private static Sigar instance = null; static { String os = System.getProperty("os.name"); if(!StringUtils.isEmpty(os) && os.toLowerCase().contains("windows")) { try { LIB_PATH = URLDecoder.decode(LIB_PATH, "UTF-8").substring(1) + "lib"; } catch (UnsupportedEncodingException e) { LOG.error("fetch path of link files which are used by Sigar met errors.", e); } } } private SigarFactory() { } public static Sigar getInstance() { if (instance == null) { // 同步块,线程安全的创建实例 synchronized (SigarFactory.class) { if (instance == null) { System.setProperty("org.hyperic.sigar.path", LIB_PATH); instance = new Sigar(); } } } return instance; } }
sigar依赖的本地库下载地址:http://url.cn/PSyCnF
相关文章推荐
- 主机性能监控系统--6.获取磁盘性能信息
- 与系统相关的一些常用工具方法. 目前实现的有:获取MAC地址、IP地址、主机名
- 主机性能监控系统--3.获取内存性能信息
- 主机性能监控系统--7.获取网络性能信息(升级版)
- 主机性能监控之wmi 获取系统信息及内存性能信息
- 获取系统时间几种方法 和 使用CPU时间戳进行高精度计时
- java中获取系统属性的方法
- VC中获取主机名和IP地址的方法
- 获取本机主机名和IP的方法
- web程序中获取应用程序系统变量的方法( For.net 1.1)
- Linux系统性能获取方法
- sql server 获取系统时间的方法
- 获取客户端信息,主机名称,系统登录名,MAC地址,以及其它
- Loadrunner 监控Unix系统性能指标的解释
- 使用DateDiff方法来获取系统时间与指定时间的间隔数
- DOS命令下获取远程主机MAC地址的三种方法
- Linux攻略 系统性能监测参数获取的方法
- 用VC++获取系统时间几种方法
- 基于AVI的网络视频监控存储系统的实现方法
- Java中获取本地系统时间的方法