我使用以下App insights python sdk在app insights资源中发送自定义指标。
https://github.com/Microsoft/ApplicationInsights-Python
现在,当我想要检索它时,我能找到的是基于Rest API的方法来检索它。
https://dev.applicationinsights.io/documentation/Using-the-API/Metrics
是否有替代基于RestAPI的curl或http请求 - 在应用洞察python sdk?
答案 0 :(得分:1)
没有用于检索数据的SDK。只有REST API。
答案 1 :(得分:0)
Azure python SDK现在支持来自ApplicationInsightsDataClient的查询操作。
答案 2 :(得分:0)
直接使用 REST API。
首先在门户中转到您的实例,然后在侧面板中向下滚动到“API”,然后创建一个密钥。这里有更多关于这样做的信息:
https://dev.applicationinsights.io/documentation/Authorization/API-key-and-App-ID
然后你可以像这样简单地查询 REST api:
import requests
import json
appId = "..."
appKey = "..."
query = """
traces
| where timestamp > ago(1d)
| order by timestamp
| limit 10
"""
params = {"query": query}
headers = {'X-Api-Key': appKey}
url = f'https://api.applicationinsights.io/v1/apps/{appId}/query'
response = requests.get(url, headers=headers, params=params)
logs = json.loads(response.text)
for row in logs['tables'][0]['rows']:
structured = dict(zip(logs['tables'][0], row))
print(structured)