#author("2020-08-28T08:28:37+00:00","","") #mynavi(Azureメモ) #setlinebreak(on); #html(){{ <style> .images img { border: 1px solid #333; margin-right: 20px;} .images div { vertical-align: top; } </style> }} * 概要 [#l83f8e0c] #html(<div class="pl10">) Azure Monitor の統合アラート エクスペリエンスには、以前は Log Analytics と Application Insights によって管理されていたアラートも含まれるようになった。 ここでは Azure モニター を使用して関数アプリの異常を検知する方法について記載する。 #html(</div>) * 目次 [#q34c50fa] #contents - 関連 -- [[Azureメモ]] -- [[Azure Functions のログを参照する]] - 参考 -- [[Azure Monitor の概要>https://docs.microsoft.com/ja-jp/azure/azure-monitor/overview]] -- [[Azure App Service のアプリの監視>https://docs.microsoft.com/ja-jp/azure/app-service/web-sites-monitor]] -- [[Azure での Web アプリケーションの監視>https://docs.microsoft.com/ja-jp/azure/architecture/reference-architectures/app-service-web-app/app-monitoring]] -- [[Microsoft Azure のアラートの概要>https://docs.microsoft.com/ja-jp/azure/azure-monitor/platform/alerts-overview]] -- [[Azure Functions を監視する>https://docs.microsoft.com/ja-jp/azure/azure-functions/functions-monitoring?tabs=cmd]] -- [[Application Insights の使用量とコストを管理する>https://docs.microsoft.com/ja-jp/azure/azure-monitor/app/pricing]] -- [[Azure Monitor でログクエリの使用を開始する>https://docs.microsoft.com/ja-jp/azure/azure-monitor/log-query/get-started-queries]] -- [[Kusto の概要>https://docs.microsoft.com/ja-jp/azure/data-explorer/kusto/concepts/]] -- [[Kusto クエリ言語>https://docs.microsoft.com/ja-jp/azure/data-explorer/kusto/query/]] * どのようなログを検知するかを決める。 [#m56ceb07] #html(<div class="pl10">) Azure Monitor では、設定したクエリに合致するレコードの件数や、数値の平均値などが一定数以上の時に通知を行う事ができる。 今回は以下の前提で以降の手順を記載する。 - 関数アプリは Go で作成されているものとする。(カスタムハンドラーを使用) - 関数アプリは処理の最後に処理結果を以下の形式で出力する。 | 正常/異常 | 出力されるログ |h | 正常時 | [INFO] Result: Success ... | | 異常時時 | [ERROR] Result: Failure ... | - 異常チェックは1時間に一回行うものとする。 上記の前提で、今回は異常チェック用として以下のクエリを使用する。 #myterm2(){{ traces | where (message has_cs "[ERROR] Result:" or message has_cs "http: panic serving") and cloud_RoleName == "関数アプリ名(全て小文字)" and timestamp > ago (1h) }} ※ Kustoクエリについては [[Kusto クエリ言語>https://docs.microsoft.com/ja-jp/azure/data-explorer/kusto/query/]] を参照。 ※ 重大度(severityLevel)等も使用できるが今回は使用していない。 #html(</div>) * アラートの作成 [#ua7becfb] #html(<div class="pl10">) #html(<div class="images"><div class="ib">) モニターを検索し、選択。 &ref(azure_monitor01.png,nolink); #html(</div><div class="ib">) アラートから [新しいアラートルール] を選択。 &ref(azure_monitor02.png,nolink); #html(</div><div class="ib">) 関数アプリに関連付けている Application Insight を選択し、条件名のリンクをクリック。 &ref(azure_monitor03.png,nolink); #html(</div><div class="ib">) custom log search で下図のように入力/選択。 &ref(azure_monitor04.png,nolink); #html(</div><div class="ib">) [アクショングループの選択] を押下。 &ref(azure_monitor05.png,nolink); #html(</div><div class="ib">) リソースグループ、アクショングループ名などを入力。(まだ [確認及び作成] は押さない) &ref(azure_monitor06.png,nolink); #html(</div><div class="ib">) [通知]タブに切り替えて、通知の種類、名前を入力。(電子メール/プッシュ通知... を選択する) &ref(azure_monitor07.png,nolink); #html(</div><div class="ib">) 通知先のメールアドレスを入力し [OK] &ref(azure_monitor08.png,nolink); #html(</div><div class="ib">) アクションタブでは他の関数の起動等を設定できるが、今回は何も指定せずに [確認及び作成]。 &ref(azure_monitor09.png,nolink); #html(</div><div class="ib">) メールの件名などを入力し [アラートルールの作成] を押下。 &ref(azure_monitor10.png,nolink); #html(</div></div>) #html(</div>) * エラー通知の例 [#dce7fbf2] #html(<div class="pl10">) 上記で設定したアラートに合致するログが見つかった時には、下図のようなメールが送信されてくる。 ※ クエリに引っかかったログの最初の10件の内容もメール本文に記載されている。 #html(<div class="images">) &ref(azure_alert_mail_sample1.png,nolink); #html(</div>) メール本文の [View 10 Result(s)] ボタンを押下すると Azure ポータルの Insight のログ検索画面が開き、結果が表示される。 #html(<div class="images">) &ref(azure_alert_mail_clicked1.png,nolink); #html(</div>) #html(</div>) * 料金 [#f18b5083] #html(<div class="pl10">) https://azure.microsoft.com/ja-jp/pricing/details/monitor/ には下表の通り記載されている。(2020/8月現在) ** アラート [#n514d09c] | アラート シグナル | 含まれている無料ユニット | 料金 |h | メトリック | 監視対象メトリック時系列 10 個 (1 か月あたり) | 監視対象メトリック時系列 1 つにつき ¥11.200 (1 か月あたり) | | ログ | なし |15 分以上の間隔: 監視対象ログ 1 つにつき ¥56 (1 か月あたり)&br;10 分間隔: 監視対象ログ 1 つにつき ¥112 (1 か月あたり)&br;5 分間隔: 監視対象ログ 1 つにつき ¥168 (1 か月あたり) | | アクティビティ ログ | サブスクリプションあたり 100 ルールが上限 | 無料 | | 動的しきい値 | なし | 動的しきい値あたりの ¥11.200/月 | ** 通知 [#wb723a2c] | 機能 | 含まれている無料ユニット | 料金 |h | ITSM コネクタの作成イベントまたは更新イベント | 1 か月あたりイベント 1,000 件 | ¥560/1,000 イベント | | メール | 1 か月あたりメール 1,000 通 | メール 100,000 通につき ¥224 | | (Azure Mobile Apps への) プッシュ通知 | 1 か月あたり通知 1,000 件 | 通知 100,000 回につき ¥224 | | Web hook をセキュリティで保護する | セキュリティ保護された 1 つの Web hook | セキュリティ保護された ¥672/1,000,000 の Web hook | | webhook | 1 か月あたりの webhook 100,000 件 | webhook 1,000,000 件につき ¥67.20 | ※SMS と音声通話は省略 #html(</div>) //* クエリサンプル [#l05d37f4] //traces | where operation_Name=="BlobTrigger2" and message has_cs "test" //traces | operation_Name=="MyBlobTrigger2" and message has_cs "test" and timestamp > ago(1h)