From 7fc90d5de02e4b7247e1b2e57f8051cc6eb3202d Mon Sep 17 00:00:00 2001 From: iCell Date: Fri, 28 Feb 2020 16:50:24 +0900 Subject: [PATCH] Update monitor.go --- internal/monitor/monitor.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/internal/monitor/monitor.go b/internal/monitor/monitor.go index 0e290e1..f9c387f 100644 --- a/internal/monitor/monitor.go +++ b/internal/monitor/monitor.go @@ -16,12 +16,18 @@ import ( const alertTimes = 3 -var monitorList = map[string]string{ - "EOS": eos.ListenBlockPath, - "Mixin node 0": "/mixin/node0/status", - "Mixin node 1": "/mixin/node1/status", - "IoTex": "/iotex/status", - "Longmen": "/longmen/status", +type toMonitor struct { + Name string + Path string + Disable bool +} + +var monitorList = []toMonitor{ + toMonitor{"EOS", eos.ListenBlockPath, os.Getenv("DISABLE_EOS") == "1"}, + toMonitor{"Mixin node 0", "/mixin/node0/status", os.Getenv("DISABLE_MIXIN0") == "1"}, + toMonitor{"Mixin node 1", "/mixin/node1/status", os.Getenv("DISABLE_MIXIN2") == "1"}, + toMonitor{"IoTex", "/iotex/status", os.Getenv("DISABLE_IOTEX") == "1"}, + toMonitor{"Longmen", "/longmen/status", os.Getenv("DISABLE_LONGMEN") == "1"}, } var timeoutCache = make(map[string]int) @@ -38,12 +44,15 @@ func StartMonitor() { var msgs []*monitorMsg - for k, v := range monitorList { + for _, v := range monitorList { + if v.Disable { + continue + } host := os.Getenv("MONITOR_SERVER") - res, err := http.Get(fmt.Sprintf("http://%s:8080%s", host, v)) + res, err := http.Get(fmt.Sprintf("http://%s:8080%s", host, v.Path)) if err != nil { message.SendToTelegram( - fmt.Sprintf("Monitor for %s maybe unavailable: %s", k, err.Error()), + fmt.Sprintf("Monitor for %s maybe unavailable: %s", v.Name, err.Error()), ) break } @@ -52,9 +61,9 @@ func StartMonitor() { body, _ := ioutil.ReadAll(res.Body) msg := &monitorMsg{ - Symbol: k, + Symbol: v.Name, Code: res.StatusCode, - Msg: fmt.Sprintf("%s: %s", k, string(body)), + Msg: fmt.Sprintf("%s: %s", v.Name, string(body)), } msgs = append(msgs, msg)