我正在尝试使用其余 API 提取事件中心指标, 读完https://msdn.microsoft.com/en-us/library/azure/dn163589.aspx和 https://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 时,我得到 p>
<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 文档中的错误吗?
最佳答案
通常,当我们出现此问题时,这意味着我们为 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')
关于python - 使用 REST API 获取 Azure 事件中心指标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36531355/