From 5c127bc03f4a3f8cbb810e4a9ec968a43c15893c Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 24 Mar 2022 20:22:05 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20=E6=8F=90=E5=8D=87?= =?UTF-8?q?=E3=80=8C=E6=9C=8D=E5=8A=A1=E3=80=8D=E9=A1=B5=E9=9D=A2=E6=8A=97?= =?UTF-8?q?=E5=87=BB=E6=89=93=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- cmd/dashboard/controller/common_page.go | 19 ++++++++++--- cmd/playground/main.go | 38 +++++++++++++------------ go.mod | 1 + go.sum | 2 ++ service/singleton/singleton.go | 2 +- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index ced720e..8c5faf4 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
LOGO designed by 熊大 .

-    +   

:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,计划任务和在线终端。

diff --git a/cmd/dashboard/controller/common_page.go b/cmd/dashboard/controller/common_page.go index 707fc78..8eb9692 100644 --- a/cmd/dashboard/controller/common_page.go +++ b/cmd/dashboard/controller/common_page.go @@ -11,6 +11,7 @@ import ( "github.com/gin-gonic/gin" "github.com/gorilla/websocket" "github.com/hashicorp/go-uuid" + "github.com/jinzhu/copier" "golang.org/x/crypto/bcrypt" "golang.org/x/sync/singleflight" @@ -100,12 +101,22 @@ func (p *commonPage) checkViewPassword(c *gin.Context) { } func (p *commonPage) service(c *gin.Context) { - singleton.AlertsLock.RLock() - defer singleton.AlertsLock.RUnlock() + res, _, _ := p.requestGroup.Do("servicePage", func() (interface{}, error) { + singleton.AlertsLock.RLock() + defer singleton.AlertsLock.RUnlock() + var stats map[uint64]model.ServiceItemResponse + var statsStore map[uint64]model.CycleTransferStats + copier.Copy(&stats, singleton.ServiceSentinelShared.LoadStats()) + copier.Copy(&statsStore, singleton.AlertsCycleTransferStatsStore) + return []interface { + }{ + stats, statsStore, + }, nil + }) c.HTML(http.StatusOK, "theme-"+singleton.Conf.Site.Theme+"/service", mygin.CommonEnvironment(c, gin.H{ "Title": "服务状态", - "Services": singleton.ServiceSentinelShared.LoadStats(), - "CycleTransferStats": singleton.AlertsCycleTransferStatsStore, + "Services": res.([]interface{})[0], + "CycleTransferStats": res.([]interface{})[1], "CustomCode": singleton.Conf.Site.CustomCode, })) } diff --git a/cmd/playground/main.go b/cmd/playground/main.go index b2217c0..f2d59eb 100644 --- a/cmd/playground/main.go +++ b/cmd/playground/main.go @@ -1,25 +1,27 @@ package main import ( - "log" + "fmt" - "github.com/robfig/cron/v3" + "github.com/jinzhu/copier" ) -func main() { - c := cron.New(cron.WithSeconds()) - _, err := c.AddFunc("* * * * * *", func() { - log.Println("bingo second") - }) - if err != nil { - panic(err) - } - _, err = c.AddFunc("* * * * *", func() { - log.Println("bingo minute") - }) - if err != nil { - panic(err) - } - c.Start() - select {} +type Cat struct { + age int + name string + friends []string +} + +func main() { + a := Cat{7, "Wilson", []string{"Tom", "Tabata", "Willie"}} + b := Cat{7, "Wilson", []string{"Tom", "Tabata", "Willie"}} + c := Cat{7, "Wilson", []string{"Tom", "Tabata", "Willie"}} + wilson := []*Cat{&a, &b, &c} + nikita := []Cat{} + copier.Copy(&nikita, &wilson) + + nikita[0].friends = append(nikita[0].friends, "Syd") + + fmt.Println(wilson[0]) + fmt.Println(nikita[0]) } diff --git a/go.mod b/go.mod index ea1d158..528bab7 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/hashicorp/go-uuid v1.0.2 github.com/iamacarpet/go-winpty v1.0.2 + github.com/jinzhu/copier v0.3.5 github.com/json-iterator/go v1.1.12 github.com/ory/graceful v0.1.2 github.com/p14yground/go-github-selfupdate v0.0.0-20220205132106-76a6d59b925b diff --git a/go.sum b/go.sum index c930ce2..0ab176c 100644 --- a/go.sum +++ b/go.sum @@ -200,6 +200,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1: github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf h1:WfD7VjIE6z8dIvMsI4/s+1qr5EL+zoIGev1BQj1eoJ8= github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf/go.mod h1:hyb9oH7vZsitZCiBt0ZvifOrB+qc8PS5IiilCIb87rg= +github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg= +github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.4 h1:tHnRBy1i5F2Dh8BAFxqFzxKqqvezXrL2OW1TnX+Mlas= diff --git a/service/singleton/singleton.go b/service/singleton/singleton.go index fa061f5..475be93 100644 --- a/service/singleton/singleton.go +++ b/service/singleton/singleton.go @@ -15,7 +15,7 @@ import ( pb "github.com/naiba/nezha/proto" ) -var Version = "v0.12.16" // !!记得修改 README 中的 badge 版本!! +var Version = "v0.12.17" // !!记得修改 README 中的 badge 版本!! var ( Conf *model.Config