python - 使用 REST API 获取 Azure 事件中心指标?

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

网址是否有问题,或者是 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/

相关文章:

python - 如何正确压缩此 Python IF 语句?

Python scipy.signal.remez 高通滤波器设计产生奇怪的传递函数

Android @RestService 通过 androidannotations 注入(inject)导致 nullPointerException

.net - 在 VB.NET 中构建 REST 服务的教程?

c# - 将 ASP.NET Core 2.1 预览应用程序部署到 Azure

sql-server - 将 SQL Server 2008 R2 数据同步到 Azure 错误

给定期间每月第一天的 Python 列表

python - 忽略 Python 字符串中的大小写

java - 如何将Spring war文件部署到Tomcat?

azure - 用户无权执行操作“Microsoft.Resources/deployments/validate/action”