Skip to content
This repository was archived by the owner on Apr 20, 2019. It is now read-only.

Commit 0b7107c

Browse files
committed
Added the munin ping plugin
1 parent 8e6d4c7 commit 0b7107c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tests/munin.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/Cubox-/libping"
6+
"os"
7+
"strings"
8+
)
9+
10+
func main() {
11+
if os.Getenv("hosts") == "" {
12+
os.Exit(1)
13+
}
14+
15+
if len(os.Args) > 1 && os.Args[1] == "config" {
16+
for _, host := range strings.Split(os.Getenv("hosts"), " ") {
17+
fmt.Printf("multigraph ping_%s\n", strings.Replace(host, ".", "_", -1))
18+
fmt.Printf("graph_title Latency to %s\n", host)
19+
fmt.Println("graph_category latency")
20+
fmt.Println("graph_vlabel ping")
21+
fmt.Println("graph_scale no")
22+
fmt.Printf("graph_info This graph show the latency to reach %s\n", host)
23+
fmt.Println("ping.label ping")
24+
}
25+
} else if len(os.Args) == 1 {
26+
for _, host := range strings.Split(os.Getenv("hosts"), " ") {
27+
libping.Pingonce(host)
28+
duration, err := libping.Pingonce(host)
29+
30+
if err != nil {
31+
continue
32+
}
33+
34+
fmt.Printf("multigraph ping_%s\n", strings.Replace(host, ".", "_", -1))
35+
fmt.Printf("ping.value %.5f\n", float64(duration.Nanoseconds())/float64(1000000))
36+
}
37+
} else {
38+
os.Exit(1)
39+
}
40+
}

0 commit comments

Comments
 (0)