Documentation ¶
Index ¶
Constants ¶
const ( // ProtocolTCP is a constant to specify the protocol TCP ProtocolTCP = "tcp" // ProtocolUDP is a constant to specify the protocol UDP ProtocolUDP = "udp" )
const ( // DefaultTimeout specifies the default timeout to use when connecting to graphite. DefaultTimeout = 1 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator interface { AddSum(string, interface{}) Increase(string) AddAverage(string, interface{}) SetActive(string) SetInactive(string) Run(time.Duration, chan bool) Aggregator Flush() (int, error) Retry() (int, error) }
Aggregator is an interface exposing the methods that we can use to work with different kinds of metrics in a transparent way for the user.
type Config ¶
type Config struct { // Host is a string specifying the address where graphite is listening. It can be // a host name "example.com" or an IP address "219.123.43.21". This field is required. Host string // Port is an integer specifying the port where graphite is listening. This field is required. Port int // Namespace specifies a prefix to use for all the metrics, so we don't need to set it // every time we want to send something. Namespace string // Timeout specifies a new timeout in time.Duration format in case we want to increase/decrease // the default one. Defaults to 1 second. Timeout time.Duration // ForceReconnect is a boolean specifying if we want to force a reconnection every time we send metrics // to graphite. This is useful when working with AWS ELB or any other network components that might // be tampering with the connections. ForceReconnect bool }
Config stores the configuration to pass to the graphite client.
type Graphite ¶
type Graphite interface { Send(string, string) (int, error) SendBuffer(*bytes.Buffer) (int, error) NewAggregator() Aggregator Connect() error Reconnect() error Disconnect() error }
Graphite is an interface for a graphite client
func NewGraphiteTCP ¶
NewGraphiteTCP creates a new graphite client based on TCP.
func NewGraphiteUDP ¶
NewGraphiteUDP creates a new graphite client based on UDP.
type Metric ¶
type Metric interface { // Update receives a generic value through interface{} to update its internal value. Update(interface{}) // Clear is used to reset the metric to the initial value. Clear() // Calculate is used to perform the necessary operations to retrieve the final value // that will be sent to graphite, standarised as a string. Calculate() string }
Metric is an interface to be able to create new metric types easily. Each metric must have some methods to be able to be used by the Aggregator.
type MetricActive ¶
type MetricActive struct {
State bool
}
MetricActive creates a metric to set a boolean status in graphite.
func (*MetricActive) Calculate ¶
func (metric *MetricActive) Calculate() string
Calculate calculates the value to send.
func (*MetricActive) Clear ¶
func (metric *MetricActive) Clear()
Clear reinitiales the value to inactive.
func (*MetricActive) Update ¶
func (metric *MetricActive) Update(value interface{})
Update sets the active/inactive status through a boolean.
type MetricAverage ¶
MetricAverage creates a metric to store the average value between several values.
func (*MetricAverage) Calculate ¶
func (metric *MetricAverage) Calculate() string
Calculate calculates the value to send.
func (*MetricAverage) Clear ¶
func (metric *MetricAverage) Clear()
Clear reinitiales the average value and counter.
func (*MetricAverage) Update ¶
func (metric *MetricAverage) Update(value interface{})
Update increases the components necessary to calculate afterwards the average value. Each time the metric is updated, the result of Calculate will change.