Package com.santaba.agent.groovyapi.esx
Class ESX
- java.lang.Object
-
- com.logicmonitor.common.sse.utils.SSEResource
-
- com.santaba.agent.groovyapi.esx.ESX
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ESX extends com.logicmonitor.common.sse.utils.SSEResource implements java.io.Closeable
This class will help to collect esx related performance data.
Example:
import com.santaba.agent.groovyapi.esx.ESX; import com.vmware.vim25.ManagedObjectReference; import com.vmware.vim25.mo.InventoryNavigator; import com.vmware.vim25.mo.ManagedEntity; import java.util.HashSet; import java.util.Map; import java.util.Set; ESX esx = new ESX(); // step 1 : connect to a remote host // if the host is IPv6 address, the url must like: https://[ipv6]/sdk esx.open("https://10.130.171.1/sdk", "YourUser", "YourPass"); // step 2: find a mor ManagedEntity[] hostsystems = new InventoryNavigator(esx.getServiceInstance().getRootFolder()).searchManagedEntities("HostSystem"); ManagedObjectReference hostSystem = hostsystems[0].getMOR(); // step 3: query data Set<String> counterForHostSystem = new HashSet<>(); counterForHostSystem.add("cpu.coreUtilization.average"); counterForHostSystem.add("cpu.coreUtilization.maximum"); Map<String, String> perfForCpu0 = esx.getPerfs(hostSystem, counterForHostSystem, "0" ); //{cpu.coreUtilization.maximum=3522.0, cpu.coreUtilization.average=3522.0} println perfForCpu0; // step 3.2 query data for all instances Map<String, Map<String, String>> perfForAllCpus = esx.getAllPerfs(hostSystem, counterForHostSystem); println perfForAllCpus; //{cpu.coreUtilization.maximum={=8331, 0=4505, 1=4505, 2=4148}, cpu.coreUtilization.average={=8331, 0=4505, 1=4505, 2=4148}} // get all counter -> id map println esx.getCounterToIdMap(); // mem.granted.average=65541, mem.swaptarget.minimum=65597, .... // get all id -> counter map // 196611=net.usage.minimum, 0=cpu.usage.none ... println esx.getIdToCounterMap();
For any unprovided functions, you can call the methodgetServiceInstance()
to implement.
-
-
Constructor Summary
Constructors Constructor Description ESX()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
close related resource.static com.vmware.vim25.ManagedObjectReference
createMOR(java.lang.String value, java.lang.String morType)
here we provide a simple method to create MOR object from a specified value and morTypejava.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>>
getAllPerfs(com.vmware.vim25.ManagedObjectReference mor, java.util.Set<java.lang.String> counters)
here the main get perf method provided - will get all instances perfs.java.util.Map<java.lang.String,java.lang.Integer>
getCounterToIdMap()
get the counter name to it's id map.
Example output:
mem.granted.average=65541 mem.swaptarget.minimum=65597java.util.Map<java.lang.Integer,java.lang.String>
getIdToCounterMap()
get the counter id to it's name map.
Example output:
65541=mem.granted.average 65597=mem.swaptarget.minimumjava.util.Map<java.lang.String,java.lang.String>
getPerfs(com.vmware.vim25.ManagedObjectReference mor, java.util.Set<java.lang.String> counters, java.lang.String instance)
here the main get perf method provided Example output:
cpu.coreUtilization.maximum=4505.0 cpu.coreUtilization.average=4505.0com.vmware.vim25.mo.ServiceInstance
getServiceInstance()
get the service instance object by this way, you can do more thingsboolean
isReleased()
closed related resource.void
open(java.lang.String url, java.lang.String username, java.lang.String password)
open a connection to a target host, we may provide another method without timeout param (with a default value, eg 10) use a default timeout 10 secondsvoid
open(java.lang.String url, java.lang.String username, java.lang.String password, long timeoutInSeconds)
open a connection to a target host, we may provide another method with timeout in secondsvoid
release()
close related resource.
-
-
-
Method Detail
-
isReleased
public boolean isReleased()
closed related resource.
no need to call manually.- Specified by:
isReleased
in classcom.logicmonitor.common.sse.utils.SSEResource
- Returns:
- the resource is released or not
-
close
public void close()
close related resource.
no need to call manually.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
release
public void release()
close related resource.
no need to call manually.- Specified by:
release
in classcom.logicmonitor.common.sse.utils.SSEResource
-
open
public void open(java.lang.String url, java.lang.String username, java.lang.String password, long timeoutInSeconds) throws java.lang.Exception
open a connection to a target host, we may provide another method with timeout in seconds- Parameters:
url
- host url eg: https://host/sdk, if the host is IPv6 address, the url must like: https://[ipv6]/sdkusername
- usernamepassword
- passwordtimeoutInSeconds
- timeout in seconds- Throws:
java.lang.Exception
-
getCounterToIdMap
public java.util.Map<java.lang.String,java.lang.Integer> getCounterToIdMap()
get the counter name to it's id map.
Example output:
- mem.granted.average=65541
- mem.swaptarget.minimum=65597
- Returns:
- a map the key is the counter name, the value is the counter id
-
getIdToCounterMap
public java.util.Map<java.lang.Integer,java.lang.String> getIdToCounterMap()
get the counter id to it's name map.
Example output:
- 65541=mem.granted.average
- 65597=mem.swaptarget.minimum
- Returns:
- a map the key is the counter id and the value is the counter name
-
open
public void open(java.lang.String url, java.lang.String username, java.lang.String password) throws java.lang.Exception
open a connection to a target host, we may provide another method without timeout param (with a default value, eg 10) use a default timeout 10 seconds- Parameters:
url
- host url eg: https://host/sdk, if the host is IPv6 address, the url must like: https://[ipv6]/sdkusername
- usernamepassword
- password- Throws:
java.lang.Exception
-
getServiceInstance
public com.vmware.vim25.mo.ServiceInstance getServiceInstance()
get the service instance object by this way, you can do more things- Returns:
- ServiceInstance
-
createMOR
public static com.vmware.vim25.ManagedObjectReference createMOR(java.lang.String value, java.lang.String morType)
here we provide a simple method to create MOR object from a specified value and morType- Parameters:
value
- value/idmorType
- this morType will be provided to esx sdk. eg HostSystem,VirtualMachine,Datastore- Returns:
- ManagedObjectReference object
-
getPerfs
public java.util.Map<java.lang.String,java.lang.String> getPerfs(com.vmware.vim25.ManagedObjectReference mor, java.util.Set<java.lang.String> counters, java.lang.String instance) throws java.lang.Exception
here the main get perf method provided Example output:
- cpu.coreUtilization.maximum=4505.0
- cpu.coreUtilization.average=4505.0
- Parameters:
mor
- the mor object, may call createMOR or extract from serviceInstancecounters
- the counter string setinstance
- the instance, not null, will get this instance's perf data- Returns:
- a map key is the counter name and value is the perf value
- Throws:
java.lang.Exception
-
getAllPerfs
public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> getAllPerfs(com.vmware.vim25.ManagedObjectReference mor, java.util.Set<java.lang.String> counters) throws java.lang.Exception
here the main get perf method provided - will get all instances perfs.
note this will return a map like
you can find this contains two instances with id 0, 1 and a instance without name -- that's the avg value.{ cpu.coreUtilization.maximum={=537, 0=404, 1=670} cpu.usage.average={=481, 0=329, 1=634} cpu.coreUtilization.average={=537, 0=404, 1=670} }
note (670 + 404) / 2 = 537 This should contain a key (empty) indicated a special meaning (here is avg),
but this was not test on all counters- Parameters:
mor
- the mor object, may call createMOR or extract from serviceInstancecounters
- the counter string set- Returns:
- a map, key is the counter name and value is a map (key is the instance name and value is the perf)
- Throws:
java.lang.Exception
-
-