使用rest api获取Azure Event Hubs指标?

时间:2016-04-10 15:01:21

标签: python rest azure azure-eventhub cortana-intelligence

我尝试使用其余API来提取事件中心指标, 阅读https://msdn.microsoft.com/en-us/library/azure/dn163589.aspxhttps://msdn.microsoft.com/en-us/library/azure/mt652158.aspx后 我有python代码,实际上可以调用url并获得响应 我目前正在尝试以下代码

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

我的问题在于url,当我在上面的代码中使用url时,我得到了

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

我可以让API输出所有可能的汇总和所有可能的指标但是在尝试获取实际值时它会失败。

网址中有什么问题,或者它是天蓝色/天蓝色文档中的错误?

1 个答案:

答案 0 :(得分:2)

通常,当我们遇到此问题时,这意味着我们为Rest Apis组合的端点出现了问题,因此在解析端点时服务引发异常。

与我成功的测试相比,我发现的有趣之处在于过滤器参数timestamp引发的问题,其第一个字母应该大写为Timestamp。以下端点在我这边工作正常。希望它对你有所帮助。

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')