cloudemu

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 call
  • call_duration — histogram of call durations
  • errors_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

TypeDescription
CounterTypeMonotonically increasing counter
GaugeTypeValue that can go up and down
HistogramTypeDistribution of values (durations)

On this page