fix(all):

- config fixes for singleton values (most)
- add monitor into internal/metrics
- clean up cmd folders to remove monitor
- implement versions on all apps
This commit is contained in:
Tit Petric
2018-10-26 11:20:15 +02:00
parent 259e7bac4d
commit adeefdbeaa
20 changed files with 88 additions and 176 deletions
+1 -11
View File
@@ -5,19 +5,9 @@ import (
"github.com/namsral/flag"
)
type configuration struct {
monitorInterval int
}
func flags(prefix string, mountFlags ...func(...string)) configuration {
var config configuration
flag.IntVar(&config.monitorInterval, "monitor-interval", 300, "Monitor interval (seconds, 0 = disable)")
func flags(prefix string, mountFlags ...func(...string)) {
for _, mount := range mountFlags {
mount(prefix)
}
flag.Parse()
return config
}
+1 -2
View File
@@ -11,12 +11,11 @@ import (
)
func main() {
config := flags("auth", service.Flags, auth.Flags, rbac.Flags)
flags("auth", service.Flags, auth.Flags, rbac.Flags)
// log to stdout not stderr
log.SetOutput(os.Stdout)
log.SetFlags(log.LstdFlags | log.Lshortfile)
go NewMonitor(config.monitorInterval)
if err := service.Init(); err != nil {
log.Fatalf("Error initializing auth: %+v", err)
-59
View File
@@ -1,59 +0,0 @@
package main
import (
"encoding/json"
"expvar"
"fmt"
"runtime"
"time"
)
type Monitor struct {
Alloc,
TotalAlloc,
Sys,
Mallocs,
Frees,
LiveObjects,
PauseTotalNs uint64
NumGC uint32
NumGoroutine int
}
func NewMonitor(duration int) {
var (
m = Monitor{}
rtm runtime.MemStats
goroutines = expvar.NewInt("num_goroutine")
)
var interval = time.Duration(duration) * time.Second
for {
<-time.After(interval)
// Read full mem stats
runtime.ReadMemStats(&rtm)
// Number of goroutines
m.NumGoroutine = runtime.NumGoroutine()
goroutines.Set(int64(m.NumGoroutine))
// Misc memory stats
m.Alloc = rtm.Alloc
m.TotalAlloc = rtm.TotalAlloc
m.Sys = rtm.Sys
m.Mallocs = rtm.Mallocs
m.Frees = rtm.Frees
// Live objects = Mallocs - Frees
m.LiveObjects = m.Mallocs - m.Frees
// GC Stats
m.PauseTotalNs = rtm.PauseTotalNs
m.NumGC = rtm.NumGC
// Just encode to json and print
b, _ := json.Marshal(m)
fmt.Println(string(b))
}
}
+1 -11
View File
@@ -5,19 +5,9 @@ import (
"github.com/namsral/flag"
)
type configuration struct {
monitorInterval int
}
func flags(prefix string, mountFlags ...func(...string)) configuration {
var config configuration
flag.IntVar(&config.monitorInterval, "monitor-interval", 300, "Monitor interval (seconds, 0 = disable)")
func flags(prefix string, mountFlags ...func(...string)) {
for _, mount := range mountFlags {
mount(prefix)
}
flag.Parse()
return config
}
+1 -2
View File
@@ -11,12 +11,11 @@ import (
)
func main() {
config := flags("crm", service.Flags, auth.Flags, rbac.Flags)
flags("crm", service.Flags, auth.Flags, rbac.Flags)
// log to stdout not stderr
log.SetOutput(os.Stdout)
log.SetFlags(log.LstdFlags | log.Lshortfile)
go NewMonitor(config.monitorInterval)
if err := service.Init(); err != nil {
log.Fatalf("Error initializing crm: %+v", err)
-59
View File
@@ -1,59 +0,0 @@
package main
import (
"encoding/json"
"expvar"
"fmt"
"runtime"
"time"
)
type Monitor struct {
Alloc,
TotalAlloc,
Sys,
Mallocs,
Frees,
LiveObjects,
PauseTotalNs uint64
NumGC uint32
NumGoroutine int
}
func NewMonitor(duration int) {
var (
m = Monitor{}
rtm runtime.MemStats
goroutines = expvar.NewInt("num_goroutine")
)
var interval = time.Duration(duration) * time.Second
for {
<-time.After(interval)
// Read full mem stats
runtime.ReadMemStats(&rtm)
// Number of goroutines
m.NumGoroutine = runtime.NumGoroutine()
goroutines.Set(int64(m.NumGoroutine))
// Misc memory stats
m.Alloc = rtm.Alloc
m.TotalAlloc = rtm.TotalAlloc
m.Sys = rtm.Sys
m.Mallocs = rtm.Mallocs
m.Frees = rtm.Frees
// Live objects = Mallocs - Frees
m.LiveObjects = m.Mallocs - m.Frees
// GC Stats
m.PauseTotalNs = rtm.PauseTotalNs
m.NumGC = rtm.NumGC
// Just encode to json and print
b, _ := json.Marshal(m)
fmt.Println(string(b))
}
}
+1 -11
View File
@@ -5,19 +5,9 @@ import (
"github.com/namsral/flag"
)
type configuration struct {
monitorInterval int
}
func flags(prefix string, mountFlags ...func(...string)) configuration {
var config configuration
flag.IntVar(&config.monitorInterval, "monitor-interval", 300, "Monitor interval (seconds, 0 = disable)")
func flags(prefix string, mountFlags ...func(...string)) {
for _, mount := range mountFlags {
mount(prefix)
}
flag.Parse()
return config
}
+1 -5
View File
@@ -8,18 +8,14 @@ import (
"github.com/crusttech/crust/internal/auth"
"github.com/crusttech/crust/internal/rbac"
"github.com/crusttech/crust/internal/version"
)
func main() {
config := flags("sam", service.Flags, auth.Flags, rbac.Flags)
log.Printf("Starting sam, version: %v, built on: %v", version.Version, version.BuildTime)
flags("sam", service.Flags, auth.Flags, rbac.Flags)
// log to stdout not stderr
log.SetOutput(os.Stdout)
log.SetFlags(log.LstdFlags | log.Lshortfile)
go NewMonitor(config.monitorInterval)
if err := service.Init(); err != nil {
log.Fatalf("Error initializing sam: %+v", err)
-59
View File
@@ -1,59 +0,0 @@
package main
import (
"encoding/json"
"expvar"
"fmt"
"runtime"
"time"
)
type Monitor struct {
Alloc,
TotalAlloc,
Sys,
Mallocs,
Frees,
LiveObjects,
PauseTotalNs uint64
NumGC uint32
NumGoroutine int
}
func NewMonitor(duration int) {
var (
m = Monitor{}
rtm runtime.MemStats
goroutines = expvar.NewInt("num_goroutine")
)
var interval = time.Duration(duration) * time.Second
for {
<-time.After(interval)
// Read full mem stats
runtime.ReadMemStats(&rtm)
// Number of goroutines
m.NumGoroutine = runtime.NumGoroutine()
goroutines.Set(int64(m.NumGoroutine))
// Misc memory stats
m.Alloc = rtm.Alloc
m.TotalAlloc = rtm.TotalAlloc
m.Sys = rtm.Sys
m.Mallocs = rtm.Mallocs
m.Frees = rtm.Frees
// Live objects = Mallocs - Frees
m.LiveObjects = m.Mallocs - m.Frees
// GC Stats
m.PauseTotalNs = rtm.PauseTotalNs
m.NumGC = rtm.NumGC
// Just encode to json and print
b, _ := json.Marshal(m)
fmt.Println(string(b))
}
}