mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2025-02-03 02:48:10 +00:00
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
|
package collector
|
||
|
|
||
|
import "time"
|
||
|
|
||
|
// MaxCollector is a simple aggregator collector that returns the maximum value
|
||
|
// of metrics from all collectors.
|
||
|
type MaxCollector struct {
|
||
|
collectors []Collector
|
||
|
interval time.Duration
|
||
|
}
|
||
|
|
||
|
// NewMaxCollector initializes a new MacCollector.
|
||
|
func NewMaxCollector(interval time.Duration, collectors ...Collector) *MaxCollector {
|
||
|
return &MaxCollector{
|
||
|
collectors: collectors,
|
||
|
interval: interval,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// GetMetrics gets metrics from all collectors and return the higest value.
|
||
|
func (c *MaxCollector) GetMetrics() ([]CollectedMetric, error) {
|
||
|
var max CollectedMetric
|
||
|
for _, collector := range c.collectors {
|
||
|
values, err := collector.GetMetrics()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
for _, value := range values {
|
||
|
if value.Custom.Value.MilliValue() > max.Custom.Value.MilliValue() {
|
||
|
max = value
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
return []CollectedMetric{max}, nil
|
||
|
}
|
||
|
|
||
|
// Interval returns the interval at which the collector should run.
|
||
|
func (c *MaxCollector) Interval() time.Duration {
|
||
|
return c.interval
|
||
|
}
|