0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Grafana で 複数クエリの結果を条件にしたアラートルールの作成手順

Last updated at Posted at 2024-05-12

Grafana で Azure Monitor をデータソースとして使用し、特定の条件に基づくアラートを設定する方法を解説します。
この例では、Kusto クエリ言語(KQL)を用いて、Azure のサインインログを分析し、アクセス成功率が過去 5 日間の平均の 85%未満に低下した場合にアラートを出す設定を行います。

前提条件

  • Grafana に Azure Monitor データソースが追加されていること。
  • Azure Monitor で Kusto クエリ言語(KQL)が利用可能であること。

ステップ 1: アラートルールの作成

  1. Grafana のメニュー画面から、「Alerting」⇒「Alert rules」を選択します。
  2. 「Create alert rule」を押します。

ステップ 2: Azure Monitor データソースの設定

  1. パネルのデータソースとして「Azure Monitor」を選択します。
  2. 「Logs」タブを選択し、KQL を用いてサインインログのクエリを設定します。

ステップ 3: クエリの作成

  • クエリ A (本日のアクセス成功数)

    SigninLogs
        | where TimeGenerated >= startofday(now()) and TimeGenerated < endofday(now())
        | summarize successful_signins = countif(ResultType == 0)
    
  • クエリ B (本日のアクセス総数)

    SigninLogs
        | where TimeGenerated >= startofday(now()) and TimeGenerated < endofday(now())
        | summarize signin_attempts = count()
    
  • クエリ C (過去 5 日間の平均アクセス成功数)

      // 過去5日間のサインイン成功数と試行数を取得
      SigninLogs
      | where TimeGenerated >= startofday(now()) - 5d and TimeGenerated < startofday(now())
      | summarize successful_signins = countif(ResultType == 0)
    
  • クエリ D (過去 5 日間の平均アクセス総数)

      // 過去5日間のサインイン成功数と試行数を取得
      SigninLogs
      | where TimeGenerated >= startofday(now()) - 5d and TimeGenerated < startofday(now())
      | summarize signin_attempts = count()
    
  • Expression E (本日のアクセス成功率)
    クエリ A 結果をクエリ B 結果で割り、100 を掛ける。

    ${A} / ${B} * 100
    
  • Expression F (過去 5 日間の平均アクセス成功率の 85%)
    クエリ C 結果をクエリ D 結果で割り、0.85 を掛けて、100 を掛ける。

    ${C} / ${D} * 0.85 * 100
    
  • Expression G (判断上の計算)
    Expression E から、Expression F を引く。(アクセス成功率が過去 5 日間の平均の 85%未満に低下したのか)

    ${E} - ${F}
    
  • Expression H (アラート要否の判断)
    最終的に下記をアラート要否の判断としたいので「Threshold」とする。
    Expression E から、Expression F を引いて、0 以上は正常。0 未満でアラートとする。

    ${G}「IS BELOW 0」
    

ステップ 4: 評価期間と通知チャネルの設定

  1. アラートの評価期間を「5m」や「10m」など、適切な間隔で設定します。
  2. 「Notifications」セクションで通知チャネルを選択し、アラート発生時に通知されるように設定します。

ステップ 5: アラートルールの保存

  1. 全ての設定を確認し、右上の「Save」ボタンをクリックしてアラートルールを保存します。
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?