Documentation ¶
Overview ¶
Plugins allows users to operate on statistics recorded for each circuit operation. Plugins should be careful to be lightweight as they will be called frequently.
Index ¶
- Constants
- func InitializeGraphiteCollector(config *GraphiteCollectorConfig)
- func NewDatadogCollector(addr, prefix string) (func(string) metricCollector.MetricCollector, error)
- func NewDatadogCollectorWithClient(client DatadogClient) func(string) metricCollector.MetricCollector
- func NewGraphiteCollector(name string) metricCollector.MetricCollector
- type DatadogClient
- type DatadogCollector
- type GraphiteCollector
- type GraphiteCollectorConfig
- type StatsdCollector
- type StatsdCollectorClient
- type StatsdCollectorConfig
Constants ¶
const ( // DM = Datadog Metric DM_CircuitOpen = "hystrix.circuitOpen" DM_Attempts = "hystrix.attempts" DM_Errors = "hystrix.errors" DM_Successes = "hystrix.successes" DM_Failures = "hystrix.failures" DM_Rejects = "hystrix.rejects" DM_ShortCircuits = "hystrix.shortCircuits" DM_Timeouts = "hystrix.timeouts" DM_FallbackSuccesses = "hystrix.fallbackSuccesses" DM_FallbackFailures = "hystrix.fallbackFailures" DM_TotalDuration = "hystrix.totalDuration" DM_RunDuration = "hystrix.runDuration" )
These metrics are constants because we're leveraging the Datadog tagging extension to statsd.
They only apply to the DatadogCollector and are only useful if providing your own implemenation of DatadogClient
const ( WANStatsdFlushBytes = 512 LANStatsdFlushBytes = 1432 GigabitStatsdFlushBytes = 8932 )
https://github.com/etsy/statsd/blob/master/docs/metric_types.md#multi-metric-packets
Variables ¶
This section is empty.
Functions ¶
func InitializeGraphiteCollector ¶
func InitializeGraphiteCollector(config *GraphiteCollectorConfig)
InitializeGraphiteCollector creates the connection to the graphite server and should be called before any metrics are recorded.
func NewDatadogCollector ¶
NewDatadogCollector creates a collector for a specific circuit with a "github.com/DataDog/datadog-go/statsd".(*Client).
addr is in the format "<host>:<port>" (e.g. "localhost:8125")
prefix may be an empty string
Example use
package main import ( "github.com/afex/hystrix-go/plugins" "github.com/afex/hystrix-go/hystrix/metric_collector" ) func main() { collector, err := plugins.NewDatadogCollector("localhost:8125", "") if err != nil { panic(err) } metricCollector.Registry.Register(collector) }
func NewDatadogCollectorWithClient ¶
func NewDatadogCollectorWithClient(client DatadogClient) func(string) metricCollector.MetricCollector
NewDatadogCollectorWithClient accepts an interface which allows you to provide your own implementation of a statsd client, alter configuration on "github.com/DataDog/datadog-go/statsd".(*Client), provide additional tags per circuit-metric tuple, and add logging if you need it.
func NewGraphiteCollector ¶
func NewGraphiteCollector(name string) metricCollector.MetricCollector
NewGraphiteCollector creates a collector for a specific circuit. The prefix given to this circuit will be {config.Prefix}.{circuit_name}.{metric}. Circuits with "/" in their names will have them replaced with ".".
Types ¶
type DatadogClient ¶
type DatadogClient interface { Count(name string, value int64, tags []string, rate float64) error Gauge(name string, value float64, tags []string, rate float64) error TimeInMilliseconds(name string, value float64, tags []string, rate float64) error }
DatadogClient is the minimum interface needed by NewDatadogCollectorWithClient
type DatadogCollector ¶
type DatadogCollector struct {
// contains filtered or unexported fields
}
DatadogCollector fulfills the metricCollector interface allowing users to ship circuit stats to Datadog.
This Collector, by default, uses github.com/DataDog/datadog-go/statsd for transport. The main advantage of this over statsd is building graphs and multi-alert monitors around single metrics (constantized above) and adding tag dimensions. You can set up a single monitor to rule them all across services and geographies. Graphs become much simpler to setup by allowing you to create queries like the following
{ "viz": "timeseries", "requests": [ { "q": "max:hystrix.runDuration.95percentile{$region} by {hystrixcircuit}", "type": "line" } ] }
As new circuits come online you get graphing and monitoring "for free".
func (*DatadogCollector) Reset ¶
func (dc *DatadogCollector) Reset()
Reset is a noop operation in this collector.
func (*DatadogCollector) Update ¶
func (dc *DatadogCollector) Update(r metricCollector.MetricResult)
type GraphiteCollector ¶
type GraphiteCollector struct {
// contains filtered or unexported fields
}
GraphiteCollector fulfills the metricCollector interface allowing users to ship circuit stats to a graphite backend. To use users must call InitializeGraphiteCollector before circuits are started. Then register NewGraphiteCollector with metricCollector.Registry.Register(NewGraphiteCollector).
This Collector uses github.com/rcrowley/go-metrics for aggregation. See that repo for more details on how metrics are aggregated and expressed in graphite.
func (*GraphiteCollector) Reset ¶
func (g *GraphiteCollector) Reset()
Reset is a noop operation in this collector.
func (*GraphiteCollector) Update ¶
func (g *GraphiteCollector) Update(r metricCollector.MetricResult)
type GraphiteCollectorConfig ¶
type GraphiteCollectorConfig struct { // GraphiteAddr is the tcp address of the graphite server GraphiteAddr *net.TCPAddr // Prefix is the prefix that will be prepended to all metrics sent from this collector. Prefix string // TickInterval spcifies the period that this collector will send metrics to the server. TickInterval time.Duration }
GraphiteCollectorConfig provides configuration that the graphite client will need.
type StatsdCollector ¶
type StatsdCollector struct {
// contains filtered or unexported fields
}
StatsdCollector fulfills the metricCollector interface allowing users to ship circuit stats to a Statsd backend. To use users must call InitializeStatsdCollector before circuits are started. Then register NewStatsdCollector with metricCollector.Registry.Register(NewStatsdCollector).
This Collector uses https://github.com/cactus/go-statsd-client/ for transport.
func (*StatsdCollector) Reset ¶
func (g *StatsdCollector) Reset()
Reset is a noop operation in this collector.
func (*StatsdCollector) Update ¶
func (g *StatsdCollector) Update(r metricCollector.MetricResult)
type StatsdCollectorClient ¶
type StatsdCollectorClient struct {
// contains filtered or unexported fields
}
func InitializeStatsdCollector ¶
func InitializeStatsdCollector(config *StatsdCollectorConfig) (*StatsdCollectorClient, error)
InitializeStatsdCollector creates the connection to the Statsd server and should be called before any metrics are recorded.
Users should ensure to call Close() on the client.
func (*StatsdCollectorClient) NewStatsdCollector ¶
func (s *StatsdCollectorClient) NewStatsdCollector(name string) metricCollector.MetricCollector
NewStatsdCollector creates a collector for a specific circuit. The prefix given to this circuit will be {config.Prefix}.{circuit_name}.{metric}. Circuits with "/" in their names will have them replaced with ".".
type StatsdCollectorConfig ¶
type StatsdCollectorConfig struct { // StatsdAddr is the tcp address of the Statsd server StatsdAddr string // Prefix is the prefix that will be prepended to all metrics sent from this collector. Prefix string // StatsdSampleRate sets statsd sampling. If 0, defaults to 1.0. (no sampling) SampleRate float32 // FlushBytes sets message size for statsd packets. If 0, defaults to LANFlushSize. FlushBytes int }
StatsdCollectorConfig provides configuration that the Statsd client will need.