private void sendNodeOsStats(OsStats osStats) { String prefix = this.getPrefix("os"); double[] loadAverage = osStats.getLoadAverage(); if (loadAverage.length > 0) { this.sendGauge(prefix + ".load_average", "1m", loadAverage[0]); this.sendGauge(prefix + ".load_average", "5m", loadAverage[1]); this.sendGauge(prefix + ".load_average", "15m", loadAverage[2]); } if (osStats.cpu() != null) { this.sendGauge(prefix + ".cpu", "sys", osStats.cpu().sys()); this.sendGauge(prefix + ".cpu", "user", osStats.cpu().user()); this.sendGauge(prefix + ".cpu", "idle", osStats.cpu().idle()); this.sendGauge(prefix + ".cpu", "stolen", osStats.cpu().stolen()); } if (osStats.mem() != null) { this.sendGauge(prefix + ".mem", "free_in_bytes", osStats.mem().free().bytes()); this.sendGauge(prefix + ".mem", "used_in_bytes", osStats.mem().used().bytes()); this.sendGauge(prefix + ".mem", "free_percent", osStats.mem().freePercent()); this.sendGauge(prefix + ".mem", "used_percent", osStats.mem().usedPercent()); this.sendGauge(prefix + ".mem", "actual_free_in_bytes", osStats.mem().actualFree().bytes()); this.sendGauge(prefix + ".mem", "actual_used_in_bytes", osStats.mem().actualUsed().bytes()); } if (osStats.swap() != null) { this.sendGauge(prefix + ".swap", "free_in_bytes", osStats.swap().free().bytes()); this.sendGauge(prefix + ".swap", "used_in_bytes", osStats.swap().used().bytes()); } }
public OsStats osStats() { OsStats stats = new OsStats(); stats.timestamp = System.currentTimeMillis(); stats.cpu = new OsStats.Cpu(); stats.cpu.percent = getSystemCpuPercent(); stats.cpu.loadAverage = getSystemLoadAverage(); OsStats.Mem mem = new OsStats.Mem(); mem.total = getTotalPhysicalMemorySize(); mem.free = getFreePhysicalMemorySize(); stats.mem = mem; OsStats.Swap swap = new OsStats.Swap(); swap.total = getTotalSwapSpaceSize(); swap.free = getFreeSwapSpaceSize(); stats.swap = swap; return stats; }