metric

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2017 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SumAggregation     = "sum"
	MaxAggregation     = "max"
	MinAggregation     = "min"
	DefaultAggregation = "sum"
)

Variables

DerivedResources is a map from a derived resource(a resource that is not supported by heapster) to native resource (supported by heapster) to which derived resource should be converted. For example, deployment is not available in heapster so it has to be converted to its pods before downloading any data. Hence deployments map to pods.

View Source
var HeapsterAllInOneDownloadConfig = map[common.ResourceKind]bool{
	common.ResourceKindPod:  true,
	common.ResourceKindNode: false,
}

HeapsterAllInOneDownloadConfig holds config information specifying whether given native heapster resource type supports list download.

View Source
var OnlyDefaultAggregation = AggregationNames{DefaultAggregation}
View Source
var OnlySumAggregation = AggregationNames{SumAggregation}

Functions

func HeapsterUnmarshalType

func HeapsterUnmarshalType(client client.HeapsterClient, path string, v interface{}) error

HeapsterUnmarshalType performs heapster GET request to the specifies path and transfers the data to the interface provided.

func MaxAggregate

func MaxAggregate(values []int64) int64

func MinAggregate

func MinAggregate(values []int64) int64

func SumAggregate

func SumAggregate(values []int64) int64

Types

type AggregationName

type AggregationName string

type AggregationNames

type AggregationNames []AggregationName

type DataPoint

type DataPoint struct {
	X int64 `json:"x"`
	Y int64 `json:"y"`
}

type DataPoints

type DataPoints []DataPoint

func DataPointsFromMetricJSONFormat

func DataPointsFromMetricJSONFormat(raw heapster.MetricResult) DataPoints

DataPointsFromMetricJSONFormat converts all the data points from format used by heapster to our format.

type HeapsterSelector

type HeapsterSelector struct {
	TargetResourceType common.ResourceKind
	Path               string
	Resources          []string
	Label
}

func NewHeapsterSelectorFromNativeResource

func NewHeapsterSelectorFromNativeResource(resourceType common.ResourceKind, namespace string, resourceNames []string) (HeapsterSelector, error)

NewHeapsterSelectorFromNativeResource returns new heapster selector for native resources specified in arguments. returns error if requested resource is not native or is not supported.

func (HeapsterSelector) DownloadMetric

func (self HeapsterSelector) DownloadMetric(client client.HeapsterClient, metricName string) MetricPromise

DownloadMetric downloads one metric for this drill from heapster and returns it as a DataPromise Note, if you want to download data for multiple selectors make sure to pack them into HeapsterSelectors object. HeapsterSelectors uses smart download process in order to perform smallest number of heapster requests.

type HeapsterSelectors

type HeapsterSelectors []HeapsterSelector

func (HeapsterSelectors) DownloadAndAggregate

func (self HeapsterSelectors) DownloadAndAggregate(client client.HeapsterClient, metricNames []string, aggregations AggregationNames) MetricPromises

DownloadAndAggregate downloads and aggregates requested metrics for all resources present in HeapsterSelectors. Each item in HeapsterSelectors is treated as a separate resource and aggregation reflects that - ie. first we calculate, metrics for every heapster selector separately and afterwards we aggregate the data. So for example, we have 2 HeapsterSelectors each one consisting of many pods. If aggregation MIN is specified, then first for each HeapsterSelector the sum of metrics of all its pods is calculated and afterwards the min is taken. This function downloads the data using smallest possible number of requests to Heapster and returns the result as MetricPromises.

func (HeapsterSelectors) DownloadMetric

func (self HeapsterSelectors) DownloadMetric(client client.HeapsterClient, metricName string) MetricPromises

DownloadMetric downloads requested metric for each HeapsterSelector present in HeapsterSelectors and returns the result as MetricPromises - one promise for each HeapsterSelector. If HeapsterSelector consists of many native resources (eg. for example deployments can consist of hundreds of pods) then the sum for all its native resources is calculated. HeapsterSelectors are compressed before download process so that the smallest number of heapster requests is used.

type Label

type Label map[common.ResourceKind][]string

Label stores information about identity of resources described by this metric.

func AggregatingMapFromDataList

func AggregatingMapFromDataList(metricList []Metric, metricName string) (map[int64][]int64, Label)

AggregatingMapFromDataList for all Data entries of given metric generates a cumulative map X -> [List of all Ys at this X]. Afterwards this list of Ys can be easily aggregated.

func (Label) AddMetricLabel

func (self Label) AddMetricLabel(other Label) Label

AddMetricLabel returns a combined Label of self and other resource. (new label describes both resources).

type Metric

type Metric struct {
	// DataPoints is a list of X, Y int64 data points, sorted by X.
	DataPoints `json:"dataPoints"`
	// MetricName is the name of metric stored in this struct.
	MetricName string `json:"metricName"`
	// Label stores information about identity of resources described by this metric.
	Label `json:"-"`
	// Names of aggregating function used.
	Aggregate AggregationName `json:"aggregation,omitempty"`
}

Metric is a format of data used in this module. This is also the format of data that is being sent by backend API.

func AggregateData

func AggregateData(metricList []Metric, metricName string, aggregationName AggregationName) Metric

AggregateData aggregates all the data from dataList using AggregatingFunction with name aggregateName. Standard data aggregation function.

type MetricPromise

type MetricPromise struct {
	Metric chan *Metric
	Error  chan error
}

MetricPromise is used for parallel data extraction. Contains len 1 channels for Metric and Error.

func NewMetricPromise

func NewMetricPromise() MetricPromise

NewMetricPromise creates a MetricPromise structure with both channels of length 1.

func (MetricPromise) GetMetric

func (self MetricPromise) GetMetric() (*Metric, error)

GetMetric returns pointer to received Metrics and forwarded error (if any)

type MetricPromises

type MetricPromises []MetricPromise

func NewMetricPromises

func NewMetricPromises(length int) MetricPromises

NewMetricPromises returns a list of MetricPromises with requested length.

func (MetricPromises) GetMetrics

func (self MetricPromises) GetMetrics() ([]Metric, error)

GetMetrics returns all metrics from MetricPromises. In case of no metrics were downloaded it does not initialise []Metric and returns nil.

func (MetricPromises) PutMetrics

func (self MetricPromises) PutMetrics(metrics []Metric, err error)

PutMetrics forwards provided list of metrics to all channels. If provided err is not nil, error will be forwarded.

type ResourceSelector

type ResourceSelector struct {
	// Namespace of this resource.
	Namespace string
	// Type of this resource
	ResourceType common.ResourceKind
	// Name of this resource.
	ResourceName string
	// Selector used to identify this resource (if any).
	Selector map[string]string
	// Newer version of selector used to identify this resource (if any).
	LabelSelector *unversioned.LabelSelector
}

ResourceSelector is a structure used to quickly and uniquely identify given resource. This struct can be later used for heapster data download etc.

func (*ResourceSelector) GetHeapsterSelector

func (self *ResourceSelector) GetHeapsterSelector(cachedPods []api.Pod) (HeapsterSelector, error)

GetHeapsterSelector calculates and returns HeapsterSelector that can be used to download metrics for this resource.

type SortableInt64

type SortableInt64 []int64

SortableInt64 implements sort.Interface for []int64. This allows to use built in sort with int64.

func (SortableInt64) Len

func (a SortableInt64) Len() int

func (SortableInt64) Less

func (a SortableInt64) Less(i, j int) bool

func (SortableInt64) Swap

func (a SortableInt64) Swap(i, j int)

Jump to

Keyboard shortcuts

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