Documentation ¶
Overview ¶
Package clistats implements a progress monitor functionality which exposes statistics in json format on a api endpoint bound to localhost
Index ¶
- Variables
- func FmtDuration(d time.Duration) string
- func String(from interface{}) string
- type DynamicCallback
- type Options
- type RequestPerSecondCallbackOptions
- type Statistics
- func (s *Statistics) AddCounter(id string, value uint64)
- func (s *Statistics) AddDynamic(id string, Callback DynamicCallback)
- func (s *Statistics) AddStatic(id string, value interface{})
- func (s *Statistics) GetCounter(id string) (uint64, bool)
- func (s *Statistics) GetDynamic(id string) (DynamicCallback, bool)
- func (s *Statistics) GetStatResponse(interval time.Duration, callback func(string, error) error)
- func (s *Statistics) GetStatic(id string) (interface{}, bool)
- func (s *Statistics) IncrementCounter(id string, count int)
- func (s *Statistics) Start() error
- func (s *Statistics) Stop() error
- type StatisticsClient
Constants ¶
This section is empty.
Variables ¶
var DefaultOptions = Options{ ListenPort: 63636, Web: true, }
DefaultOptions for clistats
Functions ¶
func FmtDuration ¶ added in v0.0.6
FmtDuration formats the duration for the time elapsed
Types ¶
type DynamicCallback ¶
type DynamicCallback func(client StatisticsClient) interface{}
DynamicCallback is called during statistics calculation for a dynamic field.
The value returned from this callback is displayed as the current value of a dynamic field. This can be utilised to calculate things like elapsed time, requests per seconds, etc.
func NewRequestsPerSecondCallback ¶
func NewRequestsPerSecondCallback(options RequestPerSecondCallbackOptions) DynamicCallback
NewRequestsPerSecondCallback creates a request per second callback function.
type RequestPerSecondCallbackOptions ¶
type RequestPerSecondCallbackOptions struct { // StartTimeFieldID is the ID of the start time field for the client. StartTimeFieldID string // RequestsCounterID is the ID of the request sent counter RequestsCounterID string }
RequestPerSecondCallbackOptions returns a callback function which generates requests per second metrics based on total requests and time elapsed since the scan.
type Statistics ¶
type Statistics struct { Options *Options // contains filtered or unexported fields }
Statistics is a client for showing statistics on the stdout.
func New ¶
func New() (*Statistics, error)
New creates a new statistics client for cli stats printing with default options
func NewWithOptions ¶ added in v0.0.10
func NewWithOptions(ctx context.Context, options *Options) (*Statistics, error)
NewWithOptions creates a new client with custom options
func (*Statistics) AddCounter ¶
func (s *Statistics) AddCounter(id string, value uint64)
AddCounter adds an uint64 counter field to the statistics client.
A counter is used to track an increasing quantity, like requests, errors etc.
func (*Statistics) AddDynamic ¶
func (s *Statistics) AddDynamic(id string, Callback DynamicCallback)
AddDynamic adds a dynamic field to display whose value is retrieved by running a callback function.
The callback function performs some actions and returns the value to display. Generally this is used for calculating requests per seconds, elapsed time, etc.
func (*Statistics) AddStatic ¶
func (s *Statistics) AddStatic(id string, value interface{})
AddStatic adds a static information field to the statistics.
The value for these metrics will remain constant throughout the lifecycle of the statistics client. All the values will be converted into string and displayed as such.
func (*Statistics) GetCounter ¶
func (s *Statistics) GetCounter(id string) (uint64, bool)
GetCounter returns the current value of a counter.
func (*Statistics) GetDynamic ¶
func (s *Statistics) GetDynamic(id string) (DynamicCallback, bool)
GetDynamic returns the dynamic field callback for data retrieval.
func (*Statistics) GetStatResponse ¶ added in v0.0.17
GetStatResponse returns '/metrics' response for a given interval
func (*Statistics) GetStatic ¶
func (s *Statistics) GetStatic(id string) (interface{}, bool)
GetStatic returns the original value for a static field.
func (*Statistics) IncrementCounter ¶
func (s *Statistics) IncrementCounter(id string, count int)
IncrementCounter increments the value of a counter by a count.
func (*Statistics) Start ¶
func (s *Statistics) Start() error
Start starts the event loop of the stats client.
func (*Statistics) Stop ¶
func (s *Statistics) Stop() error
Stop stops the event loop of the stats client
type StatisticsClient ¶
type StatisticsClient interface { // Start starts the event loop of the stats client. Start() error // Stop stops the event loop of the stats client Stop() error // AddCounter adds a uint64 counter field to the statistics client. // // A counter is used to track an increasing quantity, like requests, // errors etc. AddCounter(id string, value uint64) // GetCounter returns the current value of a counter. GetCounter(id string) (uint64, bool) // IncrementCounter increments the value of a counter by a count. IncrementCounter(id string, count int) // AddStatic adds a static information field to the statistics. // // The value for these metrics will remain constant throughout the // lifecycle of the statistics client. All the values will be // converted into string and displayed as such. AddStatic(id string, value interface{}) // GetStatic returns the original value for a static field. GetStatic(id string) (interface{}, bool) // AddDynamic adds a dynamic field to display whose value // is retrieved by running a callback function. // // The callback function performs some actions and returns the value // to display. Generally this is used for calculating requests per // seconds, elapsed time, etc. AddDynamic(id string, Callback DynamicCallback) // GetDynamic returns the dynamic field callback for data retrieval. GetDynamic(id string) (DynamicCallback, bool) //GetStatResponse returns '/metrics' response for a given interval GetStatResponse(interval time.Duration, callback func(string, error) error) }
StatisticsClient is an interface implemented by a statistics client.
A unique ID is to be provided along with a description for the field to be displayed as output.
Multiple types of statistics are provided like Counters as well as static fields which display static information only.
A metric cannot be added once the client has been started. An error will be returned if the metric cannot be added. Already existing fields of same names are overwritten.