概要
Azure Web AppsでWEBサービスを立ち上げ、そのログ監視をApplication Insightsで設定するチュートリアル的な記事です。
リソースグループ作成
リソースグループで各Azureリソースをまとめると、チュートリアル実施後のクリーンアップが楽になります。

グループ名は任意です。今回は「test-8839-rg」としました。

最後に[作成]します。

App Service作成
Web AppsでWEBサービスを立ち上げます。

ランタイムは Node.js を選択します。
また、[SKU とサイズ]で[サイズを変更します]を選択することで
App Serviceプラン(コンピューティングリソース)のサイズ(スペック)を変更できます。

Application Insightsを有効にします。
ランタイムによっては有効化できるもの/できないものがあります。

App Serviceを作成します。

リソースのデプロイが完了したら、作成されたリソースに移動します。

以下の通りWEBサービスのURLが確認できます。

URLにアクセスすると、以下のようなページが表示されます。

Application Insights監視設定
ログ確認
App Serviceから、Application Insightsの画面に遷移できます。


監視設定
Application Insightsの画面から、アラートルールを作成します。

アラートの発生条件を追加します。

それぞれ[ログ検索]、[Custom log search]を選択します。

図の通り設定します。

「"test-8839-access" を含むURLでアクセスされた場合」という条件になっています。
1 2 |
requests | where url contains "test-8839-access" |
※検索クエリについては後述します。
次にアクショングループを作成します。
アラートが発生した場合のアクション(今回の場合はメール通知)を定義します。

アクショングループ名などは任意です。

アラートメールの送付先を指定します。

アクショングループのアクション名を入力し[OK]を選択します。

アラートメールの件名などを入力し、アラートルールを作成します。

アラートテスト
監視対象の文字列(test-8839-access)が含まれるURLでWEBサービスにアクセスしてみます。

しばらくすると、以下のようなアラートメールが送信されていました。

Application Insightsの検索クエリ
Application Insightsの[検索]画面から[ログ(Analytics)]を選択すると、

検索クエリを実行できる画面に遷移します。

以下クエリサンプルが参考になります。
投稿者プロフィール
- 2015年8月入社。弊社はインフラ屋ですが、アプリも作ってみたいです。