• EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

이 한글 문서는 사용자의 편의를 위해 기계 번역되었습니다.

영문본과 번역본이 일치하지 않는 경우 영문본이 우선합니다. 보다 자세한 내용은 이 페이지를 방문하시기 바랍니다.

문제 신고

New Relic 및 Terraform 시작하기

Terraform 은 HashiCorp에서 구축한 널리 사용되는 코드형 인프라 소프트웨어 도구입니다. 이를 사용하여 New Relic 대시보드 및 경고를 포함하여 모든 종류의 인프라 및 서비스를 프로비저닝합니다.

이 가이드에서는 Terraform으로 New Relic 알림을 설정하는 방법을 알아봅니다. 보다 구체적으로 경고 정책, 4가지 경고 조건 및 알림 채널을 프로비저닝합니다. 네 가지 알림 조건은 Google의 사이트 안정성 엔지니어링 책 에 소개된 모니터링의 네 가지 황금 신호 를 기반으로 합니다.

  • 대기 시간: 애플리케이션이 요청을 처리하는 데 걸리는 시간입니다.
  • 트래픽: 시스템이 수신하는 요청의 양입니다.
  • 오류: 실패한 요청 비율입니다.
  • 포화도: 애플리케이션의 요구 사항을 충족하기 위한 리소스에 대한 스트레스입니다.

시작하기 전에

이 가이드를 사용하려면 New Relic과 Terraform에 대한 기본 지식이 있어야 합니다. 아직 New Relic 오픈 소스 에이전트를 배포하지 않은 경우 애플리케이션에 New Relic을 설치 합니다. 또한 Terraform CLI를 설치합니다 .

Bootstrap Terraform 및 New Relic 공급자

작업 디렉터리를 초기화하고 Terraform 구성 파일을 생성하여 시작합니다.

bash
$
mkdir terraform-project && cd terraform-project
$
touch main.tf

그런 다음 main.tf 에서 terraformrequired_providers 블록을 설정하여 Terraform에 New Relic 공급자를 설치하고 사용하도록 지시합니다.

terraform {
# Require Terraform version 1.0 (recommended)
required_version = "~> 1.0"
# Require the latest 2.x version of the New Relic provider
required_providers {
newrelic = {
source = "newrelic/newrelic"
}
}
}

이 코드 블록에서는 필요한 Terraform 버전을 1.0으로 설정하고 New Relic 공급자를 최신 2.x 버전으로 설정합니다. 설정에 적합한 버전 제약 조건 을 사용하면 Terraform 실행의 안정성이 향상됩니다.

이제 Terraform 및 New Relic 공급자 버전을 설정했으므로 New Relic 공급자를 구성해야 합니다.

New Relic 제공자 구성

terraform 이 모두 설정되면 다음 항목으로 New Relic provider 을 구성합니다.

  1. 귀하의 New Relic 계정 ID .

  2. 당신의 New Relic

    . 대부분의 사용자 키는 접두사 NRAK-로 시작합니다.

  3. 당신의 New Region 지역 . 계정 설정 페이지가 one.newrelic.com 에 있는 경우 지역은 US 이고 계정이 one.eu.newrelic.com 에 있는 경우 EU }입니다.

    main.tf 에서 공급자에서 해당 값을 설정합니다.

    provider "newrelic" {
    account_id = 12345 # Your New Relic account ID
    api_key = "NRAK-***" # Your New Relic user key
    region = "US" # US or EU (defaults to US)
    }

    New Relic 공급자에 이러한 값을 설정하면 해당 공급자가 New Relic API를 통해 계정을 대신하여 변경하도록 구성됩니다.

    환경 변수 를 사용하여 New Relic 제공자를 구성할 수도 있습니다. 이는 공급자 구성에 대한 기본값을 설정하는 유용한 방법입니다.

    New Relic 제공자 구성에 대한 자세한 내용은 공식 제공자 문서 를 참조하십시오.

    New Relic 공급자가 구성된 상태에서 Terraform을 초기화합니다.

    bash
    $
    terraform init

    Terraform이 New Relic 공급자 설치 및 등록을 마치면 성공 메시지와 실행 가능한 다음 단계(예: terraform plan 실행)를 받게 됩니다. 그러나 terraform plan 를 실행하기 전에 리소스를 생성해야 합니다.

골든 시그널 알림으로 New Relic 알림 정책 생성

New Relic 공급자를 구성하고 초기화하면 애플리케이션에 대한 경고 전략을 정의할 수 있습니다.

특정 애플리케이션을 대상으로 하고 있으므로newrelic_entity 를 사용하여 New Relic에서 애플리케이션 정보를 가져오고 구성의 다른 위치에서 해당 데이터를 참조할 수 있도록 합니다.

data "newrelic_entity" "example_app" {
name = "Your App Name" # Must be an exact match to your application name in New Relic
domain = "APM" # or BROWSER, INFRA, MOBILE, SYNTH, depending on your entity's domain
type = "APPLICATION"
}

다음으로 newrelic_alert_policy 를 생성합니다. 애플리케이션 이름을 기반으로 정책에 동적 이름을 지정합니다. 이렇게 하면 정책 범위를 지정하는 데 도움이 됩니다.

resource "newrelic_alert_policy" "golden_signal_policy" {
name = "Golden Signals - ${data.newrelic_entity.example_app.name}"
}

이 시점에서 테스트 실행으로 구성을 테스트할 수 있어야 합니다.

bash
$
terraform plan

Terraform의 실행 계획을 표시하는 출력이 표시되어야 합니다. 계획에는 terraform apply 실행 시 Terraform이 수행하는 작업이 포함됩니다.

bash
# Example output
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# newrelic_alert_policy.golden_signal_policy will be created
+ resource "newrelic_alert_policy" "golden_signal_policy" {
+ account_id = (known after apply)
+ id = (known after apply)
+ incident_preference = "PER_POLICY"
+ name = "Golden Signals - Your App Name"
}
Plan: 1 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------

이 경우 계획은 terraform apply 를 실행할 때 Terraform이 새 경고 정책을 생성함을 보여줍니다. 세부 정보를 확인한 후 계획을 실행하여 New Relic 계정에서 알림 정책 리소스를 프로비저닝합니다.

bash
$
terraform apply

apply 이 변경될 때마다 Terraform은 실행하도록 지시한 작업을 확인하도록 요청합니다. "예"를 입력합니다.

실행 중인 동안 Terraform은 콘솔에 로그를 보냅니다.

bash
# Example output of `terraform apply`
newrelic_alert_policy.golden_signal_policy: Creating...
newrelic_alert_policy.golden_signal_policy: Creation complete after 1s [id=111222333]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

New Relic에 로그인하고 알림 정책 으로 이동하여 Terraform이 새 정책을 생성했는지 확인합니다.

알림 조건 생성의 다음 단계를 진행하면서 각 리소스를 구성한 후 terraform apply 를 실행할 수 있습니다. 알림 정책 웹페이지를 새로고침하여 새 리소스를 확인하세요.

네 가지 황금 신호를 기반으로 경고 조건 제공

다음으로 대기 시간, 트래픽, 오류 및 포화의 네 가지 황금 신호를 기반으로 애플리케이션에 대한 경고 조건을 추가합니다. 이전 단계에서 생성한 경고 정책에 이러한 경고 조건을 적용합니다.

지연 시간

대부분의 사람들은 느린 응답 시간을 피하고 싶어합니다. 애플리케이션의 전체 응답 시간이 5분 동안 5초를 초과하면 트리거되는 newrelic_alert_condition 를 만들 수 있습니다.

# Response time
resource "newrelic_alert_condition" "response_time_web" {
policy_id = newrelic_alert_policy.golden_signal_policy.id
name = "High Response Time (Web) - ${data.newrelic_entity.example_app.name}"
type = "apm_app_metric"
entities = [data.newrelic_entity.example_app.application_id]
metric = "response_time_web"
runbook_url = "https://www.example.com"
condition_scope = "application"
term {
duration = 5
operator = "above"
priority = "critical"
threshold = "5"
time_function = "all"
}
}

이 알림 조건을 policy_id 을(를) 사용하여 이전에 구성한 알림 정책에 연결하고 있습니다.

교통

트래픽은 주어진 순간에 시스템에 얼마나 많은 수요가 있는지를 나타냅니다. 처리량은 애플리케이션으로 이동하는 트래픽 양을 측정하는 지표입니다. 애플리케이션의 전체 응답률이 5분 동안 분당 요청 5개 미만으로 떨어지면 트리거되는 newrelic_alert_condition 를 생성합니다.

# Low throughput
resource "newrelic_alert_condition" "throughput_web" {
policy_id = newrelic_alert_policy.golden_signal_policy.id
name = "Low Throughput (Web)"
type = "apm_app_metric"
entities = [data.newrelic_entity.example_app.application_id]
metric = "throughput_web"
condition_scope = "application"
# Define a critical alert threshold that will
# trigger after 5 minutes below 5 requests per minute.
term {
priority = "critical"
duration = 5
operator = "below"
threshold = "5"
time_function = "all"
}
}

이 유형의 알림은 하루 종일 트래픽 기준선이 일정할 것으로 예상되는 경우에 유용합니다. 트래픽 감소는 문제를 나타낼 수 있습니다.

오류

애플리케이션의 오류율이 급증하는 경우 이에 대해 알아야 합니다. 애플리케이션의 오류율이 5분 동안 5% 이상으로 상승하면 트리거되는 newrelic_alert_condition 를 생성합니다.

# Error percentage
resource "newrelic_alert_condition" "error_percentage" {
policy_id = newrelic_alert_policy.golden_signal_policy.id
name = "High Error Percentage"
type = "apm_app_metric"
entities = [data.newrelic_entity.example_app.application_id]
metric = "error_percentage"
runbook_url = "https://www.example.com"
condition_scope = "application"
# Define a critical alert threshold that will trigger after 5 minutes above a 5% error rate.
term {
duration = 5
operator = "above"
threshold = "5"
time_function = "all"
}
}

포화

포화도는 서비스가 "가득 찬" 정도를 나타내며 CPU 시간, 메모리 할당 또는 대기열 깊이와 같은 다양한 형태를 취할 수 있습니다. 이 예에서는 애플리케이션을 제공하는 호스트에 이미 New Relic Infrastructure 에이전트가 설치되어 있고 CPU 사용률이 특정 임계값을 초과할 때 경고를 구성하려고 한다고 가정합니다.

# High CPU usage
resource "newrelic_infra_alert_condition" "high_cpu" {
policy_id = newrelic_alert_policy.golden_signal_policy.id
name = "High CPU usage"
type = "infra_metric"
event = "SystemSample"
select = "cpuPercent"
comparison = "above"
runbook_url = "https://www.example.com"
where = "(`applicationId` = '${data.newrelic_entity.example_app.application_id}')"
# Define a critical alert threshold that will trigger after 5 minutes above 90% CPU utilization.
critical {
duration = 5
value = 90
time_function = "all"
}
}

인프라 알림의 경우 이러한 호스트의 총 CPU 사용량이 5분 동안 90% 이상으로 증가하면 트리거되는 newrelic_infra_alert_condition 를 생성했습니다.

알림이 트리거될 때 알림 받기

몇 가지 중요한 알림 조건을 구성했으므로 이제 알림 대상과 알림 채널을 알림 정책에 추가하여 알림이 트리거될 때 적절한 사용자에게 알릴 수 있습니다. 이렇게 하려면 newrelic_notification_destinationnewrelic_notification_channel 를 사용합니다.

시작하려면 이메일 알림 대상을 생성하여 특정 사람 또는 팀이 될 수 있는 수신자 목록을 구성하십시오. 이는 알림 채널을 만들 때 사용됩니다.

resource "newrelic_notification_destination" "team_email_destination" {
name = "email-example"
type = "EMAIL"
property {
key = "email"
value = "team.member1@email.com,team.member2@email.com,team.member3@email.com"
}
}

여러 이메일을 지정하려면 쉼표로 구분된 이메일 목록을 사용하십시오.

그런 다음 이메일 알림 채널 템플릿을 생성하여 경고 알림을 이메일로 보냅니다. 채널을 대상 ID와 연결합니다.

resource "newrelic_notification_channel" "team_email_channel" {
name = "email-example"
type = "EMAIL"
destination_id = newrelic_notification_destination.team_email_destination.id
product = "IINT"
property {
key = "subject"
value = "New Subject"
}
}

마지막으로 알림 채널을 알림 정책에 적용하기 위해 newrelic_workflow 를 만듭니다.

resource "newrelic_workflow" "team_workflow" {
name = "workflow-example"
enrichments_enabled = true
destinations_enabled = true
workflow_enabled = true
muting_rules_handling = "NOTIFY_ALL_ISSUES"
enrichments {
nrql {
name = "Log"
configurations {
query = "SELECT count(*) FROM Metric"
}
}
}
issues_filter {
name = "filter-example"
type = "FILTER"
predicates {
attribute = "accumulations.sources"
operator = "EXACTLY_MATCHES"
values = [ "newrelic" ]
}
}
destination_configurations {
channel_id = newrelic_notification_channel.team_email_channel.id
}
}

newrelic_workflow 는 방금 만든 알림 채널을 알림에 연결합니다.

알림 구성을 완료하려면 마지막으로 terraform apply 를 실행하여 구성된 모든 리소스가 최신 상태인지 확인합니다.

알림이 트리거될 때 알림 받기(더 이상 사용되지 않음)

중요

경고 채널은 더 이상 사용되지 않으며 향후 버전에서 지원되지 않습니다.

이제 몇 가지 중요한 경고 조건을 구성했으므로 경고가 트리거될 때 적절한 사용자에게 알림을 받을 수 있도록 경고 정책에 알림 채널을 추가합니다. 이렇게 하려면 newrelic_alert_channel 를 사용하세요.

시작하려면 전자 메일로 경고 알림을 보낼 전자 메일 알림 채널을 만듭니다. 경고가 트리거될 때 특정 사람이나 팀에 알리고 싶을 때 사용하십시오.

resource "newrelic_alert_channel" "team_email" {
name = "example"
type = "email"
config {
recipients = "yourawesometeam@example.com"
include_json_attachment = "1"
}
}

여러 recipients 를 지정하려면 쉼표로 구분된 이메일 목록을 사용하세요.

마지막으로 알림 채널을 알림 정책에 적용하기 위해 newrelic_alert_policy_channel 를 만듭니다.

resource "newrelic_alert_policy_channel" "golden_signals" {
policy_id = newrelic_alert_policy.golden_signal_policy.id
channel_ids = [newrelic_alert_channel.team_email.id]
}

newrelic_alert_policy_channel 는 방금 만든 알림 채널을 알림 정책에 연결합니다.

골든 신호 알림 구성을 완료하려면 마지막으로 terraform apply 를 실행하여 구성된 모든 리소스가 최신 상태인지 확인합니다.

추가 학점

new_relic_alert_channel 이메일, Slack 및 PagerDuty를 비롯한 여러 유형의 알림 채널을 지원합니다 . 따라서 이에 대해 자세히 알아보려면 Slack과 같은 두 번째 채널 유형에 대한 알림 채널을 생성해 보십시오.

# Slack notification channel
resource "newrelic_alert_channel" "slack_notification" {
name = "slack-example"
type = "slack"
config {
# Use the URL provided in your New Relic Slack integration
url = "https://hooks.slack.com/services/XXXXXXX/XXXXXXX/XXXXXXXXXX"
channel = "your-slack-channel-for-alerts"
}
}

이 변경을 apply 하기 전에 Slack 계정에 New Relic Slack 앱 을 추가하고 Slack 채널을 선택하여 알림을 보내야 합니다. 이 새로운 알림 채널을 사용하면 트리거된 알림이 선택한 Slack 채널로 알림을 보냅니다.

결론

팀에서 배치한 경고 시스템을 평가할 때 경고 임계값 및 기간과 같은 구성 값을 조정해야 할 수도 있습니다. 원격 리포지토리에서 Terraform 프로젝트를 관리하는 경우 풀 요청을 제출하여 팀에서 나머지 코드 기여와 함께 이러한 변경 사항을 검토할 수 있습니다.

CI/CD 파이프라인에서 이 프로세스를 자동화하는 것도 고려할 수 있습니다. Terraform의 권장 사례 가이드 를 사용하여 권장 작업 흐름과 프로비저닝 사례를 발전시키는 방법에 대해 자세히 알아보세요.

축하합니다! 당신은 공식적으로 observability-as-code를 연습하고 있습니다. New Relic Terraform 제공자 문서 를 검토하여 구성을 한 단계 끌어올리는 방법을 알아보세요.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.