Documentation ¶
Index ¶
- Constants
- func GetHostHealthBytes(now time.Time) []byte
- type Event
- type HealthMsg
- type HttpSignal
- type IReporter
- type Reporter
- func (r *Reporter) AddHostnameSuffix(suffix string)
- func (r *Reporter) AddStat(key string, val interface{})
- func (r *Reporter) ClearAll()
- func (r *Reporter) ClearStat(key string)
- func (r *Reporter) ClearStatFns()
- func (r *Reporter) ClearStats()
- func (r *Reporter) GetKafkaLogWriter() io.Writer
- func (r *Reporter) GetStat(key string) interface{}
- func (r *Reporter) Health() Event
- func (r *Reporter) HealthHandler(w http.ResponseWriter, req *http.Request)
- func (r *Reporter) Initialize() (bool, error)
- func (r *Reporter) JsonStats() []byte
- func (r *Reporter) KafkaHealthy() (bool, error)
- func (r *Reporter) PersistStat(key string, val interface{})
- func (r *Reporter) RegisterStatFn(name string, fn func(reporter IReporter))
- func (r *Reporter) ReportHealth()
- func (r *Reporter) SetErrFn(efn func(err error))
- func (r *Reporter) SetHealth(state State, message string)
- func (r *Reporter) SetStdOutFallback(b bool)
- func (r *Reporter) SetTopic(topic string)
- func (r *Reporter) StartIntervalReporting(interval time.Duration)
- func (r *Reporter) Stop() error
- func (r *Reporter) StopWithFinalState(final State, msg string) error
- type Signal
- type State
- type VersionMsg
Constants ¶
const ( Blue = State("blue") // init or shut-down Green = State("green") // A-OK Yellow = State("yellow") // may need assistance Red = State("red") // HELP! Gray = State("gray") // maintenance mode )
const DefaultFlushTimeout = 1000 // ms
const EventType = "health"
EventType value is "health"
const MaxKafkaHealthCheckInterval = time.Minute * 5
const SignalUrl = "https://signal.atsu.io/"
const StateDefault = Blue
StateDefault health is Blue
Variables ¶
This section is empty.
Functions ¶
func GetHostHealthBytes ¶
Types ¶
type Event ¶
type Event struct { Hostname string `json:"hostname"` // Emitting host Timestamp int64 `json:"timestamp"` // Timestamp of event Type string `json:"etype"` // Type of event ( "health") Name string `json:"event"` // Name of event (e.g. status, startup, shutdown) Service string `json:"service"` // Operating service (e.g. gather) Version string `json:"version"` // Service version State State `json:"state"` // Enumeration of health Message string `json:"msg"` // User actionable message Data interface{} `json:"data,omitempty"` // Service-specific data }
Event is the basic format for all JSON-encoded Health Example of a json encoded health event
{"hostname":"host123", "timestamp":1559761560, "etype":"health", "event":"status", "service":"gather", "version":"v0.0.1", "state":"green", "msg":"a-ok", "data": { "testmode": "off", "kernel": true }}
type HttpSignal ¶
type HttpSignal struct {
// contains filtered or unexported fields
}
HttpSignal implements against our canonical endpoint SignalUrl
func NewHttpSignal ¶
func NewHttpSignal(url string) *HttpSignal
func (*HttpSignal) RawReport ¶
func (r *HttpSignal) RawReport(jsonPayload []byte) error
RawReport will POST the provided jsonPayload to SignalUrl
func (*HttpSignal) Report ¶
func (r *HttpSignal) Report(e Event, i interface{}) error
Report will Marshal and send, or error
type IReporter ¶
type IReporter interface { Initialize() (bool, error) Health() Event SetStdOutFallback(b bool) SetErrFn(efn func(err error)) SetHealth(state State, message string) SetTopic(topic string) PersistStat(key string, val interface{}) RegisterStatFn(name string, fn func(reporter IReporter)) AddStat(key string, val interface{}) GetStat(key string) interface{} ClearStat(key string) ClearStats() ClearStatFns() ClearAll() GetKafkaLogWriter() io.Writer KafkaHealthy() (bool, error) ReportHealth() AddHostnameSuffix(string) StartIntervalReporting(interval time.Duration) HealthHandler(w http.ResponseWriter, req *http.Request) Stop() error StopWithFinalState(final State, msg string) error }
type Reporter ¶
type Reporter struct { // Errfn is the callback function that fires whenever there is an error. Errfn func(err error) // contains filtered or unexported fields }
Reporter is the front door for reporting
func NewReporter ¶
NewReporter create a new reporter
func (*Reporter) AddHostnameSuffix ¶
func (*Reporter) ClearAll ¶
func (r *Reporter) ClearAll()
ClearAll clears all stats and persistent stats
func (*Reporter) ClearStat ¶
ClearStat clears an individual stat by key, does not clear persistent stats
func (*Reporter) ClearStatFns ¶
func (r *Reporter) ClearStatFns()
ClearStatFns clears the reporter functions
func (*Reporter) ClearStats ¶
func (r *Reporter) ClearStats()
ClearStats clears all non persistent stats
func (*Reporter) GetKafkaLogWriter ¶
GetKafkaLogWriter returns an io.Writer which can be used to produce to the service log stream, *Note* if you use pass this io.Writer to log.SetOutput(), be careful not to call any log functions
in the error callback, otherwise you may cause a deadlock.
this stream is always `<prefix>.service.log`
func (*Reporter) GetStat ¶
GetStat retrieve a previously entered stat or persistent stat. persistent stats will act as default stats.
func (*Reporter) HealthHandler ¶
func (r *Reporter) HealthHandler(w http.ResponseWriter, req *http.Request)
HealthHandler return the current health on demand
func (*Reporter) Initialize ¶
Initialize must be called to create a new producer If Initialize fails with a fatal, non-recoverable error, it returns false and the non-nil error. when false is returned, kafka monitoring is disabled because no producer could be created or found Otherwise it returns true and and a non-nil error only if kafka is unhealthy
func (*Reporter) KafkaHealthy ¶
KafkaHealthy returns true if kafka is healthy, false if it isn't, and the last error associated with the unhealthy state
func (*Reporter) PersistStat ¶
PersistStat is akin to storing a stat, but a persistent stat is a stat that does not clear when Clear is called.
func (*Reporter) RegisterStatFn ¶
RegisterStatFn registers a function to be called before each call of ReportHealth.
func (*Reporter) ReportHealth ¶
func (r *Reporter) ReportHealth()
ReportHealth sends the current health to kafka
func (*Reporter) SetStdOutFallback ¶
SetStdOutFallback defaults to false. When enabled, health messages will be written to std out if kafka is unhealthy or if no producer is set
func (*Reporter) SetTopic ¶
SetTopic provides the ability to override the default topic. if never called, Initialize() will default the topic to `health.<service name>`
func (*Reporter) StartIntervalReporting ¶
StartIntervalReporting starts automatic reporting over the given interval.
func (*Reporter) Stop ¶
Stop interval reporting and close the kafka producer, after calling stop, the health reporter should no longer be used. To re-start, you should create a new reporter calling this function will result in emitting a default shutdown state of Gray with an empty message if you want to set the final state or message, use StopWithFinalState
type VersionMsg ¶
type VersionMsg struct { Version string `json:"version"` Build string `json:"build"` Hostname string `json:"hostname"` Kernel string `json:"kernel"` ModuleLoaded bool `json:"loaded"` Timestamp int64 `json:"timestamp"` LastEventTimestamp int64 `json:"last"` Count uint64 `json:"count"` EventsSkipped int `json:"skipped"` Health State `json:"health"` }