forked from statping/statping
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparklines.go
31 lines (28 loc) · 952 Bytes
/
sparklines.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package core
import (
"github.com/hunterlong/statping/utils"
"strings"
"time"
)
// SparklineDayFailures returns a string array of daily service failures
func (s *Service) SparklineDayFailures(days int) string {
var arr []string
ago := time.Now().Add((time.Duration(days) * -24) * time.Hour)
for day := 1; day <= days; day++ {
ago = ago.Add(24 * time.Hour)
failures, _ := s.TotalFailuresOnDate(ago)
arr = append(arr, utils.ToString(failures))
}
return "[" + strings.Join(arr, ",") + "]"
}
// SparklineHourResponse returns a string array for the average response or ping time for a service
func (s *Service) SparklineHourResponse(hours int, method string) string {
var arr []string
end := time.Now().UTC()
start := end.Add(time.Duration(-hours) * time.Hour)
obj := GraphDataRaw(s, start, end, "hour", method)
for _, v := range obj.Array {
arr = append(arr, utils.ToString(v.Value))
}
return "[" + strings.Join(arr, ",") + "]"
}