mirror of https://github.com/divan/expvarmon.git
Merge branch 'vasilcovsky-master'
This commit is contained in:
commit
8665b88cbb
25
service.go
25
service.go
|
@ -10,6 +10,14 @@ import (
|
||||||
"github.com/antonholmquist/jason"
|
"github.com/antonholmquist/jason"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// uptimeCounter is a variable used for tracking uptime status.
|
||||||
|
// It should be always incrementing and included into default expvar vars.
|
||||||
|
// Could be replaced with something different or made configurable in
|
||||||
|
// the future.
|
||||||
|
uptimeCounter = VarName("memstats.PauseTotalNs").ToSlice()
|
||||||
|
)
|
||||||
|
|
||||||
// Service represents constantly updating info about single service.
|
// Service represents constantly updating info about single service.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Port string
|
Port string
|
||||||
|
@ -18,8 +26,9 @@ type Service struct {
|
||||||
|
|
||||||
stacks map[VarName]*Stack
|
stacks map[VarName]*Stack
|
||||||
|
|
||||||
Err error
|
Err error
|
||||||
Restarted bool
|
Restarted bool
|
||||||
|
UptimeCounter int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns new Service object.
|
// NewService returns new Service object.
|
||||||
|
@ -47,6 +56,18 @@ func (s *Service) Update(wg *sync.WaitGroup) {
|
||||||
}
|
}
|
||||||
s.Err = err
|
s.Err = err
|
||||||
|
|
||||||
|
// if memstat.PauseTotalNs less than s.UptimeCounter
|
||||||
|
// then service was restarted
|
||||||
|
c, err := expvar.GetInt64(uptimeCounter...)
|
||||||
|
if err != nil {
|
||||||
|
s.Err = err
|
||||||
|
} else {
|
||||||
|
if s.UptimeCounter > c {
|
||||||
|
s.Restarted = true
|
||||||
|
}
|
||||||
|
s.UptimeCounter = c
|
||||||
|
}
|
||||||
|
|
||||||
// Update Cmdline & Name only once
|
// Update Cmdline & Name only once
|
||||||
if len(s.Cmdline) == 0 {
|
if len(s.Cmdline) == 0 {
|
||||||
cmdline, err := expvar.GetStringArray("cmdline")
|
cmdline, err := expvar.GetStringArray("cmdline")
|
||||||
|
|
Loading…
Reference in New Issue