heartbeat

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2019 License: Apache-2.0 Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB implements Store using Postgres as a backend.

func NewDB

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

func (*DB) CreateTx

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

func (*DB) DeleteTx

func (db *DB) DeleteTx(ctx context.Context, tx *sql.Tx, id string) error

func (*DB) FindAllByService

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

func (*DB) Heartbeat

func (db *DB) Heartbeat(ctx context.Context, id string) error

func (*DB) Update

func (db *DB) Update(ctx context.Context, m *Monitor) error

type Monitor

type Monitor struct {
	ID              string `json:"id,omitempty"`
	Name            string `json:"name,omitempty"`
	ServiceID       string `json:"service_id,omitempty"`
	IntervalMinutes int    `json:"interval_minutes,omitempty"`
	// contains filtered or unexported fields
}

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

func (Monitor) LastHeartbeatMinutes

func (m Monitor) LastHeartbeatMinutes() (int, bool)

LastHeartbeatMinutes returns the minutes since the heartbeat last reported. The interval is truncated, so a value of 0 means "less than 1 minute".

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 interface {
	// Heartbeat records a heartbeat for the given heartbeat ID.
	Heartbeat(context.Context, string) error

	// CreateTx creates a new heartbeat check within the transaction.
	CreateTx(context.Context, *sql.Tx, *Monitor) (*Monitor, error)

	// Delete deletes the heartbeat check with the given heartbeat ID.
	DeleteTx(context.Context, *sql.Tx, string) error

	// FindAllByService returns all heartbeats belonging to the given service ID.
	FindAllByService(context.Context, string) ([]Monitor, error)
}

Store manages heartbeat checks and recording heartbeats.

Jump to

Keyboard shortcuts

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