From 055349aba3a122d62bd643966ad2cd8c3fcf0438 Mon Sep 17 00:00:00 2001 From: Igor Vasilcovsky Date: Sat, 9 May 2015 12:40:10 -0400 Subject: [PATCH 1/2] improved detection if service was restarted --- service.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/service.go b/service.go index b5632f2..3ecbc50 100644 --- a/service.go +++ b/service.go @@ -10,6 +10,10 @@ import ( "github.com/antonholmquist/jason" ) +var ( + uptimeCounter = VarName("memstats.PauseTotalNs").ToSlice() +) + // Service represents constantly updating info about single service. type Service struct { Port string @@ -18,8 +22,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 +52,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") From 6b39ee8005d782c324de4487f18b70eccb382d9e Mon Sep 17 00:00:00 2001 From: Ivan Daniluk Date: Tue, 12 May 2015 12:50:25 +0300 Subject: [PATCH 2/2] Added annotation --- service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/service.go b/service.go index 3ecbc50..ca5420a 100644 --- a/service.go +++ b/service.go @@ -11,6 +11,10 @@ import ( ) 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() )