Summary: Simple API to monitor and administer GigaSpaces services and components.
OverviewThe Admin API provides a way to administer and monitor all of GigaSpaces services and components using a simple API. The API provides information and the ability to operate on the currently running GigaSpaces Agents, GigaSpaces Managers, GigaSpaces Containers, Lookup Services, Processing Units and Spaces.
Before diving into the Admin API, here are some code examples showing how the Admin API can be used to display information on the of currently deployed services / components:
GSA
Admin admin = new AdminFactory().addGroup("myGroup").createAdmin(); // wait till things get discovered (you can also use specific waitFor) for (GridServiceAgent gsa : admin.getGridServiceAgents()) { System.out.println("GSA [" + gsa.getUid() + "] running on Machine [" + gsa.getMachine().getHostAddress()); for (AgentProcessDetails processDetails : gsa.getProcessesDetails()) { System.out.println(" -> Process [" + Arrays.toString(processDetails.getCommand()) + "]"); } } GSM Admin admin = new AdminFactory().addGroup("myGroup").createAdmin(); // wait till things get discovered (you can also use specific waitFor) for (GridServiceManager gsm : admin.getGridServiceManagers()) { System.out.println("GSM [" + gsm.getUid() + "] running on Machine " + gsm.getMachine().getHostAddress()); } GSC Admin admin = new AdminFactory().addGroup("myGroup").createAdmin(); // wait till things get discovered (you can also use specific waitFor) for (GridServiceContainer gsc : admin.getGridServiceContainers()) { System.out.println("GSC [" + gsc.getUid() + "] running on Machine " + gsc.getMachine().getHostAddress()); for (ProcessingUnitInstance puInstance : gsc.getProcessingUnitInstances()) { System.out.println(" -> PU [" + puInstance.getName() + "][" + puInstance.getInstanceId() + "][" + puInstance.getBackupId() + "]"); } } Processing Unit Admin admin = new AdminFactory().addGroup("myGroup").createAdmin(); // wait till things get discovered (you can also use specific waitFor) for (ProcessingUnit processingUnit : admin.getProcessingUnits()) { System.out.println("Processing Unit: " + processingUnit.getName() + " status: " + processingUnit.getStatus()); if (processingUnit.isManaged()) { System.out.println(" -> Managing GSM: " + processingUnit.getManagingGridServiceManager().getUid()); } else { System.out.println(" -> Managing GSM: NA"); } for (GridServiceManager backupGSM : processingUnit.getBackupGridServiceManagers()) { System.out.println(" -> Backup GSM: " + backupGSM.getUid()); } for (ProcessingUnitInstance processingUnitInstance : processingUnit) { System.out.println(" [" + processingUnitInstance.getClusterInfo() + "] on GSC [" + processingUnitInstance.getGridServiceContainer().getUid() + "]"); if (processingUnitInstance.isEmbeddedSpaces()) { System.out.println(" -> Embedded Space [" + processingUnitInstance.getSpaceInstance().getUid() + "]"); } for (ServiceDetails details : processingUnitInstance) { System.out.println(" -> Service " + details); } } } Space for (Space space : admin.getSpaces()) { System.out.println("Space [" + space.getUid() + "] numberOfInstances [" + space.getNumberOfInstances() + "] numberOfbackups [" + space.getNumberOfBackups() + "]"); System.out.println(" Stats: Write [" + space.getStatistics().getWriteCount() + "/" + space.getStatistics().getWritePerSecond() + "]"); for (SpaceInstance spaceInstance : space) { System.out.println(" -> INSTANCE [" + spaceInstance.getUid() + "] instanceId [" + spaceInstance.getInstanceId() + "] backupId [" + spaceInstance.getBackupId() + "] Mode [" + spaceInstance.getMode() + "]"); System.out.println(" -> Host: " + spaceInstance.getMachine().getHostAddress()); System.out.println(" -> Stats: Write [" + spaceInstance.getStatistics().getWriteCount() + "/" + spaceInstance.getStatistics().getWritePerSecond() + "]"); } for (SpacePartition spacePartition : space.getPartitions()) { System.out.println(" -> Partition [" + spacePartition.getPartitiondId() + "]"); for (SpaceInstance spaceInstance : spacePartition) { System.out.println(" -> INSTANCE [" + spaceInstance.getUid() + "]"); } } } Virtual Machine Admin admin = new AdminFactory().addGroup("myGroup").createAdmin(); // wait till things get discovered (you can also use specific waitFor) System.out.println("VM TOTAL STATS: Heap Committed [" + admin.getVirtualMachines().getStatistics().getMemoryHeapCommittedInGB() +"GB]"); System.out.println("VM TOTAL STATS: GC PERC [" + admin.getVirtualMachines().getStatistics().getGcCollectionPerc() + "], Heap Used [" + admin.getVirtualMachines().getStatistics().getMemoryHeapPerc() + "%]"); for (VirtualMachine virtualMachine : admin.getVirtualMachines()) { System.out.println("VM [" + virtualMachine.getUid() + "] " + "Host [" + virtualMachine.getMachine().getHostAddress() + "] " + "GC Perc [" + virtualMachine.getStatistics().getGcCollectionPerc() + "], " + "Heap Usage [" + virtualMachine.getStatistics().getMemoryHeapPerc() + "%]"); for (ProcessingUnitInstance processingUnitInstance : virtualMachine.getProcessingUnitInstances()) { System.out.println(" -> PU [" + processingUnitInstance.getUid() + "]"); } for (SpaceInstance spaceInstance : virtualMachine.getSpaceInstances()) { System.out.println(" -> Space [" + spaceInstance.getUid() + "]"); } } Machine Admin admin = new AdminFactory().addGroup("myGroup").createAdmin(); // wait till things get discovered (you can also use specific waitFor) for (Machine machine : admin.getMachines()) { System.out.println("Machine [" + machine.getUid() + "], " + "TotalPhysicalMem [" + machine.getOperatingSystem().getDetails().getTotalPhysicalMemorySizeInGB() + "GB], " + "FreePhysicalMem [" + machine.getOperatingSystem().getStatistics().getFreePhysicalMemorySizeInGB() + "GB]]"); for (SpaceInstance spaceInstance : machine.getSpaceInstances()) { System.out.println(" -> Space [" + spaceInstance.getUid() + "]"); } for (ProcessingUnitInstance processingUnitInstance : machine.getProcessingUnitInstances()) { System.out.println(" -> PU [" + processingUnitInstance.getUid() + "]"); } }
Admin ConstructionThe Admin API uses the AdminFactory in order to create Admin instances. Once working with the Admin is done, its Admin#close() method should be called. The Admin discovers all the advertised services from the Lookup Services. In order to define which lookup groups the AdminFactory#addGroup can be used. The lookup locators can also be used for non multicast enabled environment using AdminFactory#addLocator can be used. If the services started are secured, the username and password can be set on the Admin API as well. Discovery ProcessOnce the Admin is created, it will start to receive discovery events of all the advertised services / components within its lookup groups / lookup locators. Note, the events occur asynchronously and the data model within the Admin gets initialized in the background with services coming and going. This means that just creating the Admin and calling a specific "getter" for a data structure might not return what is currently deployed, and one should wait till the structures are filled. Some components has a waitFor method that allow to wait for specific number of services to be up. When navigating the data model, the Admin API will provide its most up to date state of the system it is monitoring. Domain ModelThe Admin Domain Model has representation to all GigaSpaces level main actors. They include:
Accessing the Domain ModelThere are two ways the Admin API can be used to access information the Admin API can provide.
If we want to register, for example, for Grid Service Container additions, we can use the following code (note, removing the event listener is not shown here for clarity): admin.getGridServiceContainers().getGridServiceContainerAdded().add(new GridServiceContainerAddedEventListener() { public void gridServiceContainerAdded(GridServiceContainer gridServiceContainer) { // do something here } }); Removals are done in similar manner: admin.getGridServiceContainers().getGridServiceContainerRemoved().add(new GridServiceContainerRemovedEventListener() { public void gridServiceContainerRemoved(GridServiceContainer gridServiceContainer) { // do something here } }); Since both removals and additions are common events that we would like to register for in one go, we can use: admin.getGridServiceContainers().addLifecycleListener(new GridServiceContainerLifecycleEventListener() { public void gridServiceContainerAdded(GridServiceContainer gridServiceContainer) { // do something here } public void gridServiceContainerRemoved(GridServiceContainer gridServiceContainer) { // do something here } }); All other data structures use similar API to register for events. Some might have specific events that goes beyond just additions and removals, but they still use the same model. For example, here is how we can register for Space Mode change events across all currently running Space topologies and Space Instances: admin.getSpaces().getSpaceModeChanged().add(new SpaceModeChangedEventListener() { public void spaceModeChanged(SpaceModeChangedEvent event) { System.out.println("Space [" + event.getSpaceInstance().getSpace().getName() + "] " + "Instance [" + event.getSpaceInstance().getInstanceId() + "/" + event.getSpaceInstance().getBackupId() + "] " + "changed mode from [" + event.getPreviousMode() + "] to [" + event.getNewMode() + "]"); } }); Of course, we can register the same listener on a specific Space topology or event on a specific SpaceInstance. Last, the Admin interface provides a one stop method called addEventListener that accepts an AdminListener. Most events listener implement this interface. One can create a class that implements several chosen listener interfaces, call the addEventListener method, and they will automatically be added to their respective components. For example, if our listener implements GridServiceContainerAddedEventListener and GridServiceManagerAddedEventListener, the listener will automatically be added to the GridServiceManagers and GridServiceContainers. Details and Statistics
Space Runtime StatisticsThe space maintains statistics information about all the data types (e.ge. space class types) it stores and the amount of space objects stored in memory for each data type. Below example how to retrieve this data. This approach avoiding the need to use the GigaSpace.Count() that is relatively expensive with spaces that store large number of objects. public static void printAllClassInstanceCountForAllPartitions (String spaceName) throws Exception { Admin admin = new AdminFactory().addLocator("127.0.0.1").createAdmin(); Space space = admin.getSpaces().waitFor(spaceName, 10 , TimeUnit.SECONDS); SpacePartition spacePartitions[] = space.getPartitions(); System.out.println(spaceName + " have " +spacePartitions.length + " Partitions , Total " + space.getTotalNumberOfInstances() + " Instances"); Arrays.sort(spacePartitions, new SpacePartitionsComperator ()); for (int i = 0; i < spacePartitions.length; i++) { SpacePartition partition = spacePartitions [i]; while (partition.getPrimary()==null) { Thread.sleep(1000); } SpaceInstance primaryInstance = partition.getPrimary(); System.out.println ("Partition " + partition.getPartitionId() + " Primary:"); Map<String, Integer> classInstanceCountsPrimary = primaryInstance.getRuntimeDetails().getCountPerClassName(); Iterator<String> keys = classInstanceCountsPrimary.keySet().iterator(); while (keys.hasNext()) { String className = keys.next(); System.out.println ("Class:" + className +" Instance count:" + classInstanceCountsPrimary.get(className)); } SpaceInstance backupInstance = partition.getBackup(); System.out.println ("Partition " + partition.getPartitionId() + " Backup:"); Map<String, Integer> classInstanceCountsBackup = backupInstance .getRuntimeDetails().getCountPerClassName(); keys = classInstanceCountsPrimary.keySet().iterator(); while (keys.hasNext()) { String className = keys.next(); System.out.println ("Class:" + className +" Instance count:" + classInstanceCountsBackup.get(className)); } admin.close(); } } static class SpacePartitionsComperator implements Comparator<SpacePartition>{ public int compare(SpacePartition o1,SpacePartition o2) { if (o2.getPartitionId() > o1.getPartitionId()) return 0; else return 1; } } Monitoring the Mirror ServiceYou are now able to monitor various aspects of the mirror service using the administration and monitoring API. for (Space space : admin.getSpaces()) { System.out.println("Space [" + space.getUid() + "] numberOfInstances [" + space.getNumberOfInstances() + "] numberOfbackups [" + space.getNumberOfBackups() + "]"); for (SpaceInstance spaceInstance : space) { System.out.println(" -> INSTANCE [" + spaceInstance.getUid() + "] instanceId [" + spaceInstance.getInstanceId() + "] backupId [" + spaceInstance.getBackupId() + "] Mode [" + spaceInstance.getMode() + "]"); System.out.println(" -> Host: " + spaceInstance.getMachine().getHostAddress()); MirrorStatistics mirrorStat = spaceInstance.getStatistics().getMirrorStatistics(); // check if this instance is mirror if(mirrorStat != null) { System.out.println("Mirror Stats:"); System.out.println("total operation count:" + mirrorStat.getOperationCount()); System.out.println("successful operation count:" + mirrorStat.getSuccessfulOperationCount()); System.out.println("failed operation count:" + mirrorStat.getFailedOperationCount()); } } } For more information please refer to the API documentation: {javadocos-versioned:9.5|com/gigaspaces/cluster/replication/async/mirror/MirrorStatistics|MirrorStatistics} Monitoring the Remote Transport ActivityYou may monitor the remote communication activity via the Administration and Monitoring API. You may receive information in real-time about every aspect of the communication and transport activity. See the Monitoring LRMI via the Administration API for details. |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |