2
votes

I'm trying to pull the event hubs metrics using the rest API, after reading https://msdn.microsoft.com/en-us/library/azure/dn163589.aspx and https://msdn.microsoft.com/en-us/library/azure/mt652158.aspx I have got python code that can actually call the url and get a response I currently try the following code

def get_metrics(subscription, eventhub, cert, specific_partition=None):
    apiversion = '2014-01'
    namespace = eventhub['namespace']
    eventhubname = eventhub['name']
    url = "https://management.core.windows.net/{}/services/ServiceBus/Namespaces/{}/eventhubs/{}/Metrics/requests.total/Rollups/P1D/Values/?$filter=timestamp%20gt%20datetime'2016-04-09T00:00:00.0000000Z'&api-version={}".format(
        subscription, namespace, eventhubname, apiversion)
    request = requests.Request('GET', url, headers=DEFAULT_HEADERS).prepare()
    session = requests.Session()
    if cert is None or not os.path.isfile(cert):
        raise ValueError('You must give certificate file')
    session.cert = cert
    result = session.send(request)
    return result

my problem is with the url, when using the url in the code above I get

<Error xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><Code>InternalError</Code><Message>The server encountered an internal error. Please retry the request.</Message></Error>

I can get the API to output all possible rollups and all possible metrics but when trying to get actual values it fails.

is there something wrong in the url or is it a bug in azure/azure documantation?

1
What is your DEFAULT_HEADERS? Just Content-Type and Authorization?Jack Zeng
Content-Type and x-ms-version, I use certificate for the sessionSrgrn

1 Answers

2
votes

Usually, when we occur this issue, it means that there something wrong with the endpoint we combined for the Rest Apis, so that then service raise exception when parse the endpoint.

As compared with my successfully test, what the interesting I found is that the issue raised by the filter param timestamp whose first letter should be uppercased as Timestamp. The following endpoint works fine on my side. Hope it will be helpful to you.

url = "https://management.core.windows.net/{}/services/ServiceBus/Namespaces/{}/eventhubs/{}/Metrics/requests.total/Rollups/P1D/Values/?$filter=Timestamp%20gt%20datetime'2016-04-09T00:00:00.0000000Z'&api-version={}".format(
        subscription, namespace, eventhubname, '2012-03-01')