metrics

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte  = 1
	KByte = Byte * 1000
	MByte = KByte * 1000
	GByte = MByte * 1000
	TByte = GByte * 1000
)

Constants for computing the size buckets

Variables

View Source
var DefaultStatsd statsd.Statsd

DefaultStatsd is the default statsd implementation

Functions

func Absolute

func Absolute(stat string, value int64) error

Absolute calls Absolute on DefaultStatsd

func Close

func Close() error

Close calls Close on DefaultStatsd

func CreateSocket

func CreateSocket() error

CreateSocket calls CreateSocket on DefaultStatsd

func Decr

func Decr(stat string, count int64) error

Decr calls Decr on DefaultStatsd

func Duration

func Duration(start int64) int64

Duration provided a start time in milliseconds, returns the difference / duration between that time and the time of Duration being called as an int64. The returned calue is the duration in time in milliseconds.

func FAbsolute

func FAbsolute(stat string, value float64) error

FAbsolute calls FAbsolute on DefaultStatsd

func FGauge

func FGauge(stat string, value float64) error

FGauge calls FGauge on DefaultStatsd

func FGaugeDelta

func FGaugeDelta(stat string, value float64) error

FGaugeDelta calls FGaugeDelta on DefaultStatsd

func Gauge

func Gauge(stat string, value int64) error

Gauge calls Gauge on DefaultStatsd

func GaugeDelta

func GaugeDelta(stat string, value int64) error

GaugeDelta calls GaugeDelta on DefaultStatsd

func Handler

func Handler(next http.Handler, endpoint string) http.Handler

Handler provides a middleware that will report how much time the wrapped handler took

func HandlerFunc

func HandlerFunc(next http.HandlerFunc, endpoint string) http.Handler

HandlerFunc is a convenience method to wrap http.HandlerFunc with the middleware

func HandlerFuncCtx

func HandlerFuncCtx(h func(context.Context, http.ResponseWriter, *http.Request), endpoint string) http.Handler

HandlerFuncCtx is the same implementation as Handler but accepts context.Context as the first parameter

func Incr

func Incr(stat string, count int64) error

Incr calls Incr on DefaultStatsd

func IncrPanic

func IncrPanic()

IncrPanic increment number of panics of the app

func InstrumentRouter

func InstrumentRouter(r *mux.Router) error

InstrumentRouter walks all the handlers on a mux.Router and wraps each route's handler with a metrics Handler for reporting sanitized route timing metrics

func MSTime

func MSTime() int64

MSTime returns the current time in milliseconds.

func Middleware

func Middleware(next http.Handler) http.Handler

Middleware is a metrics handler middleware. If your route contains wildcards (ie `/some/route/with/{id_of_object}/foo`) you should not use this middleware as it will create individual metrics for each value of `{id_of_object}`. Instead, you want to use Handler() and send it the same route that you gave to the router, but sanitized.

func PrecisionTiming

func PrecisionTiming(stat string, delta time.Duration) error

PrecisionTiming calls PrecisionTiming on DefaultStatsd

func Range

func Range(size int64) string

Range returns a size range string based on the input size in bytes

func SanitizeRoute

func SanitizeRoute(method, route string) string

SanitizeRoute cleans up a route for the Gorilla Mux to be used as a metric name

func Statsd

func Statsd(service string) statsd.Statsd

Statsd returns a ready to use Statsd interface, in case of error connecting to the statsd instance returns a no operation interface, Connection with Statsd is UDP (fire and forget) is recommended to use just one instance, to send all the stats, and call Close when the service stops to

func Timer

func Timer() func() int64

Timer returns a function which returns an int64 that represents the difference in time between Time being called and the returning function being called in milliseconds.

func Timing

func Timing(stat string, delta int64) error

Timing calls Timing on DefaultStatsd

func Total

func Total(stat string, value int64) error

Total calls Total on DefaultStatsd

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config contains all the logic for parsing command line flags.

func NewConfig

func NewConfig(l *logger.L, flag *flag.FlagSet, appName string) *Config

NewConfig prepares a new configuration for parsing CLI flags.

func (*Config) Service

func (cfg *Config) Service(ctx context.Context, l *logger.L) error

Service sets the DefaultStatsd with a given service name that should be call just once on the service intialization in case the env variable 'gm_service' is not set.

type LoggingClient

type LoggingClient struct {
	// contains filtered or unexported fields
}

LoggingClient is a client that dumps stats to a Logger

func NewLoggingClient

func NewLoggingClient(l *logger.L, level string) *LoggingClient

NewLoggingClient creates a new logging client that will log to logger

func (*LoggingClient) Absolute

func (c *LoggingClient) Absolute(stat string, value int64) error

Absolute logs a Absolute operation

func (*LoggingClient) Close

func (c *LoggingClient) Close() error

Close is a noop

func (*LoggingClient) CreateSocket

func (c *LoggingClient) CreateSocket() error

CreateSocket is a noop

func (*LoggingClient) CreateTCPSocket

func (c *LoggingClient) CreateTCPSocket() error

CreateTCPSocket is a noop

func (*LoggingClient) Decr

func (c *LoggingClient) Decr(stat string, count int64) error

Decr logs a Decr operation

func (*LoggingClient) FAbsolute

func (c *LoggingClient) FAbsolute(stat string, value float64) error

FAbsolute logs a FAbsolute operation

func (*LoggingClient) FGauge

func (c *LoggingClient) FGauge(stat string, value float64) error

FGauge logs a FGauge operation

func (*LoggingClient) FGaugeDelta

func (c *LoggingClient) FGaugeDelta(stat string, value float64) error

FGaugeDelta logs a FGaugeDelta operation

func (*LoggingClient) Gauge

func (c *LoggingClient) Gauge(stat string, value int64) error

Gauge logs a Gauge operation

func (*LoggingClient) GaugeDelta

func (c *LoggingClient) GaugeDelta(stat string, value int64) error

GaugeDelta logs a GaugeDelta operation

func (*LoggingClient) Incr

func (c *LoggingClient) Incr(stat string, count int64) error

Incr logs an Incr operation

func (*LoggingClient) PrecisionTiming

func (c *LoggingClient) PrecisionTiming(stat string, delta time.Duration) error

PrecisionTiming logs a PrecisionTiming operation

func (*LoggingClient) SendEvents

func (c *LoggingClient) SendEvents(events map[string]event.Event) error

SendEvents does nothing.

func (*LoggingClient) Timing

func (c *LoggingClient) Timing(stat string, delta int64) error

Timing logs a Timing operation

func (*LoggingClient) Total

func (c *LoggingClient) Total(stat string, value int64) error

Total logs a Total operation

type MultiClient

type MultiClient struct {
	// contains filtered or unexported fields
}

MultiClient passes metrics to multiple statsd backends

func (*MultiClient) Absolute

func (c *MultiClient) Absolute(stat string, value int64) error

Absolute calls Absolute for each backend

func (*MultiClient) Append

func (c *MultiClient) Append(client statsd.Statsd)

Append adds a new statsd client to the MultiClient

func (*MultiClient) Close

func (c *MultiClient) Close() error

Close calls Close for each backend

func (*MultiClient) CreateSocket

func (c *MultiClient) CreateSocket() error

CreateSocket calls CreateSocket for each backend

func (*MultiClient) CreateTCPSocket

func (c *MultiClient) CreateTCPSocket() error

CreateTCPSocket calls CreateTCPSocket for each backend

func (*MultiClient) Decr

func (c *MultiClient) Decr(stat string, count int64) error

Decr calls Decr for each backend

func (*MultiClient) FAbsolute

func (c *MultiClient) FAbsolute(stat string, value float64) error

FAbsolute calls FAbsolute for each backend

func (*MultiClient) FGauge

func (c *MultiClient) FGauge(stat string, value float64) error

FGauge calls FGauge for each backend

func (*MultiClient) FGaugeDelta

func (c *MultiClient) FGaugeDelta(stat string, value float64) error

FGaugeDelta calls FGaugeDelta for each backend

func (*MultiClient) Gauge

func (c *MultiClient) Gauge(stat string, value int64) error

Gauge calls Gauge for each backend

func (*MultiClient) GaugeDelta

func (c *MultiClient) GaugeDelta(stat string, value int64) error

GaugeDelta calls GaugeDelta for each backend

func (*MultiClient) Incr

func (c *MultiClient) Incr(stat string, count int64) error

Incr calls Incr for each backend

func (*MultiClient) PrecisionTiming

func (c *MultiClient) PrecisionTiming(stat string, delta time.Duration) error

PrecisionTiming calls PrecisionTiming for each backend

func (*MultiClient) SendEvents

func (c *MultiClient) SendEvents(events map[string]event.Event) error

SendEvents does nothing.

func (*MultiClient) Timing

func (c *MultiClient) Timing(stat string, delta int64) error

Timing calls Timing for each backend

func (*MultiClient) Total

func (c *MultiClient) Total(stat string, value int64) error

Total calls Total for each backend

type Recorder

type Recorder interface {
	http.ResponseWriter
	Status() int
}

Recorder is a convenience interface to record the response codes

type RecorderResponseWriter

type RecorderResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

RecorderResponseWriter is an http.ResponseWriter that keeps track of the http status code

func (*RecorderResponseWriter) Flush

func (r *RecorderResponseWriter) Flush()

Flush flushes the writer

func (*RecorderResponseWriter) Hijack

Hijack fulfills the Hijacker interface and allows the handler to take over the connection

func (*RecorderResponseWriter) Status

func (r *RecorderResponseWriter) Status() int

Status returns the status code

func (*RecorderResponseWriter) WriteHeader

func (r *RecorderResponseWriter) WriteHeader(code int)

WriteHeader keeps track of the status code

func (*RecorderResponseWriter) Written

func (r *RecorderResponseWriter) Written() bool

Written returns true if a status code has been seen

type StopFunc

type StopFunc func()

StopFunc stops the timer started with NewTimer and publishes the result

func NewTimer

func NewTimer(name string) StopFunc

NewTimer convenience function start and publish Timing stat, typical use is:

stop := metrics.NewTimer("my_metric")
defer stop()

func NewTimerBySize

func NewTimerBySize(name string, size int64) StopFunc

NewTimerBySize convenience function start and publish Timing stat bucketed by byte size, typical use is:

stop := metrics.NewTimerBySize("my_metric", size)
defer stop()

Jump to

Keyboard shortcuts

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