forked from mackerelio/mackerel-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice-with-meta.go
55 lines (49 loc) · 986 Bytes
/
dice-with-meta.go
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
package main
import (
"encoding/json"
"fmt"
"math/rand"
"os"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
type graph struct {
Label string `json:"label"`
Unit string `json:"unit"`
Metrics []metric `json:"metrics"`
}
type metric struct {
Name string `json:"name"`
Label string `json:"label"`
}
var graphDefinition = graph{
Label: "My Dice",
Unit: "integer",
Metrics: []metric{
{
Name: "d6",
Label: "Die (d6)",
},
{
Name: "d20",
Label: "Die (d20)",
},
},
}
func main() {
if os.Getenv("MACKEREL_AGENT_PLUGIN_META") == "1" {
meta := struct {
Graphs map[string]graph `json:"graphs"`
}{
Graphs: map[string]graph{"dice": graphDefinition},
}
bs, _ := json.Marshal(meta)
fmt.Println("# mackerel-agent-plugin")
fmt.Printf("%s\n", string(bs))
os.Exit(0)
}
fmt.Printf("%s\t%d\t%d\n", "dice.d6", rand.Int()%6+1, time.Now().Unix())
fmt.Printf("%s\t%d\t%d\n", "dice.d20", rand.Int()%20+1, time.Now().Unix())
}