0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【GCP × New Relic】Cloud Runを可視化・監視するベストプラクティス

Posted at

📚 目的

  • Cloud Runはサーバレスながらアプリを導入しやすいが、観測性に難がある
  • Google Cloud Monitoring に加えて New Relic を使うことで APM とログを統合的に可視化

🖥️ 全体構成図

+---------------------------+
|       Cloud Run          |
|  (GCP Serverless App)    |
+---------------------------+
          |
          |  Export Logs / Metrics
          v
+---------------------------+
| Google Cloud Logging      |
+---------------------------+
          |
          | via Log Export (Pub/Sub)
          v
+---------------------------+
| New Relic Infrastructure |
| (Logs / Metrics Ingest)  |
+---------------------------+

⚙️ Cloud Run 監視のポイント

1. パフォーマンス

項目 説明
request_latencies レイテンシ分布 (P95/最大値)。遅延を検知
request_count リクエスト数。急増急減を検知
container_start_count コールドスタートの発生回数

2. エラー系

項目 説明
HTTP 5xx率 response_code_class = 5xx の割合
タイムアウト回数 出力時間超過の検知
クラッシュ回数 アプリ内クラッシュが原因

3. リソース

項目 説明
cpu_utilization CPU利用率
memory_utilization メモリ使用量
instance_count スケール状況を可視化

4. コスト

項目 説明
リクエスト数 x 処理時間 コストへの直等関係指標
非活性インスタンスの時間 無駄な空走を検出

5. セキュリティ

項目 説明
IAM/デプロイログ Audit Logs で確認
不正IPからのアクセス 地域情報ベースで検知

⚙️ New Relic 連携手順

1. GCP のログを New Relic に連携

  • Google Cloud Logging のログルーターで、Pub/Sub 経由でログを送信
  • New Relic 側に GCP Integration を設定
  • Terraform や UI で Service Account / Role / Subscription を設定

2. Cloud Run のログ出力

  • 構造化ログ (structured logging) を使用
{
  "severity": "ERROR",
  "message": "外部APIタイムアウト",
  "labels": {
    "request_id": "abc-123"
  }
}

3. New Relic ダッシュボード

  • NRQL を使って Cloud Run の表示
NRQL例 説明
SELECT average(duration) FROM Transaction レイテンシ可視化
SELECT count(*) FROM Transaction WHERE http.statusCode LIKE '5%' 5xx検出
SELECT rate(http.server.request.count, 1 minute) リクエスト速度

🚧 よくあるトラブル

問題 対処
ログが届かない Pub/Sub サブスクの設定ミス
メトリクスが表示されない 監視設定、Cloud Run API 権限を確認
エラーログの抽出できず structured logging を設計

✅ まとめ

  • New Relic による Cloud Run 監視は観測性を大きく向上
  • GCPのログ・メトリクスを一元管理
  • Terraformやインフラコードと組み合わせて DevOps に組み込める

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?