org.hyperic.sigar.Mem Java Examples
The following examples show how to use
org.hyperic.sigar.Mem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sigar.java From sigar-system_runtime with MIT License | 6 votes |
private static void memory() throws SigarException { Sigar sigar = new Sigar(); Mem mem = sigar.getMem(); // 内存总量 System.out.println("内存总量: " + mem.getTotal() / 1024L + "K av"); // 当前内存使用量 System.out.println("当前内存使用量: " + mem.getUsed() / 1024L + "K used"); // 当前内存剩余量 System.out.println("当前内存剩余量: " + mem.getFree() / 1024L + "K free"); Swap swap = sigar.getSwap(); // 交换区总量 System.out.println("交换区总量: " + swap.getTotal() / 1024L + "K av"); // 当前交换区使用量 System.out.println("当前交换区使用量: " + swap.getUsed() / 1024L + "K used"); // 当前交换区剩余量 System.out.println("当前交换区剩余量: " + swap.getFree() / 1024L + "K free"); }
Example #2
Source File: MemSwapUsageSampler.java From kieker with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void sample(final IMonitoringController monitoringCtr) throws SigarException { if (!monitoringCtr.isMonitoringEnabled()) { return; } if (!monitoringCtr.isProbeActivated(SignatureFactory.createMemSwapSignature())) { return; } final Mem mem = this.sigar.getMem(); final Swap swap = this.sigar.getSwap(); final MemSwapUsageRecord r = new MemSwapUsageRecord( monitoringCtr.getTimeSource().getTime(), monitoringCtr.getHostname(), mem.getTotal(), mem.getActualUsed(), mem.getActualFree(), swap.getTotal(), swap.getUsed(), swap.getFree()); monitoringCtr.newMonitoringRecord(r); }
Example #3
Source File: SigarNodeInfoProvider.java From ankush with GNU Lesser General Public License v3.0 | 6 votes |
/** * Method getNodeMemoryInfo. * * @return Map<Object,Object> */ public Map<Object, Object> getNodeMemoryInfo() { Map<Object, Object> nodeMemoryInfo = new HashMap<Object, Object>(); Mem mem = null; try { mem = sigar.getMem(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } nodeMemoryInfo.put("total", mem.getTotal()); nodeMemoryInfo.put("free", mem.getFree()); nodeMemoryInfo.put("used", mem.getUsed()); nodeMemoryInfo.put("actualFree", mem.getActualFree()); nodeMemoryInfo.put("actualUsed", mem.getActualUsed()); nodeMemoryInfo.put("freePercentage", mem.getFreePercent()); nodeMemoryInfo.put("usedPercentage", mem.getUsedPercent()); return nodeMemoryInfo; }
Example #4
Source File: NodeMetricsManager.java From onos with Apache License 2.0 | 6 votes |
private void pollMetrics() { try { CpuPerc cpu = sigar.getCpuPerc(); Mem mem = sigar.getMem(); FileSystemUsage disk = sigar.getFileSystemUsage(SLASH); NodeMemoryUsage memoryNode = new NodeMemoryUsage.Builder().free(mem.getFree()) .used(mem.getUsed()).total(mem.getTotal()).withUnit(Units.BYTES) .withNode(localNodeId).build(); NodeCpuUsage cpuNode = new NodeCpuUsage.Builder().withNode(localNodeId) .usage(cpu.getCombined() * PERCENTAGE_MULTIPLIER).build(); NodeDiskUsage diskNode = new NodeDiskUsage.Builder().withNode(localNodeId) .free(disk.getFree()).used(disk.getUsed()).withUnit(Units.KBYTES) .total(disk.getTotal()).build(); diskStore.put(localNodeId, diskNode); memoryStore.put(localNodeId, memoryNode); cpuStore.put(localNodeId, cpuNode); } catch (SigarException e) { log.error("Exception occurred ", e); } }
Example #5
Source File: PerformanceService.java From WeBASE-Front with Apache License 2.0 | 5 votes |
/** * getConfigInfo. * * @return */ public Map<String, String> getConfigInfo() throws UnknownHostException, SigarException { log.info("getConfigInfo."); Map<String, String> configMap = new HashMap<>(); String ip = getIp(); log.debug("local ip: " + ip); configMap.put("ip", ip); Mem mem = sigar.getMem(); log.debug("memory total: " + mem.getTotal() / 1024L + "K av"); log.debug("memory used now: " + mem.getUsed() / 1024L + "K used"); configMap.put("memoryTotalSize", Long.toString(mem.getTotal() / 1024L)); configMap.put("memoryUsedSize", Long.toString(mem.getUsed() / 1024L)); CpuPerc cpu = sigar.getCpuPerc(); CpuInfo[] infos = sigar.getCpuInfoList(); log.debug("CPU mhz: " + infos[0].getMhz()); log.debug("CPU core number: " + infos.length); configMap.put("cpuSize", Integer.toString(infos[0].getMhz())); configMap.put("cpuAmount", Integer.toString(infos.length)); long total; long use; FileSystem[] fslist = sigar.getFileSystemList(); log.debug("****fs " + fslist.length); use = sigar.getFileSystemUsage(constants.getMonitorDisk()).getUsed(); total = sigar.getFileSystemUsage(constants.getMonitorDisk()).getTotal(); log.debug("diskTotalSize: " + total); log.debug("diskUsedSize: " + use); configMap.put("diskTotalSize", Long.toString(total)); configMap.put("diskUsedSize", Long.toString(use)); return configMap; }
Example #6
Source File: SystemRuntime.java From sigar-system_runtime with MIT License | 5 votes |
public Mem memory() throws SigarException { Mem mem = sigar.getMem(); // // 内存总量 // System.out.println("内存总量: " + mem.getTotal() / 1024L + "K av"); // // 当前内存使用量 // System.out.println("当前内存使用量: " + mem.getUsed() / 1024L + "K used"); // // 当前内存剩余量 // System.out.println("当前内存剩余量: " + mem.getFree() / 1024L + "K free"); return mem; }
Example #7
Source File: StatsGraphServlet.java From document-management-system with GNU General Public License v2.0 | 5 votes |
/** * Generate memory statistics * http://casidiablo.net/capturar-informacion-sistema-operativo-java/ */ public JFreeChart osMemStats() throws IOException, ServletException { DefaultPieDataset dataset = new DefaultPieDataset(); Sigar sigar = new Sigar(); String title = null; try { Mem mem = sigar.getMem(); long max = mem.getRam(); long available = mem.getFree(); long total = mem.getTotal(); long used = mem.getUsed(); long free = mem.getFree(); title = "OS memory: " + FormatUtil.formatSize(total); log.debug("OS maximun memory: {}", FormatUtil.formatSize(max)); log.debug("OS available memory: {}", FormatUtil.formatSize(available)); log.debug("OS free memory: {}", FormatUtil.formatSize(free)); log.debug("OS used memory: {}", FormatUtil.formatSize(used)); log.debug("OS total memory: {}", FormatUtil.formatSize(total)); dataset.setValue("Available (" + FormatUtil.formatSize(free) + ")", free * 100 / total); dataset.setValue("Used (" + FormatUtil.formatSize(used) + ")", used * 100 / total); } catch (SigarException se) { title = "OS memory: " + se.getMessage(); } catch (UnsatisfiedLinkError ule) { title = "OS memory: (missing native libraries)"; } return ChartFactory.createPieChart(title, dataset, true, false, false); }
Example #8
Source File: MachineStatsCheckerTest.java From micro-server with Apache License 2.0 | 5 votes |
@Before public void setUp() { sigar = mock(Sigar.class); swap = mock(Swap.class); cpuPerc = mock(CpuPerc.class); cpuInfo = mock(CpuInfo.class); mem = mock(Mem.class); machineStatsChecker = new MachineStatsChecker(); }
Example #9
Source File: PerformanceService.java From WeBASE-Front with Apache License 2.0 | 4 votes |
private BigDecimal getMemoryRatio() throws SigarException { ; Mem mem = sigar.getMem(); // log.info("内存总量: " + mem.getTotal() / 1024L + "K av"); return BigDecimal.valueOf(mem.getUsedPercent()); }
Example #10
Source File: HttpClientTool.java From maintain with MIT License | 4 votes |
public static Mem getMemJson(String url) { return getJson(url + "memInfo", Mem.class); }
Example #11
Source File: ServerInfo.java From maintain with MIT License | 4 votes |
public Mem getMem() { return mem; }
Example #12
Source File: ServerInfo.java From maintain with MIT License | 4 votes |
public void setMem(Mem mem) { this.mem = mem; }
Example #13
Source File: MemTotalMetric.java From perfmon-agent with Apache License 2.0 | 4 votes |
public void getValue(StringBuffer res) throws SigarException { Mem mem = sigarProxy.getMem(); double val; int factor = 1; switch (type) { case ACTUAL_FREE: val = mem.getActualFree(); factor = dividingFactor; break; case ACTUAL_USED: val = mem.getActualUsed(); factor = dividingFactor; break; case FREE: val = mem.getFree(); factor = dividingFactor; break; case FREE_PERCENT: val = mem.getFreePercent(); break; case RAM: val = mem.getRam(); break; case TOTAL: val = mem.getTotal(); factor = dividingFactor; break; case USED: val = mem.getUsed(); factor = dividingFactor; break; case USED_PERCENT: val = mem.getUsedPercent(); break; default: throw new SigarException("Unknown total mem type " + type); } val = val / factor; res.append(Double.toString(val)); }