Make system work
This commit is contained in:
parent
60a4e00a4e
commit
3adbf11558
4 changed files with 19 additions and 24 deletions
|
@ -15,7 +15,7 @@ func (g *goDash) setupLogger() {
|
||||||
OutputPaths: []string{"stdout"},
|
OutputPaths: []string{"stdout"},
|
||||||
ErrorOutputPaths: []string{"stderr"},
|
ErrorOutputPaths: []string{"stderr"},
|
||||||
EncoderConfig: zap.NewProductionEncoderConfig(),
|
EncoderConfig: zap.NewProductionEncoderConfig(),
|
||||||
}.Build())
|
}.Build()).Sugar()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *goDash) setupEchoLogging() {
|
func (g *goDash) setupEchoLogging() {
|
||||||
|
|
10
main.go
10
main.go
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/labstack/echo/v4/middleware"
|
"github.com/labstack/echo/v4/middleware"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"godash/bookmarks"
|
"godash/bookmarks"
|
||||||
|
"godash/system"
|
||||||
"godash/weather"
|
"godash/weather"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -15,7 +16,7 @@ import (
|
||||||
|
|
||||||
type goDash struct {
|
type goDash struct {
|
||||||
router *echo.Echo
|
router *echo.Echo
|
||||||
logger *zap.Logger
|
logger *zap.SugaredLogger
|
||||||
config config
|
config config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,8 +41,11 @@ func main() {
|
||||||
defer g.logger.Sync()
|
defer g.logger.Sync()
|
||||||
g.setupEchoLogging()
|
g.setupEchoLogging()
|
||||||
|
|
||||||
w := weather.NewWeatherService(g.logger.Sugar())
|
w := weather.NewWeatherService(g.logger)
|
||||||
b := bookmarks.NewBookmarkService(g.logger.Sugar())
|
b := bookmarks.NewBookmarkService(g.logger)
|
||||||
|
if g.config.LiveSystem {
|
||||||
|
system.NewSystemService(g.logger)
|
||||||
|
}
|
||||||
|
|
||||||
g.router.Use(middleware.Recover())
|
g.router.Use(middleware.Recover())
|
||||||
g.router.Use(middleware.GzipWithConfig(middleware.GzipConfig{Level: 5}))
|
g.router.Use(middleware.GzipWithConfig(middleware.GzipConfig{Level: 5}))
|
||||||
|
|
|
@ -1,20 +1,13 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/sirupsen/logrus"
|
"go.uber.org/zap"
|
||||||
"godash/config"
|
|
||||||
"godash/hub"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Config = PackageConfig{}
|
func NewSystemService(logging *zap.SugaredLogger) {
|
||||||
var Sys = System{}
|
s := System{log: logging}
|
||||||
|
s.Initialize()
|
||||||
func NewSystemService() {
|
|
||||||
config.ParseViperConfig(&Config, config.AddViperConfig("system"))
|
|
||||||
if Config.LiveSystem {
|
|
||||||
Sys.Initialize()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *System) UpdateLiveInformation() {
|
func (s *System) UpdateLiveInformation() {
|
||||||
|
@ -23,7 +16,6 @@ func (s *System) UpdateLiveInformation() {
|
||||||
s.liveRam()
|
s.liveRam()
|
||||||
s.liveDisk()
|
s.liveDisk()
|
||||||
s.uptime()
|
s.uptime()
|
||||||
hub.LiveInformationCh <- hub.Message{WsType: hub.System, Message: s.Live}
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,5 +26,5 @@ func (s *System) Initialize() {
|
||||||
s.Static.Ram = staticRam()
|
s.Static.Ram = staticRam()
|
||||||
s.Static.Disk = staticDisk()
|
s.Static.Disk = staticDisk()
|
||||||
go s.UpdateLiveInformation()
|
go s.UpdateLiveInformation()
|
||||||
logrus.WithFields(logrus.Fields{"cpu": s.Static.CPU.Name, "arch": s.Static.Host.Architecture}).Debug("system updated")
|
s.log.Debugw("system updated", "cpu", s.Static.CPU.Name, "arch", s.Static.Host.Architecture)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
type PackageConfig struct {
|
import "go.uber.org/zap"
|
||||||
LiveSystem bool `mapstructure:"LIVE_SYSTEM"`
|
|
||||||
|
type System struct {
|
||||||
|
log *zap.SugaredLogger
|
||||||
|
Live LiveInformation `json:"live"`
|
||||||
|
Static StaticInformation `json:"static"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LiveStorageInformation struct {
|
type LiveStorageInformation struct {
|
||||||
|
@ -49,8 +53,3 @@ type StaticInformation struct {
|
||||||
Disk Disk `json:"disk"`
|
Disk Disk `json:"disk"`
|
||||||
Host Host `json:"host"`
|
Host Host `json:"host"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type System struct {
|
|
||||||
Live LiveInformation `json:"live"`
|
|
||||||
Static StaticInformation `json:"static"`
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue