Babuza Metrics Skill
Package:
github.com/fanaujie/babuza/pkg/metricsObservability 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
| Type | Builder Constant | Description |
|---|---|---|
| Prometheus | builder.MetricsPrometheus | Expose metrics via HTTP endpoint for Prometheus scraping. |
| OpenTelemetry | builder.MetricsOtel | Push metrics to OTLP collector (Jaeger, Grafana, etc.). |
When to Use Each Type
| Scenario | Recommended Type |
|---|---|
| Existing Prometheus infrastructure | Prometheus |
| Cloud-native / Kubernetes | OpenTelemetry |
| Distributed tracing integration | OpenTelemetry |
| Simple setup | Prometheus |
When Answering Questions
- •Prometheus: Explain that metrics are exposed at
/metricsendpoint and require a Prometheus server to scrape. - •OpenTelemetry: Explain that OTLP pushes metrics to a collector, which can then export to various backends.
- •Key Metrics: Highlight important Raft metrics like leader election count, proposal latency, and log entry count.