mirror of https://github.com/divan/expvarmon.git
Merge branch 'vasilcovsky-master'
This commit is contained in:
commit
8665b88cbb
21
service.go
21
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
|
||||
|
@ -20,6 +28,7 @@ type Service struct {
|
|||
|
||||
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