prometheus-configuration について
Prometheusのメトリクス収集、アラート、監視を設定するためのスキルです。スクレイプ先の検出や記録ルール、検証を扱い、一部の参照ファイルが含まれないことも示します。
主な機能
- 01スクレイプ対象の設定
- 02ファイルとKubernetesの検出
- 03記録ルールとアラートルール
- 04設定とルールの検証
活用シーン
- 01インフラ監視の導入
- 02アプリのメトリクス収集設定
- 03クエリ向け記録ルールの作成
- 04Prometheus設定とルールの確認
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ sickn33/ agentic-awesome-skills --skill prometheus-configurationインストール後、Claude Code で/prometheus-configurationを入力して読み込まれたか確認します。
詳細
補足資料の入手可能性
このカタログのコピーには以下のインラインガイダンスが含まれていますが、次の補足パスは含まれていません。これらは同梱ファイルではなく、外部の前提資料です。
<support-root>/assets/prometheus.yml.template<support-root>/references/scrape-configs.md<support-root>/references/recording-rules.md<support-root>/scripts/validate-prometheus.sh
これらのパスに依存する手順を実行する前に、元の補足資料または既存のインストール環境を用意してください。このカタログでは、確認済みのダウンロード元を特定していません。各パスをそのインストール環境を基準に解決して内容を確認し、該当するライセンスと実行上の前提条件を検証してください。必要なファイルが存在することを確認するまでは、コマンドを実行したり、参照先の手順を実施したと主張したりしないでください。不足しているスクリプトを捏造したり、同名の無関係なファイルを同等のものとして扱ったりしないでください。ここに完全に記載されている独立した手順は、ユーザーが承認した範囲内で実施できます。依存する手順については、利用できないことを報告してください。
Prometheus の設定
Prometheus のセットアップ、メトリクス収集、スクレイプ設定、レコーディングルールに関する包括的なガイドです。
このスキルを使用しない場合
- タスクが Prometheus の設定に関係しない場合
- この範囲外の別ドメインやツールが必要な場合
指示
- 目標、制約、必要な入力を明確にします。
- 関連するベストプラクティスを適用し、結果を検証します。
- 実行可能な手順と検証方法を提示します。
目的
Prometheus を設定し、インフラストラクチャとアプリケーションの包括的なメトリクス収集、アラート、監視を実現します。
このスキルを使用する場面
- Prometheus の監視をセットアップする
- メトリクスのスクレイピングを設定する
- レコーディングルールを作成する
- アラートルールを設計する
- サービスディスカバリーを実装する
Prometheus アーキテクチャ
┌──────────────┐
│ Applications │ ← Instrumented with client libraries
└──────┬───────┘
│ /metrics endpoint
↓
┌──────────────┐
│ Prometheus │ ← Scrapes metrics periodically
│ Server │
└──────┬───────┘
│
├─→ AlertManager (alerts)
├─→ Grafana (visualization)
└─→ Long-term storage (Thanos/Cortex)
インストール前に、チャート/イメージのバージョンと値を固定し、内容を確認してください。Helm の PVC フラグメントには適切な StorageClass と容量も必要です。レンダリング済みマニフェストを検証してください。Compose の例には、完全な設定で参照されている Alertmanager、エクスポーター、Kubernetes API の認証情報/RBAC、TLS ファイル、ルールのマウントがありません。これらを明示的に用意するか、未使用のジョブを削除してください。監視 API は非公開にし、ラベルや設定レスポンスからテナントデータやシークレットが漏えいしないよう保護してください。メトリクスのラベルカーディナリティに上限を設け、ルールを promtool で検証してください。しきい値は例示であり、普遍的な SLO ではありません。エラー系列が存在しない場合は、意図的なゼロ埋め戦略が必要になることがあります。また、トラフィックがゼロの場合に健全なパーセンテージであると仮定してはなりません。
インストール
Helm を使用した Kubernetes
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install prometheus prometheus-community/kube-prometheus-stack \
--namespace monitoring \
--create-namespace \
--set prometheus.prometheusSpec.retention=30d \
--set prometheus.prometheusSpec.storageSpec.volumeClaimTemplate.spec.accessModes[0]=ReadWriteOnce \
--set prometheus.prometheusSpec.storageSpec.volumeClaimTemplate.spec.resources.requests.storage=50Gi
Docker Compose
version: '3.8'
services:
prometheus:
image: prom/prometheus:latest
ports:
- "127.0.0.1:9090:9090"
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
- prometheus-data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=30d'
volumes:
prometheus-data:
設定ファイル
prometheus.yml:
global:
scrape_interval: 15s
evaluation_interval: 15s
external_labels:
cluster: 'production'
region: 'us-west-2'
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
# Load rules files
rule_files:
- /etc/prometheus/rules/*.yml
# Scrape configurations
scrape_configs:
# Prometheus itself
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
# Node exporters
- job_name: 'node-exporter'
static_configs:
- targets:
- 'node1:9100'
- 'node2:9100'
- 'node3:9100'
relabel_configs:
- source_labels: [__address__]
target_label: instance
regex: '([^:]+)(:[0-9]+)?'
replacement: '${1}'
# Kubernetes pods with annotations
- job_name: 'kubernetes-pods'
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape]
action: keep
regex: "true"
- source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
- source_labels: [__address__, __meta_kubernetes_pod_annotation_prometheus_io_port]
action: replace
regex: ([^:]+)(?::\d+)?;(\d+)
replacement: $1:$2
target_label: __address__
- source_labels: [__meta_kubernetes_namespace]
action: replace
target_label: namespace
- source_labels: [__meta_kubernetes_pod_name]
action: replace
target_label: pod
# Application metrics
- job_name: 'my-app'
static_configs:
- targets:
- 'app1.example.com:9090'
- 'app2.example.com:9090'
metrics_path: '/metrics'
scheme: 'https'
tls_config:
ca_file: /etc/prometheus/ca.crt
cert_file: /etc/prometheus/client.crt
key_file: /etc/prometheus/client.key
参考: assets/prometheus.yml.template を参照してください。
スクレイプ設定
静的ターゲット
scrape_configs:
- job_name: 'static-targets'
static_configs:
- targets: ['host1:9100', 'host2:9100']
labels:
env: 'production'
region: 'us-west-2'
ファイルベースのサービスディスカバリー
scrape_configs:
- job_name: 'file-sd'
file_sd_configs:
- files:
- /etc/prometheus/targets/*.json
- /etc/prometheus/targets/*.yml
refresh_interval: 5m
targets/production.json:
[
{
"targets": ["app1:9090", "app2:9090"],
"labels": {
"env": "production",
"service": "api"
}
}
]
Kubernetes サービスディスカバリー
scrape_configs:
- job_name: 'kubernetes-services'
kubernetes_sd_configs:
- role: service
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
action: keep
regex: "true"
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
action: replace
target_label: __scheme__
regex: (https?)
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
action: replace
target_label: __metrics_path__
regex: (.+)
参考: references/scrape-configs.md を参照してください。
レコーディングルール
頻繁にクエリされる式の事前計算済みメトリクスを作成します。
# /etc/prometheus/rules/recording_rules.yml
groups:
- name: api_metrics
interval: 15s
rules:
# HTTP request rate per service
- record: job:http_requests:rate5m
expr: sum by (job) (rate(http_requests_total[5m]))
# Error rate percentage
- record: job:http_requests_errors:rate5m
expr: sum by (job) (rate(http_requests_total{status=~"5.."}[5m]))
- record: job:http_requests_error_rate:percentage
expr: |
(job:http_requests_errors:rate5m / job:http_requests:rate5m) * 100
# P95 latency
- record: job:http_request_duration:p95
expr: |
histogram_quantile(0.95,
sum by (job, le) (rate(http_request_duration_seconds_bucket[5m]))
)
- name: resource_metrics
interval: 30s
rules:
# CPU utilization percentage
- record: instance:node_cpu:utilization
expr: |
100 - (avg by (instance) (rate(node_cpu_seconds_total{mode="idle"}[5m])) * 100)
# Memory utilization percentage
- record: instance:node_memory:utilization
expr: |
100 - ((node_memory_MemAvailable_bytes / node_memory_MemTotal_bytes) * 100)
# Disk usage percentage
- record: instance:node_disk:utilization
expr: |
100 - ((node_filesystem_avail_bytes / node_filesystem_size_bytes) * 100)
参考: references/recording-rules.md を参照してください。
アラートルール
# /etc/prometheus/rules/alert_rules.yml
groups:
- name: availability
interval: 30s
rules:
- alert: ServiceDown
expr: up{job="my-app"} == 0
for: 1m
labels:
severity: critical
annotations:
summary: "Service {{ $labels.instance }} is down"
description: "{{ $labels.job }} has been down for more than 1 minute"
- alert: HighErrorRate
expr: job:http_requests_error_rate:percentage > 5
for: 5m
labels:
severity: warning
annotations:
summary: "High error rate for {{ $labels.job }}"
description: "Error rate is {{ $value }}% (threshold: 5%)"
- alert: HighLatency
expr: job:http_request_duration:p95 > 1
for: 5m
labels:
severity: warning
annotations:
summary: "High latency for {{ $labels.job }}"
description: "P95 latency is {{ $value }}s (threshold: 1s)"
- name: resources
interval: 1m
rules:
- alert: HighCPUUsage
expr: instance:node_cpu:utilization > 80
for: 5m
labels:
severity: warning
annotations:
summary: "High CPU usage on {{ $labels.instance }}"
description: "CPU usage is {{ $value }}%"
- alert: HighMemoryUsage
expr: instance:node_memory:utilization > 85
for: 5m
labels:
severity: warning
annotations:
summary: "High memory usage on {{ $labels.instance }}"
description: "Memory usage is {{ $value }}%"
- alert: DiskSpaceLow
expr: instance:node_disk:utilization > 90
for: 5m
labels:
severity: critical
annotations:
summary: "Low disk space on {{ $labels.instance }}"
description: "Disk usage is {{ $value }}%"
検証
# Validate configuration
promtool check config prometheus.yml
# Validate rules
promtool check rules /etc/prometheus/rules/*.yml
# Test query
promtool query instant http://localhost:9090 'up'
参考: scripts/validate-prometheus.sh を参照してください。
ベストプラクティス
- 一貫した命名規則を使用する(prefix_name_unit)
- 適切なスクレイプ間隔を設定する(通常は 15~60 秒)
- 負荷の高いクエリにはレコーディングルールを使用する
- 高可用性を実装する(複数の Prometheus インスタンス)
- ストレージ容量に応じて保持期間を設定する
- メトリクスの整理に再ラベリングを使用する
- Prometheus 自体を監視する
- 大規模なデプロイではフェデレーションを実装する
- 長期保存には Thanos/Cortex を使用する
- カスタムメトリクスを文書化する
トラブルシューティング
スクレイプターゲットを確認する:
curl http://localhost:9090/api/v1/targets
設定を確認する:
curl http://localhost:9090/api/v1/status/config
クエリをテストする:
curl 'http://localhost:9090/api/v1/query?query=up'
参考ファイル
assets/prometheus.yml.template- 設定テンプレート全体references/scrape-configs.md- スクレイプ設定のパターンreferences/recording-rules.md- 記録ルールの例scripts/validate-prometheus.sh- 検証スクリプト
関連スキル
grafana-dashboards- 可視化用slo-implementation- SLO 監視用distributed-tracing- リクエストトレーシング用
制限事項
- 上記で説明されている範囲にタスクが明確に当てはまる場合にのみ、このスキルを使用してください。
- 出力を、環境固有の検証、テスト、専門家によるレビューの代替として扱わないでください。
- 必要な入力、権限、安全上の境界、または成功基準が不足している場合は、作業を中断して確認を求めてください。