時間枠全体で NRQL 結果を比較し、標準のアラートでは検出できない異常を検出します。
要件:
- New Relicアカウント
- メールの送信先(通知の送信を参照)
- CreateSchedule API経由でスケジュールします。
キーアクション: newrelic.nrdb.query 、 newrelic.notification.sendEmail
使用例: 次のような標準アラートが要件を満たせない場合にこのパターンを使用します。
- 複数の時間枠にわたるメトリクスの比較
- クエリ結果にカスタム数学演算を適用する
- 特定の閾値またはパターンが検出された場合にのみトリガーする
- 条件付きロジックを使用して複数のクエリからのデータを結合する
name: Complex_Alert_Workflow description: 'Compares NRQL results across time windows and sends alerts when new events are detected'
workflowInputs: destinationId: type: String query: type: String defaultValue: 'FROM Span SELECT count(*)'
steps: - name: query1 type: action action: newrelic.nrdb.query version: 1 inputs: query: "${{ .workflowInputs.query }} SINCE 10 minutes ago UNTIL 5 minutes ago" accountIds: - 7401815 selectors: - name: length expression: '[ .results[] | length ]' - name: count expression: '[ .results[0].count ]'
- name: query2 type: action action: newrelic.nrdb.query version: 1 inputs: query: "${{ .workflowInputs.query }} SINCE 5 minutes ago" accountIds: - 7401815 selectors: - name: length expression: '[ .results[] | length ]' - name: count expression: '[ .results[0].count ]'
- name: CheckForNewEvents type: switch switch: - condition: >- ${{ (.steps.query2.outputs.count - .steps.query1.outputs.count) > 0 }} next: sendEmail next: end
- name: sendEmail type: action action: newrelic.notification.sendEmail version: 1 inputs: destinationId: ${{ .workflowInputs.destinationId }} subject: Hello there! message: >- More spans incoming!!! There are --- ${{ (.steps.query2.outputs.count - .steps.query1.outputs.count) }} --- new Spans that were ingested in the last 5 minutes attachments: - type: QUERY query: ${{ .workflowInputs.query }} SINCE 5 minutes ago format: CSV filename: span_count.csv next: endスケジュールするには、cron 式*/10 * * * * (10 分ごと) でCreateSchedule APIを使用します。最小間隔は10分です。詳細については、ワークフローの制限を参照してください。
次のステップ
- デプロイメント ロールバック: 自動デプロイメント監視
- EC2管理:インフラストラクチャの自動化