/
nolo-ganglia.go
60 lines (50 loc) · 1.01 KB
/
nolo-ganglia.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
56
57
58
59
60
package main
import (
"github.com/jbuchbinder/go-gmetric/gmetric"
"github.com/nolo-metrics/go-nolo"
"log"
"net"
"os"
"os/exec"
"path/filepath"
)
func main() {
args := os.Args
if 1 == len(args) {
log.Fatal("usage: nolo-ganglia path-to-plugin")
}
name := args[1]
out, err := exec.Command(name).Output()
if err != nil {
log.Fatal(err)
}
basename := filepath.Base(name)
plugin := nolo.Parse(basename, string(out))
gIP := net.IPv4(127, 0, 0, 1)
gangliaPort := 1234
host := "127.0.0.1"
spoofHost := "127.0.0.1:spoof"
gm := gmetric.Gmetric{
Host: host,
Spoof: spoofHost,
}
gm.AddServer(gmetric.Server{gIP, gangliaPort})
for _, metric := range plugin.Metrics {
m_name := metric.Identifier
m_value := metric.Value
m_units := ""
m_type := uint32(gmetric.VALUE_UNSIGNED_INT)
m_slope := uint32(gmetric.SLOPE_BOTH)
m_grp := plugin.Identifier
m_interval := uint32(300)
go gm.SendMetric(
m_name,
m_value,
m_type,
m_units,
m_slope,
m_interval,
m_interval,
m_grp)
}
}