-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathgaiacli_status.go
63 lines (55 loc) · 1.57 KB
/
gaiacli_status.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
61
62
63
package targets
import (
"cosmos-validator-mission-control/config"
"encoding/json"
"fmt"
"log"
"strconv"
client "github.com/influxdata/influxdb1-client/v2"
)
// GetGaiaCliStatus to reponse of validator status like
//current block height and node status
func GetGaiaCliStatus(ops HTTPOptions, cfg *config.Config, c client.Client) {
bp, err := createBatchPoints(cfg.InfluxDB.Database)
if err != nil {
return
}
var pts []*client.Point
resp, err := HitHTTPTarget(ops)
if err != nil {
log.Printf("Error: %v", err)
return
}
var status ValidatorRpcStatus
err = json.Unmarshal(resp.Body, &status)
if err != nil {
log.Printf("Error: %v", err)
return
}
var bh int
currentBlockHeight := status.Result.SyncInfo.LatestBlockHeight
if currentBlockHeight != "" {
bh, _ = strconv.Atoi(currentBlockHeight)
p2, err := createDataPoint("vcf_current_block_height", map[string]string{}, map[string]interface{}{"height": bh})
if err == nil {
pts = append(pts, p2)
}
}
var synced int
caughtUp := !status.Result.SyncInfo.CatchingUp
if !caughtUp {
_ = SendTelegramAlert(fmt.Sprintf("%s Your validator node is not synced!", cfg.ValidatorName), cfg)
_ = SendEmailAlert(fmt.Sprintf("%s Your validator node is not synced!", cfg.ValidatorName), cfg)
synced = 0
} else {
synced = 1
}
p3, err := createDataPoint("vcf_node_synced", map[string]string{}, map[string]interface{}{"status": synced})
if err == nil {
pts = append(pts, p3)
}
bp.AddPoints(pts)
_ = writeBatchPoints(c, bp)
log.Printf("\nCurrent Block Height: %s \nCaught Up? %t \n",
currentBlockHeight, caughtUp)
}