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