| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package testrandom |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/plugin/framework/collectorapi" |
| 9 | ) |
| 10 | |
| 11 | func (c *Collector) collect() (map[string]int64, error) { |
| 12 | collected := make(map[string]int64) |
| 13 | |
| 14 | for _, chart := range *c.Charts() { |
| 15 | c.collectChart(collected, chart) |
| 16 | } |
| 17 | return collected, nil |
| 18 | } |
| 19 | |
| 20 | func (c *Collector) collectChart(collected map[string]int64, chart *collectorapi.Chart) { |
| 21 | var num int |
| 22 | if chart.Opts.Hidden { |
| 23 | num = c.Config.HiddenCharts.Dims |
| 24 | } else { |
| 25 | num = c.Config.Charts.Dims |
| 26 | } |
| 27 | |
| 28 | for i := 0; i < num; i++ { |
| 29 | name := fmt.Sprintf("random%d", i) |
| 30 | id := fmt.Sprintf("%s_%s", chart.ID, name) |
| 31 | |
| 32 | if !c.collectedDims[id] { |
| 33 | c.collectedDims[id] = true |
| 34 | |
| 35 | dim := &collectorapi.Dim{ID: id, Name: name} |
| 36 | if err := chart.AddDim(dim); err != nil { |
| 37 | c.Warning(err) |
| 38 | } |
| 39 | chart.MarkNotCreated() |
| 40 | } |
| 41 | if i%2 == 0 { |
| 42 | collected[id] = c.randInt() |
| 43 | } else { |
| 44 | collected[id] = -c.randInt() |
| 45 | } |
| 46 | } |
| 47 | } |