LoginSignup
7
1

More than 5 years have passed since last update.

Python 3 で Application Insights を使う(bottleも含む)

Last updated at Posted at 2017-01-23

TL;DR

Azure 版 New Relic とも言える Application Insights ですがあまり情報が無いので書いてみます。

GitHub

Microsoft/ApplicationInsights-Python: Application Insights SDK for Python
https://github.com/Microsoft/ApplicationInsights-Python

使い方はGitHubを読めばわかります。
。。。というだけでは寂しいので以下簡単に使い方。

インストール方法

インストールは pip だけでいけます。
$ pip install applicationinsights

使い方

GitHub の READMEでは、クライアントテレメトリーとサーバー側処理が一緒くたになっていて、分かりにくいのですが、クライアントからリクエストを送る時のモニタリングと、リクエストを受けるサーバー側のモニタリングの2つの分類でのモニタリングが可能です。

INSTRUMENTATION KEY

どの様な使い方にせよ、INSTRUMENTATION KEY がいります。
INSTRUMENTATION KEY は、Azure の Application Insights のブレードの中のプロパティにあります。
キャプチャ.PNG

サーバー側として

とりあえずリクエスト

基本的にWSGIなアプリケーションであれば簡単に組み込めます。
Python の軽量フレームワーク bottle + uWSG な環境でももちろん出来ました。

from applicationinsights.requests import WSGIApplication
from bottle import route, run, default_app, get, post, request, static_file
~略~
if __name__ == '__main__':
    # コマンドから"python index.py"で起動した場合
    run(host='0.0.0.0', port=8080, debug=True)
else:
    # uWSGIから起動した場合
    application = WSGIApplication('<INSTRUMENTATION KEY>', default_app())

こんな感じで表示されます。
キャプチャ.PNG

※ブラウザ表示時のJavaScriptとしても組み込んでいるのでその表示も含まれてます。

ロギング

これからやってみる

例外

これからやってみる

クライアント側として

これからやってみる

7
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
1