Documentation
¶
Overview ¶
Package clistats implements a progress bar like functionality which displays periodic progress based on various rules.
Rather than rendering and maintaining a dynamic progress bar, statistics are displayed in individual lines either based on user keystrokes or using a display alogrithm that observes changes in statistics over time.
It is heavily inspired from nmap which is a very popular security scanning tool.
Index ¶
- func FmtDuration(d time.Duration) string
- func String(from interface{}) string
- type DynamicCallback
- type PrintCallback
- 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) GetStatic(id string) (interface{}, bool)
- func (s *Statistics) IncrementCounter(id string, count int)
- func (s *Statistics) Start(printer PrintCallback, tickDuration time.Duration) error
- func (s *Statistics) Stop() error
- type StatisticsClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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 calculated things like elapsed time, requests per seconds, etc.
func NewRequestsPerSecondCallback ¶
func NewRequestsPerSecondCallback(options RequestPerSecondCallbackOptions) DynamicCallback
NewRequestsPerSecondCallback creates a request per second callback function.
type PrintCallback ¶
type PrintCallback func(client StatisticsClient)
PrintCallback is used by clients to build and display a string on the screen.
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 sent request 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 {
// 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.
func (*Statistics) AddCounter ¶
func (s *Statistics) AddCounter(id string, value uint64)
AddCounter adds a 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) 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(printer PrintCallback, tickDuration time.Duration) 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(printer PrintCallback, tickDuration time.Duration) 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)
}
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.