none
Azure REST API - Unable to get Service Bus queue rollup metrics

    Question

  • I'm following the advice found on http://msdn.microsoft.com/en-us/library/windowsazure/dn163589.aspx to view the metric rollup values for some Azure service bus queues we have.  Whenever I attempt to view the metrics I get an error 400 returned.

    This is the PowerShell I'm using in my attempt:

    $url = "https://management.core.windows.net/<mysubscriptionid>/services/servicebus/Namespaces/<mynamespace>/Queues/<myqueue>/Metrics/length/Rollups/PT5M/Values"
    $cert = <mypfx>

    $req = [System.Net.WebRequest]::Create($url)
    $req.ClientCertificates.Add($cert)
    $req.Headers.Add("x-ms-version", "2013-08-01")

    $res = $req.GetResponse()

    $stream = $res.GetResponseStream()
    $sr  = new-object System.IO.StreamReader $stream
    $res.StatusCode
    $sr.ReadToEnd()

    This happens for any combination of supported metric and rollup type I try. It only happens when I'm attempting to view the metric values - if I remove the word "values" from the end of the $url string, or just look for supported metrics, or just look for supported rollups for those metrics, I get the expected result. I've also tried adding a filter term to the end of the string, but I still get an error 400.

    An example of some Powershell that does work:

    $url = "https://management.core.windows.net/<mysubscriptionid>/services/servicebus/Namespaces/<mynamespace>/Queues/<myqueue>/Metrics/length/Rollups/PT5M"
    $cert = <mypfx>

    $req = [System.Net.WebRequest]::Create($url)
    $req.ClientCertificates.Add($cert)
    $req.Headers.Add("x-ms-version", "2013-08-01")

    $res = $req.GetResponse()

    $stream = $res.GetResponseStream()
    $sr  = new-object System.IO.StreamReader $stream
    $res.StatusCode
    $sr.ReadToEnd()

    Does anyone know what I'm doing wrong?


    • Edited by phryhi Monday, February 17, 2014 10:02 AM
    Monday, February 17, 2014 10:01 AM

Answers

  • After a bit of asking around, someone pointed me at the Azure Monitoring Services Library (https://github.com/WindowsAzure/azure-sdk-for-net/pull/308/files) and I managed to cannibalise a url that works from the source code (specifically ListAsync() at line 2106 of libraries/src/Monitoring/MetricsClient.cs).

    Somewhat annoyingly, it bears no resemblance to the url suggested on MSDN:

    "https://management.core.windows.net/<mysubscriptionid>/services/monitoring/metricvalues/query?resourceId=/servicebus/namespaces/<mynamespace>/Queues/<myqueue>&names=size,incoming,outgoing,length,requests.total,requests.successful,requests.failed,requests.failed.internalservererror,requests.failed.serverbusy,requests.failed.other&timeGrain=PT5M&startTime=2014-02-18T12:59:27.7243529Z&endTime=2014-02-18T13:19:27.7243529Z"

    • Marked as answer by phryhi Tuesday, February 18, 2014 2:08 PM
    Tuesday, February 18, 2014 2:08 PM

All replies

  • hi,

    From your description, I suggest you could add the queryOptions (Get Metric Data ) on the url, like this:

    $url="https://management.core.windows.net/<mysubscriptionid>/services/servicebus/Namespaces/<mynamespace>/Queues/<myqueue>/Metrics/length/Rollups/PT5M/Values/?<queryOptions>"

    Please try it.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, February 18, 2014 3:40 AM
    Moderator
  • Hi Will

    Thanks for your reply.

    Following the instructions in your link, I tried the following (making allowances for syntax discrepancies):

    $url = "https://management.core.windows.net/mysubscriptionid/services/servicebus/Namespaces/mynamespace/Queues/myqueue/Metrics/size/Rollups/PT5M/Values?`$filter=timestamp%20gt%20datetime'2014-02-13T15:05:09.5409008Z'" # This gets error 400
    
    $url = "https://management.core.windows.net/mysubscriptionid/services/servicebus/Namespaces/mynamespace/Queues/myqueue/Metrics/size/Rollups/PT5M/Values?filter=timestamp%20gt%20datetime'2014-02-13T15:05:09.5409008Z'" # This gets error 400
    
    $url = "https://management.core.windows.net/mysubscriptionid/services/servicebus/Namespaces/mynamespace/Queues/myqueue/Metrics/length/Rollups/PT5M/Values/?`$filter=timestamp%20gt%20datetime'2014-02-13T15:05:09.5409008Z'" # This gets error 400
    
    $url = "https://management.core.windows.net/mysubscriptionid/services/servicebus/Namespaces/mynamespace/Queues/myqueue/Metrics/length/Rollups/PT5M/Values/?filter=timestamp%20gt%20datetime'2014-02-13T15:05:09.5409008Z'" # This gets error 400
    
    $url = "https://management.core.windows.net/mysubscriptionid/services/servicebus/Namespaces/mynamespace/Queues/myqueue/Metrics/length/Rollups/PT5M/Values/`$filter=timestamp%20gt%20datetime'2014-02-13T15:05:09.5409008Z'" # This gets error 400
    
    $url = "https://management.core.windows.net/mysubscriptionid/services/servicebus/Namespaces/mynamespace/Queues/myqueue/Metrics/length/Rollups/PT5M/Values/filter=timestamp%20gt%20datetime'2014-02-13T15:05:09.5409008Z'" # This gets error 501

    I also tried removing the x-ms-version: 2013-08-01 header from the request, adding an authorization header containing an SWT obtained from ACS (which I've used for successful API calls to mynamespace.servicebus.windows.net), and sending both headers - none of these things made a difference.

    Do you have any other ideas?  Are you able to make a successful call and retrieve SB queue metrics yourself?  If so, what was the syntax you used?

    Thanks in advance.

    Phil


    • Edited by phryhi Tuesday, February 18, 2014 9:21 AM
    Tuesday, February 18, 2014 9:19 AM
  • After a bit of asking around, someone pointed me at the Azure Monitoring Services Library (https://github.com/WindowsAzure/azure-sdk-for-net/pull/308/files) and I managed to cannibalise a url that works from the source code (specifically ListAsync() at line 2106 of libraries/src/Monitoring/MetricsClient.cs).

    Somewhat annoyingly, it bears no resemblance to the url suggested on MSDN:

    "https://management.core.windows.net/<mysubscriptionid>/services/monitoring/metricvalues/query?resourceId=/servicebus/namespaces/<mynamespace>/Queues/<myqueue>&names=size,incoming,outgoing,length,requests.total,requests.successful,requests.failed,requests.failed.internalservererror,requests.failed.serverbusy,requests.failed.other&timeGrain=PT5M&startTime=2014-02-18T12:59:27.7243529Z&endTime=2014-02-18T13:19:27.7243529Z"

    • Marked as answer by phryhi Tuesday, February 18, 2014 2:08 PM
    Tuesday, February 18, 2014 2:08 PM
  • Hi phryhi,

    Congratulations!

    Thanks for sharing your solutions and experience here. It will be very beneficial for other community members who have similar questions. If you have any difficulty in future programming, we welcome you to post in forums again.

    Regards,

    Will


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, February 19, 2014 1:15 AM
    Moderator