@Override @SuppressWarnings("unchecked") protected NetInfo getNetInfo() { NetInfo netInfo = new NetInfo(); Statistics stats = docker.getStatistics(containerId); Map<String, StatisticNetworksConfig> networksStats = stats.getNetworks(); for (String key : networksStats.keySet()) { Map<String, Object> iface = (Map<String, Object>) networksStats.get(key); int rxBytes = (Integer) iface.get("rx_bytes"); int txBytes = (Integer) iface.get("tx_bytes"); netInfo.putNetInfo(key, rxBytes, txBytes); } return netInfo; }
@Override @SuppressWarnings("unchecked") protected NetInfo getNetInfo() { NetInfo netInfo = new NetInfo(); Statistics stats = docker.getStatistics(containerId); Map<String, StatisticNetworksConfig> networksStats = stats.getNetworks(); for (String key : networksStats.keySet()) { Map<String, Object> iface = (Map<String, Object>) networksStats.get(key); int rxBytes = (Integer) iface.get("rx_bytes"); int txBytes = (Integer) iface.get("tx_bytes"); netInfo.putNetInfo(key, rxBytes, txBytes); } return netInfo; }
public static CubeStatistics updateStats(Statistics statistics) { CubeStatistics stats = new CubeStatistics(); Map<String, Long> blkio = extractIORW(statistics.getBlkioStats()); Map<String, Long> memory = extractMemoryStats(statistics.getMemoryStats(), "usage", "max_usage", "limit"); stats.setIoBytesRead(blkio.get("io_bytes_read")); stats.setIoBytesWrite(blkio.get("io_bytes_write")); stats.setMaxUsage(memory.get("max_usage")); stats.setUsage(memory.get("usage")); stats.setLimit(memory.get("limit")); stats.setNetworks(extractNetworksStats(statistics.getNetworks())); return stats; }
private void configureCube() throws IOException { cubeRegistry = new LocalCubeRegistry(); when(cube.getId()).thenReturn(CUBE_ID); cubeRegistry.addCube(cube); when(statistics.getNetworks()).thenReturn(getNetworks()); when(statistics.getMemoryStats()).thenReturn(getMemory()); when(statistics.getBlkioStats()).thenReturn(getIOStats()); when(dockerClientExecutor.statsContainer(CUBE_ID)).thenReturn(statistics); }
@Override public Optional<ContainerStats> getContainerStats(ContainerName containerName) { try { DockerStatsCallback statsCallback = dockerClient.statsCmd(containerName.asString()).exec(new DockerStatsCallback()); statsCallback.awaitCompletion(5, TimeUnit.SECONDS); return statsCallback.stats.map(stats -> new ContainerStats( stats.getNetworks(), stats.getCpuStats(), stats.getMemoryStats(), stats.getBlkioStats())); } catch (NotFoundException ignored) { return Optional.empty(); } catch (RuntimeException | InterruptedException e) { numberOfDockerDaemonFails.add(); throw new DockerException("Failed to get stats for container '" + containerName.asString() + "'", e); } }
@Override public void onNext(Statistics stats) { Map<String, Object> memStat = stats.getMemoryStats(); Map<String, Object> blkioStat = stats.getBlkioStats(); Map<String, Object> netStat = stats.getNetworks(); double cpuPercent = 0.0; if (this.preStats != null) { cpuPercent = calculateCpuPercentUnix(this.preStats, stats); } int[] netIO = calculateNetwork(netStat); int[] memUsageLimit = calculateMemory(memStat); int[] blockIo = calculateBlock(blkioStat); logHost.log(Level.INFO, "\n%s(%s)\nCPU %4.3f%% | MEM %4.3f%% (%d KB / %d KB) | NET %d KB / %d KB | BLOCK %d KB / %d KB", this.containerId, this.containerUri, cpuPercent, (memUsageLimit[0] * 1.0 / memUsageLimit[1] * 1.0) * 100, memUsageLimit[0] / 1024, memUsageLimit[1] / 1024, netIO[0] / 1024, netIO[1] / 1024, blockIo[0] / 1024, blockIo[1] / 1024); this.preStats = stats; this.countDownLatch.countDown(); }