metrics

package
v0.0.0-...-e45c2a7 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: MIT Imports: 13 Imported by: 12

Documentation

Overview

pkg metrics is for gathering metrics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppName

func AppName() string

AppName returns the application name.

func DataDogHttp

func DataDogHttp(apiKey, hostName, appName string, logger Logger)

DataDogHttp initiates collection of HTTP and system metrics every 60s. if apiKey is non zero metrics are send to Data Dog otherwise they are logged using logger. Errors are logged with logger. If logger is nil log messages are discarded.

func DataDogMsg

func DataDogMsg(apiKey, hostName, appName string, logger Logger)

DataDogMsg initiates collection of messaging and system metrics every 60s. if apiKey is non zero metrics are send to Data Dog otherwise they are logged using logger. Errors are logged with logger. If logger is nil log messages are discarded

func DataDogMsgSync

func DataDogMsgSync(apiKey, hostName, appName string, logger Logger)

Sends current metrics immediately

func DoProcess

func DoProcess(m Processor, b []byte) error

DoProcess executes m.Process with messaging metrics.

func DoProcessWithContext

func DoProcessWithContext(ctx context.Context, m ProcessorWithContext, b []byte) error

DoProcess executes m.Process with messaging metrics. pass a context to processor to catch system stop signal

func HostName

func HostName() string

Hostname returns the hostname (can be empty).

func MsgErr

func MsgErr()

MsgErr increments the message error counter. It is safe for concurrent access.

func MsgProc

func MsgProc()

MsgProc increments the message processed counter. It is safe for concurrent access.

func MsgRx

func MsgRx()

MsgRx increments the message received counter. It is safe for concurrent access.

func MsgTx

func MsgTx()

MsgTx increments the message transmitted counter. It is safe for concurrent access.

func ReadHttpCounters

func ReadHttpCounters(m *HttpCounters)

ReadHttpCounters populates m with http counter delta values since last time it was called.

func ReadMsgCounters

func ReadMsgCounters(m *MsgCounters)

ReadMsgCounters populates m with message counter delta values since last time it was called.

func Request

func Request()

Request increments the http request counter. It is safe for concurrent access.

func StatusBadRequest

func StatusBadRequest()

StatusBadRequest increments the http response 400 counter. It is safe for concurrent access.

func StatusInternalServerError

func StatusInternalServerError()

StatusInternalServerError increments the http response 500 counter. It is safe for concurrent access.

func StatusNotFound

func StatusNotFound()

StatusNotFound increments the http response 404 counter. It is safe for concurrent access.

func StatusOK

func StatusOK()

StatusOK increments the http response 200 counter. It is safe for concurrent access.

func StatusServiceUnavailable

func StatusServiceUnavailable()

StatusServiceUnavailable increments the http response 503 counter. It is safe for concurrent access.

func StatusUnauthorized

func StatusUnauthorized()

StatusUnauthorized increments the http response 400 counter. It is safe for concurrent access.

func Written

func Written(n int64)

Written increments the bytes sent counter by n.

Types

type HttpCounters

type HttpCounters struct {
	// Request is the count of http requests.
	Request uint64

	// StatusOK is the count of http 200 responses.
	StatusOK uint64

	// StatusBadRequest is the count of http 400 responses.
	StatusBadRequest uint64

	// StatusUnauthorized is the count of http 401 responses.
	StatusUnauthorized uint64

	// StatusNotFound is the count of http 404 responses.
	StatusNotFound uint64

	// StatusInternalServerError is the count of http 500 responses.
	StatusInternalServerError uint64

	// StatusServiceUnavailable is the count of http 503 responses.
	StatusServiceUnavailable uint64

	// Written is the number of bytes written.
	Written uint64

	// At is the time the counters were sampled at.
	At time.Time
}

A HttpCounters records http counters.

type Logger

type Logger interface {
	Printf(string, ...interface{})
}

Logger defines an interface for logging.

type MsgCounters

type MsgCounters struct {
	// Rx is the count of messages received.
	Rx uint64

	// Tx is the count of messages transmitted.
	Tx uint64

	// Proc is the count of messages processed.
	Proc uint64

	// Err is the count of errored messages.
	Err uint64

	// At is the time the counters were sampled at.
	At time.Time
}

A MsgCounters records message counters.

type Processor

type Processor interface {
	Process([]byte) error
}

Message defines an interface for processing bytes.

type ProcessorWithContext

type ProcessorWithContext interface {
	Process(context.Context, []byte) error
}

processor with passed in context to catch possible system stop signal

type Timer

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

Timer is for timing events

func Start

func Start() Timer

Start returns started Timer.

func (*Timer) Stop

func (t *Timer) Stop()

Stops the timer

func (*Timer) Taken

func (t *Timer) Taken() int

Returns the time taken between start and stop in milliseconds.

func (*Timer) Track

func (t *Timer) Track(id string) error

Stops the timer if it is not already stopped. Tracks the time taken in milliseconds with identity id.

type TimerStats

type TimerStats struct {
	ID           string
	Count        int
	Average      int
	Percentile95 int
	Percentile50 int
}

func ReadTimers

func ReadTimers() []TimerStats

Jump to

Keyboard shortcuts

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