state

package
v0.0.1-alpha Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColumnUnixSeconds         = "unix_seconds"
	ColumnMetricName          = "metric_name"
	ColumnMetricSecondaryName = "metric_secondary_name"
	ColumnMetricValue         = "metric_value"
)
View Source
const DefaultTableName = "components_metrics"

Variables

This section is empty.

Functions

func AvgSince

func AvgSince(ctx context.Context, db *sql.DB, tableName string, name string, secondaryName string, since time.Time) (float64, error)

Computes the average of the last metrics. If the since is zero, all metrics are used. Returns zero if no record is found ("database/sql.ErrNoRows").

func CreateTable

func CreateTable(ctx context.Context, db *sql.DB, tableName string) error

func EMASince

func EMASince(ctx context.Context, db *sql.DB, tableName string, name string, secondaryName string, period time.Duration, since time.Time) (float64, error)

EMASince calculates the Exponential Moving Average since a given time

func Insert

func Insert(ctx context.Context, db *sql.DB, tableName string, metric Metric) error

func Purge

func Purge(ctx context.Context, db *sql.DB, tableName string, before time.Time) (int, error)

Types

type Metric

type Metric struct {
	UnixSeconds         int64   `json:"unix_seconds"`
	MetricName          string  `json:"metric_name"`
	MetricSecondaryName string  `json:"metric_secondary_name,omitempty"`
	Value               float64 `json:"value"`
}

func ReadLast

func ReadLast(ctx context.Context, db *sql.DB, tableName string, name string, secondaryName string) (*Metric, error)

Reads the last metric. Returns nil if no record is found ("database/sql.ErrNoRows").

type Metrics

type Metrics []Metric

func ReadSince

func ReadSince(ctx context.Context, db *sql.DB, tableName string, name string, secondaryName string, since time.Time) (Metrics, error)

Returns nil if no record is found ("database/sql.ErrNoRows").

Jump to

Keyboard shortcuts

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