metriclogger

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMetricDuration = 30 * time.Second

DefaultMetricDuration will be used for calculation of metrics

View Source
const DefaultNumberOfBuckets = 3

Number Of Buckets that can be used for metric storage

View Source
const DefaultRefreshPeriod = 30 * time.Second

DefaultRefreshPeriod represents the bucket move period

Variables

View Source
var MetricDefinitions = map[string]MetricInfo{
	"responseDuration":    NewMetricInfo(Valued, "response_duration_%v"),
	"responseCode":        NewMetricInfo(Categorical, "response_code_%v"),
	"Memory":              NewMetricInfo(Valued, "memory_%v"),
	"CPU":                 NewMetricInfo(Valued, "cpu_%v"),
	"Replicas":            NewMetricInfo(Valued, "replicas_%v"),
	"UpdatedReplicas":     NewMetricInfo(Valued, "updated_replicas_%v"),
	"ReadyReplicas":       NewMetricInfo(Valued, "updated_replicas_%v"),
	"AvailableReplicas":   NewMetricInfo(Valued, "available_replicas_%v"),
	"UnavailableReplicas": NewMetricInfo(Valued, "unavailable_replicas_%v"),
	"Availability":        NewMetricInfo(Valued, "availability_%v"),
	"requests":            NewMetricInfo(Categorical, "requests_%v"),
}

MetricDefinitions is a mapping of metrics from input name to output name

View Source
var MetricLoggerGroupMap = map[string]*MetricLoggerGroup{
	"response_duration":         NewMetricLoggerGroup("response_duration", Valued),
	"response_duration_200":     NewMetricLoggerGroup("response_duration_200", Valued),
	"response_duration_2xx":     NewMetricLoggerGroup("response_duration_2xx", Valued),
	"response_duration_get_2xx": NewMetricLoggerGroup("response_duration_get_2xx", Valued),
	"response_duration_500":     NewMetricLoggerGroup("response_duration_500", Valued),
	"response_duration_5xx":     NewMetricLoggerGroup("response_duration_5xx", Valued),
	"response_duration_get_5xx": NewMetricLoggerGroup("response_duration_get_5xx", Valued),
	"response_code_200":         NewMetricLoggerGroup("response_code_200", Categorical),
	"response_code_2xx":         NewMetricLoggerGroup("response_code_2xx", Categorical),
	"response_code_get_2xx":     NewMetricLoggerGroup("response_code_get_2xx", Categorical),
	"response_code_500":         NewMetricLoggerGroup("response_code_500", Categorical),
	"response_code_5xx":         NewMetricLoggerGroup("response_code_5xx", Categorical),
	"memory":                    NewMetricLoggerGroup("memory", Valued),
	"cpu":                       NewMetricLoggerGroup("cpu", Valued),
	"replicas":                  NewMetricLoggerGroup("replicas", Valued),
	"updated_replicas":          NewMetricLoggerGroup("updated_replicas", Valued),
	"ready_replicas":            NewMetricLoggerGroup("ready_replicas", Valued),
	"available_replicas":        NewMetricLoggerGroup("available_replicas", Valued),
	"unavailable_replicas":      NewMetricLoggerGroup("unavailable_replicas", Valued),
	"availability":              NewMetricLoggerGroup("availability", Valued),
}

MetricLoggerGroupMap returns map of metric logger groups This is the default map other new values will be created on the fly

Functions

func CalculateMetricStats

func CalculateMetricStats(valuesRaw []float64) (*models.MetricStats, error)

CalculateMetricStats calculate metris stats with stats library

func ConvertToFloat64

func ConvertToFloat64(i interface{}) float64

ConvertToFloat64 gets an interface and converts into float64 All metrics are stored as float64, if a new type added this should be updated

func MapValueToPossibleCodes

func MapValueToPossibleCodes(apiProtocol string, requestMethod string, responseCode string) []string

MapValueToPossibleCodes generates codes for possible variations of a metric

func Rate

func Rate(input stats.Float64Data) (float64, error)

Rate provides calculation of the rate

func Setup

func Setup()

Setup sets up timer to regularly process a metric group. This is actually not needed anymore, since dynamic setup is possible now.

Types

type MetricInfo

type MetricInfo struct {
	Type       MetricType
	NameFormat string
}

MetricInfo is a struct used for defining metric name mapping

func NewMetricInfo added in v0.0.3

func NewMetricInfo(metricType MetricType, nameFormat string) MetricInfo

NewMetricInfo creates a metric info with given inputs

func (*MetricInfo) GetMetricLoggerNames

func (m *MetricInfo) GetMetricLoggerNames(name string, apiProtocol, requestMethod, responseCode string, value interface{}) []string

GetMetricLoggerNames return name to be used as metric identifier

type MetricLogger

type MetricLogger struct {
	Name            string
	MetricType      MetricType
	Destination     string
	Port            string
	Subset          string
	NumberOfBuckets int
	ValueMaps       []map[int64][]float64
	ActiveID        int32
	RefreshPeriod   time.Duration
	LastUpdate      int64
}

MetricLogger is a struct that holds metrics for a single stream of metric

func NewMetricLogger

func NewMetricLogger(destination string, port string, subset string, metricName string, metricType MetricType, refreshPeriod time.Duration) *MetricLogger

NewMetricLogger creates a new metric logger and pre-initializes buckets

func (*MetricLogger) MergeValuesOfNonActiveBucketsWithTimeBasedFiltering

func (m *MetricLogger) MergeValuesOfNonActiveBucketsWithTimeBasedFiltering(now int64) *MetricValues

MergeValuesOfNonActiveBucketsWithTimeBasedFiltering merges values in unused buckets

func (*MetricLogger) ProcessCategoricalMetricLogger

func (m *MetricLogger) ProcessCategoricalMetricLogger(metricValues *MetricValues) error

ProcessCategoricalMetricLogger processes metrics and trigger send metrics

func (*MetricLogger) ProcessMetricLogger

func (m *MetricLogger) ProcessMetricLogger(metricValues *MetricValues) error

ProcessMetricLogger processes metrics and trigger send metrics

func (*MetricLogger) ProcessValuedMetricLogger

func (m *MetricLogger) ProcessValuedMetricLogger(metricValues *MetricValues) error

ProcessValuedMetricLogger processes metrics and trigger send metrics

func (*MetricLogger) Push

func (m *MetricLogger) Push(timestamp int64, value interface{})

Push add data to the active bucket

func (*MetricLogger) RefreshMetricLogger

func (m *MetricLogger) RefreshMetricLogger() error

RefreshMetricLogger trigger process and cleanup of metric buckets

type MetricLoggerGroup

type MetricLoggerGroup struct {
	Name          string
	MetricType    MetricType
	RefreshPeriod time.Duration
	MetricLoggers map[string]*MetricLogger
	IsSetup       bool
}

MetricLoggerGroup is used to group similar metrics to decrease processing

func GetOrCreateMetricLoggerGroup added in v0.0.3

func GetOrCreateMetricLoggerGroup(name string, metricType MetricType) *MetricLoggerGroup

GetOrCreateMetricLoggerGroup adds non existing metrics to the metric list and returns it

func NewMetricLoggerGroup

func NewMetricLoggerGroup(metricName string, metricType MetricType) *MetricLoggerGroup

NewMetricLoggerGroup creates a new metric logger group

func (*MetricLoggerGroup) GetMetricLogger

func (g *MetricLoggerGroup) GetMetricLogger(destination string, port string, subset string) *MetricLogger

GetMetricLogger gets or creates a metric logger for destination, port, subset

func (*MetricLoggerGroup) Setup

func (g *MetricLoggerGroup) Setup()

Setup sets up a periodic process to calculate and send metrics

type MetricType

type MetricType int

MetricType represent enum type of Valued or Categorical metrics

const (
	// Valued metrics that are not time series
	Valued MetricType = iota
	// Categorical metrics are time series like 200s, 500s per second
	Categorical
)

func (MetricType) String

func (d MetricType) String() string

type MetricValues

type MetricValues struct {
	StartTime int64
	EndTime   int64
	Values    map[int64][]float64
}

MetricValues is a struct to hold one bucket of metric stream

Jump to

Keyboard shortcuts

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