-
Notifications
You must be signed in to change notification settings - Fork 18
/
discovery.go
43 lines (35 loc) · 975 Bytes
/
discovery.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
package main
import (
"encoding/json"
"fmt"
hierr "github.com/reconquest/hierr-go"
)
func discovery(dsn string) error {
discoveryData := make(map[string][]map[string]string)
var discoveredItems []map[string]string
statsGalera, err := getGlobalStats(queryGalera, dsn)
if err != nil {
return hierr.Errorf(err, "can't get galera stats.")
}
if len(statsGalera[0]) > 1 {
discoveredItem := make(map[string]string)
discoveredItem["{#TYPE}"] = "galera"
discoveredItems = append(discoveredItems, discoveredItem)
}
statsSlave, err := getStats(querySlave, dsn)
if err != nil {
return hierr.Errorf(err, "can't get slave stats.")
}
if len(statsSlave) > 1 {
discoveredItem := make(map[string]string)
discoveredItem["{#TYPE}"] = "slave"
discoveredItems = append(discoveredItems, discoveredItem)
}
discoveryData["data"] = discoveredItems
out, err := json.Marshal(discoveryData)
if err != nil {
return err
}
fmt.Printf("%s\n", out)
return nil
}