NerdGraphAPIを使用してアラート条件を管理できます。
ヒント
NerdGraphおよびNerdGraphエクスプローラーの使用を開始するためのヘルプについては、 NerdGraphの概要を参照してください。
本ドキュメントでは、以下の内容をカバーしています。
NRQLの条件を作成する手順
以下の手順に従ってください。
作成する条件タイプを決定します( NRQL 条件しきい値タイプ を参照)。
次のいずれかを実行して、関連する
policyID
を見つけます。- NerdGraphポリシーAPIを使用する.
- one.newrelic.comにアクセスし、上部のナビゲーションで[Alerts & AI(アラートとAI) ]をクリックしてから、[Alert conditions (Policies)(アラート条件(ポリシー) ]をクリックします。ポリシーを選択します。ポリシー名の下でIDを見つけます。
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
}
}
条件の更新
次の項目を完了します。
次のように
nrqlConditionsSearch
クエリのタイプフィールドをリクエストして、既存の条件のタイプを判別します。{ actor { account(id: YOUR_ACCOUNT_ID) { alerts { nrqlConditionsSearch { nrqlConditions { id type } } } } } }
ヒント
返される
type
は、更新ミューテーションに使用するものです。たとえば、返されるタイプがSTATIC
の場合、alertsNrqlConditionStaticUpdate
を使用します。返されるタイプがBASELINE
の場合は、alertsNrqlConditionBaselineUpdate
を使用します。条件の
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のアラート条件に 説明文 を作成する手順を説明します。
- 保険契約の条件をすべて把握する。
{
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つの条件の詳細を取得します。
{
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
}
}
}
}
}
- 説明文で変異を作成します。
ここには空の変異テンプレートがあります。
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
}
}