1

I need to find the current usage of IP addresses within subnets in Azure. I found free IPs in Virtual Networks->subnets but the number is the total available IP addresses within the subnet. How can I see how many of the available IPs within the subnet are actually in use (how many of them are free)? Is there a way to set the monitoring for free IP addresses (or used IP addresses) for Azure subnets? Thanks in advance.

Alex
  • 97
  • 8

1 Answers1

3

You can call the listUsage API /subscriptions/****/resourceGroups/aoprod9574-stamp-canadacentral-rg/providers/Microsoft.Network/virtualNetworks/vnet-name/usages?api-version=2021-02-01 to get the current allocations per Subnet in a VNet

{
  "value": [
    {
      "currentValue": 3,
      "id": "/subscriptions/****/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/aoprod9574-canadacen-vnet/subnets/cosmosdb-pe-snet",
      "limit": 27,
      "name": {
        "localizedValue": "Subnet size and usage",
        "value": "SubnetSpace"
      },
      "resourceGroup": "my-rg",
      "unit": "Count"
    },
    {
      "currentValue": 93,
      "id": "/subscriptions/****/resourceGroups/my-rg/providers/Microsoft.Network/virtualNetworks/aoprod9574-canadacen-vnet/subnets/kubernetes-snet",
      "limit": 1019,
      "name": {
        "localizedValue": "Subnet size and usage",
        "value": "SubnetSpace"
      },
      "resourceGroup": "my-rg",
      "unit": "Count"
    }
  ]
}
silent
  • 14,494
  • 4
  • 46
  • 86
  • Thanks a lot! Are you maybe aware of an option to monitor IP address usage in Azure in order to create an alert when any IP subnet is out of free IP addresses? – Alex Aug 20 '21 at 13:37
  • nope. But you could easily achieve this by regularly running an Azure Function which polls the above API – silent Aug 20 '21 at 13:51
  • Thanks, I will try that! – Alex Aug 20 '21 at 19:14
  • Glad I could help. Please accept the answer if that’s the case – silent Aug 20 '21 at 20:21