github.com/netdata/go.d.plugin@v0.58.1/modules/example/charts.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package example 4 5 import ( 6 "fmt" 7 "github.com/netdata/go.d.plugin/agent/module" 8 ) 9 10 var chartTemplate = module.Chart{ 11 ID: "random_%d", 12 Title: "A Random Number", 13 Units: "random", 14 Fam: "random", 15 Ctx: "example.random", 16 } 17 18 var hiddenChartTemplate = module.Chart{ 19 ID: "hidden_random_%d", 20 Title: "A Random Number", 21 Units: "random", 22 Fam: "random", 23 Ctx: "example.random", 24 Opts: module.Opts{ 25 Hidden: true, 26 }, 27 } 28 29 func newChart(num, ctx, labels int, typ module.ChartType) *module.Chart { 30 chart := chartTemplate.Copy() 31 chart.ID = fmt.Sprintf(chart.ID, num) 32 chart.Type = typ 33 if ctx > 0 { 34 chart.Ctx += fmt.Sprintf("_%d", ctx) 35 } 36 for i := 0; i < labels; i++ { 37 chart.Labels = append(chart.Labels, module.Label{ 38 Key: fmt.Sprintf("example_name_%d", i), 39 Value: fmt.Sprintf("example_value_%d_%d", num, i), 40 }) 41 } 42 return chart 43 } 44 45 func newHiddenChart(num, ctx, labels int, typ module.ChartType) *module.Chart { 46 chart := hiddenChartTemplate.Copy() 47 chart.ID = fmt.Sprintf(chart.ID, num) 48 chart.Type = typ 49 if ctx > 0 { 50 chart.Ctx += fmt.Sprintf("_%d", ctx) 51 } 52 for i := 0; i < labels; i++ { 53 chart.Labels = append(chart.Labels, module.Label{ 54 Key: fmt.Sprintf("example_name_%d", i), 55 Value: fmt.Sprintf("example_value_%d_%d", num, i), 56 }) 57 } 58 return chart 59 }