I use below App insights python sdk to send my custom metrics in app insights resource.
https://github.com/Microsoft/ApplicationInsights-Python
Now when I want to retrieve it, all i can find is Rest API based method to retrieve it.
https://dev.applicationinsights.io/documentation/Using-the-API/Metrics
Is there an alternative to RestAPI based curl or http request - in app insights python sdk ?
There are no SDKs for retrieving data. Only REST API.
Use the REST API directly.
First go to your instance in the portal and on the side panel scroll down to 'API', and create a key. There is more info of doing this here:
https://dev.applicationinsights.io/documentation/Authorization/API-key-and-App-ID
Then you can simply query the REST api like this:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With