Documentation ¶
Index ¶
- Constants
- Variables
- func EnableGlobalMetrics()
- func ErrorStackFormatCSV(errors []error) string
- func ErrorStackFormatNewline(errors []error) string
- func ErrorStackFormatNumbered(errors []error) string
- func RecoverShutdown()
- func RecoverTrace()
- func ReturnAfter(runtimeLimit time.Duration, callback func()) bool
- func WithRecover(callback func())
- func WithRecoverShutdown(callback func())
- type ErrorStack
- func (stack *ErrorStack) Clear()
- func (stack ErrorStack) Error() string
- func (stack ErrorStack) Errors() []error
- func (stack ErrorStack) Len() int
- func (stack *ErrorStack) OrNil() error
- func (stack *ErrorStack) Pop() error
- func (stack *ErrorStack) Push(err error) bool
- func (stack *ErrorStack) PushAndDescribe(message string, err error) bool
- func (stack *ErrorStack) Pushf(message string, args ...interface{})
- func (stack *ErrorStack) SetFormat(formatter ErrorStackFormatter)
- func (stack ErrorStack) Top() error
- type ErrorStackFormatter
- type MetricServer
- type Metrics
- func (met *Metrics) Add(name string, value int64)
- func (met *Metrics) AddF(name string, value float64)
- func (met *Metrics) AddI(name string, value int)
- func (met *Metrics) Close()
- func (met *Metrics) Dec(name string)
- func (met *Metrics) Dump() ([]byte, error)
- func (met *Metrics) FetchAndReset(keys ...string) map[string]int64
- func (met *Metrics) Get(name string) (int64, error)
- func (met *Metrics) Inc(name string)
- func (met *Metrics) InitSystemMetrics()
- func (met *Metrics) New(name string)
- func (met *Metrics) NewRate(baseMetric string, name string, interval time.Duration, numSamples uint8, ...) error
- func (met *Metrics) ResetMetrics()
- func (met *Metrics) Set(name string, value int64)
- func (met *Metrics) SetB(name string, value bool)
- func (met *Metrics) SetF(name string, value float64)
- func (met *Metrics) SetI(name string, value int)
- func (met *Metrics) Sub(name string, value int64)
- func (met *Metrics) SubF(name string, value float64)
- func (met *Metrics) SubI(name string, value int)
- func (met *Metrics) UpdateSystemMetrics()
Constants ¶
const ( // MetricProcessStart is the metric name storing the time when this process // has been started. MetricProcessStart = "ProcessStart" // MetricGoRoutines is the metric name storing the number of active go // routines. MetricGoRoutines = "GoRoutines" // MetricGoVersion holds the go version as Major*10000+Minor*100+Patch MetricGoVersion = "GoVersion" // MetricMemoryAllocated holds the currently active memory in bytes MetricMemoryAllocated = "GoMemoryAllocated" // MetricMemoryNumObjects holds the total number of allocated heap objects MetricMemoryNumObjects = "GoMemoryNumObjects" // MetricMemoryGCEnabled holds 1 or 0 depending on the state of garbage collection MetricMemoryGCEnabled = "GoMemoryGCEnabled" )
Variables ¶
var Metric = (*Metrics)(nil)
Metric allows any part of gollum to store and/or modify metric values by name.
var ProcessStartTime time.Time
ProcessStartTime stores the time this process has started. This value is also stored in the metric MetricProcessStart
var ShutdownCallback = func() { proc, _ := os.FindProcess(os.Getpid()) proc.Signal(os.Interrupt) }
ShutdownCallback holds the function that is called when RecoverShutdown detects a panic and could recover. By default this functions sends an os.Interrupt signal to the process. This function can be overwritten for customization.
Functions ¶
func EnableGlobalMetrics ¶
func EnableGlobalMetrics()
EnableGlobalMetrics initializes the Metric global variable (if it is not nil) This function is not threadsafe and should be called once directly after the process started.
func ErrorStackFormatCSV ¶
ErrorStackFormatNumbered returns errors separated by comma
func ErrorStackFormatNewline ¶
ErrorStackFormatNumbered returns errors separated by newline
func ErrorStackFormatNumbered ¶
ErrorStackFormatNumbered returns errors with a number prefix, separated by newline.
func RecoverShutdown ¶
func RecoverShutdown()
RecoverShutdown will trigger a shutdown via os.Interrupt if a panic was issued. A callstack will be printed like with RecoverTrace(). Typically used as "defer RecoverShutdown()".
func RecoverTrace ¶
func RecoverTrace()
RecoverTrace will trigger a stack trace when a panic was recovered by this function. Typically used as "defer RecoverTrace()".
func ReturnAfter ¶
ReturnAfter calls a function. If that function does not return after the given limit, the function returns regardless of the callback being done or not. This guarantees the call to finish before or at the given limit.
func WithRecover ¶
func WithRecover(callback func())
WithRecover can be used instead of RecoverTrace when using a function without any parameters. E.g. "go WithRecover(myFunction)"
func WithRecoverShutdown ¶
func WithRecoverShutdown(callback func())
WithRecoverShutdown can be used instead of RecoverShutdown when using a function without any parameters. E.g. "go WithRecoverShutdown(myFunction)"
Types ¶
type ErrorStack ¶
type ErrorStack struct {
// contains filtered or unexported fields
}
ErrorStack is a helper to store errors from multiple statements for batch handling. Convenience functions to wrap function calls of the form func() (<type>, error) do exist for all golang base types.
func (ErrorStack) Error ¶
func (stack ErrorStack) Error() string
Error implements the Error interface
func (ErrorStack) Errors ¶
func (stack ErrorStack) Errors() []error
Errors returns all gathered errors as an array
func (ErrorStack) Len ¶
func (stack ErrorStack) Len() int
Len returns the number of error on the stack
func (*ErrorStack) OrNil ¶
func (stack *ErrorStack) OrNil() error
OrNil returns this object or nil of no errors are stored
func (*ErrorStack) Pop ¶
func (stack *ErrorStack) Pop() error
Pop removes an error from the top of the stack and returns it
func (*ErrorStack) Push ¶
func (stack *ErrorStack) Push(err error) bool
Push adds a new error to the top of the error stack. Returns if err != nil.
func (*ErrorStack) PushAndDescribe ¶
func (stack *ErrorStack) PushAndDescribe(message string, err error) bool
PushAndDescribe behaves like Push but allows to prepend a text before the error messages returned by err. The type of err will be lost.
func (*ErrorStack) Pushf ¶
func (stack *ErrorStack) Pushf(message string, args ...interface{})
Pushf adds a new error message to the top of the error stack
func (*ErrorStack) SetFormat ¶
func (stack *ErrorStack) SetFormat(formatter ErrorStackFormatter)
SetFormat set the format used when Error() is called.
func (ErrorStack) Top ¶
func (stack ErrorStack) Top() error
Top returns the error on top of the stack (last error pushed)
type ErrorStackFormatter ¶
ErrorStackFormatter is used by ErroStack to generate a single error string from an array of errors.
type MetricServer ¶
type MetricServer struct {
// contains filtered or unexported fields
}
MetricServer contains state information about the metric server process
func NewMetricServer ¶
func NewMetricServer() *MetricServer
NewMetricServer creates a new server state for a metric server based on the global Metric variable.
func NewMetricServerFor ¶
func NewMetricServerFor(m *Metrics) *MetricServer
NewMetricServerFor creates a new server state for a metric server based on a custom Metrics variable
func (*MetricServer) Start ¶
func (server *MetricServer) Start(address string)
Start causes a metric server to listen for a specific address and port. If this address/port is accessed a JSON containing all metrics will be returned and the connection is closed. You can use the standard go notation for addresses like ":80".
func (*MetricServer) Stop ¶
func (server *MetricServer) Stop()
Stop notifies the metric server to halt.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics is the container struct for runtime metrics that can be used with the metrics server.
func NewMetrics ¶
func NewMetrics() *Metrics
NewMetrics creates a new metrics container. To initialize the global Metrics variable use EnableGlobalMetrics.
func (*Metrics) Close ¶
func (met *Metrics) Close()
Close stops the internal go routines used for e.g. sampling
func (*Metrics) FetchAndReset ¶
FetchAndReset resets all of the given keys to 0 and returns the value before the reset as array. If a given metric does not exist it is ignored. This locks all writes in the process.
func (*Metrics) Get ¶
Get returns the value of a given metric or rate. If the value does not exists error is non-nil and the returned value is 0.
func (*Metrics) InitSystemMetrics ¶
func (met *Metrics) InitSystemMetrics()
InitSystemMetrics Adds system metrics (memory, go routines, etc.) to this metric storage. System metrics need to be updated manually by calling UpdateSystemMetrics().
func (*Metrics) NewRate ¶
func (met *Metrics) NewRate(baseMetric string, name string, interval time.Duration, numSamples uint8, numMedianSamples uint8, relative bool) error
NewRate creates a new rate. Rates are based on another metric and sample this given base metric every second. When numSamples have been stored, old samples are overriden (oldest first). Retrieving samples via GetRate will calculate the median of a set of means. numMedianSamples defines how many values will be used for mean calculation. A value of 0 will calculate the mean value of all samples. A value of 1 or a value >= numSamples will build a median over all samples. Any other value will divide the stored samples into the given number of groups and build a median over the mean of all these groups. The relative parameter defines if the samples are taking by storing the current value (false) or the difference to the last sample (true).
func (*Metrics) ResetMetrics ¶
func (met *Metrics) ResetMetrics()
ResetMetrics resets all registered key values to 0 expect for system Metrics. This locks all writes in the process.
func (*Metrics) UpdateSystemMetrics ¶
func (met *Metrics) UpdateSystemMetrics()
UpdateSystemMetrics updates all default or system based metrics like memory consumption and number of go routines. This function is not called automatically.