🔊 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> <br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small> <small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br> <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>
<br> <br>
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p> <p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>

View File

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

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"log"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
@ -102,11 +101,6 @@ func (n *Notification) Send(message string) error {
err = fmt.Errorf("%d %s", resp.StatusCode, resp.Status) 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 return err
} }

View File

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

View File

@ -71,7 +71,7 @@ func SendNotification(desc string, muteable bool) {
if !flag { if !flag {
if Conf.Debug { if Conf.Debug {
log.Println("muted notification", desc, muteable) log.Println("静音的重复通知:", desc, muteable)
} }
return return
} }
@ -80,6 +80,8 @@ func SendNotification(desc string, muteable bool) {
notificationsLock.RLock() notificationsLock.RLock()
defer notificationsLock.RUnlock() defer notificationsLock.RUnlock()
for i := 0; i < len(notifications); i++ { 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 ss.serviceCurrentStatusIndex[mh.MonitorID] = 0
dataToSave := ss.serviceCurrentStatusData[mh.MonitorID] dataToSave := ss.serviceCurrentStatusData[mh.MonitorID]
if err := DB.Create(&dataToSave).Error; err != nil { 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]) upPercent = ss.serviceResponseDataStoreCurrentUp[mh.MonitorID] * 100 / (ss.serviceResponseDataStoreCurrentDown[mh.MonitorID] + ss.serviceResponseDataStoreCurrentUp[mh.MonitorID])
} }
stateStr := getStateStr(upPercent) stateStr := getStateStr(upPercent)
if Conf.Debug { if !mh.Successful {
ServerLock.RLock() 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() ServerLock.RUnlock()
} }
if stateStr == "故障" || stateStr != ss.lastStatus[mh.MonitorID] { if stateStr == "故障" || stateStr != ss.lastStatus[mh.MonitorID] {