org.kurento.test.monitor.KmsDockerMonitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kurento-test Show documentation
Show all versions of kurento-test Show documentation
This project contains test cases for testing Kurento
Java Client and Kurento Media Server.
/*
* (C) Copyright 2015 Kurento (http://kurento.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.kurento.test.monitor;
import java.util.List;
import java.util.Map;
import org.kurento.test.docker.Docker;
import com.github.dockerjava.api.model.CpuStatsConfig;
import com.github.dockerjava.api.model.MemoryStatsConfig;
import com.github.dockerjava.api.model.StatisticNetworksConfig;
import com.github.dockerjava.api.model.Statistics;
/**
* Monitor when KMS is dockerized.
*
* @author Boni Garcia ([email protected])
* @since 6.1.1
*/
public class KmsDockerMonitor extends KmsMonitor {
private int kmsPid;
private Docker docker;
private String containerId;
private long previousCpu = -1;
private long previousSystem = -1;
public KmsDockerMonitor(String containerId) {
this.containerId = containerId;
this.docker = Docker.getSingleton();
this.kmsPid = getKmsPid();
}
@Override
@SuppressWarnings("unchecked")
protected NetInfo getNetInfo() {
NetInfo netInfo = new NetInfo();
Statistics stats = docker.getStatistics(containerId);
Map networksStats = stats.getNetworks();
for (String key : networksStats.keySet()) {
Map iface = (Map) 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 double getCpuUsage() {
double cpuUsage = 0;
Statistics stats = docker.getStatistics(containerId);
CpuStatsConfig cpuStats = stats.getCpuStats();
if (cpuStats != null) {
Map cpuUsageMap = (Map) cpuStats.getCpuUsage();
long systemUsage = Long.parseLong(cpuStats.getSystemCpuUsage().toString());
long totalUsage = Long.parseLong(cpuUsageMap.get("total_usage").toString());
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy