deer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2020 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check interface {
	Validatable

	RunFn(s *Store) func()
	Check(resp *Response) bool
}

Check is a interface for monitoring checks.

type CheckResult

type CheckResult struct {
	MonitorID  string
	ServiceID  string
	At         time.Time
	Success    bool
	Trace      *Trace
	Error      error
	StatusCode int
}

CheckResult is a struct.

type Config

type Config struct {
	Server   *Server    `hcl:"server,block"`
	Monitors []*Monitor `hcl:"monitor,block"`
}

Config keeps monitor configuration.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads and parses config from given path.

func ParseConfig

func ParseConfig(path string, src []byte) (*Config, error)

ParseConfig parses config from given data.

func (*Config) ActiveServices

func (c *Config) ActiveServices() map[string][]string

ActiveServices returns list of active services per monitor.

func (*Config) IsTLSConfigured added in v0.1.5

func (c *Config) IsTLSConfigured() bool

IsTLSConfigured returns true if config for TLS is valid.

type Details

type Details struct {
	Trace    *Trace           `json:"trace"`
	Error    *ErrorDetails    `json:"error,omitempty"`
	Response *ResponseDetails `json:"response,omitempty"`
}

Details for checks.

type ErrorDetails added in v0.1.5

type ErrorDetails struct {
	Message string `json:"message"`
}

ErrorDetails contains response error.

type Expect

type Expect struct {
	// label
	Subject string `hcl:"subject,label"`
	// body
	Inclusion []int `hcl:"in"`
}

Expect defines service assertion.

type HTTPCheck

type HTTPCheck struct {

	// body
	IntervalSec  uint64   `hcl:"interval"`
	TimeoutSec   uint64   `hcl:"timeout"`
	Addr         string   `hcl:"addr"`
	Expectations []Expect `hcl:"expect,block"`
	// contains filtered or unexported fields
}

HTTPCheck defines http type check.

func (*HTTPCheck) Check

func (h *HTTPCheck) Check(resp *Response) bool

Check verifies if check is valid or not.

func (*HTTPCheck) RunFn

func (h *HTTPCheck) RunFn(s Store) func()

RunFn returns task function to run check.

func (*HTTPCheck) Validate

func (h *HTTPCheck) Validate() error

Validate ensures correct values are set for http check.

type Metric

type Metric struct {
	MonitorID    string    `json:"monitor_id"`
	ServiceID    string    `json:"service_id"`
	Bucket       time.Time `json:"bucket"`
	Health       float64   `json:"health"`
	Details      Details   `json:"details"`
	PassedChecks uint64    `json:"passed_checks"`
	FailedChecks uint64    `json:"failed_checks"`
}

Metric represents metric for given time bucket.

type Monitor

type Monitor struct {
	// label
	ID string `hcl:"id,label"`

	// body
	Name     string     `hcl:"name"`
	Services []*Service `hcl:"service,block"`
}

Monitor keeps the configuration of a single monitor. It aggregates one or more services.

type ReadFilter

type ReadFilter struct {
	Since          time.Time
	TimeBucket     uint
	TimeBucketUnit string
	Interval       uint
	IntervalUnit   string
	ActiveServices map[string][]string
}

ReadFilter contains params to configure metrics read.

func (*ReadFilter) IntervalToDuration

func (f *ReadFilter) IntervalToDuration() time.Duration

IntervalToDuration converts user defined interval to time.Duration.

func (*ReadFilter) Until

func (f *ReadFilter) Until() time.Time

Until calculates when interval should stop.

type Request

type Request struct{}

Request is a http request with tracing.

func (*Request) Get

func (*Request) Get(address string, timeout time.Duration) *Response

Get executes GET request.

type Response

type Response struct {
	Err   error
	Resp  *http.Response
	Trace Trace
}

Response contains the result of the request check.

type ResponseDetails added in v0.2.0

type ResponseDetails struct {
	StatusCode int `json:"status_code"`
}

ResponseDetails contains response error.

type Runner

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

Runner is responsible for scheduling jobs.

func NewRunner

func NewRunner(cfg *Config, store Store) *Runner

NewRunner creates runner instance.

func (*Runner) Shutdown

func (r *Runner) Shutdown(ctx context.Context)

Shutdown stops all the tasks and closes scheduler.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context)

Start begins cron jobs.

type Server added in v0.1.5

type Server struct {
	BindAddress string `hcl:"bind_address"`
	TLSCertFile string `hcl:"tls_cert_file"`
	TLSKeyFile  string `hcl:"tls_key_file"`
}

Server configuration.

type Service

type Service struct {
	// label
	ID string `hcl:"id,label"`

	// body
	Name       string       `hcl:"name"`
	HTTPChecks []*HTTPCheck `hcl:"http,block"`
}

Service defines monitor checks.

type Store

type Store interface {
	// Migrate runs right after creating a connection to store.
	// Store implementation is responsible for creating/migrating schema.
	Migrate(ctx context.Context) error

	// Close shuts down the connection to store.
	Close(ctx context.Context)

	// Save inserts service check result to store.
	Save(ctx context.Context, result *CheckResult)

	// Read loads all metrics from store.
	Read(ctx context.Context, filter *ReadFilter) ([]*Metric, error)

	// Truncate removes all metrics from store.
	Truncate(ctx context.Context) error
}

Store interface.

type Trace

type Trace struct {
	DNSLookup        time.Duration `json:"dns_lookup"`
	TCPConnection    time.Duration `json:"tcp_connection"`
	TLSHandshake     time.Duration `json:"tls_handshake"`
	ServerProcessing time.Duration `json:"server_processing"`
	ContentTransfer  time.Duration `json:"content_transfer"`
	Total            time.Duration `json:"total"`
}

Trace contains details about the request duration.

func (Trace) String

func (t Trace) String() string

type Validatable

type Validatable interface {
	Validate() error
}

Validatable interface.

Jump to

Keyboard shortcuts

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