アラート条件は、GraphQL NerdGraph APIを使って管理できます。ここでは、 NerdGraph API エクスプローラー で開発できる条件クエリとミューテーションをご紹介します。
ヒント
NerdGraph API explorerの使用方法については、 NerdGraph introduction を参照してください。
本ドキュメントでは、以下の内容をカバーしています。
NRQLの条件を作成する手順
以下の手順に従ってください。
作成する条件タイプを決定します( NRQL 条件しきい値タイプ を参照)。
以下のいずれかの方法で、関連する
policyID
を見つけてください。- NerdGraphポリシーAPIを使用する.
- one.newrelic.com にアクセスし、トップナビで Alerts& AI をクリックし、次に Policies をクリックします。ポリシーを選択します。ポリシー名の下に ID があります。
NRQL の条件タイプに適したミューテーションと関連する値を提供してください。
ヒント
NerdGraph GraphiQLエクスプローラは、NerdGraph NRQL Conditions APIのフィールドごとの仕様に関する最新のドキュメントを探すのに最適な場所です。たとえば、"What does the valueFunction
field accept?" のような質問には、インラインの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
クエリで type フィールドを要求して、既存の条件のタイプを決定します。{ actor { account(id: YOUR_ACCOUNT_ID) { alerts { nrqlConditionsSearch { nrqlConditions { id 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 を使用して、単数の条件を照会できます。 nrqlCondition
クエリを alerts ネームスペースで実行します。
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
変異を使って、あらゆるタイプの条件を削除することができます。delete変異では、 id
フィールドのみを要求することができます。
mutation {
alertsConditionDelete(accountId: YOUR_ACCOUNT_ID, id: YOUR_CONDITION_ID) {
id
}
}