From 8d38067a507facd4776d33e975041c767809d8c9 Mon Sep 17 00:00:00 2001 From: Li Kexian Date: Thu, 28 Feb 2019 20:44:09 +0800 Subject: [PATCH] update mod and add logrotate --- doc/CHANGS-ZH.md | 5 +++++ doc/CHANGS.md | 5 +++++ service.sh | 8 ++++---- setup.sh | 2 +- src/go.mod | 4 ++-- src/main.go | 2 ++ src/stat.go | 18 +++++++++--------- src/template.go | 2 +- src/version.go | 2 +- 9 files changed, 30 insertions(+), 18 deletions(-) diff --git a/doc/CHANGS-ZH.md b/doc/CHANGS-ZH.md index d8ef01e..5c83461 100644 --- a/doc/CHANGS-ZH.md +++ b/doc/CHANGS-ZH.md @@ -1,3 +1,8 @@ +0.102.2 Beta 版本的变更 2019-02-28 + +- 修正:增加日志滚动支持 + + 0.102.1 Beta 版本的变更 2019-02-28 - 修正:数据目录所有者自动修改为 daemon 用户 diff --git a/doc/CHANGS.md b/doc/CHANGS.md index 2e072ca..de00e3a 100644 --- a/doc/CHANGS.md +++ b/doc/CHANGS.md @@ -1,3 +1,8 @@ +Changes with Stat Hub 0.102.2 Beta 2019-02-28 + +- Bugfix: add logrotate support + + Changes with Stat Hub 0.102.1 Beta 2019-02-28 - Bugfix: chown data dir to daemon user diff --git a/service.sh b/service.sh index 71b80f5..2180482 100755 --- a/service.sh +++ b/service.sh @@ -7,7 +7,7 @@ cd $BASEDIR start() { echo "starting" - if [ ! -f $PID ]; then + if [ ! -f $PIDFILE ]; then ./stathub -c conf/stathub.conf echo "ok" echo "----------------------------------------------------" @@ -24,9 +24,9 @@ start() { stop() { echo "stopping" - if [ -f $PID ]; then - kill -9 `cat $PID` - rm -rf $PID + if [ -f $PIDFILE ]; then + kill -9 `cat $PIDFILE` + rm -rf $PIDFILE echo "ok" fi } diff --git a/setup.sh b/setup.sh index 3ddddd5..b1f8699 100755 --- a/setup.sh +++ b/setup.sh @@ -1,6 +1,6 @@ #!/bin/bash -VERSION="0.102.1" +VERSION="0.102.2" STATHUB_URL="https://github.com/likexian/stathub-go/releases/download/v${VERSION}" BASEDIR="/usr/local/stathub" diff --git a/src/go.mod b/src/go.mod index e45097d..e5a07e0 100644 --- a/src/go.mod +++ b/src/go.mod @@ -2,7 +2,7 @@ module github.com/likexian/stathub-go require ( github.com/likexian/daemon-go v0.0.0-20190221033618-0592c546bf05 - github.com/likexian/host-stat-go v0.0.0-20190216111529-8a8a9b671efc - github.com/likexian/logger-go v0.0.0-20190226031613-ce60a16be240 + github.com/likexian/host-stat-go v0.0.0-20190228023633-df00c4c0fa03 + github.com/likexian/logger-go v0.0.0-20190228122243-d1e1433d7f31 github.com/likexian/simplejson-go v0.0.0-20190215071240-f9f264a657d1 ) diff --git a/src/main.go b/src/main.go index 2840111..312d6cf 100644 --- a/src/main.go +++ b/src/main.go @@ -33,6 +33,8 @@ func main() { if DEBUG { SERVER_LOGGER = logger.New(os.Stderr, logger.DEBUG) + } else { + SERVER_LOGGER.SetSizeRotate(3, 100*1024*1024) } showVersion := flag.Bool("v", false, "show current version") diff --git a/src/stat.go b/src/stat.go index 23d9fae..d1f4935 100644 --- a/src/stat.go +++ b/src/stat.go @@ -45,7 +45,7 @@ func GetStat(id string, name string) (result string, err error) { hostInfo, err := hoststat.GetHostInfo() if err != nil { - SERVER_LOGGER.Debug("get host info failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get host info failed: %s", err.Error()) } stat.OSRelease = hostInfo.Release + " " + hostInfo.OSBit @@ -57,27 +57,27 @@ func GetStat(id string, name string) (result string, err error) { cpuInfo, err := hoststat.GetCPUInfo() if err != nil { - SERVER_LOGGER.Debug("get cpu info failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get cpu info failed: %s", err.Error()) } stat.CPUName = cpuInfo.ModelName stat.CPUCore = cpuInfo.CoreCount cpuStat, err := hoststat.GetCPUStat() if err != nil { - SERVER_LOGGER.Debug("get cpu stat failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get cpu stat failed: %s", err.Error()) } stat.CPURate = Round(100-cpuStat.IdleRate, 2) memStat, err := hoststat.GetMemStat() if err != nil { - SERVER_LOGGER.Debug("get mem stat failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get mem stat failed: %s", err.Error()) } stat.MemRate = memStat.MemRate stat.SwapRate = memStat.SwapRate diskStat, err := hoststat.GetDiskStat() if err != nil { - SERVER_LOGGER.Debug("get disk stat failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get disk stat failed: %s", err.Error()) } diskTotal := uint64(0) diskUsed := uint64(0) @@ -92,7 +92,7 @@ func GetStat(id string, name string) (result string, err error) { ioStat, err := hoststat.GetIOStat() if err != nil { - SERVER_LOGGER.Debug("get io stat failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get io stat failed: %s", err.Error()) } diskRead := uint64(0) diskWrite := uint64(0) @@ -105,7 +105,7 @@ func GetStat(id string, name string) (result string, err error) { netStat, err := hoststat.GetNetStat() if err != nil { - SERVER_LOGGER.Debug("get net stat failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get net stat failed: %s", err.Error()) } netWrite := uint64(0) netRead := uint64(0) @@ -120,13 +120,13 @@ func GetStat(id string, name string) (result string, err error) { uptimeStat, err := hoststat.GetUptimeStat() if err != nil { - SERVER_LOGGER.Debug("get uptime stat failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get uptime stat failed: %s", err.Error()) } stat.Uptime = uint64(uptimeStat.Uptime) loadStat, err := hoststat.GetLoadStat() if err != nil { - SERVER_LOGGER.Debug("get load stat failed: %s", err.Error()) + SERVER_LOGGER.ErrorOnce("get load stat failed: %s", err.Error()) } stat.Load = fmt.Sprintf("%.2f %.2f %.2f", loadStat.LoadNow, loadStat.LoadPre, loadStat.LoadFar) diff --git a/src/template.go b/src/template.go index 73528f5..f0d9776 100644 --- a/src/template.go +++ b/src/template.go @@ -11,7 +11,7 @@ package main // variable for tpl file var ( - TPL_REVHEAD = "faa6343" + TPL_REVHEAD = "7f8a987" TPL_CERT = map[string]string{} TPL_STATIC = map[string]string{} TPL_TEMPLATE = map[string]string{} diff --git a/src/version.go b/src/version.go index f0eda78..e416beb 100644 --- a/src/version.go +++ b/src/version.go @@ -11,7 +11,7 @@ package main // Version returns package version func Version() string { - return "0.102.1" + return "0.102.2" } // Author returns package author