Debian Codegraph @

examples/wave_plugin.go

raw symbols SCIP
1 package main
2
3 import (
4 "github.com/yvasiyarov/newrelic_platform_go"
5 )
6
7 type WaveMetrica struct {
8 sawtoothMax int
9 sawtoothCounter int
10 }
11
12 func (metrica *WaveMetrica) GetName() string {
13 return "Wave_Metrica"
14 }
15 func (metrica *WaveMetrica) GetUnits() string {
16 return "Queries/Second"
17 }
18 func (metrica *WaveMetrica) GetValue() (float64, error) {
19 metrica.sawtoothCounter++
20 if metrica.sawtoothCounter > metrica.sawtoothMax {
21 metrica.sawtoothCounter = 0
22 }
23 return float64(metrica.sawtoothCounter), nil
24 }
25
26 type SquareWaveMetrica struct {
27 squarewaveMax int
28 squarewaveCounter int
29 }
30
31 func (metrica *SquareWaveMetrica) GetName() string {
32 return "SquareWave_Metrica"
33 }
34 func (metrica *SquareWaveMetrica) GetUnits() string {
35 return "Queries/Second"
36 }
37 func (metrica *SquareWaveMetrica) GetValue() (float64, error) {
38 returnValue := 0
39 metrica.squarewaveCounter++
40
41 if metrica.squarewaveCounter < (metrica.squarewaveMax / 2) {
42 returnValue = 0
43 } else {
44 returnValue = metrica.squarewaveMax
45 }
46
47 if metrica.squarewaveCounter > metrica.squarewaveMax {
48 metrica.squarewaveCounter = 0
49 }
50 return float64(returnValue), nil
51 }
52
53 func main() {
54 plugin := newrelic_platform_go.NewNewrelicPlugin("0.0.1", "7bceac019c7dcafae1ef95be3e3a3ff8866de246", 60)
55 component := newrelic_platform_go.NewPluginComponent("Wave component", "com.exmaple.plugin.gowave", true)
56 plugin.AddComponent(component)
57
58 m := &WaveMetrica{
59 sawtoothMax: 10,
60 sawtoothCounter: 5,
61 }
62 component.AddMetrica(m)
63
64 m1 := &SquareWaveMetrica{
65 squarewaveMax: 4,
66 squarewaveCounter: 1,
67 }
68 component.AddMetrica(m1)
69
70 plugin.Verbose = true
71 plugin.Run()
72 }