Documentation ¶
Overview ¶
Package spectator provides a minimal Go implementation of the Netflix Java Spectator library. The goal of this package is to allow Go programs to emit metrics to Atlas.
Please refer to the Java Spectator documentation for information on spectator / Atlas fundamentals: https://netflix.github.io/spectator/en/latest/
Index ¶
- func CollectMemStats(registry *Registry)
- func CollectRuntimeMetrics(registry *Registry)
- func CollectSysStats(registry *Registry)
- type Clock
- type Config
- type Counter
- type DefaultLogger
- type DistributionSummary
- type Gauge
- type HttpClient
- type HttpClientOption
- type HttpResponse
- type Id
- func (id *Id) MapKey() string
- func (id *Id) Name() string
- func (id *Id) String() string
- func (id *Id) Tags() map[string]string
- func (id *Id) WithDefaultStat(stat string) *Id
- func (id *Id) WithStat(stat string) *Id
- func (id *Id) WithTag(key string, value string) *Id
- func (id *Id) WithTags(tags map[string]string) *Id
- type LogEntry
- type Logger
- type ManualClock
- type Measurement
- type Meter
- type MeterFactoryFun
- type MonotonicCounter
- type Registry
- func (r *Registry) Clock() Clock
- func (r *Registry) Count() int
- func (r *Registry) Counter(name string, tags map[string]string) *Counter
- func (r *Registry) CounterWithId(id *Id) *Counter
- func (r *Registry) DistributionSummary(name string, tags map[string]string) *DistributionSummary
- func (r *Registry) DistributionSummaryWithId(id *Id) *DistributionSummary
- func (r *Registry) Gauge(name string, tags map[string]string) *Gauge
- func (r *Registry) GaugeWithId(id *Id) *Gauge
- func (r *Registry) GetLogger() Logger
- func (r *Registry) Measurements() []Measurement
- func (r *Registry) Meters() []Meter
- func (r *Registry) NewId(name string, tags map[string]string) *Id
- func (r *Registry) NewMeter(id *Id, meterFactory MeterFactoryFun) Meter
- func (r *Registry) SetLogger(logger Logger)
- func (r *Registry) Start() error
- func (r *Registry) Stop()
- func (r *Registry) Timer(name string, tags map[string]string) *Timer
- func (r *Registry) TimerWithId(id *Id) *Timer
- type SystemClock
- type Timer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CollectMemStats ¶
func CollectMemStats(registry *Registry)
CollectMemStats collects memory stats
func CollectRuntimeMetrics ¶
func CollectRuntimeMetrics(registry *Registry)
CollectRuntimeMetrics starts the collection of memory and file handle metrics
func CollectSysStats ¶
func CollectSysStats(registry *Registry)
CollectSysStats collects system stats: current/max file handles, number of goroutines
Types ¶
type Config ¶
type Config struct { Frequency time.Duration `json:"frequency"` Timeout time.Duration `json:"timeout"` Uri string `json:"uri"` BatchSize int `json:"batch_size"` CommonTags map[string]string `json:"common_tags"` PublishWorkers int64 `json:"publish_workers"` Log Logger IsEnabled func() bool IpcTimerRecord func(registry *Registry, id *Id, duration time.Duration) }
Config represents the Registry's configuration.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is used to measure the rate at which some event is occurring. This type is safe for concurrent use.
You can find more about this type by viewing the relevant Java Spectator documentation here:
https://netflix.github.io/spectator/en/latest/intro/counter/
func NewCounter ¶
NewCounter generates a new counter, using the provided meter identifier.
func (*Counter) Measure ¶
func (c *Counter) Measure() []Measurement
Measure returns the list of measurements known by the counter. This will either contain one item, the last value, or no items. This also resets the internal counter to 0.0.
type DefaultLogger ¶
type DefaultLogger struct {
// contains filtered or unexported fields
}
DefaultLogger is a plain text stdout logger.
func (*DefaultLogger) Debugf ¶
func (l *DefaultLogger) Debugf(format string, v ...interface{})
Debugf is for debug level messages. Satisfies Logger interface.
func (*DefaultLogger) Errorf ¶
func (l *DefaultLogger) Errorf(format string, v ...interface{})
Errorf is for error level messages. Satisfies Logger interface.
func (*DefaultLogger) Infof ¶
func (l *DefaultLogger) Infof(format string, v ...interface{})
Infof is for info level messages. Satisfies Logger interface.
type DistributionSummary ¶
type DistributionSummary struct {
// contains filtered or unexported fields
}
DistributionSummary is used to track the distribution of events. This is safe for concurrent use.
You can find more about this type by viewing the relevant Java Spectator documentation here:
https://netflix.github.io/spectator/en/latest/intro/dist-summary/
func NewDistributionSummary ¶
func NewDistributionSummary(id *Id) *DistributionSummary
NewDistributionSummary generates a new distribution summary, using the provided meter identifier.
func (*DistributionSummary) Count ¶
func (d *DistributionSummary) Count() int64
Count returns the number of unique events that have been tracked.
func (*DistributionSummary) Measure ¶
func (d *DistributionSummary) Measure() []Measurement
Measure returns the list of measurements known by the counter. This should return 4 measurements in the slice:
count totalAmount totalOfSquares max
func (*DistributionSummary) MeterId ¶
func (d *DistributionSummary) MeterId() *Id
MeterId returns the meter identifier.
func (*DistributionSummary) Record ¶
func (d *DistributionSummary) Record(amount int64)
Record records a new value to track within the distribution.
func (*DistributionSummary) TotalAmount ¶
func (d *DistributionSummary) TotalAmount() int64
TotalAmount is the total of all records summed together.
type Gauge ¶
type Gauge struct {
// contains filtered or unexported fields
}
Gauge represents a value that is sampled at a specific point in time. One example might be the pending messages in a queue. This type is safe for concurrent use.
You can find more about this type by viewing the relevant Java Spectator documentation here:
https://netflix.github.io/spectator/en/latest/intro/gauge/
func (*Gauge) Measure ¶
func (g *Gauge) Measure() []Measurement
Measure returns the list of measurements known by the gauge. This will either contain one item (the current value). This also resets the internal value to NaN.
type HttpClient ¶
HttpClient represents a spectator HTTP client.
func NewHttpClient ¶
func NewHttpClient(registry *Registry, timeout time.Duration, opts ...HttpClientOption) *HttpClient
NewHttpClient generates a new *HttpClient, allowing us to specify the timeout on requests.
func (*HttpClient) PostJson ¶
func (h *HttpClient) PostJson(uri string, jsonBytes []byte) (response HttpResponse, err error)
PostJson attempts to submit JSON to the uri, with a 100 ms delay between failures.
type HttpClientOption ¶ added in v0.1.4
type HttpClientOption func(client *HttpClient)
func WithCompressThreshold ¶ added in v0.2.0
func WithCompressThreshold(threshold int) HttpClientOption
WithCompressThreshold is an HttpClientOption that specifies the size threshold for compressing payloads. A value of 0 disables compression.
type HttpResponse ¶ added in v0.1.2
HttpResponse represents a read HTTP response.
type Id ¶
type Id struct {
// contains filtered or unexported fields
}
Id represents a meter's identifying information and dimensions (tags).
func NewId ¶
NewId generates a new *Id from the metric name, and the tags you want to include on your metric.
func (*Id) MapKey ¶ added in v0.1.1
MapKey computes and saves a key within the struct to be used to uniquely identify this *Id in a map. This does use the information from within the *Id, so it assumes you've not accidentally double-declared this *Id.
func (*Id) Tags ¶
Tags directly exposes the internal tags map. This is not a copy of the map, so any modifications to it will be observed by the *Id.
func (*Id) WithDefaultStat ¶
WithDefaultStat is effectively the WithStat() method, except it only creates the deep copy if the "statistic" tag is not set or is set to empty string. If the "statistic" tag is already present, the *Id is returned without being copied.
func (*Id) WithStat ¶
WithStat is id.WithTag("statistic", stat). See that method's documentation for more info.
type LogEntry ¶
type LogEntry struct {
// contains filtered or unexported fields
}
LogEntry represents a type for logging the information about POST requests to the remote endpoint. It's not really a log, so much as a specific collector for the registry's outbound HTTP requests.
func NewLogEntry ¶
NewLogEntry creates a new LogEntry.
func (*LogEntry) Log ¶
func (entry *LogEntry) Log()
Log captures the time it took for the request to be completed, and records it within the registry.
func (*LogEntry) SetAttempt ¶
SetAttempt sets the ipc.attempt and ipc.attempt.final tags.
func (*LogEntry) SetError ¶
SetError sets the ipc.result tag to "failure", and the ipc.status tag to the error string.
func (*LogEntry) SetStatusCode ¶
SetStatusCode is for setting the http.status tag.
func (*LogEntry) SetSuccess ¶
func (entry *LogEntry) SetSuccess()
SetSuccess sets both ipc.result and ipc.status to "success".
type Logger ¶
type Logger interface { Debugf(format string, v ...interface{}) Infof(format string, v ...interface{}) Errorf(format string, v ...interface{}) }
Logger represents the shape of the logging dependency that the spectator library expects.
type ManualClock ¶
type ManualClock struct {
// contains filtered or unexported fields
}
ManualClock satisfies the Clock interface, using provided values as the time source. You need to seed the time with either .SetFromDuration() or .SetNanos().
func (*ManualClock) Nanos ¶
func (c *ManualClock) Nanos() int64
Nanos returns the internal nanoseconds. Satisfies Clock interface.
func (*ManualClock) Now ¶
func (c *ManualClock) Now() time.Time
Now effectively returns time.Unix(0, c.Nanos()). Satisfies Clock interface.
func (*ManualClock) SetFromDuration ¶
func (c *ManualClock) SetFromDuration(duration time.Duration)
SetFromDuration takes a duration, and sets that to the internal nanosecond value. The .Now() probably has no value when this is used to populate the data.
func (*ManualClock) SetNanos ¶
func (c *ManualClock) SetNanos(nanos int64)
SetNanos sets the internal nanoseconds value directly.
type Measurement ¶
type Measurement struct {
// contains filtered or unexported fields
}
Measurement represents a single meter's measurement at a given point in time.
func NewMeasurement ¶
func NewMeasurement(id *Id, Value float64) Measurement
NewMeasurement generates a new measurement, using the provided identifier and value.
func (Measurement) String ¶
func (m Measurement) String() string
func (Measurement) Value ¶
func (m Measurement) Value() float64
Value returns the measurement's value.
type Meter ¶
type Meter interface { MeterId() *Id Measure() []Measurement }
Meter represents the functionality presented by the individual meter types.
type MeterFactoryFun ¶
type MeterFactoryFun func() Meter
MeterFactoryFun is a type to allow dependency injection of the function used to generate meters.
type MonotonicCounter ¶
type MonotonicCounter struct {
// contains filtered or unexported fields
}
MonotonicCounter is used track a monotonically increasing counter.
You can find more about this type by viewing the relevant Java Spectator documentation here:
https://netflix.github.io/spectator/en/latest/intro/gauge/#monotonic-counters
func NewMonotonicCounter ¶
func NewMonotonicCounter(registry *Registry, name string, tags map[string]string) *MonotonicCounter
NewMonotonicCounter generates a new monotonic counter, taking the registry so that it can lazy-load the underlying counter once `Set` is called the first time. It generates a new meter identifier from the name and tags.
func NewMonotonicCounterWithId ¶
func NewMonotonicCounterWithId(registry *Registry, id *Id) *MonotonicCounter
NewMonotonicCounterWithId generates a new monotonic counter, using the provided meter identifier.
func (*MonotonicCounter) Count ¶
func (c *MonotonicCounter) Count() int64
Count returns the current counter value.
func (*MonotonicCounter) Set ¶
func (c *MonotonicCounter) Set(amount int64)
Set adds amount to the current counter.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is the collection of meters being reported.
func NewRegistry ¶
NewRegistry generates a new registry from the config.
If the config.IpcTimerRecord is unset, a default implementation is used.
If config.IsEnabled is unset, it defaults to an implementation that returns true.
If config.Log is unset, it defaults to using the default logger.
func NewRegistryConfiguredBy ¶
NewRegistryConfiguredBy loads a new Config JSON file from disk at the path specified.
Please note, when this method is used to load the configuration both Config.Frequency and Config.Timeout are assumed to not be a time.Duration but an int64 with second precision. As such this function multiplies those configuration values by time.Second, to convert them to time.Duration values.
func NewRegistryWithClock ¶
NewRegistryWithClock returns a new registry with the clock overriden to the one injected here. This function is mostly used for testing.
func (*Registry) Counter ¶
Counter calls NewId() with the name and tags, and then calls r.CounterWithId() using that *Id.
func (*Registry) CounterWithId ¶
CounterWithId returns a new *Counter, using the provided meter identifier.
func (*Registry) DistributionSummary ¶
func (r *Registry) DistributionSummary(name string, tags map[string]string) *DistributionSummary
DistributionSummary calls NewId() using the name and tags, and then calls r.DistributionSummaryWithId() using that *Id.
func (*Registry) DistributionSummaryWithId ¶
func (r *Registry) DistributionSummaryWithId(id *Id) *DistributionSummary
DistributionSummaryWithId returns a new *DistributionSummary, using the provided meter identifier.
func (*Registry) Gauge ¶
Gauge calls NewId() with the name and tags, and then calls r.GaugeWithId() using that *Id.
func (*Registry) GaugeWithId ¶
GaugeWithId returns a new *Gauge, using the provided meter identifier.
func (*Registry) Measurements ¶
func (r *Registry) Measurements() []Measurement
Measurements returns the list of internal measurements that should be sent.
func (*Registry) NewMeter ¶
func (r *Registry) NewMeter(id *Id, meterFactory MeterFactoryFun) Meter
NewMeter registers a new meter internally, and then returns it to the caller. The meterFactory is used to generate this meter. If the id.MapKey() is already present in the internal collection, that is returned instead of creating a new one.
func (*Registry) Stop ¶
func (r *Registry) Stop()
Stop shuts down the running goroutine(s), and attempts to flush the metrics.
func (*Registry) Timer ¶
Timer calls NewId() with the name and tags, and then calls r.TimerWithId() using that *Id.
func (*Registry) TimerWithId ¶
TimerWithId returns a new *Timer, using the provided meter identifier.
type SystemClock ¶
type SystemClock struct{}
SystemClock satisfies the Clock interface, using the system's time as its source.
func (*SystemClock) Nanos ¶
func (c *SystemClock) Nanos() int64
Nanos returns time.Now().UnixNano(). Satisfies Clock interface.
func (*SystemClock) Now ¶
func (c *SystemClock) Now() time.Time
Now returns time.Now(). Satisfies Clock interface.
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer is used to measure how long (in seconds) some event is taking. This type is safe for concurrent use.
func (*Timer) Measure ¶
func (t *Timer) Measure() []Measurement
Measure returns the list of measurements known by the counter. This should return 4 measurements in the slice:
count totalTime totalOfSquares max