Server now stores 10 minutes of stats
This commit is contained in:
parent
58007b38ab
commit
71a8441a8b
|
@ -31,7 +31,7 @@ func main() {
|
||||||
server.Start()
|
server.Start()
|
||||||
|
|
||||||
s := satan.Summon()
|
s := satan.Summon()
|
||||||
s.SubscribeFunc = kafka.Subscribe
|
s.Subscriber = kafka.Subscriber{}
|
||||||
s.DaemonStats = stats.NewGroup(statsLogger, statsServer)
|
s.DaemonStats = stats.NewGroup(statsLogger, statsServer)
|
||||||
|
|
||||||
s.AddDaemon(&daemons.NumberPrinter{})
|
s.AddDaemon(&daemons.NumberPrinter{})
|
||||||
|
|
|
@ -13,9 +13,22 @@ type Server struct {
|
||||||
history map[string][]*serverStatsSnapshot
|
history map[string][]*serverStatsSnapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type serverStatsSnapshot struct {
|
||||||
|
timestamp int64
|
||||||
|
processed int64
|
||||||
|
errors int64
|
||||||
|
min float64
|
||||||
|
p25 float64
|
||||||
|
mean float64
|
||||||
|
median float64
|
||||||
|
p75 float64
|
||||||
|
max float64
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
serverSnapshotIntervl = 3 * time.Second
|
// 60 of 10 second snapshots is 10 minutes worth of stats
|
||||||
serverHistorySize = 30
|
serverSnapshotIntervl = 10 * time.Second
|
||||||
|
serverHistorySize = 61 // +1 extra
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewServer() *Server {
|
func NewServer() *Server {
|
||||||
|
@ -58,6 +71,7 @@ func (s *Server) takeSnapshots() {
|
||||||
|
|
||||||
func makeServerStatsSnapshot(s *baseStats) *serverStatsSnapshot {
|
func makeServerStatsSnapshot(s *baseStats) *serverStatsSnapshot {
|
||||||
ps := s.time.Percentiles([]float64{0.25, 0.5, 0.75})
|
ps := s.time.Percentiles([]float64{0.25, 0.5, 0.75})
|
||||||
|
|
||||||
return &serverStatsSnapshot{
|
return &serverStatsSnapshot{
|
||||||
timestamp: time.Now().UTC().Unix(),
|
timestamp: time.Now().UTC().Unix(),
|
||||||
processed: s.time.Count(),
|
processed: s.time.Count(),
|
||||||
|
@ -71,18 +85,6 @@ func makeServerStatsSnapshot(s *baseStats) *serverStatsSnapshot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type serverStatsSnapshot struct {
|
|
||||||
timestamp int64
|
|
||||||
processed int64
|
|
||||||
errors int64
|
|
||||||
min float64
|
|
||||||
p25 float64
|
|
||||||
mean float64
|
|
||||||
median float64
|
|
||||||
p75 float64
|
|
||||||
max float64
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements json.Marshaler
|
// Implements json.Marshaler
|
||||||
func (s *serverStatsSnapshot) MarshalJSON() ([]byte, error) {
|
func (s *serverStatsSnapshot) MarshalJSON() ([]byte, error) {
|
||||||
return []byte(fmt.Sprintf("[%d,%d,%d,%.6f,%.6f,%.6f,%.6f,%.6f,%.6f]",
|
return []byte(fmt.Sprintf("[%d,%d,%d,%.6f,%.6f,%.6f,%.6f,%.6f,%.6f]",
|
||||||
|
|
Loading…
Reference in New Issue