Documentation ¶
Overview ¶
Package stats includes helpers for writing stats to collectors by adding listeners to logger instances.
It also includes sub-packages for working with distributed tracing.
Index ¶
- Constants
- func AddDefaultTags(collector Collector, serviceName, serviceEnv, container string)
- func AddDefaultTagsFromEnv(collector Collector)
- func AddErrorListeners(log logger.Listenable, stats Collector)
- func AddErrorListenersByClass(log logger.Listenable, stats Collector)
- func Runtime(collector Collector)
- func SplitTag(tag string) (key, value string)
- func Tag(key, value string) string
- type Collector
- type Event
- type EventCollector
- type MockCollector
- func (mc *MockCollector) AddDefaultTag(name, value string)
- func (mc *MockCollector) AddDefaultTags(tags ...string)
- func (mc *MockCollector) AllMetrics() (output []MockMetric)
- func (mc MockCollector) Close() error
- func (mc MockCollector) Count(name string, value int64, tags ...string) error
- func (mc MockCollector) DefaultTags() []string
- func (mc MockCollector) Distribution(name string, value float64, tags ...string) error
- func (mc MockCollector) Flush() error
- func (mc MockCollector) Gauge(name string, value float64, tags ...string) error
- func (mc *MockCollector) GetCount(metricName string) (count int)
- func (mc *MockCollector) GetTagCount(metricName string, tagName string) (count int)
- func (mc MockCollector) Histogram(name string, value float64, tags ...string) error
- func (mc MockCollector) Increment(name string, tags ...string) error
- func (mc MockCollector) TimeInMilliseconds(name string, value time.Duration, tags ...string) error
- type MockEventCollector
- func (mec *MockEventCollector) AddDefaultTag(name, value string)
- func (mec *MockEventCollector) AddDefaultTags(tags ...string)
- func (mec MockEventCollector) CreateEvent(title, text string, tags ...string) Event
- func (mec MockEventCollector) DefaultTags() []string
- func (mec MockEventCollector) SendEvent(e Event) error
- type MockMetric
- type MultiCollector
- func (collectors MultiCollector) AddDefaultTag(name, value string)
- func (collectors MultiCollector) AddDefaultTags(tags ...string)
- func (collectors MultiCollector) Close() (err error)
- func (collectors MultiCollector) Count(name string, value int64, tags ...string) (err error)
- func (collectors MultiCollector) DefaultTags() (output []string)
- func (collectors MultiCollector) Distribution(name string, value float64, tags ...string) (err error)
- func (collectors MultiCollector) Flush() (err error)
- func (collectors MultiCollector) Gauge(name string, value float64, tags ...string) (err error)
- func (collectors MultiCollector) HasTagKey(tagKey string) bool
- func (collectors MultiCollector) Histogram(name string, value float64, tags ...string) (err error)
- func (collectors MultiCollector) Increment(name string, tags ...string) (err error)
- func (collectors MultiCollector) TimeInMilliseconds(name string, value time.Duration, tags ...string) (err error)
- type Printer
- func (p *Printer) AddDefaultTag(name, value string)
- func (p *Printer) AddDefaultTags(tags ...string)
- func (p Printer) Close() error
- func (p Printer) Count(name string, value int64, tags ...string) error
- func (p Printer) DefaultTags() []string
- func (p Printer) Distribution(name string, value float64, tags ...string) error
- func (p Printer) Flush() error
- func (p Printer) Gauge(name string, value float64, tags ...string) error
- func (p Printer) Histogram(name string, value float64, tags ...string) error
- func (p Printer) Increment(name string, tags ...string) error
- func (p Printer) TimeInMilliseconds(name string, value time.Duration, tags ...string) error
- type Taggable
Constants ¶
const ( TagClass string = "class" TagContainer string = "container" TagEnv string = "env" TagError string = "error" TagHostname string = "hostname" TagJob string = "job" TagService string = "service" TagSeverity string = "severity" TagVersion string = "version" )
Tag names are names for tags, either on metrics or traces.
const ( FilterNameSanitization = "sanitization" ListenerNameStats string = "stats" )
Specialized / default values
const ( // EventAlertTypeInfo is the "info" AlertType for events EventAlertTypeInfo = "info" // EventAlertTypeError is the "error" AlertType for events EventAlertTypeError = "error" // EventAlertTypeWarning is the "warning" AlertType for events EventAlertTypeWarning = "warning" // EventAlertTypeSuccess is the "success" AlertType for events EventAlertTypeSuccess = "success" )
const ( // EventPriorityNormal is the "normal" Priority for events. EventPriorityNormal = "normal" // EventPriorityLow is the "low" Priority for events. EventPriorityLow = "low" )
const (
MetricNameError string = string(logger.Error)
)
MetricNames are names we use when sending data to the collectors.
Variables ¶
This section is empty.
Functions ¶
func AddDefaultTags ¶ added in v0.3.0
AddDefaultTags adds default tags to a stats collector.
func AddDefaultTagsFromEnv ¶
func AddDefaultTagsFromEnv(collector Collector)
AddDefaultTagsFromEnv adds default tags to a collector from environment values.
func AddErrorListeners ¶
func AddErrorListeners(log logger.Listenable, stats Collector)
AddErrorListeners adds error listeners.
func AddErrorListenersByClass ¶ added in v1.20201204.1
func AddErrorListenersByClass(log logger.Listenable, stats Collector)
AddErrorListenersByClass adds error listeners that add an exception class tag.
NOTE: this will create many tag values if you do not use exceptions correctly, that is, if you put variable data in the exception class. If there is any doubt which of these to use (AddErrorListeners or AddErrorListenersByClass) use the version that does not add the class information (AddErrorListeners).
Types ¶
type Collector ¶
type Collector interface { Taggable Count(name string, value int64, tags ...string) error Increment(name string, tags ...string) error Gauge(name string, value float64, tags ...string) error Histogram(name string, value float64, tags ...string) error Distribution(name string, value float64, tags ...string) error TimeInMilliseconds(name string, value time.Duration, tags ...string) error Flush() error Close() error }
Collector is a stats collector.
type Event ¶
type Event struct { // Title of the event. Required. Title string // Text is the description of the event. Required. Text string // Timestamp is a timestamp for the event. If not provided, the dogstatsd // server will set this to the current time. Timestamp time.Time // Hostname for the event. Hostname string // AggregationKey groups this event with others of the same key. AggregationKey string // Priority of the event. Can be statsd.Low or statsd.Normal. Priority string // SourceTypeName is a source type for the event. SourceTypeName string // AlertType can be statsd.Info, statsd.Error, statsd.Warning, or statsd.Success. // If absent, the default value applied by the dogstatsd server is Info. AlertType string // Tags for the event. Tags []string }
Event is an event to be collected.
type EventCollector ¶
type EventCollector interface { Taggable SendEvent(Event) error CreateEvent(title, text string, tags ...string) Event }
EventCollector is a collector for events.
type MockCollector ¶
type MockCollector struct { Field struct { Namespace string DefaultTags []string } Metrics chan MockMetric Errors chan error FlushErrors chan error CloseErrors chan error }
MockCollector is a mocked collector for stats.
func NewMockCollector ¶
func NewMockCollector(capacity int) *MockCollector
NewMockCollector returns a new mock collector.
func (*MockCollector) AddDefaultTag ¶
func (mc *MockCollector) AddDefaultTag(name, value string)
AddDefaultTag adds a default tag.
func (*MockCollector) AddDefaultTags ¶ added in v1.20201204.1
func (mc *MockCollector) AddDefaultTags(tags ...string)
AddDefaultTags adds default tags.
func (*MockCollector) AllMetrics ¶ added in v1.20210103.1
func (mc *MockCollector) AllMetrics() (output []MockMetric)
AllMetrics returns all the metrics from the collector.
func (MockCollector) Close ¶ added in v1.20201204.1
func (mc MockCollector) Close() error
Close returns an error from the errors channel if any.
func (MockCollector) Count ¶
func (mc MockCollector) Count(name string, value int64, tags ...string) error
Count adds a mock count event to the event stream.
func (MockCollector) DefaultTags ¶
func (mc MockCollector) DefaultTags() []string
DefaultTags returns the default tags set.
func (MockCollector) Distribution ¶ added in v1.20210103.1
func (mc MockCollector) Distribution(name string, value float64, tags ...string) error
Distribution adds a mock count event to the event stream with value (1).
func (MockCollector) Flush ¶ added in v1.20201204.1
func (mc MockCollector) Flush() error
Flush does nothing on a MockCollector.
func (MockCollector) Gauge ¶
func (mc MockCollector) Gauge(name string, value float64, tags ...string) error
Gauge adds a mock count event to the event stream with value (1).
func (*MockCollector) GetCount ¶ added in v1.20201204.1
func (mc *MockCollector) GetCount(metricName string) (count int)
GetCount returns the number of events logged for a given metric name.
func (*MockCollector) GetTagCount ¶ added in v1.20210428.4
func (mc *MockCollector) GetTagCount(metricName string, tagName string) (count int)
GetTagCount returns the number of events logged for a given metric name & tag name.
func (MockCollector) Histogram ¶
func (mc MockCollector) Histogram(name string, value float64, tags ...string) error
Histogram adds a mock count event to the event stream with value (1).
func (MockCollector) Increment ¶
func (mc MockCollector) Increment(name string, tags ...string) error
Increment adds a mock count event to the event stream with value (1).
func (MockCollector) TimeInMilliseconds ¶
TimeInMilliseconds adds a mock time in millis event to the event stream with a value.
type MockEventCollector ¶
type MockEventCollector struct { Events chan Event // contains filtered or unexported fields }
MockEventCollector is a mocked collector for stats.
func NewMockEventCollector ¶
func NewMockEventCollector() *MockEventCollector
NewMockEventCollector returns a new mock collector.
func (*MockEventCollector) AddDefaultTag ¶
func (mec *MockEventCollector) AddDefaultTag(name, value string)
AddDefaultTag adds a default tag.
func (*MockEventCollector) AddDefaultTags ¶ added in v1.20201204.1
func (mec *MockEventCollector) AddDefaultTags(tags ...string)
AddDefaultTags adds default tags.
func (MockEventCollector) CreateEvent ¶
func (mec MockEventCollector) CreateEvent(title, text string, tags ...string) Event
CreateEvent creates a mock event with the default tags.
func (MockEventCollector) DefaultTags ¶
func (mec MockEventCollector) DefaultTags() []string
DefaultTags returns the default tags set.
func (MockEventCollector) SendEvent ¶
func (mec MockEventCollector) SendEvent(e Event) error
SendEvent sends an event.
type MockMetric ¶
type MockMetric struct { Name string Count int64 Gauge float64 Histogram float64 Distribution float64 TimeInMilliseconds float64 Tags []string }
MockMetric is a mock metric.
type MultiCollector ¶ added in v1.20201204.1
type MultiCollector []Collector
MultiCollector is a class that wraps a set of statsd collectors
func (MultiCollector) AddDefaultTag ¶ added in v1.20201204.1
func (collectors MultiCollector) AddDefaultTag(name, value string)
AddDefaultTag implements Taggable.
func (MultiCollector) AddDefaultTags ¶ added in v1.20201204.1
func (collectors MultiCollector) AddDefaultTags(tags ...string)
AddDefaultTags implements Taggable.
func (MultiCollector) Close ¶ added in v1.20201204.1
func (collectors MultiCollector) Close() (err error)
Close closes all collectors.
func (MultiCollector) Count ¶ added in v1.20201204.1
func (collectors MultiCollector) Count(name string, value int64, tags ...string) (err error)
Count increments a counter by a value and writes to the collectors.
func (MultiCollector) DefaultTags ¶ added in v1.20201204.1
func (collectors MultiCollector) DefaultTags() (output []string)
DefaultTags returns the unique default tags for the collectors.
func (MultiCollector) Distribution ¶ added in v1.20210103.1
func (collectors MultiCollector) Distribution(name string, value float64, tags ...string) (err error)
Distribution sets a distribution value and writes to the collectors.
func (MultiCollector) Flush ¶ added in v1.20201204.1
func (collectors MultiCollector) Flush() (err error)
Flush forces a flush on all collectors.
func (MultiCollector) Gauge ¶ added in v1.20201204.1
func (collectors MultiCollector) Gauge(name string, value float64, tags ...string) (err error)
Gauge sets a gauge value and writes to the collectors.
func (MultiCollector) HasTagKey ¶ added in v1.20210103.1
func (collectors MultiCollector) HasTagKey(tagKey string) bool
HasTagKey returns if the collector has a given tag key in *any* collector's default tags.
func (MultiCollector) Histogram ¶ added in v1.20201204.1
func (collectors MultiCollector) Histogram(name string, value float64, tags ...string) (err error)
Histogram sets a histogram value and writes to the collectors.
func (MultiCollector) Increment ¶ added in v1.20201204.1
func (collectors MultiCollector) Increment(name string, tags ...string) (err error)
Increment increments a counter by 1 and writes to the collectors.
func (MultiCollector) TimeInMilliseconds ¶ added in v1.20201204.1
func (collectors MultiCollector) TimeInMilliseconds(name string, value time.Duration, tags ...string) (err error)
TimeInMilliseconds sets a timing value and writes to the different hosts
type Printer ¶ added in v1.20210103.1
Printer is a collector that prints calls to a given writer.
func NewPrinter ¶ added in v1.20210103.1
NewPrinter creates a printer from a given logger.
func (*Printer) AddDefaultTag ¶ added in v1.20210103.1
AddDefaultTag adds a default tag.
func (*Printer) AddDefaultTags ¶ added in v1.20210103.1
AddDefaultTags adds default tags.
func (Printer) DefaultTags ¶ added in v1.20210103.1
DefaultTags returns the default tags set.
func (Printer) Distribution ¶ added in v1.20210103.1
Distribution implemenents stats.Collector.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package dbstats provides shims for writing db logger events to a stats collector.
|
Package dbstats provides shims for writing db logger events to a stats collector. |
Package grpcstats provides shims for writing rpc logger events to a stats collector.
|
Package grpcstats provides shims for writing rpc logger events to a stats collector. |
Package httpstats provides shims for writing webutil logger events to a stats collector.
|
Package httpstats provides shims for writing webutil logger events to a stats collector. |