0

I want to monitor and get information regarding the different instances in an Azure Virtual Machine Scale Set (VMSS).

I used the command (Python):

vmss = compute_client.virtual_machine_scale_sets.list(resource_group, scale_set_name)

But I am not able to get the result I am expecting.

Any suggestions what to do?

Software Fan
  • 609
  • 3
  • 8
  • 17
  • 1
    well, use monitoring solutions? – 4c74356b41 Jul 25 '18 at 19:29
  • If you do not mind using 3rd party products, look into CloudMonix @ https://www.cloudmonix.com -- it fully supports VMSS, any performance counters, instance healing and scaling, and more... HTH – Igorek Jul 27 '18 at 20:40

3 Answers3

1

You can use the following code to get the ip and powerstate.

compute_client = ComputeManagementClient(credentials, subscription_id)
vmss = compute_client.virtual_machine_scale_set_vms.list(resource_group_name="", vmss="")
for item in vmss:
    print("name: ", item.name)
    ni_reference = item.network_profile.network_interfaces[0].id
    resource_client = ResourceManagementClient(credentials, subscription_id)
    nic = resource_client.resources.get_by_id(
        ni_reference,
        api_version='2017-12-01')
    ip_reference = nic.properties['ipConfigurations'][0]['properties']
    print("ip info: ", ip_reference)

    instance_view = compute_client.virtual_machine_scale_set_vms.get_instance_view(resource_group_name="", vmss="", instance_id=item.instance_id)
    print(instance_view.statuses[1].code)

result:

name:  yangtestvmss_1
ip info:  {'provisioningState': 'Succeeded', 'privateIPAddress': '10.0.0.5', 'privateIPAllocationMethod': 'Dynamic', 'subnet': {'id': '/subscriptions/e5b0fcfa-e859-43f3-8d84-5e5fe29f4c68/resourceGroups/yangtestvmss/providers/Microsoft.Network/virtualNetworks/yangtestvmssVnet/subnets/default'}, 'primary': True, 'privateIPAddressVersion': 'IPv4', 'isInUseWithService': False}
PowerState/running
name:  yangtestvmss_3
ip info:  {'provisioningState': 'Succeeded', 'privateIPAddress': '10.0.0.7', 'privateIPAllocationMethod': 'Dynamic', 'subnet': {'id': '/subscriptions/e5b0fcfa-e859-43f3-8d84-5e5fe29f4c68/resourceGroups/yangtestvmss/providers/Microsoft.Network/virtualNetworks/yangtestvmssVnet/subnets/default'}, 'primary': True, 'privateIPAddressVersion': 'IPv4', 'isInUseWithService': False}
PowerState/running
axfd
  • 291
  • 1
  • 6
0

If you want to get the VMs information, please use the following code.

subscription_id = 'subscription Id'
credentials = ServicePrincipalCredentials(client_id=CLIENT, secret=KEY, tenant=TENANT_ID)
client = ComputeManagementClient(credentials, subscription_id)
vmss = client.virtual_machine_scale_set_vms.list("resourcegroup Name","VMSS name")
for item in vmss:  
    print("id:",item.id)
    print("name",item.name)

Test Result:

enter image description here

Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47
  • Yeah, but this gives me only the names of the instances that are actually running before or after a scale-in or scale-out has occured. But I want to get the information regarding those instances. Like IP address, instance state (running or stopped) etc. So, I want to monitor those instances that are running currently running in the VMSS. I checked the following link, but was not able to get the required output: https://learn.microsoft.com/en-us/python/api/azure-mgmt-compute/azure.mgmt.compute.v2015_06_15.operations.virtualmachinescalesetvmsoperations?view=azure-python#list – Software Fan Jul 26 '18 at 13:15
  • Is there any specific documentation, which I can use to get info regarding the instances like the .id and .name u have used? Because .ip or.discinfo doesnt seem to work. – Software Fan Jul 26 '18 at 13:28
0

There is a cool tool that a guy from Microsoft has been build for monitoring VMSS see this link VMSS Dashboard

The mentioned tool helps you to see the status of VMs in the scale set: you can see the update domain and fault domain grouping of VMs. It lets you start or deallocate a VM. The code is for more than two years ago.

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
  • Could you please summarize here the contents of the link? – Roberto Caboni Nov 29 '19 at 19:54
  • The mentioned tool helps you to see the status of VMs in the scale set, you can see the update domain and fault domain grouping of VMs. It let you start or deallocate a VM. The code is for more than two years ago. – Benyamin Famili Dec 02 '19 at 13:47