【问题标题】:Getting Azure Event Hubs metrics using rest api?使用 rest api 获取 Azure 事件中心指标?
【发布时间】:2016-04-10 15:01:20
【问题描述】:

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

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 输出所有可能的汇总和所有可能的指标,但是在尝试获取实际值时它会失败。

网址有问题还是 azure/azure 文档中的错误?

【问题讨论】:

  • 你的DEFAULT_HEADERS 是什么?只是内容类型和授权?
  • Content-Type 和 x-ms-version,我为会话使用证书

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


【解决方案1】:

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

与我的成功测试相比,我发现有趣的是过滤参数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')

【讨论】:

  • 谢谢,你能更新一下 azure 网站上的文档吗?
猜你喜欢
  • 2016-09-23
  • 2020-03-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-05-06
  • 1970-01-01
  • 2022-01-02
相关资源
最近更新 更多