此项目允许在使用数据分析工具(如numpy)分析结果以进行进一步处理的同时查询application insights分析api。
aianalytics-client的Python项目详细描述
此项目允许查询application insights分析api,同时以简单的方式解析结果以进行进一步的处理。Application Insights Analytics是application insights的强大搜索功能,它允许查询applciation insights遥测。 此模块用于其他数据分析包,如numpy和matplotlib。查询结果是numpy数组。
Note: this package is not for sending telemetry to the Application Insights serivce. For that you can use the official python sdk repo.
要求
该模块在Python2.7和Python3.5上进行了测试。python 3的旧版本可能也可以工作。
要在Microsoft Visual Studio中打开项目,您需要Python Tools for Visual Studio。
用法
安装后,您可以查询应用程序Insights遥测。这是一些样品。
查询过去24小时的异常并打印它们
fromanalytics.clientimportAnalyticsClientclient=AnalyticsClient('<Your app id goes here>','<You app key goes here>')result=client.query('exceptions | where timestamp > ago(24h) | project timestamp, type, outerMessage')forrowinresult.row_iterator():print("at {0} there was an exception of type {1} with message {2}".format(row['timestamp'],row['type'],row['outerMessage']))# Indexes can also be used instead of column names, e.g.:print("at {0} there was an exception of type {1} with message {2}".format(row[0],row[1],row[2]))
查询上周的平均请求持续时间,并使用matplotlib进行绘图
fromanalytics.clientimportAnalyticsClientclient=AnalyticsClient('<Your app id goes here>','<You app key goes here>')result=client.query('requests | where timestamp > ago(7d) | summarize Duration = avg(duration/1000) by bin(timestamp, 1h) | order by timestamp asc')importmatplotlib.pyplotaspltplt.plot(result["timestamp"],result["Duration"])plt.show()