1 回答

TA贡献2039条经验 获得超8个赞
因此,几天后,我找到了一种从 azure insights 中阅读的方法,尽管我没有坚持使用该解决方案。
洞察法
对于任何感兴趣的人,要从您需要使用azure-applicationinsights包(而不是 azure-mgmt-applicationinsights)的见解中读取指标。然后,您使用 Azure 凭据实例化一个 ApplicationInsightsDataClient,您可以按如下方式发送查询:
from azure.applicationinsights import ApplicationInsightsDataClient client = ApplicationInsightsDataClient(<credentials>) metric = client.metrics.get(<application_id>, <metric>, custom_headers=<custom_headers>, **<other_kwargs>)
现在,棘手的部分是这个“application_id”和“custom_headers”。首先,您可以从 azure 中的 API 访问密钥选项卡上的洞察力资源中检索它。
对于自定义标头,您需要将令牌指定为您需要在见解资源中创建的一个 API_key(与上述相同的位置)。格式应该是:
custom_headers = {'x-api-key': <api_key>}
要了解您可以从洞察资源中获得哪些指标,您可以
available_metrics = client.metrics.get_metadata(<application_id>, custom_headers=custom_headers)
此外,如果您在 CI/CD 管道中进行部署,您还可以自动检索 ApplicationID 和创建 api_key。
要在我刚刚创建的 gitlab 管道日志上获取应用程序 ID 并在 terraform 中为其输出(检查关于输出的 terraform 文档)对于 api_key 创建,您需要使用azure-mgmt-applicationinsights包并实例化一个 ApplicationInsightsManagementClient(不确定这个名字现在)
传递凭据并在“api_keys”属性中使用“create”方法。这可能有点棘手,因为您需要传递一些“linked_read_properties”。
我的建议是首先在 azure 门户中创建它,在 python 中读取它,检查您需要的属性,然后尝试通过 python 创建它。
至于我最终坚持的解决方案。
我创建了我的 azure 函数,该函数将结果写入 blob_storage 以同时写入“元数据”键/值。
如果还有一些批处理尚未运行,它将把它写为 False。如果是最后一批,则将其更改为 True。
然后我只读取 python 中的 blob 属性,直到值为 True。
希望这可以帮助任何有类似问题的人;)
添加回答
举报