collection

package
v0.19.3 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package collection holds routines for collecting "high frequency" metrics and handling their auto-expiry based on a configured retention time. This becomes more interesting as the number of MySQL servers monitored by vtorc increases.

Most monitoring systems look at different metrics over a period like 1, 10, 30 or 60 seconds but even at second resolution vtorc may have polled a number of servers.

It can be helpful to collect the raw values, and then allow external monitoring to pull via an http api call either pre-cooked aggregate data or the raw data for custom analysis over the period requested.

This is expected to be used for the following types of metric:

  • discovery metrics (time to poll a MySQL server and collect status)
  • queue metrics (statistics within the discovery queue itself)
  • query metrics (statistics on the number of queries made to the backend MySQL database)

VTOrc code can just add a new metric without worrying about removing it later, and other code which serves API requests can pull out the data when needed for the requested time period.

For current metrics two api urls have been provided: one provides the raw data and the other one provides a single set of aggregate data which is suitable for easy collection by monitoring systems.

Expiry is triggered by default if the collection is created via CreateOrReturnCollection() and uses an expiry period of DiscoveryCollectionRetentionSeconds. It can also be enabled by calling StartAutoExpiration() after setting the required expire period with SetExpirePeriod().

This will trigger periodic calls (every second) to ensure the removal of metrics which have passed the time specified. Not enabling expiry will mean data is collected but never freed which will make vtorc run out of memory eventually.

Current code uses DiscoveryCollectionRetentionSeconds as the time to keep metric data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collection

type Collection struct {
	sync.Mutex // for locking the structure
	// contains filtered or unexported fields
}

Collection contains a collection of Metrics

func CreateOrReturnCollection

func CreateOrReturnCollection(name string) *Collection

CreateOrReturnCollection allows for creation of a new collection or returning a pointer to an existing one given the name. This allows access to the data structure from the api interface (http/api.go) and also when writing (inst).

func (*Collection) Append

func (c *Collection) Append(m Metric) error

Append a new Metric to the existing collection

func (*Collection) ExpirePeriod

func (c *Collection) ExpirePeriod() time.Duration

ExpirePeriod returns the currently configured expiration period

func (*Collection) Metrics

func (c *Collection) Metrics() []Metric

Metrics returns a slice containing all the metric values

func (*Collection) SetExpirePeriod

func (c *Collection) SetExpirePeriod(duration time.Duration)

SetExpirePeriod determines after how long the collected data should be removed

func (*Collection) Since

func (c *Collection) Since(t time.Time) ([]Metric, error)

Since returns the Metrics on or after the given time. We assume the metrics are stored in ascending time. Iterate backwards until we reach the first value before the given time or the end of the array.

func (*Collection) StartAutoExpiration

func (c *Collection) StartAutoExpiration()

StartAutoExpiration initiates the auto expiry procedure which periodically checks for metrics in the collection which need to be expired according to bc.ExpirePeriod.

func (*Collection) StopAutoExpiration

func (c *Collection) StopAutoExpiration()

StopAutoExpiration prepares to stop by terminating the auto-expiration process

type Metric

type Metric interface {
	When() time.Time // when the metric was taken
}

Metric is an interface containing a metric

Jump to

Keyboard shortcuts

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