use of org.jolokia.client.request.J4pReadRequest in project fabric8 by fabric8io.
the class Example method findPods.
public void findPods(String selector) {
Map<String, Pod> podMap = KubernetesHelper.getSelectedPodMap(kubernetes, selector);
Collection<Pod> pods = podMap.values();
for (Pod pod : pods) {
String host = KubernetesHelper.getHost(pod);
List<Container> containers = KubernetesHelper.getContainers(pod);
for (Container container : containers) {
System.out.println("pod " + KubernetesHelper.getName(pod) + " container: " + container.getName() + " image: " + container.getImage());
J4pClient jolokia = clients.clientForContainer(host, container, pod);
if (jolokia != null) {
System.out.println(" has jolokia client: " + jolokia + " from host: " + host + " URL: " + jolokia.getUri());
try {
ObjectName objectName = new ObjectName("java.lang:type=OperatingSystem");
J4pResponse<J4pReadRequest> results = jolokia.execute(new J4pReadRequest(objectName, "SystemCpuLoad"));
Object value = results.getValue();
System.out.println(" System CPU Load: " + value);
} catch (Exception e) {
LOG.error("Failed to look up attribute. " + e, e);
}
}
}
}
}
Aggregations