locked
Get-AzMetric MetricNamespace issue/bug? RRS feed

  • Question

  • Hi guys, 

    Been working with Azure Metrics for some custom reports and faced with an issue (same for both env)
    Environment A:
    Az.Monitor 1.0.0
    PowerShell 6.1.0

    Environment B:
    AzureRM.Insights 5.1.4     
    PowerShell 5.1.17134

    1) What I'm trying to achieve is - number of blobs in container. It's available from UI in Metric Namespace "Blob". Gel-AzStorageBlob is not an option as there are more then 1000000 blobs in each container

    2) However, as I got - powershell command should be like:

    Get-AzMetric `
     -ResourceId /subscriptions/{SubscriptionID}/resourceGroups/{rgNname}/providers/Microsoft.Storage/storageAccounts/{storageAccountName} `
     -MetricNames BlobCount `
     -MetricNamespace "blobServices/default"


    However it returns nothing.

    *---* So I've tried to debug it and the request is:

    Absolute Uri:
    https://management.azure.com//subscriptions/{SubscriptionID}/resourceGroups/{rgName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/providers/microsoft.insights/metrics?timespan=2019-02-12T07:00:53.9500008Z%2F2019-02-12T08:00:53.9500008Z&metricnames=blobServices&api-version=2018-01-01&metricnamespace=blobServices%2Fdefault

    I've tried different metricnamespaces like blob , blobservices and etc.
    With -MetricNamespace "Microsoft.Storage/storageAccounts/blobServices/default" it returns:
    "message": "Detect invalid value: Microsoft.Storage/storageAccounts/blobServices/default for query parameter: 'metricnamespace', the value must be: Microsoft.Storage/storageAccounts if the query parameter is provided, you can also 
    skip this optional query parameter."

    However, according to the guide the request should be:

    Absolute Uri:
    https://management.azure.com//subscriptions/{SubscriptionID}/resourceGroups/{rgName}/providers/Microsoft.Storage/storageAccounts/{storageAccountName}/blobServices/default/providers/microsoft.insights/metrics?timespan=2019-02-12T07:03:00.3461219Z%2F2019-02-12T08:03:00.3461219Z&metricnames=BlobCount&api-version=2018-01-01
    


    So to get the right respond I've to run:

    Get-AzMetric `
      -ResourceId /subscriptions/{SubscriptionID}/resourceGroups/{rgName}/providers/Microsoft.Storage/storageAccounts/{storageAccountname}/blobServices/default `
      -MetricNames BlobCount
    


    Is it a feature or a bug or I'm doing something wrong?

    Tuesday, February 12, 2019 8:28 AM

All replies

  • Hello Artem,

    Thanks for posting here !

    In the place of metricnamespace parameter, you need to give ‘blob’ for your requirement.

    You can compare the both below scripts which you mentioned in the OP.

    ##Here you specified the resource id of storage account
    
    Get-AzMetric `
    
    -ResourceId /subscriptions/{SubscriptionID}/resourceGroups/{rgNname}/providers/Microsoft.Storage/storageAccounts/{storageAccountName} `
    
    -MetricNames BlobCount `
    
    -MetricNamespace "blobServices/default"
    
    ##Here you specified the resource id of blob
    
    Get-AzMetric `
    
      -ResourceId /subscriptions/{SubscriptionID}/resourceGroups/{rgName}/providers/Microsoft.Storage/storageAccounts/{storageAccountname}/blobServices/default `
    
      -MetricNames BlobCount

    If you check specifically in the storage account properties tile under Azure portal, there are different type of resource id’s.

    For example, the storage account resource id will be something like this

    “/subscriptions/xxxxxx-xxxx-xx-b5ba-xxxxx/resourceGroups/yashfilesyncrg/providers/Microsoft.Storage/storageAccounts/yashfilestg”

    For blob resource id will be like this

    “/subscriptions/xxxxx-xxxx-xxx-b5ba-xxxxx/resourceGroups/yashfilesyncrg/providers/Microsoft.Storage/storageAccounts/yashfilestg/blobServices/default”

    But as you are using Get-AzMetric cmdlet so for the ‘resourceId’ parameter you may have to give ‘resource id of the metric’ but not the resource id of storage account or blob. For reference please check https://docs.microsoft.com/en-us/powershell/module/azurerm.insights/get-azurermmetric?view=azurermps-6.13.0#required-parameters

    In the metricnames parameter you should give the type of blob, file, table, queue or storageaccount as per your requirement. In the Azure portal UI, if you check the metric namespace and metric name, you need to specify the resource type as shown below.

    To get more info on this, you can refer the following document on Azure metrics for Storage Account. Kindly let us know if you need any further assistance on this.


    • Edited by YASWANTH MADI Thursday, February 14, 2019 6:56 AM
    • Proposed as answer by YASWANTH MADI Thursday, February 14, 2019 6:57 AM
    Thursday, February 14, 2019 6:55 AM
  • @Artem, Just checking in to see if the above answer helped. If this answers your query, do click “Mark as Answer” and Up-Vote for the same, which might be beneficial to other community members reading this thread. And, if you have any further query do let us know.
    Wednesday, February 27, 2019 9:59 AM