metric

package
v0.0.0-...-6b32d26 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Copyright 2021 SANGFOR TECHNOLOGIES

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Package query provides query metric with this file providing aggregated metric based on the underlying values.

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

Most monitoring systems look at different metric over a period like 1, 10, 30 or 60 seconds but even at second resolution ham4db 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 metric (time to poll a MySQL server and collect status)
  • queue metric (statistics within the discovery queue itself)
  • query metric (statistics on the number of queries made to the backend MySQL database)

This 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 metric 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 metric which have passed the time specified. Not enabling expiry will mean data is collected but never freed which will make ham4db run out of memory eventually.

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

Copyright 2021 SANGFOR TECHNOLOGIES

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggregatedDiscoverSince

func AggregatedDiscoverSince(c *dtstruct.Collection, t time.Time) (dtstruct.MetricAggregatedDiscovery, error)

AggregatedDiscoverSince returns a large number of aggregated metric based on the raw metric collected since the given time.

func AggregatedQuerySince

func AggregatedQuerySince(c *dtstruct.Collection, t time.Time) dtstruct.MetricAggregatedQuery

AggregatedQuerySince returns the aggregated query metric for the period given from the values provided.

func CreateOrReturnCollection

func CreateOrReturnCollection(name string) *dtstruct.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 OnMetricTick

func OnMetricTick(f func())

OnMetricTick append callback function to tick list, will be called periodically

func RunAllMetricCallback

func RunAllMetricCallback(tick time.Duration)

RunAllMetricCallback is called once in the lifetime of the app, after config has been loaded

Types

This section is empty.

Directories

Path Synopsis
Copyright 2021 SANGFOR TECHNOLOGIES
Copyright 2021 SANGFOR TECHNOLOGIES

Jump to

Keyboard shortcuts

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