heartbeat

package
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Monitor

type Monitor struct {
	ID        string        `json:"id,omitempty"`
	Name      string        `json:"name,omitempty"`
	ServiceID string        `json:"service_id,omitempty"`
	Timeout   time.Duration `json:"timeout,omitempty"`
	// contains filtered or unexported fields
}

A Monitor will generate an alert if it does not receive a heartbeat within the configured TimeoutMinutes.

func (Monitor) LastHeartbeat added in v0.24.0

func (m Monitor) LastHeartbeat() time.Time

LastHeartbeat returns the timestamp of the last successful heartbeat.

func (Monitor) LastState

func (m Monitor) LastState() State

LastState returns the last known state.

func (Monitor) Normalize

func (m Monitor) Normalize() (*Monitor, error)

Normalize performs validation and returns a new copy.

type State

type State string

State represents the health of a heartbeat monitor.

const (
	// StateInactive means the heartbeat has not yet reported for the first time.
	StateInactive State = "inactive"

	// StateHealthy indicates a heartbeat was received within the past interval.
	StateHealthy State = "healthy"

	// StateUnhealthy indicates a heartbeat has not been received since beyond the interval.
	StateUnhealthy State = "unhealthy"
)

func (*State) Scan

func (r *State) Scan(value interface{}) error

Scan handles reading State from the DB format

type Store

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

Store manages heartbeat checks and recording heartbeats.

func NewStore added in v0.28.0

func NewStore(ctx context.Context, db *sql.DB) (*Store, error)

NewStore creates a new Store and prepares all sql statements.

func (*Store) CreateTx

func (s *Store) CreateTx(ctx context.Context, tx *sql.Tx, m *Monitor) (*Monitor, error)

CreateTx creates a new heartbeat Monitor.

func (*Store) DeleteTx

func (s *Store) DeleteTx(ctx context.Context, tx *sql.Tx, ids ...string) error

DeleteTx deletes the heartbeat check with the given ID(s).

func (*Store) FindAllByService

func (s *Store) FindAllByService(ctx context.Context, serviceID string) ([]Monitor, error)

FindAllByService returns all heartbeats belonging to the given service ID.

func (*Store) FindMany added in v0.24.0

func (s *Store) FindMany(ctx context.Context, ids []string) ([]Monitor, error)

FindMany returns the heartbeat monitors with the given IDs.

The order and number of returned monitors is not guaranteed.

func (*Store) FindOneTx added in v0.24.0

func (s *Store) FindOneTx(ctx context.Context, tx *sql.Tx, id string) (*Monitor, error)

FindOneTx returns a heartbeat montior for updating.

func (*Store) RecordHeartbeat added in v0.28.0

func (s *Store) RecordHeartbeat(ctx context.Context, id string) error

RecordHeartbeat records a heartbeat for the given heartbeat ID.

func (*Store) UpdateTx added in v0.24.0

func (s *Store) UpdateTx(ctx context.Context, tx *sql.Tx, m *Monitor) error

UpdateTx updates a heartbeat Monitor.

Jump to

Keyboard shortcuts

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