Skip to content

Commit

Permalink
doc: generate metrics should include metrics
Browse files Browse the repository at this point in the history
Created by builtin plugins: Aggregator, Max, and MetricAgent
  • Loading branch information
cgrinds committed Oct 6, 2023
1 parent 93ec35b commit 6551cef
Show file tree
Hide file tree
Showing 9 changed files with 2,264 additions and 447 deletions.
10 changes: 10 additions & 0 deletions cmd/poller/plugin/aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,3 +306,13 @@ func (a *Aggregator) NewLabels() []string {

return newLabelNames
}

// NewMetrics returns the new metrics the receiver creates
func (a *Aggregator) NewMetrics() []plugin.DerivedMetric {
var derivedMetrics []plugin.DerivedMetric
for _, r := range a.rules {
derivedMetrics = append(derivedMetrics, plugin.DerivedMetric{Name: r.label, Source: r.object})
}

return derivedMetrics
}
12 changes: 11 additions & 1 deletion cmd/poller/plugin/max/max.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Max struct {
rules []*rule
}

func New(p *plugin.AbstractPlugin) plugin.Plugin {
func New(p *plugin.AbstractPlugin) *Max {
return &Max{AbstractPlugin: p}
}

Expand Down Expand Up @@ -239,3 +239,13 @@ func (m *Max) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) {

return matricesArray, nil
}

// NewMetrics returns the new metrics the receiver creates
func (m *Max) NewMetrics() []plugin.DerivedMetric {
var derivedMetrics []plugin.DerivedMetric
for _, r := range m.rules {
derivedMetrics = append(derivedMetrics, plugin.DerivedMetric{Name: r.object, Source: r.label, IsMax: true})
}

return derivedMetrics
}
15 changes: 14 additions & 1 deletion cmd/poller/plugin/metricagent/metric_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/netapp/harvest/v2/pkg/errs"
"github.com/netapp/harvest/v2/pkg/matrix"
"strconv"
"strings"
)

type MetricAgent struct {
Expand All @@ -17,7 +18,7 @@ type MetricAgent struct {
computeMetricRules []computeMetricRule
}

func New(p *plugin.AbstractPlugin) plugin.Plugin {
func New(p *plugin.AbstractPlugin) *MetricAgent {
return &MetricAgent{AbstractPlugin: p}
}

Expand Down Expand Up @@ -144,3 +145,15 @@ func (a *MetricAgent) getMetric(m *matrix.Matrix, name string) *matrix.Metric {
}
return m.GetMetric(name)
}

// NewMetrics returns the new metrics the receiver creates
func (a *MetricAgent) NewMetrics() []plugin.DerivedMetric {
var derivedMetrics []plugin.DerivedMetric
for _, rule := range a.computeMetricRules {
derivedMetrics = append(derivedMetrics, plugin.DerivedMetric{
Name: rule.metric,
Source: strings.Join(rule.metricNames, ", "),
})
}
return derivedMetrics
}
6 changes: 6 additions & 0 deletions cmd/poller/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ func GetInterval(param *node.Node, defaultInterval time.Duration) float64 {
}
return defaultInterval.Seconds()
}

type DerivedMetric struct {
Name string
Source string
IsMax bool
}
Loading

0 comments on commit 6551cef

Please sign in to comment.