Get the State of the Cluster

Problem

You want to get the list of agents connected to the cluster.

Solution

Call the get_coordinator_snapshot() method on the ClusterJobScheduler to retrieve the list of agents currently connected to the coordinator.

 1from agiparallel.client import ClusterJobScheduler
 2
 3
 4def agent_info_example():
 5    with ClusterJobScheduler("localhost") as scheduler:
 6        scheduler.connect()
 7
 8        agents = scheduler.get_coordinator_snapshot().agents
 9
10        for agent in agents:
11            print("Machine name:", agent.machine_name)
12            print("    Capacity:", agent.capacity)
13            print("    Activity:", agent.activity)
14
15
16if __name__ == "__main__":
17    agent_info_example()

Discussion

Getting the list of agents is useful when checking to make sure the coordinator is in a certain state before submitting tasks. Another use for getting the list of agents is to display the information for monitoring purposes.

See Also

Reference

Other Resources