qcache_health

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2017 License: Apache-2.0 Imports: 15 Imported by: 0

README

cache-health

Cache to keep health information around and serves it at HTTP endpoint

Health Endpoint

This creates a health endpoint on :8123.

$ go run main.go
2017/07/26 13:42:22.340385 [  INFO] Dispatch broadcast for Back, Data and Tick
2017/07/26 13:42:22.341392 [NOTICE]          health Name:health     >> Start plugin v0.0.0
2017/07/26 13:42:22.341482 [  INFO]          health Name:health     >> Start ticker 'health-ticker' with duration of 2500ms
2017/07/26 13:42:22.342211 [  INFO]          health Name:health     >> Start health-endpoint: 0.0.0.0:8123
2017/07/26 13:42:22.588183 [II] Start listener for: 'gracious_perlman' [ee191cd6faed7f4719a68b607d9c5771ad5aafc690c6a63b91f99a648d260c35]
2017/07/26 13:42:24.343265 [  INFO]          health Name:health     >> Received HealthBeat: {{0.1.2  2017-07-26 08:59:38 +0000 UTC 0 [stats] true map[]} statsRoutine ee191cd6faed7f4719a68b607d9c5771ad5aafc690c6a63b91f99a648d260c35 start}
2017/07/26 13:42:24.343329 [  INFO]          health Name:health     >> Received HealthBeat: {{0.1.2  2017-07-26 08:59:38 +0000 UTC 0 [logs] true map[]} logSkipRoutine ee191cd6faed7f4719a68b607d9c5771ad5aafc690c6a63b91f99a648d260c35 start}

The endpoint looks like this, as the logs of the logging container are skipped, it shows up under skipped - otherwise a log-loop would be created.

$ curl -s http://localhost:8123/health |jq '"health:"+.health+" | healthMsg: "+.healthMsg'
"health:healthy | healthMsg: RunningContainers:1 | metricsGoRoutines:1 | logsGoRoutine:(0 [logs] + 1 [skipped])"
$ curl -s http://localhost:8123/health |jq '"stats:"+.statsRoutines+" | log: "+.logRoutines +" | logSkip: "+.logSkipRoutines'
"stats:ee191cd6faed7f4719a68b607d9c5771ad5aafc690c6a63b91f99a648d260c35 | log:  | logSkip: ee191cd6faed7f4719a68b607d9c5771ad5aafc690c6a63b91f99a648d260c35"

When starting a new container...

$ docker run -e SKIP_ENTRYPOINTS=true -ti --rm --no-healthcheck qnib/uplain-init sleep 15
[II] qnib/init-plain script v0.4.28
> execute CMD 'sleep 15'

... the endpoint changes...

$ curl -s http://localhost:8123/health |jq '"stats:"+.statsRoutines+" | log: "+.logRoutines +" | logSkip: "+.logSkipRoutines'
"stats:54859ad125ea7b18286b8592882b090807bcd35efffdae3f147e6baba7912624,ee191cd6faed7f4719a68b607d9c5771ad5aafc690c6a63b91f99a648d260c35 | log: 54859ad125ea7b18286b8592882b090807bcd35efffdae3f147e6baba7912624 | logSkip: ee191cd6faed7f4719a68b607d9c5771ad5aafc690c6a63b91f99a648d260c35"

In case the container counts are not matching, the health becomes unhealthy.

Documentation

Index

Constants

View Source
const (
	Healthy   = "healthy"
	Unhealthy = "unhealthy"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HealthEndpoint added in v0.1.1

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

func NewHealthEndpoint added in v0.1.1

func NewHealthEndpoint(routines []string) *HealthEndpoint

func (*HealthEndpoint) AddRoutine added in v0.1.1

func (he *HealthEndpoint) AddRoutine(routine, id string) (err error)

func (*HealthEndpoint) CountRoutine added in v0.1.1

func (he *HealthEndpoint) CountRoutine(routine string) int

func (*HealthEndpoint) CurrentHealth added in v0.1.2

func (he *HealthEndpoint) CurrentHealth() (s, m string)

func (*HealthEndpoint) DelRoutine added in v0.1.1

func (he *HealthEndpoint) DelRoutine(routine, id string) (err error)

func (*HealthEndpoint) GetJSON added in v0.1.1

func (he *HealthEndpoint) GetJSON() map[string]interface{}

func (*HealthEndpoint) GetTXT added in v0.1.1

func (he *HealthEndpoint) GetTXT() string

func (*HealthEndpoint) Handle added in v0.1.1

func (he *HealthEndpoint) Handle(w http.ResponseWriter, req *http.Request)

func (*HealthEndpoint) SetHealth added in v0.1.2

func (he *HealthEndpoint) SetHealth(status, msg string) (err error)

func (*HealthEndpoint) UpsertVitals added in v0.1.2

func (he *HealthEndpoint) UpsertVitals(name, state string, t time.Time)

/ Vitals

type Plugin

type Plugin struct {
	qtypes.Plugin

	HealthEndpoint *HealthEndpoint
	// contains filtered or unexported fields
}

func New

func New(qChan qtypes.QChan, cfg *config.Config, name string) (Plugin, error)

func (*Plugin) LogMiddleware added in v0.1.1

func (p *Plugin) LogMiddleware(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

func (*Plugin) RoutineAdd added in v0.1.1

func (p *Plugin) RoutineAdd(routine, id string)

func (*Plugin) RoutineDel added in v0.1.1

func (p *Plugin) RoutineDel(routine, id string)

func (*Plugin) Run

func (p *Plugin) Run()

Run fetches everything from the Data channel and flushes it to stdout

func (*Plugin) SetHealth added in v0.1.1

func (p *Plugin) SetHealth(status, msg string)

type Routines

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

func NewRoutines

func NewRoutines() *Routines

func (*Routines) Add

func (r *Routines) Add(str string)

func (*Routines) Count

func (r *Routines) Count() int

func (*Routines) Del

func (r *Routines) Del(str string)

func (*Routines) Get

func (r *Routines) Get() []string

func (*Routines) String

func (r *Routines) String() string

type Vitals added in v0.1.2

type Vitals struct {
	LastSign  time.Time
	LastState string
}

func NewVitals added in v0.1.2

func NewVitals() *Vitals

func (*Vitals) GetJSON added in v0.1.2

func (v *Vitals) GetJSON() map[string]interface{}

func (*Vitals) UpdateLast added in v0.1.2

func (v *Vitals) UpdateLast(t time.Time, state string)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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