File: wave_plugin.go

package info (click to toggle)
golang-github-yvasiyarov-newrelic-platform-go 0.0~git20160601.9c099fb-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 96 kB
  • sloc: makefile: 5
file content (72 lines) | stat: -rw-r--r-- 1,626 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main

import (
	"github.com/yvasiyarov/newrelic_platform_go"
)

type WaveMetrica struct {
	sawtoothMax     int
	sawtoothCounter int
}

func (metrica *WaveMetrica) GetName() string {
	return "Wave_Metrica"
}
func (metrica *WaveMetrica) GetUnits() string {
	return "Queries/Second"
}
func (metrica *WaveMetrica) GetValue() (float64, error) {
	metrica.sawtoothCounter++
	if metrica.sawtoothCounter > metrica.sawtoothMax {
		metrica.sawtoothCounter = 0
	}
	return float64(metrica.sawtoothCounter), nil
}

type SquareWaveMetrica struct {
	squarewaveMax     int
	squarewaveCounter int
}

func (metrica *SquareWaveMetrica) GetName() string {
	return "SquareWave_Metrica"
}
func (metrica *SquareWaveMetrica) GetUnits() string {
	return "Queries/Second"
}
func (metrica *SquareWaveMetrica) GetValue() (float64, error) {
	returnValue := 0
	metrica.squarewaveCounter++

	if metrica.squarewaveCounter < (metrica.squarewaveMax / 2) {
		returnValue = 0
	} else {
		returnValue = metrica.squarewaveMax
	}

	if metrica.squarewaveCounter > metrica.squarewaveMax {
		metrica.squarewaveCounter = 0
	}
	return float64(returnValue), nil
}

func main() {
	plugin := newrelic_platform_go.NewNewrelicPlugin("0.0.1", "7bceac019c7dcafae1ef95be3e3a3ff8866de246", 60)
	component := newrelic_platform_go.NewPluginComponent("Wave component", "com.exmaple.plugin.gowave", true)
	plugin.AddComponent(component)

	m := &WaveMetrica{
		sawtoothMax:     10,
		sawtoothCounter: 5,
	}
	component.AddMetrica(m)

	m1 := &SquareWaveMetrica{
		squarewaveMax:     4,
		squarewaveCounter: 1,
	}
	component.AddMetrica(m1)

	plugin.Verbose = true
	plugin.Run()
}