0
votes

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?

3
well, use monitoring solutions?4c74356b41
If you do not mind using 3rd party products, look into CloudMonix @ cloudmonix.com -- it fully supports VMSS, any performance counters, instance healing and scaling, and more... HTHIgorek

3 Answers

0
votes

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

1
votes

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
0
votes

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.