meter

package
v1.34.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

func QueryEvents

func QueryEvents(db *datastore.Datastore) datastore.Query

Types

type AggregationType

type AggregationType string

AggregationType controls how meter events are aggregated.

const (
	AggSum   AggregationType = "sum"
	AggCount AggregationType = "count"
	AggLast  AggregationType = "last"
)

type Meter

type Meter struct {
	mixin.Model

	Name            string          `json:"name"`
	EventName       string          `json:"eventName"`
	AggregationType AggregationType `json:"aggregationType"`
	Currency        currency.Type   `json:"currency"`

	// JSON-encoded list of dimension names, e.g. ["model","region"]
	Dimensions  []string `json:"dimensions,omitempty" datastore:"-"`
	Dimensions_ string   `json:"-" datastore:",noindex"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

Meter defines a named usage metric with a specific aggregation strategy. Each meter has a unique EventName per org (e.g. "input_tokens", "api_calls").

func New

func New(db *datastore.Datastore) *Meter

func (*Meter) Defaults

func (m *Meter) Defaults()

func (*Meter) Init

func (m *Meter) Init(db *datastore.Datastore)

func (Meter) Kind

func (m Meter) Kind() string

func (*Meter) Load

func (m *Meter) Load(ps []datastore.Property) (err error)

func (*Meter) Save

func (m *Meter) Save() (ps []datastore.Property, err error)

func (*Meter) Validator

func (m *Meter) Validator() *val.Validator

type MeterEvent

type MeterEvent struct {
	mixin.Model

	MeterId   string    `json:"meterId"`
	UserId    string    `json:"userId"`
	Value     int64     `json:"value"`
	Timestamp time.Time `json:"timestamp"`

	// Idempotency key for deduplication
	Idempotency string `json:"idempotency,omitempty"`

	// JSON-encoded dimension values, e.g. {"model":"gpt-4","region":"us"}
	Dimensions  Map    `json:"dimensions,omitempty" datastore:"-"`
	Dimensions_ string `json:"-" datastore:",noindex"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

MeterEvent records a single usage data point for a meter.

func NewEvent

func NewEvent(db *datastore.Datastore) *MeterEvent

func (*MeterEvent) Defaults

func (e *MeterEvent) Defaults()

func (*MeterEvent) Init

func (e *MeterEvent) Init(db *datastore.Datastore)

func (MeterEvent) Kind

func (e MeterEvent) Kind() string

func (*MeterEvent) Load

func (e *MeterEvent) Load(ps []datastore.Property) (err error)

func (*MeterEvent) Save

func (e *MeterEvent) Save() (ps []datastore.Property, err error)

func (*MeterEvent) Validator

func (e *MeterEvent) Validator() *val.Validator

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL