Hoping someone knows the specific .Net library (or if not, REST service) for getting the names of active (running instances) in a given Azure Cloud Service.
Asked
Active
Viewed 1,720 times
2 Answers
5
Use "RoleEnvironment.CurrentRoleInstance.Id
" from the .NET code. Ensure that this code has access to ServiceRuntime DLL (usually only referenced by your WebRole or WorkerRole projects).
This call will also fail in local mode, non-emulated code, so try/catch might be a good idea
Edit: To get all instances in a role, try this? RoleEnvironment.CurrentRoleInstance.Role.Instances
-
Thanks for that, helpful for finding the name when on the machine itself. However do you know if there is a way to get all the active instances in a single request/response message? Basically I need to see how many workers are currently active for load leveling purposes (lease pattern). I could implement a checkin pattern where each machine checks in with a service and timestamp the checkin, but I'm hoping there is already a service that knows all the current running machines. – Paul Fryer Dec 01 '15 at 00:38
-
added Edit with the info on all instances in a Role – Igorek Dec 01 '15 at 00:58
0
By using the following check the code should work both locally and in azure
var roleName = Environment.MachineName;
if (RoleEnvironment.IsAvailable)
{
roleName = RoleEnvironment.CurrentRoleInstance.Id;
}

Abe
- 61
- 1
- 2