Google Cloud Monitoring 데이터 소스 구성

Google Cloud Monitoring 데이터 소스 구성 (Configure the Google Cloud Monitoring data source)

이 문서는 Grafana에서 Google Cloud Monitoring 데이터 소스를 구성하는 방법을 설명해요. Grafana는 Grafana OSS와 Enterprise 모두에 Google Cloud Monitoring 데이터 소스를 미리 설치해 제공하므로 설치할 것이 없어요.

출처: 문서

본문

GCP 인증 설정

Google Cloud Monitoring에서 데이터를 요청하기 전에 인증을 구성해야 해요. Google API에 대한 모든 요청은 Grafana 백엔드가 서버 측에서 수행해요. 인증 옵션과 구성 세부 사항은 "Google 인증" 문서를 참고하세요.

GCP 서비스 계정 구성

GCP 서비스 계정과 키 파일을 만들 때 서비스 계정에 Monitoring Viewer 역할(Role > Select a role > Monitoring > Monitoring Viewer)을 부여해야 해요.

GCE 기본 서비스 계정 스코프 부여

Grafana가 Google Compute Engine(GCE) 가상 머신에서 실행 중이면, GCE Default Service Account를 구성할 때 그 서비스 계정에 "Cloud Monitoring API" 스코프에 대한 접근 권한도 부여해야 해요.

Google Cloud Platform API 활성화

Google Cloud Monitoring에서 데이터를 요청하기 전에 GCP 프로젝트에서 필요한 API를 활성화해야 해요: Cloud Monitoring API와 (SLO 사용 시) Service Management API.

데이터 소스 추가

Connections > Data sources에서 Add data source를 클릭하고 Google Cloud Monitoring을 선택하면 Settings 탭으로 이동해 데이터 소스를 구성해요.

UI에서 데이터 소스 구성

설정 설명
Name 패널과 쿼리에서 데이터 소스를 참조하는 이름 설정
Default 새 패널에서 데이터 소스가 미리 선택되는지 설정
Universe Domain 연결할 universe domain. 기본값은 googleapis.com

인증 (Authentication)

설정 설명
Authentication type 인증 방법 선택: 서비스 계정 키 파일은 Google JWT File, GCE VM에서 Grafana를 실행하면 GCE Default Service Account, Google에 로그인한 Grafana 사용자로 인증은 Forward OAuth Identity, 외부 OIDC ID 프로바이더로 인증은 Workload Identity Federation(Grafana Cloud 전용)
Google JWT File 인증 구성
설정 설명
JWT token Google JWT 토큰 업로드/붙여넣기. .json 키 파일을 드래그&드롭하거나, Click to browse files로 업로드하거나, Paste JWT Token / Fill In JWT Token manually 사용
Forward OAuth Identity 구성
설정 설명
Default project 쿼리할 GCP 프로젝트 ID 입력. 사용자의 OAuth 토큰이 프로젝트 컨텍스트를 담지 않으므로 이 필드는 필수. 로그인한 사용자가 이 프로젝트에 Monitoring Viewer 역할을 가져야 함

전달된 토큰이 Cloud Monitoring 데이터를 읽을 수 있도록 Grafana Google 인증이 다음 스코프를 요청해야 해요. grafana.ini 또는 custom.ini[auth.google] 아래, 또는 SSO Settings UI의 Scopes에 전체 목록을 설정하세요:

[auth.google]
scopes = openid email profile https://www.googleapis.com/auth/monitoring.read

스코프를 변경한 뒤 각 사용자는 로그아웃하고, https://myaccount.google.com/permissions 에서 기존 승인을 취소한 후 다시 로그인해야 해요. Google은 승인이 취소될 때까지 이전 동의를 재사용하므로 기존 세션은 이전 스코프 집합으로 발급된 토큰을 계속 보유해요.

Workload Identity Federation 구성

Grafana Cloud에서만 사용할 수 있어요. 외부 OIDC ID 프로바이더(예: Okta)를 통해 인증해 각 쿼리를 로그인한 사용자로 실행할 수 있게 해주는 방법이에요.

설정 설명
Workload Identity Pool Provider 프로바이더의 전체 리소스 경로 입력: projects/<project-number>/locations/global/workloadIdentityPools/<pool-id>/providers/<provider-id>. 프로젝트 ID가 아니라 프로젝트 번호 사용
Service account email (선택) 가장(impersonate)할 서비스 계정 입력. Monitoring Viewer 역할을 Workload Identity 풀 주체에 직접 부여했다면 비워 둠
Default project Cloud Monitoring 쿼리가 실행되는 GCP 프로젝트 ID 입력

참고: Workload Identity Federation의 자격 증명은 로그인한 사용자 세션에 묶이므로, 사용자가 없는 상태에서 실행되는 기능(알림, 예약 보고서, 공개 대시보드)은 동작하지 않아요. 이런 기능에 의존한다면 서비스 계정 키(Google JWT File)를 대신 사용하세요.

서비스 계정 가장 (Service account impersonation)

JWT 토큰에 제공된 것과 다른 서비스 계정으로 Grafana가 인증하게 하려면 서비스 계정 가장을 사용해요. Enable 토글을 켜고, Google Cloud 요청 시 가장할 서비스 계정의 이메일을 입력하세요.

Private data source connect (Grafana Cloud 전용)

PDC를 사용해 Grafana Cloud에서의 인바운드 트래픽에 네트워크를 열지 않고 보안 네트워크 내의 데이터에 연결·쿼리할 수 있어요. 드롭다운에서 PDC 연결을 선택하거나 새 연결을 만들 수 있어요.

저장 및 테스트

Save & test를 클릭해 연결을 테스트하세요. 성공하면 다음 메시지가 표시돼요:

Successfully queried the Google Cloud Monitoring API.

데이터 소스 프로비저닝

YAML 구성 파일로 데이터 소스를 정의·구성할 수 있어요.

JWT(서비스 계정 키 파일) 인증 유형 사용:

apiVersion: 1

datasources:
  - name: Google Cloud Monitoring
    type: stackdriver
    access: proxy
    jsonData:
      tokenUri: https://oauth2.googleapis.com/token
      clientEmail: [email protected]
      authenticationType: jwt
      defaultProject: my-project-name
      universeDomain: googleapis.com
    secureJsonData:
      privateKey: |
        [REDACTED PRIVATE KEY]

JWT(서비스 계정 프라이빗 키 경로) 인증 유형 사용:

apiVersion: 1

datasources:
  - name: Google Cloud Monitoring
    type: stackdriver
    access: proxy
    jsonData:
      tokenUri: https://oauth2.googleapis.com/token
      clientEmail: [email protected]
      authenticationType: jwt
      defaultProject: my-project-name
      universeDomain: googleapis.com
      privateKeyPath: /etc/secrets/gce.pem

GCE Default Service Account 인증 사용:

apiVersion: 1

datasources:
  - name: Google Cloud Monitoring
    type: stackdriver
    access: proxy
    jsonData:
      authenticationType: gce
      universeDomain: googleapis.com

Terraform으로 프로비저닝

Grafana Terraform 프로바이더를 사용해 프로비저닝할 수 있어요. 프로바이더 구성 예시:

terraform {
  required_providers {
    grafana = {
      source  = "grafana/grafana"
      version = ">= 2.0.0"
    }
  }
}

# For Grafana Cloud
provider "grafana" {
  url  = "<YOUR_GRAFANA_CLOUD_STACK_URL>"
  auth = "<YOUR_SERVICE_ACCOUNT_TOKEN>"
}

# For self-managed Grafana
# provider "grafana" {
#   url  = "http://localhost:3000"
#   auth = "<API_KEY_OR_SERVICE_ACCOUNT_TOKEN>"
# }

JWT(서비스 계정 키 파일) 인증 유형 사용:

resource "grafana_data_source" "google_cloud_monitoring" {
  type = "stackdriver"
  name = "Google Cloud Monitoring"

  json_data_encoded = jsonencode({
    tokenUri           = "https://oauth2.googleapis.com/token"
    clientEmail        = "<SERVICE_ACCOUNT_EMAIL>"
    authenticationType = "jwt"
    defaultProject     = "<GCP_PROJECT_ID>"
    universeDomain     = "googleapis.com"
  })

  secure_json_data_encoded = jsonencode({
    privateKey = "<PRIVATE_KEY_CONTENT>"
  })
}

JWT(서비스 계정 프라이빗 키 경로) 인증 유형 사용:

resource "grafana_data_source" "google_cloud_monitoring" {
  type = "stackdriver"
  name = "Google Cloud Monitoring"

  json_data_encoded = jsonencode({
    tokenUri           = "https://oauth2.googleapis.com/token"
    clientEmail        = "<SERVICE_ACCOUNT_EMAIL>"
    authenticationType = "jwt"
    defaultProject     = "<GCP_PROJECT_ID>"
    universeDomain     = "googleapis.com"
    privateKeyPath     = "/etc/secrets/gce.pem"
  })
}

GCE Default Service Account 인증 사용:

resource "grafana_data_source" "google_cloud_monitoring" {
  type = "stackdriver"
  name = "Google Cloud Monitoring"

  json_data_encoded = jsonencode({
    authenticationType = "gce"
    universeDomain     = "googleapis.com"
  })
}

다음 단계

데이터 소스를 구성한 뒤에는 쿼리 에디터로 메트릭을 쿼리하고, 템플릿 변수·애노테이션을 사용할 수 있어요.

더 알아보기 (Learn more)