
CPRAは、大規模なマイクロサービスアーキテクチャを管理するプラットフォームチーム向けに設計された高性能インフラストラクチャ監視システムです。Entity-Component-System(ECS)アーキテクチャと待ち行列理論の原理に基づき、CPRAは自動ワーカープールスケーリングによりSLO目標を達成しながら、100万以上の同時ヘルスチェックを処理します。
数百万のサービスを並行監視し、自動修復と動的ワーカースケーリングを実現します。
CPRA は、大規模なマイクロサービスアーキテクチャを管理するプラットフォームチーム向けに設計された高性能インフラストラクチャ監視システムです。Entity-Component-System(ECS)アーキテクチャと待ち行列理論の原則に基づいて構築されており、SLO 目標を達成するための自動ワーカープールスケーリングにより、100 万以上の並行ヘルスチェックを処理します。
以下のニーズがある場合は CPRA を使用してください:
詳細なベンチマークと分析については、アーキテクチャ概要 を参照してください。
CPRA は、Entity-Component-System の原則に基づいて構築された 3 パイプラインアーキテクチャを採用しています:


各パイプラインは、独自のキューと動的にスケーリングされるワーカープールを持ち、独立して動作します。これにより以下が可能になります:

キューの実装:
動的ワーカープール:
包括的なアーキテクチャの説明については、アーキテクチャ概要 を参照してください。
# Prerequisites: Go 1.25 or later
go version # Should show go1.25 or higher
# Build from source
git clone https://github.com/ziad/cpra.git
cd cpra
go build .
# Run with example configuration
./cpra --yaml mock-servers/test_10k.yaml
期待される出力:
Starting CPRA Optimized Controller for 1M Monitors
Profiling server listening at http://localhost:6060/debug/pprof/
Loading monitors from mock-servers/test_10k.yaml...
Monitor loading completed in 1.2s
[INFO] Controller started successfully
[INFO] Pulse pipeline processing 10,000 monitors
[INFO] Worker pool scaled to 143 workers (target SLO: 100ms)
リポジトリをクローン:
git clone https://github.com/ziad/cpra.git
cd cpra
依存関係をダウンロード:
go mod download
アプリケーションをビルド:
go build .
インストールを確認:
./cpra --help
Docker イメージをビルド:
docker build -f docker/Dockerfile -t cpra:latest .
コンテナを実行:
docker run -it --rm \
-v $(pwd)/my-monitors.yaml:/app/monitors.yaml \
cpra:latest \
./cpra --yaml monitors.yaml
ヘルスチェックを定義する monitors.yaml ファイルを作成します:
monitors:
- name: "my-service-health-check"
pulse_check:
type: http
interval: 30s
timeout: 5s
max_failures: 3
config:
method: GET
url: http://my-service.example.com/health
retries: 2
intervention:
action: docker
config:
container: my-service-container
action: restart
codes:
red:
dispatch: true
notify: pagerduty
config:
url: https://events.pagerduty.com/v2/enqueue
yellow:
dispatch: true
notify: log
config:
file: /var/log/cpra-alerts.log
テスト設定の生成:
mock-servers/generate_monitors.py を使用すると、任意の数のモニターを含むテスト設定を生成できます。
CPRA の動作をプログラムで設定します:
package main
import (
"cpra/internal/controller"
)
func main() {
config := controller.DefaultConfig()
// Debug mode
config.Debug = true
// Worker pool settings (applies to all three pipelines)
config.WorkerConfig.MinWorkers = 10
config.WorkerConfig.MaxWorkers = 500
// Queue settings
config.QueueCapacity = 131072 // Must be power of 2
// Performance tuning
config.BatchSize = 2000
config.SizingServiceTime = 20 * time.Millisecond // Average job duration
config.SizingSLO = 100 * time.Millisecond // Target latency
config.SizingHeadroomPct = 0.15 // 15% safety buffer
ctrl := controller.NewController(config)
// ... rest of initialization
}
完全な設定オプションについては、API リファレンス を参照してください。
./cpra [OPTIONS]
例:
# Run with debug logging
./cpra --yaml monitors.yaml --debug
# Run with custom pprof port
./cpra --yaml monitors.yaml --pprof.addr localhost:8080
# Disable profiling
./cpra --yaml monitors.yaml --pprof=false
問題: YAML ファイルが見つからない
Warning: YAML file monitors.yaml not found, starting without loading monitors
解決策: ファイルパスが正しいことを確認してください。絶対パス、またはバイナリを実行する場所からの相対パスを使用します:
./cpra --yaml $(pwd)/monitors.yaml
問題: Go バージョンエラーでビルドが失敗する
go.mod requires go >= 1.25
解決策: Go をバージョン 1.25 以降にアップグレードします:
go version # Check current version
# Download Go 1.25+ from https://go.dev/dl/
問題: メモリ使用量が多い
解決策: pprof を使用してメモリ使用量を確認します:
# While CPRA is running, access pprof
go tool pprof http://localhost:6060/debug/pprof/heap
# View top memory consumers
(pprof) top
設定でメモリの上限を調整します:
config.WorkerConfig.MaxWorkers = 200 // Reduce max workers
config.QueueCapacity = 65536 // Reduce queue size
問題: ワーカープールがスケーリングされない
解決策: デバッグログを有効にしてスケーリングの判断を確認します:
./cpra --yaml monitors.yaml --debug
待ち行列理論のパラメータを確認します:
config.SizingServiceTime = 50 * time.Millisecond // Increase if jobs take longer
config.SizingSLO = 200 * time.Millisecond // Relax SLO if needed
問題: モニターが実行されない
解決策: モニター設定の形式を確認し、ログを確認します:
./cpra --yaml monitors.yaml --debug 2>&1 | grep ERROR
YAML 構文を検証します:
# Use a YAML validator
python -m yaml monitors.yaml
--debug フラグを使用)コミュニティからのコントリビューションを歓迎します!CPRA はオープンソースプロジェクトであり、以下を歓迎します:
はじめに:
good first issue というラベルの付いたイシューを探します開発リソース:
このプロジェクトは MIT ライセンス の下で提供されています。詳細は LICENSE ファイルを参照してください。
CPRA は以下の優れたオープンソースライブラリをベースに構築されています:
| メトリクス | 値 |
|---|
| 最大並行モニター数 | 100 万以上 |
| スループット | パイプラインあたり毎秒 10,000 回以上のチェック |
| レイテンシ(P95) | 100ms 未満(SLO で設定可能) |
| モニターあたりのメモリ | 約 100 バイト |
| 総メモリ(100 万モニター時) | 約 100 MB + ワーカープールのオーバーヘッド |
| ワーカースケーリング | 動的(M/M/c ベース) |
| オプション | 型 | デフォルト | 説明 |
|---|
--yaml | string | internal/loader/replicated_test.yaml | モニター YAML ファイルへのパス |
--config | string | - | 設定ファイルのパス(オプション) |
--debug | bool | false | デバッグレベルのログを有効化 |
--pprof | bool | true | pprof プロファイリングサーバーを有効化 |
--pprof.addr | string | localhost:6060 | pprof サーバーのリッスンアドレス |