🔊 dashboard: 默认输出服务故障上报日志

This commit is contained in:
naiba 2021-08-27 21:04:37 +08:00
parent ff15dfbbb8
commit d7ea114068
6 changed files with 17 additions and 24 deletions

View File

@ -4,7 +4,7 @@
<br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.30&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.7.0-brightgreen?style=for-the-badge&logo=linux">
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.9.31&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.7.0-brightgreen?style=for-the-badge&logo=linux">
<br>
<br>
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>

View File

@ -120,7 +120,7 @@ func run() {
timeOutCtx, cancel := context.WithTimeout(context.Background(), networkTimeOut)
conn, err = grpc.DialContext(timeOutCtx, server, grpc.WithInsecure(), grpc.WithPerRPCCredentials(&auth))
if err != nil {
println("grpc.Dial err: ", err)
println("与面板建立连接失败:", err)
cancel()
retry()
continue
@ -131,7 +131,7 @@ func run() {
timeOutCtx, cancel = context.WithTimeout(context.Background(), networkTimeOut)
_, err = client.ReportSystemInfo(timeOutCtx, monitor.GetHost().PB())
if err != nil {
println("client.ReportSystemInfo err: ", err)
println("上报系统信息失败:", err)
cancel()
retry()
continue
@ -141,12 +141,12 @@ func run() {
// 执行 Task
tasks, err := client.RequestTask(context.Background(), monitor.GetHost().PB())
if err != nil {
println("client.RequestTask err: ", err)
println("请求任务失败:", err)
retry()
continue
}
err = receiveTasks(tasks)
println("receiveTasks exit to main: ", err)
println("receiveTasks exit to main", err)
retry()
}
}
@ -187,7 +187,7 @@ func doTask(task *pb.Task) {
case model.TaskTypeCommand:
handleCommandTask(task, &result)
default:
println("Unknown action: ", task)
println("不支持的任务:", task)
}
client.ReportTask(context.Background(), &result)
}
@ -222,16 +222,13 @@ func doSelfUpdate() {
updateCh <- struct{}{}
}()
v := semver.MustParse(version)
println("Check update", v)
println("检查更新:", v)
latest, err := selfupdate.UpdateSelf(v, "naiba/nezha")
if err != nil {
println("Binary update failed:", err)
println("自动更新失败:", err)
return
}
if latest.Version.Equals(v) {
println("Current binary is up to date", version)
} else {
println("Upgrade successfully", latest.Version)
if !latest.Version.Equals(v) {
os.Exit(1)
}
}

View File

@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strings"
@ -102,11 +101,6 @@ func (n *Notification) Send(message string) error {
err = fmt.Errorf("%d %s", resp.StatusCode, resp.Status)
}
// defer resp.Body.Close()
// body, _ := ioutil.ReadAll(resp.Body)
log.Printf("%s 通知:%s %s %+v\n", n.Name, message, reqBody, err)
return err
}

View File

@ -13,7 +13,7 @@ import (
pb "github.com/naiba/nezha/proto"
)
var Version = "v0.9.30" // !!记得修改 README 中的 badge 版本!!
var Version = "v0.9.31" // !!记得修改 README 中的 badge 版本!!
var (
Conf *model.Config

View File

@ -71,7 +71,7 @@ func SendNotification(desc string, muteable bool) {
if !flag {
if Conf.Debug {
log.Println("muted notification", desc, muteable)
log.Println("静音的重复通知:", desc, muteable)
}
return
}
@ -80,6 +80,8 @@ func SendNotification(desc string, muteable bool) {
notificationsLock.RLock()
defer notificationsLock.RUnlock()
for i := 0; i < len(notifications); i++ {
notifications[i].Send(desc)
if err := notifications[i].Send(desc); err != nil {
log.Println("发送通知失败:", err)
}
}
}

View File

@ -269,7 +269,7 @@ func (ss *ServiceSentinel) worker() {
ss.serviceCurrentStatusIndex[mh.MonitorID] = 0
dataToSave := ss.serviceCurrentStatusData[mh.MonitorID]
if err := DB.Create(&dataToSave).Error; err != nil {
log.Println(err)
log.Println("服务监控数据持久化失败:", err)
}
}
// 更新当前状态
@ -289,9 +289,9 @@ func (ss *ServiceSentinel) worker() {
upPercent = ss.serviceResponseDataStoreCurrentUp[mh.MonitorID] * 100 / (ss.serviceResponseDataStoreCurrentDown[mh.MonitorID] + ss.serviceResponseDataStoreCurrentUp[mh.MonitorID])
}
stateStr := getStateStr(upPercent)
if Conf.Debug {
if !mh.Successful {
ServerLock.RLock()
log.Println("服务监控上报:", ss.monitors[mh.MonitorID].Target, stateStr, "上报者:", ServerList[r.Reporter].Name, "是否正常:", mh.Successful, "请求输出:", mh.Data)
log.Println("服务故障上报:", ss.monitors[mh.MonitorID].Target, stateStr, "上报者", ServerList[r.Reporter].Name, "请求输出:", mh.Data)
ServerLock.RUnlock()
}
if stateStr == "故障" || stateStr != ss.lastStatus[mh.MonitorID] {