@@ -12,6 +12,7 @@ import (
1212 "time"
1313
1414 "github.com/statping-ng/statping-ng/types"
15+ "github.com/statping-ng/statping-ng/types/checkins"
1516 "github.com/statping-ng/statping-ng/types/errors"
1617 "github.com/statping-ng/statping-ng/types/failures"
1718 "github.com/statping-ng/statping-ng/types/hits"
@@ -85,8 +86,8 @@ func (s Service) Duration() time.Duration {
8586}
8687
8788// Start will create a channel for the service checking go routine
88- func (s Service ) UptimeData (hits []* hits.Hit , fails []* failures.Failure ) (* UptimeSeries , error ) {
89- if len (hits ) == 0 {
89+ func (s Service ) UptimeData (hits []* hits.Hit , checkinHits [] * checkins. CheckinHit , fails []* failures.Failure ) (* UptimeSeries , error ) {
90+ if len (hits ) == 0 && len ( checkinHits ) == 0 {
9091 return nil , errors .New ("service does not have any successful hits" )
9192 }
9293 // if theres no failures, then its been online 100%,
@@ -117,6 +118,9 @@ func (s Service) UptimeData(hits []*hits.Hit, fails []*failures.Failure) (*Uptim
117118 for _ , v := range hits {
118119 tMap [v .CreatedAt ] = true
119120 }
121+ for _ , v := range checkinHits {
122+ tMap [v .CreatedAt ] = true
123+ }
120124 for _ , v := range fails {
121125 tMap [v .CreatedAt ] = false
122126 }
@@ -212,13 +216,6 @@ func (s *Service) Close() {
212216 }
213217}
214218
215- func humanMicro (val int64 ) string {
216- if val < 10000 {
217- return fmt .Sprintf ("%d μs" , val )
218- }
219- return fmt .Sprintf ("%0.0f ms" , float64 (val )* 0.001 )
220- }
221-
222219// IsRunning returns true if the service go routine is running
223220func (s * Service ) IsRunning () bool {
224221 if s .Running == nil {
@@ -272,10 +269,15 @@ func (s *Service) UpdateStats() *Service {
272269 }
273270 }
274271
272+ firstHit := s .FirstHit ().CreatedAt
273+ if checkinHit := s .FirstCheckinHit (); checkinHit != nil && checkinHit .CreatedAt .After (firstHit ) {
274+ firstHit = checkinHit .CreatedAt
275+ }
276+
275277 s .Stats = & Stats {
276278 Failures : allFails .Count (),
277- Hits : s .AllHits ().Count (),
278- FirstHit : s . FirstHit (). CreatedAt ,
279+ Hits : s .AllHits ().Count () + s . AllCheckinHits (). Count () ,
280+ FirstHit : firstHit ,
279281 }
280282 return s
281283}
@@ -293,20 +295,21 @@ func (s Service) OnlineDaysPercent(days int) float32 {
293295
294296// OnlineSince accepts a time since parameter to return the percent of a service's uptime.
295297func (s * Service ) OnlineSince (ago time.Time ) float32 {
296- failsList := s .FailuresSince (ago ).Count ()
297- hitsList := s .HitsSince (ago ).Count ()
298+ failsCount := s .FailuresSince (ago ).Count ()
299+ hitsCount := s .HitsSince (ago ).Count ()
300+ checkinHitsCount := s .AllCheckinHits ().Since (ago ).Count ()
298301
299- if failsList == 0 {
302+ if failsCount == 0 {
300303 s .Online24Hours = 100.00
301304 return s .Online24Hours
302305 }
303306
304- if hitsList == 0 {
307+ if hitsCount == 0 && checkinHitsCount == 0 {
305308 s .Online24Hours = 0
306309 return s .Online24Hours
307310 }
308311
309- avg := (float64 (failsList ) / float64 (hitsList )) * 100
312+ avg := (float64 (failsCount ) / float64 (hitsCount + checkinHitsCount )) * 100
310313 avg = 100 - avg
311314 if avg < 0 {
312315 avg = 0
0 commit comments