plugins

package
v0.0.0-...-8ce2553 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2018 License: Apache-2.0, MIT Imports: 8 Imported by: 0

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

View Source
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

View Source
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

func NewDatadogCollector(addr, prefix string) (func(string) metricCollector.MetricCollector, error)

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) IncrementAttempts

func (dc *DatadogCollector) IncrementAttempts()

IncrementAttempts increments the number of calls to this circuit.

func (*DatadogCollector) IncrementErrors

func (dc *DatadogCollector) IncrementErrors()

IncrementErrors increments the number of unsuccessful attempts. Attempts minus Errors will equal successes within a time range. Errors are any result from an attempt that is not a success.

func (*DatadogCollector) IncrementFailures

func (dc *DatadogCollector) IncrementFailures()

IncrementFailures increments the number of requests that fail.

func (*DatadogCollector) IncrementFallbackFailures

func (dc *DatadogCollector) IncrementFallbackFailures()

IncrementFallbackFailures increments the number of failures that occurred during the execution of the fallback function.

func (*DatadogCollector) IncrementFallbackSuccesses

func (dc *DatadogCollector) IncrementFallbackSuccesses()

IncrementFallbackSuccesses increments the number of successes that occurred during the execution of the fallback function.

func (*DatadogCollector) IncrementRejects

func (dc *DatadogCollector) IncrementRejects()

IncrementRejects increments the number of requests that are rejected.

func (*DatadogCollector) IncrementShortCircuits

func (dc *DatadogCollector) IncrementShortCircuits()

IncrementShortCircuits increments the number of requests that short circuited due to the circuit being open.

func (*DatadogCollector) IncrementSuccesses

func (dc *DatadogCollector) IncrementSuccesses()

IncrementSuccesses increments the number of requests that succeed.

func (*DatadogCollector) IncrementTimeouts

func (dc *DatadogCollector) IncrementTimeouts()

IncrementTimeouts increments the number of timeouts that occurred in the circuit breaker.

func (*DatadogCollector) Reset

func (dc *DatadogCollector) Reset()

Reset is a noop operation in this collector.

func (*DatadogCollector) UpdateRunDuration

func (dc *DatadogCollector) UpdateRunDuration(runDuration time.Duration)

UpdateRunDuration updates the internal counter of how long the last run took.

func (*DatadogCollector) UpdateTotalDuration

func (dc *DatadogCollector) UpdateTotalDuration(timeSinceStart time.Duration)

UpdateTotalDuration updates the internal counter of how long we've run for.

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) IncrementAttempts

func (g *GraphiteCollector) IncrementAttempts()

IncrementAttempts increments the number of calls to this circuit. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementErrors

func (g *GraphiteCollector) IncrementErrors()

IncrementErrors increments the number of unsuccessful attempts. Attempts minus Errors will equal successes within a time range. Errors are any result from an attempt that is not a success. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementFailures

func (g *GraphiteCollector) IncrementFailures()

IncrementFailures increments the number of requests that fail. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementFallbackFailures

func (g *GraphiteCollector) IncrementFallbackFailures()

IncrementFallbackFailures increments the number of failures that occurred during the execution of the fallback function. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementFallbackSuccesses

func (g *GraphiteCollector) IncrementFallbackSuccesses()

IncrementFallbackSuccesses increments the number of successes that occurred during the execution of the fallback function. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementRejects

func (g *GraphiteCollector) IncrementRejects()

IncrementRejects increments the number of requests that are rejected. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementShortCircuits

func (g *GraphiteCollector) IncrementShortCircuits()

IncrementShortCircuits increments the number of requests that short circuited due to the circuit being open. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementSuccesses

func (g *GraphiteCollector) IncrementSuccesses()

IncrementSuccesses increments the number of requests that succeed. This registers as a counter in the graphite collector.

func (*GraphiteCollector) IncrementTimeouts

func (g *GraphiteCollector) IncrementTimeouts()

IncrementTimeouts increments the number of timeouts that occurred in the circuit breaker. This registers as a counter in the graphite collector.

func (*GraphiteCollector) Reset

func (g *GraphiteCollector) Reset()

Reset is a noop operation in this collector.

func (*GraphiteCollector) UpdateRunDuration

func (g *GraphiteCollector) UpdateRunDuration(runDuration time.Duration)

UpdateRunDuration updates the internal counter of how long the last run took. This registers as a timer in the graphite collector.

func (*GraphiteCollector) UpdateTotalDuration

func (g *GraphiteCollector) UpdateTotalDuration(timeSinceStart time.Duration)

UpdateTotalDuration updates the internal counter of how long we've run for. This registers as a timer in the graphite collector.

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) IncrementAttempts

func (g *StatsdCollector) IncrementAttempts()

IncrementAttempts increments the number of calls to this circuit. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementErrors

func (g *StatsdCollector) IncrementErrors()

IncrementErrors increments the number of unsuccessful attempts. Attempts minus Errors will equal successes within a time range. Errors are any result from an attempt that is not a success. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementFailures

func (g *StatsdCollector) IncrementFailures()

IncrementFailures increments the number of requests that fail. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementFallbackFailures

func (g *StatsdCollector) IncrementFallbackFailures()

IncrementFallbackFailures increments the number of failures that occurred during the execution of the fallback function. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementFallbackSuccesses

func (g *StatsdCollector) IncrementFallbackSuccesses()

IncrementFallbackSuccesses increments the number of successes that occurred during the execution of the fallback function. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementRejects

func (g *StatsdCollector) IncrementRejects()

IncrementRejects increments the number of requests that are rejected. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementShortCircuits

func (g *StatsdCollector) IncrementShortCircuits()

IncrementShortCircuits increments the number of requests that short circuited due to the circuit being open. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementSuccesses

func (g *StatsdCollector) IncrementSuccesses()

IncrementSuccesses increments the number of requests that succeed. This registers as a counter in the Statsd collector.

func (*StatsdCollector) IncrementTimeouts

func (g *StatsdCollector) IncrementTimeouts()

IncrementTimeouts increments the number of timeouts that occurred in the circuit breaker. This registers as a counter in the Statsd collector.

func (*StatsdCollector) Reset

func (g *StatsdCollector) Reset()

Reset is a noop operation in this collector.

func (*StatsdCollector) UpdateRunDuration

func (g *StatsdCollector) UpdateRunDuration(runDuration time.Duration)

UpdateRunDuration updates the internal counter of how long the last run took. This registers as a timer in the Statsd collector.

func (*StatsdCollector) UpdateTotalDuration

func (g *StatsdCollector) UpdateTotalDuration(timeSinceStart time.Duration)

UpdateTotalDuration updates the internal counter of how long we've run for. This registers as a timer in the Statsd collector.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL