Documentation
¶
Index ¶
Constants ¶
const SampleSeconds = 60
SampleSeconds is how long one usage_events sample row represents.
Variables ¶
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.
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 ¶
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