• /
  • ログイン
  • 無料アカウント

本書は、お客様のご参考のために原文の英語版を機械翻訳したものです。

英語版と齟齬がある場合、英語版の定めが優先するものとします。より詳しい情報については、本リンクをご参照ください。

問題を作成する

NerdGraphチュートリアルNRQLコンディションアラート

NerdGraphAPIを使用してアラート条件を管理できます。

ヒント

NerdGraphおよびNerdGraphエクスプローラーの使用を開始するためのヘルプについては、 NerdGraphの概要を参照してください。

本ドキュメントでは、以下の内容をカバーしています。

NRQLの条件を作成する手順

以下の手順に従ってください。

  1. 作成する条件タイプを決定します( NRQL 条件しきい値タイプ を参照)。

  2. 次のいずれかを実行して、関連するpolicyIDを見つけます。

    • NerdGraphポリシーAPIを使用する.
    • one.newrelic.comにアクセスし、上部のナビゲーションで[Alerts & AI(アラートとAI) ]をクリックしてから、[Alert conditions (Policies)(アラート条件(ポリシー) ]をクリックします。ポリシーを選択します。ポリシー名の下でIDを見つけます。
  3. NRQL の条件タイプに適したミューテーションと関連する値を提供してください。

ヒント

NerdGraph GraphiQLエクスプローラーは、NerdGraph NRQLConditionsAPIのフィールドごとの詳細に関する最新のドキュメントを見つけるのに最適な場所です。たとえば、「 valueFunctionフィールドは何を受け入れますか?」などの質問です。インラインのNerdGraphドキュメントで最もよく答えられます。

NRQLの静的条件

ここでは、静的な条件を作成する例を紹介します。

mutation {
  alertsNrqlConditionStaticCreate(accountId: YOUR_ACCOUNT_ID, policyId: YOUR_POLICY_ID, condition: {
    name: "Low Host Count - Catastrophic"
    enabled: true
    nrql: {
      query: "SELECT uniqueCount(host) FROM Transaction WHERE appName='my-app-name'"
    }
    signal: {
      aggregationWindow: 60
      aggregationMethod: EVENT_FLOW
      aggregationDelay: 120
    }
    terms: {
      threshold: 2
      thresholdOccurrences: AT_LEAST_ONCE
      thresholdDuration: 600
      operator: BELOW
      priority: CRITICAL
    }
    valueFunction: SINGLE_VALUE
    violationTimeLimitSeconds: 86400
  }) {
    id
    name
  }
}

NRQLベースライン条件

ここでは、ベースラインの状態を作成する例を紹介します。

mutation {
  alertsNrqlConditionBaselineCreate(accountId: YOUR_ACCOUNT_ID, policyId: YOUR_POLICY_ID, condition: {
    name: "Baseline Condition"
    enabled: true
    baselineDirection: UPPER_ONLY
    nrql: {
      query: "SELECT average(duration) FROM Transaction"
    }
    signal: {
      aggregationWindow: 60
      aggregationMethod: EVENT_FLOW
      aggregationDelay: 120
    }
    terms: {
      threshold: 13
      thresholdDuration: 180
      thresholdOccurrences: ALL
      operator: ABOVE
      priority: CRITICAL
    }
    violationTimeLimitSeconds: 86400
  }) {
    id
    name
    baselineDirection
  }
}

条件の更新

次の項目を完了します。

  1. 次のようにnrqlConditionsSearchクエリのタイプフィールドをリクエストして、既存の条件のタイプを判別します。

    {
      actor {
        account(id: YOUR_ACCOUNT_ID) {
          alerts {
            nrqlConditionsSearch {
              nrqlConditions {
                id
                type
              }
            }
          }
        }
      }
    }

    ヒント

    返されるtypeは、更新ミューテーションに使用するものです。たとえば、返されるタイプがSTATICの場合、 alertsNrqlConditionStaticUpdateを使用します。返されるタイプがBASELINEの場合は、 alertsNrqlConditionBaselineUpdateを使用します。

  2. 条件のidを関連する条件タイプのミューテーションに提供します。更新できるのは、関連するタイプの条件のみであることに注意してください。

更新したいフィールドの更新変異のみを提供します。アップデートに提供していないフィールドはタッチされません。

変異点の更新

アップデートで指定したフィールドのみが変更されます。次の例では、 baselineDirectionは変更されずに返されますが、 nameは更新されます。

mutation {
  alertsNrqlConditionBaselineUpdate(id: YOUR_CONDITION_ID, accountId: YOUR_ACCOUNT_ID, condition: {
    name: "Your updated name"
  }) {
    id
    name
    baselineDirection
  }
}

NRQL条件のリストアップとフィルタリング

NRQL条件を一覧表示またはフィルタリングするには、NerdGraphでnrqlConditionsSearchクエリを使用します。

単数形のNRQL条件検索

NRQL条件APIを使用して、単一の条件を照会できます。 alert名前空間でnrqlConditionクエリを実行します。

nrqlConditionSearchクエリのタイプ固有のフィールドと同様に、これらのインラインフラグメントを使用して、NRQL条件タイプに制限されているフィールドをリクエストすることもできます。

{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      alerts {
        nrqlCondition(id: YOUR_CONDITION_ID) {
          id
          name
          ...on AlertsNrqlStaticCondition {
            valueFunction
          }
        }
      }
    }
  }
}

説明文の更新

ここでは、NRQLのアラート条件に 説明文 を作成する手順を説明します。

  1. 保険契約の条件をすべて把握する。
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      alerts {
        nrqlConditions(policyId: YOUR_POLICY_ID) {
          nextCursor
          results {
            id
            name
            description
            enabled
            nrql {
              query
            }
            signal {
              aggregationWindow
              aggregationMethod
              aggregationDelay
              aggregationTimer
            }
            policyId
            runbookUrl
            terms {
              duration
              operator
              priority
              timeFunction
              threshold
            }
            type
            violationTimeLimitSeconds
          }
        }
      }
    }
  }
}
  1. 1つの条件の詳細を取得します。
{
  actor {
    account(id: YOUR_ACCOUNT_ID) {
      alerts {
        nrqlCondition(id: "YOUR_CONDITION_ID") {
          description
          id
          enabled
          name
          nrql {
            query
          }
          signal {
            aggregationWindow
            aggregationMethod
            aggregationDelay
            aggregationTimer
          }
          policyId
          runbookUrl
          terms {
            operator
            priority
            threshold
            thresholdDuration
            thresholdOccurrences
          }
          type
          violationTimeLimitSeconds
        }
      }
    }
  }
}
  1. 説明文で変異を作成します。

ここには空の変異テンプレートがあります。

mutation {
  alertsNrqlConditionStaticUpdate(accountId: YOUR_ACCOUNT_ID, id: "YOUR_CONDITION_ID", condition: {description: ""}) {
    description
  }
}

ここでは、記述例を含む変異の例を紹介します。

mutation {
alertsNrqlConditionStaticUpdate(accountId: 123456, id: "123456", condition: {
description: "timestamp : {{timestamp}} \n accountId : {{accountId}} \n type : {{type}} \n event : {{event}} \n description : {{description}} \n policyId : {{policyId}} \n policyName: {{policyName}} \n conditionName : {{conditionName}} \n conditionId : {{conditionId}} \n product : {{product}} \n conditionType : {{conditionType}} \n RunbookUrl : {{runbookUrl}} \n nrqlQuery : {{nrqlQuery}} \n nrqlEventType : {{nrqlEventType}} \n targetID : {{targetId}} \n targetName : {{targetName}} \n commandLine : {{tag.commandLine}} \n entityGuid : {{tag.entityGuid}} \n entityName : {{tag.entityName}} \n fullHostname : {{tag.fullHostname}} \n instanceType : {{tag.instanceType}} \n processDisplayName : {{tag.processDisplayName}}"}
) {
description
}
}

条件の削除

alertsConditionDeleteミューテーションを使用して、任意のタイプの条件を削除できます。削除ミューテーションでのみidフィールドをリクエストできます。例えば:

mutation {
  alertsConditionDelete(accountId: YOUR_ACCOUNT_ID, id: YOUR_CONDITION_ID) {
    id
  }
}
問題を作成する
Copyright © 2022 New Relic Inc.