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 orchestrator increases.
Most monitoring systems look at different metrics over a period like 1, 10, 30 or 60 seconds but even at second resolution orchestrator 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)
Orchestrator 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 orchestrator run out of memory eventually.
Current code uses DiscoveryCollectionRetentionSeconds as the time to keep metric data.
- func StopMonitoring()
- type Collection
- func (c *Collection) Append(m Metric) error
- func (c *Collection) ExpirePeriod() time.Duration
- func (c *Collection) Metrics() Metric
- func (c *Collection) SetExpirePeriod(duration time.Duration)
- func (c *Collection) Since(t time.Time) (Metric, error)
- func (c *Collection) StartAutoExpiration()
- func (c *Collection) StopAutoExpiration()
- type Metric
This section is empty.
This section is empty.
type Collection ¶
Collection contains a collection of Metrics
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).
Append a new Metric to the existing collection
func (*Collection) ExpirePeriod ¶
ExpirePeriod returns the currently configured expiration period
Metrics returns a slice containing all the metric values
func (*Collection) SetExpirePeriod ¶
SetExpirePeriod determines after how long the collected data should be removed
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.