AgentSkillsCN

babuza-metrics

用于配置可观测性与指标采集。触发关键词: babuza 指标、Prometheus、OpenTelemetry、OTel、可观测性、监控。

SKILL.md
--- frontmatter
name: babuza-metrics
description: |
  Use for configuring observability and metrics collection. Triggers on:
  babuza metrics, prometheus, opentelemetry, otel, observability, monitoring

Babuza Metrics Skill

Package: github.com/fanaujie/babuza/pkg/metrics

Observability and metrics collection for Babuza clusters.

You are an expert at babuza observability. Help users by:

  • Writing code: Configure Prometheus or OpenTelemetry metrics exporters.
  • Answering questions: Explain available metrics and monitoring best practices.

Documentation

Refer to the local files for detailed API:

  • ./references/metrics-api.md - Metrics types and configuration options.

Key Patterns

1. Configuring Metrics via Builder

Select the metrics backend using BabuzaComponentBuilder.

go
import "github.com/fanaujie/babuza/pkg/builder"

func buildWithMetrics() *ibabuza.BabuzaComponent {
    return builder.NewBabuzaComponentBuilder(&builder.BabuzaComponentConfig{
        // Select Metrics Type: MetricsPrometheus or MetricsOtel
        MetricsType: builder.MetricsPrometheus,
    }).Build()
}

2. Prometheus Configuration

Expose metrics endpoint for Prometheus scraping.

go
import (
    "net/http"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)

func startMetricsServer() {
    http.Handle("/metrics", promhttp.Handler())
    http.ListenAndServe(":9090", nil)
}

3. OpenTelemetry Configuration

Configure OTLP exporter for OpenTelemetry collectors.

go
import "github.com/fanaujie/babuza/pkg/builder"

func buildWithOtel() *ibabuza.BabuzaComponent {
    return builder.NewBabuzaComponentBuilder(&builder.BabuzaComponentConfig{
        MetricsType: builder.MetricsOtel,
    }).SetOtelConfig(&builder.OtelConfig{
        Endpoint: "localhost:4317",
        Insecure: true,
    }).Build()
}

Metrics Types

TypeBuilder ConstantDescription
Prometheusbuilder.MetricsPrometheusExpose metrics via HTTP endpoint for Prometheus scraping.
OpenTelemetrybuilder.MetricsOtelPush metrics to OTLP collector (Jaeger, Grafana, etc.).

When to Use Each Type

ScenarioRecommended Type
Existing Prometheus infrastructurePrometheus
Cloud-native / KubernetesOpenTelemetry
Distributed tracing integrationOpenTelemetry
Simple setupPrometheus

When Answering Questions

  1. Prometheus: Explain that metrics are exposed at /metrics endpoint and require a Prometheus server to scrape.
  2. OpenTelemetry: Explain that OTLP pushes metrics to a collector, which can then export to various backends.
  3. Key Metrics: Highlight important Raft metrics like leader election count, proposal latency, and log entry count.