Skip to content

Commit

Permalink
🔊 dashboard: 默认输出服务故障上报日志
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Aug 27, 2021
1 parent ff15dfb commit d7ea114
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
19 changes: 8 additions & 11 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
6 changes: 0 additions & 6 deletions model/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion service/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions service/dao/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
}
}
}
6 changes: 3 additions & 3 deletions service/dao/servicesentinel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
// 更新当前状态
Expand All @@ -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] {
Expand Down

0 comments on commit d7ea114

Please sign in to comment.