metering

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SampleSeconds = 60

SampleSeconds is how long one usage_events sample row represents.

Variables

View Source
var ValidPeriods = map[string]bool{
	"hourly": true,
	"daily":  true,
}

ValidPeriods are the allowed aggregation periods.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector samples CPU and memory of running service containers every SampleSeconds and records them in usage_events and usage_daily.

func NewCollector

func NewCollector(state, meter *sql.DB, d docker.Client) *Collector

func (*Collector) Run

func (c *Collector) Run(ctx context.Context)

Run collects until ctx is cancelled.

func (*Collector) Tick

func (c *Collector) Tick(ctx context.Context)

Tick records one sample for every running service. A failure for one container is logged and does not affect the others.

type Metric

type Metric struct {
	Timestamp      string  `json:"timestamp"`
	CPUSeconds     float64 `json:"cpu_seconds"`
	MemoryMBAvg    float64 `json:"memory_mb_avg"`
	NetworkRxBytes int64   `json:"network_rx_bytes"`
	NetworkTxBytes int64   `json:"network_tx_bytes"`
	ServiceID      string  `json:"service_id,omitempty"`
}

Metric represents an aggregated resource usage data point.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store wraps the metering SQLite database connection to provide resource usage query methods.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore creates a metering store from an existing *sql.DB connection (the metering database, not the state database).

func (*Store) QueryServiceMetrics

func (s *Store) QueryServiceMetrics(tenantID, serviceID, period string, since, until time.Time) ([]Metric, error)

QueryServiceMetrics returns aggregated usage metrics for a specific service owned by the given tenant. This is a convenience wrapper that enforces tenant isolation at the query level.

func (*Store) QueryTenantMetrics

func (s *Store) QueryTenantMetrics(tenantID, period string, since, until time.Time, serviceID string) ([]Metric, error)

QueryTenantMetrics returns aggregated usage metrics for a tenant across all or a specific service. Results are grouped by the requested period.

Parameters:

  • tenantID: required, always filters by tenant
  • period: "hourly" or "daily"
  • since, until: time range (inclusive)
  • serviceID: optional, filters to a single service when non-empty

Jump to

Keyboard shortcuts

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