java获取服务器内存数据

导包

<dependency>
	<groupId>org.fusesource</groupId>
	<artifactId>sigar</artifactId>
	<version>1.6.4</version>
</dependency>

使用

伪代码

Sigar sigar = new Sigar();
Mem mem =  sigar.getMem();

//计数单位 K
Long totalMemory = mem.getTotal() / 1024L;
Long usedMemory = mem.getUsed() / 1024L;
Long freeMemory = mem.getFree() / 1024L;