Documentation
¶
Index ¶
- Constants
- func HandleHealthcheck(w http.ResponseWriter, req *http.Request)
- func HandleMetrics(w http.ResponseWriter, req *http.Request)
- func HandlePrometheus(w http.ResponseWriter, req *http.Request)
- func RegisterGcStats(c ...GcStatsConfig)
- func SummarizeStatusMessage(component *map[string]*Status) (message string)
- func WrapUint64Counter(i uint64) (o int64)
- type ErrMetricAlreadyRegistered
- type ErrMetricAlreadyRegisteredWrongType
- type ErrMetricNotFound
- type GcStatsConfig
- type GobTag
- type HaproxyState
- type JSONOut
- type Metric
- type MetricCounter
- type MetricFloat
- type MetricFloatBackend
- type MetricGauge
- type MetricRawCounter
- type PrometheusHandler
- type Registry
- func (r *Registry) GetMetric(name string, tags ...map[string]string) (Metric, error)
- func (r *Registry) GetRegistry() *Registry
- func (r *Registry) MustRegister(name string, metric Metric, tags ...map[string]string) Metric
- func (r *Registry) Register(name string, metric Metric, tags ...map[string]string) (Metric, error)
- func (r *Registry) RegisterOrGet(name string, metric Metric, tags ...map[string]string) (Metric, error)
- func (r *Registry) SetFQDN(name string)
- func (r *Registry) SetInstance(name string)
- func (r *Registry) SetInterval(interval float64)
- func (r *Registry) UpdateTs()
- type Service
- type StatBackendFloat
- type StatBackendInt
- type State
- type Status
- func (s *Status) GetMessage() string
- func (s *Status) GetOK() bool
- func (s *Status) GetState() State
- func (s *Status) MustNewComponent(name string, p ...string) *Status
- func (s *Status) MustUpdate(status State, message string)
- func (s *Status) NewComponent(name string, p ...string) (*Status, error)
- func (s *Status) Update(status State, message string) error
Constants ¶
const ( // 0 is invalid state because that is initial value of int variable which can mean that someone didn't bother to actually set the state StatusInvalid = iota // nagios-compatible block // to get compatible state take nagios one and add +1 // Service is ok StatusOk // service is in warning state // should be only used if service is *actually* working but have some problems that need to be resolved // like "disk getting full" or "worker queue is 90% busy" StatusWarning // Service is in critical state and is not performing its function StatusCritical // check failed to get status of service (for reason other than "service is not working) // i.e. check itself crashed before providing any useful information about service StatusUnknown )
const ( // 0 is invalid state because that is initial value of int variable which can mean that someone didn't bother to actually set the state HostInvalid = iota // host (as in "unit running service checks") is up HostUp // host is directly unavailable HostDown // host is down because its parent is down (it is impossble to check because device that connects to the host is unavailable HostUnreachable )
const ( MetricTypeGauge = `G` // float64 gauge MetricTypeGaugeInt = `g` // int64 gauge MetricTypeCounter = `c` // int64 counter MetricTypeCounterFloat = `C` // float64 counter )
const Critical = State(3)
const Invalid = State(0)
const Ok = State(1)
const StateCritical = State(3)
const StateInvalid = State(0)
const StateOk = State(1)
const StateUnknown = State(4)
const StateWarning = State(2)
const Unknown = State(4)
const Warning = State(2)
Variables ¶
This section is empty.
Functions ¶
func HandleHealthcheck ¶ added in v0.0.2
func HandleHealthcheck(w http.ResponseWriter, req *http.Request)
HandleHealthchecks returns GlobalStatus with appropriate HTTP code
func HandleMetrics ¶
func HandleMetrics(w http.ResponseWriter, req *http.Request)
HandleMetrics is basic web hook that returns JSON dump of metrics in GlobalRegistry
func HandlePrometheus ¶ added in v1.4.0
func HandlePrometheus(w http.ResponseWriter, req *http.Request)
func RegisterGcStats ¶
func RegisterGcStats(c ...GcStatsConfig)
func SummarizeStatusMessage ¶ added in v0.0.2
SummarizeStatusMessage generates status message based on map of components and their statuses
func WrapUint64Counter ¶ added in v0.1.0
Wraps unsigned 64 bit counter to 64 signed one, on zero
Types ¶
type ErrMetricAlreadyRegistered ¶
type ErrMetricAlreadyRegistered struct {
Metric string
}
func (*ErrMetricAlreadyRegistered) Error ¶
func (e *ErrMetricAlreadyRegistered) Error() string
type ErrMetricAlreadyRegisteredWrongType ¶
type ErrMetricAlreadyRegisteredWrongType struct {
Metric string
NewMetricType string
OldMetricType string
}
func (*ErrMetricAlreadyRegisteredWrongType) Error ¶
func (e *ErrMetricAlreadyRegisteredWrongType) Error() string
type ErrMetricNotFound ¶
type ErrMetricNotFound struct {
Metric string
}
func (*ErrMetricNotFound) Error ¶
func (e *ErrMetricNotFound) Error() string
type GcStatsConfig ¶ added in v0.1.0
GcStats configuration. Interval is time between probes, average turns on EWMA on most stats with 5x interval as half-life
type HaproxyState ¶ added in v1.2.0
type HaproxyState struct {
State State
BackendName string
ServerName string
LBNodeName string
ServerWeight int
TotalWeight int
// Current connections going to this server
ServerCurrentConnections int
// Current connections going to backend
BackendCurrentConnections int
// Requests in server queue
Queue int
// whether header was found
Found bool
TS time.Time
sync.RWMutex
}
func HandleHaproxyState ¶ added in v1.2.0
func HandleHaproxyState(req *http.Request) (haproxyState HaproxyState, found bool, err error)
HandleHaproxyState parses haproxy state header and returns current backend state
Example header: X-Haproxy-Server-State: UP 2/3; name=bck/srv2; node=lb1; weight=1/2; scur=13/22; qcur=
func HandleHealthchecksHaproxy ¶ added in v1.2.0
func HandleHealthchecksHaproxy(emit404OnWarning ...bool) (handlerFunc func(w http.ResponseWriter, req *http.Request), haproxyState *HaproxyState)
HandleHealthchecksHaproxy returns GlobalStatus with appropriate HTTP code and handles X-Haproxy-Server-State header
func (*HaproxyState) SafeToStop ¶ added in v1.2.0
func (s *HaproxyState) SafeToStop() bool
type JSONOut ¶
type JSONOut struct {
Type string `json:"type"`
Unit string `json:"unit,omitempty"`
Invalid bool `json:"invalid,omitempty"`
Value interface{} `json:"value"`
}
API-compatible JSON output structure
type Metric ¶
Single metric handler interface
func NewCounter ¶
func NewEWMARate ¶
New exponentally weighted moving average event rate counter call Update(value is ignored) every time an event happens to get rate of the event
func NewRawCounter ¶
type MetricCounter ¶ added in v1.5.0
type MetricCounter struct {
// contains filtered or unexported fields
}
func (*MetricCounter) MarshalJSON ¶ added in v1.5.0
func (f *MetricCounter) MarshalJSON() ([]byte, error)
func (*MetricCounter) Type ¶ added in v1.5.0
func (m *MetricCounter) Type() string
func (*MetricCounter) Unit ¶ added in v1.5.0
func (m *MetricCounter) Unit() string
func (*MetricCounter) Update ¶ added in v1.5.0
func (m *MetricCounter) Update(v float64)
func (*MetricCounter) Value ¶ added in v1.5.0
func (m *MetricCounter) Value() float64
type MetricFloat ¶
raw float metric with no backend
func (*MetricFloat) MarshalJSON ¶
func (f *MetricFloat) MarshalJSON() ([]byte, error)
func (*MetricFloat) Type ¶
func (f *MetricFloat) Type() string
func (*MetricFloat) Unit ¶
func (f *MetricFloat) Unit() string
func (*MetricFloat) Update ¶
func (f *MetricFloat) Update(value float64) (err error)
func (*MetricFloat) Value ¶
func (f *MetricFloat) Value() float64
func (*MetricFloat) ValueRaw ¶
func (f *MetricFloat) ValueRaw() interface{}
type MetricFloatBackend ¶
Float metric with backend.
By default backend is updated with mutex lock, all other locking have to be handled by the backend itself
func (*MetricFloatBackend) MarshalJSON ¶
func (f *MetricFloatBackend) MarshalJSON() ([]byte, error)
func (*MetricFloatBackend) Type ¶
func (f *MetricFloatBackend) Type() string
func (*MetricFloatBackend) Unit ¶
func (f *MetricFloatBackend) Unit() string
func (*MetricFloatBackend) Update ¶
func (f *MetricFloatBackend) Update(value float64)
func (*MetricFloatBackend) Value ¶
func (f *MetricFloatBackend) Value() float64
type MetricGauge ¶ added in v1.5.0
type MetricGauge struct {
// contains filtered or unexported fields
}
func (*MetricGauge) MarshalJSON ¶ added in v1.5.0
func (f *MetricGauge) MarshalJSON() ([]byte, error)
func (*MetricGauge) Type ¶ added in v1.5.0
func (m *MetricGauge) Type() string
func (*MetricGauge) Unit ¶ added in v1.5.0
func (m *MetricGauge) Unit() string
func (*MetricGauge) Update ¶ added in v1.5.0
func (m *MetricGauge) Update(v float64)
func (*MetricGauge) Value ¶ added in v1.5.0
func (m *MetricGauge) Value() float64
type MetricRawCounter ¶ added in v1.5.0
type MetricRawCounter struct {
// contains filtered or unexported fields
}
func (*MetricRawCounter) MarshalJSON ¶ added in v1.5.0
func (f *MetricRawCounter) MarshalJSON() ([]byte, error)
func (*MetricRawCounter) Type ¶ added in v1.5.0
func (m *MetricRawCounter) Type() string
func (*MetricRawCounter) Unit ¶ added in v1.5.0
func (m *MetricRawCounter) Unit() string
func (*MetricRawCounter) Update ¶ added in v1.5.0
func (m *MetricRawCounter) Update(v float64)
func (*MetricRawCounter) Value ¶ added in v1.5.0
func (m *MetricRawCounter) Value() float64
type PrometheusHandler ¶ added in v1.4.0
type PrometheusHandler struct {
}
type Registry ¶
type Registry struct {
Metrics map[string]map[string]Metric `json:"metrics"`
Instance string `json:"instance"`
Interval float64 `json:"interval"`
FQDN string `json:"fqdn"`
Ts time.Time `json:"ts,omitempty"`
sync.Mutex
}
var GlobalRegistry *Registry
Global registry, will use app's executable name as instance and try best to guess FQDN You can change thos via Set..() family of methods
func NewRegistry ¶ added in v0.0.3
func (*Registry) GetRegistry ¶ added in v0.0.3
Returns a shallow copy of registry with current timestamp. Should be used as source for any serializer
func (*Registry) MustRegister ¶
MustRegister() does same as Register() except it panic()s if metric already exists. It is mostly intended to be used for top of the package, package-scoped metrics like
var request_rate = mon.GlobalRegistry.Register("backend.mysql.qps",mon.NewEWMARate(time.Duration(time.Minute)))
func (*Registry) RegisterOrGet ¶
func (*Registry) SetInstance ¶
Set instance name returned by registry during marshalling
func (*Registry) SetInterval ¶ added in v0.0.5
type Service ¶
type Service struct {
// name of the host/metahost service is running on
Host string `json:"host"`
// name of service
Service string `json:"service"`
// numeric state
State uint8 `json:"state"`
// timestamp of the check
Timestamp time.Time `json:"ts"`
// duration since last state change
StateDuration time.Duration `json:"duration,omitempty"`
// sub-service state
// if service (say web app) have multiple internal components (for example DB backend, video transcoder etc) that allows it to send state of them to the upstream without multiplying amount of service checks
// Note that status of them **HAVE** to be aggregated into parent's State
Components []Service `json:"components,omitempty"`
}
type StatBackendFloat ¶
backend interface handling single integer stat
type StatBackendInt ¶
backend interface handling single integer stat
type State ¶ added in v1.0.0
type State uint8
func SummarizeStatusState ¶ added in v0.0.2
SummarizeStatusState returns highest ( critical>unknown>warning>ok ) state of underlying status map
type Status ¶
type Status struct {
State State `json:"state"`
// Canonical service name (required)
Name string `json:"name"`
// FQDN
FQDN string `json:"fqdn,omitempty"`
// Pretty display name of service
DisplayName string `json:"display_name,omitempty"`
// Description of service
Description string `json:"description,omitempty"`
// status check message
Msg string `json:"msg"`
// data format initialization canary.
// Proper implementation will set ok to true if status is really okay
// but fresh (all fields zero) object will be invalid (state = 0 but ok = false)
// and that can be detected upstream.
// Other function is to allow just checking one bool flag to decide if it is ok or not
Ok bool `json:"ok"`
Ts time.Time `json:"ts"`
Components map[string]*Status `json:"components,omitempty"`
//
sync.RWMutex
// contains filtered or unexported fields
}
Status forms hierarchical structure. Parent status code and message is always generated from status of children so running update on it is pointless
var GlobalStatus *Status
func NewStatus ¶ added in v0.0.2
NewStatus creates new status object with state set to unknown optional parameters are * display name * description
func (*Status) GetMessage ¶ added in v0.0.2
update and return message
func (*Status) MustNewComponent ¶ added in v1.0.1
func (*Status) MustUpdate ¶ added in v1.0.1
func (*Status) NewComponent ¶ added in v0.0.2
NewComponent adds a new child component to the Status optional parameters are * display name * description