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"
|
||||
)
|
||||
|
||||
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.
|
||||
type Service struct {
|
||||
Port string
|
||||
|
@ -18,8 +26,9 @@ type Service struct {
|
|||
|
||||
stacks map[VarName]*Stack
|
||||
|
||||
Err error
|
||||
Restarted bool
|
||||
Err error
|
||||
Restarted bool
|
||||
UptimeCounter int64
|
||||
}
|
||||
|
||||
// NewService returns new Service object.
|
||||
|
@ -47,6 +56,18 @@ func (s *Service) Update(wg *sync.WaitGroup) {
|
|||
}
|
||||
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
|
||||
if len(s.Cmdline) == 0 {
|
||||
cmdline, err := expvar.GetStringArray("cmdline")
|
||||
|
|
Loading…
Reference in New Issue