Search in sources :

Example 11 with J4pReadRequest

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);
                }
            }
        }
    }
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) Pod(io.fabric8.kubernetes.api.model.Pod) J4pReadRequest(org.jolokia.client.request.J4pReadRequest) J4pClient(org.jolokia.client.J4pClient) ObjectName(javax.management.ObjectName)

Aggregations

J4pReadRequest (org.jolokia.client.request.J4pReadRequest)11 ObjectName (javax.management.ObjectName)7 J4pReadResponse (org.jolokia.client.request.J4pReadResponse)6 ArrayList (java.util.ArrayList)5 LinkedHashMap (java.util.LinkedHashMap)5 J4pSearchRequest (org.jolokia.client.request.J4pSearchRequest)5 J4pSearchResponse (org.jolokia.client.request.J4pSearchResponse)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 J4pException (org.jolokia.client.exception.J4pException)4 J4pRemoteException (org.jolokia.client.exception.J4pRemoteException)3 J4pExecRequest (org.jolokia.client.request.J4pExecRequest)3 List (java.util.List)2 MalformedObjectNameException (javax.management.MalformedObjectNameException)2 J4pClient (org.jolokia.client.J4pClient)2 J4pConnectException (org.jolokia.client.exception.J4pConnectException)2 AbtractJ4pMBeanRequest (org.jolokia.client.request.AbtractJ4pMBeanRequest)2 J4pResponse (org.jolokia.client.request.J4pResponse)2 J4pWriteRequest (org.jolokia.client.request.J4pWriteRequest)2 Container (io.fabric8.kubernetes.api.model.Container)1