| 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 | var chartTemplate = collectorapi.Chart{ |
| 12 | ID: "random_%d", |
| 13 | Title: "A Random Number", |
| 14 | Units: "random", |
| 15 | Fam: "random", |
| 16 | Ctx: "testrandom.random", |
| 17 | } |
| 18 | |
| 19 | var hiddenChartTemplate = collectorapi.Chart{ |
| 20 | ID: "hidden_random_%d", |
| 21 | Title: "A Random Number", |
| 22 | Units: "random", |
| 23 | Fam: "random", |
| 24 | Ctx: "testrandom.random", |
| 25 | Opts: collectorapi.Opts{ |
| 26 | Hidden: true, |
| 27 | }, |
| 28 | } |
| 29 | |
| 30 | func newChart(num, ctx, labels int, typ collectorapi.ChartType) *collectorapi.Chart { |
| 31 | chart := chartTemplate.Copy() |
| 32 | chart.ID = fmt.Sprintf(chart.ID, num) |
| 33 | chart.Type = typ |
| 34 | if ctx > 0 { |
| 35 | chart.Ctx += fmt.Sprintf("_%d", ctx) |
| 36 | } |
| 37 | for i := range labels { |
| 38 | chart.Labels = append(chart.Labels, collectorapi.Label{ |
| 39 | Key: fmt.Sprintf("random_name_%d", i), |
| 40 | Value: fmt.Sprintf("random_value_%d_%d", num, i), |
| 41 | }) |
| 42 | } |
| 43 | return chart |
| 44 | } |
| 45 | |
| 46 | func newHiddenChart(num, ctx, labels int, typ collectorapi.ChartType) *collectorapi.Chart { |
| 47 | chart := hiddenChartTemplate.Copy() |
| 48 | chart.ID = fmt.Sprintf(chart.ID, num) |
| 49 | chart.Type = typ |
| 50 | if ctx > 0 { |
| 51 | chart.Ctx += fmt.Sprintf("_%d", ctx) |
| 52 | } |
| 53 | for i := range labels { |
| 54 | chart.Labels = append(chart.Labels, collectorapi.Label{ |
| 55 | Key: fmt.Sprintf("random_name_%d", i), |
| 56 | Value: fmt.Sprintf("random_value_%d_%d", num, i), |
| 57 | }) |
| 58 | } |
| 59 | return chart |
| 60 | } |