Documentation ¶
Overview ¶
Package health provides a simple heartbeat strategy for WebPA/XMiDT services.
Deprecated: health is no longer planned to be used by future WebPA/XMiDT services.
This package is frozen and no new functionality will be added.
Index ¶
- Constants
- Variables
- type Dispatcher
- type Health
- func (h *Health) AddStatsListener(listener StatsListener)
- func (h *Health) RequestTracker(delegate http.Handler) http.Handler
- func (h *Health) Run(waitGroup *sync.WaitGroup, shutdown <-chan struct{}) error
- func (h *Health) SendEvent(healthFunc HealthFunc)
- func (h *Health) ServeHTTP(response http.ResponseWriter, request *http.Request)
- type HealthFunc
- type MemInfoReader
- type Monitor
- type Option
- type ResponseWriter
- func (r *ResponseWriter) CloseNotify() <-chan bool
- func (r *ResponseWriter) Flush()
- func (r *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
- func (r *ResponseWriter) Push(target string, opts *http.PushOptions) error
- func (r *ResponseWriter) StatusCode() int
- func (r *ResponseWriter) WriteHeader(statusCode int)
- type Stat
- type Stats
- type StatsListener
- type StatsListenerFunc
Constants ¶
const ( // DefaultMemoryReaderLocation is the default location for meminfo // under Linux DefaultMemoryReaderLocation string = "/proc/meminfo" )
Variables ¶
var ( // Invalid stat option error ErrorInvalidOption = errors.New("Invalid stat option") )
Functions ¶
This section is empty.
Types ¶
type Dispatcher ¶
type Dispatcher interface {
SendEvent(HealthFunc)
}
Dispatcher represents a sink for Health events
type Health ¶
type Health struct {
// contains filtered or unexported fields
}
Health is the central type of this package. It defines and endpoint for tracking and updating various statistics. It also dispatches events to one or more StatsListeners at regular intervals.
func (*Health) AddStatsListener ¶
func (h *Health) AddStatsListener(listener StatsListener)
AddStatsListener adds a new listener to this Health. This method is asynchronous. The listener will eventually receive events, but callers should not assume events will be dispatched immediately after this method call.
func (*Health) RequestTracker ¶
RequestTracker is an Alice-style constructor that wraps the given delegate in request-tracking code.
func (*Health) Run ¶
Run executes this Health object. This method is idempotent: once a Health object is Run, it cannot be Run again.
func (*Health) SendEvent ¶
func (h *Health) SendEvent(healthFunc HealthFunc)
SendEvent dispatches a HealthFunc to the internal event queue
type HealthFunc ¶
type HealthFunc func(Stats)
HealthFunc functions are allowed to modify the passed-in stats.
func Ensure ¶
func Ensure(stat Stat) HealthFunc
Ensure makes certain the given stat is defined. If it does not exist, it is initialized to 0. Otherwise, the existing stat value is left intact.
func Inc ¶
func Inc(stat Stat, value int) HealthFunc
Inc increments the given stat by a certain amount
func Set ¶
func Set(stat Stat, value int) HealthFunc
Set changes (or, initializes) the stat to the given value
func (HealthFunc) Set ¶
func (f HealthFunc) Set(stats Stats)
type MemInfoReader ¶
type MemInfoReader struct {
Location string
}
MemInfoReader handles extracting the linux memory information from the enclosing environment.
type Monitor ¶
type Monitor interface { Dispatcher // HACK HACK HACK // This should be moved to another package ServeHTTP(http.ResponseWriter, *http.Request) }
Monitor is the basic interface implemented by health event sinks
type Option ¶
type Option interface {
Set(Stats)
}
Option describes an option that can be set on a Stats map. Various types implement this interface.
type ResponseWriter ¶
type ResponseWriter struct { http.ResponseWriter // contains filtered or unexported fields }
ResponseWriter is a wrapper type for an http.ResponseWriter that exposes the status code.
func Wrap ¶
func Wrap(delegate http.ResponseWriter) *ResponseWriter
Wrap returns a *health.ResponseWriter which wraps the given http.ResponseWriter
func (*ResponseWriter) CloseNotify ¶
func (r *ResponseWriter) CloseNotify() <-chan bool
CloseNotify delegates to the wrapped ResponseWriter, panicking if the delegate does not implement http.CloseNotifier.
func (*ResponseWriter) Flush ¶
func (r *ResponseWriter) Flush()
Flush delegates to the wrapped ResponseWriter. If the delegate ResponseWriter does not implement http.Flusher, this method does nothing.
func (*ResponseWriter) Hijack ¶
func (r *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error)
Hijack delegates to the wrapped ResponseWriter, returning an error if the delegate does not implement http.Hijacker.
func (*ResponseWriter) Push ¶
func (r *ResponseWriter) Push(target string, opts *http.PushOptions) error
Push delegates to the wrapper ResponseWriter, returning an error if the delegate does not implement http.Pusher.
func (*ResponseWriter) StatusCode ¶
func (r *ResponseWriter) StatusCode() int
func (*ResponseWriter) WriteHeader ¶
func (r *ResponseWriter) WriteHeader(statusCode int)
type Stat ¶
type Stat string
Stat is a named piece of data to be tracked
const ( // General memory stats CurrentMemoryUtilizationAlloc Stat = "CurrentMemoryUtilizationAlloc" CurrentMemoryUtilizationHeapSys Stat = "CurrentMemoryUtilizationHeapSys" CurrentMemoryUtilizationActive Stat = "CurrentMemoryUtilizationActive" MaxMemoryUtilizationAlloc Stat = "MaxMemoryUtilizationAlloc" MaxMemoryUtilizationHeapSys Stat = "MaxMemoryUtilizationHeapSys" MaxMemoryUtilizationActive Stat = "MaxMemoryUtilizationActive" TotalRequestsReceived Stat = "TotalRequestsReceived" TotalRequestsSuccessfullyServiced Stat = "TotalRequestsSuccessfullyServiced" TotalRequestsDenied Stat = "TotalRequestsDenied" )
type Stats ¶
Stats is mapping of Stat to value
func NewStats ¶
NewStats constructs a Stats object preinitialized with the internal default statistics plus the given options.
func (Stats) UpdateMemInfo ¶
UpdateMemInfo takes memory information from a linux environment and sets the appropriate stats.
func (Stats) UpdateMemStats ¶
UpdateMemStats takes a MemStats from the golang runtime and sets the appropriate stats.
func (Stats) UpdateMemory ¶
func (s Stats) UpdateMemory(memInfoReader *MemInfoReader)
UpdateMemory updates all the memory statistics
type StatsListener ¶
type StatsListener interface { // OnStats is called with a copy of the health's stats map // at regular intervals. OnStats(Stats) }
StatsListener receives Stats on regular intervals.
type StatsListenerFunc ¶
type StatsListenerFunc func(Stats)
StatsListenerFunc is a function type that implements StatsListener.
func (StatsListenerFunc) OnStats ¶
func (f StatsListenerFunc) OnStats(stats Stats)