state

package
v0.1.8 Latest Latest
Warning

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

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

Documentation

Overview

Package state provides the persistent storage layer for the metrics.

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 CreateTableMetrics added in v0.1.6

func CreateTableMetrics(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 InsertMetric added in v0.1.6

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

func PurgeMetrics added in v0.1.6

func PurgeMetrics(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 ReadLastMetric added in v0.1.6

func ReadLastMetric(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 ReadMetricsSince added in v0.1.6

func ReadMetricsSince(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