Metrics Collection
Track call counts, durations, and errors per operation
Metrics Collection
Collect metrics about API calls for monitoring and assertions.
Setup
import "github.com/stackshy/cloudemu/metrics"
mc := &metrics.Collector{}
bucket := storage.NewBucket(aws.S3,
storage.WithMetrics(mc),
)Automatic Metrics
Every operation automatically records:
calls_total— counter incremented on each callcall_duration— histogram of call durationserrors_total— counter incremented on errors
All metrics include labels: service and operation.
Querying Metrics
// Get all counters
counters := mc.Query(metrics.Query{
Type: metrics.CounterType,
Name: "calls_total",
})
// Filter by labels
storagePuts := mc.Query(metrics.Query{
Type: metrics.CounterType,
Name: "calls_total",
Labels: map[string]string{"operation": "PutObject"},
})Metric Types
| Type | Description |
|---|---|
CounterType | Monotonically increasing counter |
GaugeType | Value that can go up and down |
HistogramType | Distribution of values (durations) |