MovieNight/stats.go
joeyak fac6e285bd Add stream stats, minor changes in main, and adding ctrl+c handling
Stream statistics will now print when enabled in settings.json. There is messages in, messages out,
and total time running. The main function was changed so the server setups for the main and rtmp
are in separate functions, and both are started with their own goroutine. OS Interrupt catching was added,
and if stream stats is true, the stats will be printed.
2019-03-21 16:20:50 -04:00

36 lines
589 B
Go

package main
import (
"fmt"
"sync"
"time"
)
type streamStats struct {
messageIn int
messageOut int
start time.Time
mutex sync.Mutex
}
func newStreamStats() streamStats {
return streamStats{start: time.Now()}
}
func (s *streamStats) msgInInc() {
s.mutex.Lock()
s.messageIn++
s.mutex.Unlock()
}
func (s *streamStats) msgOutInc() {
s.mutex.Lock()
s.messageOut++
s.mutex.Unlock()
}
func (s *streamStats) Print() {
fmt.Printf("Messages In: %d\n", s.messageIn)
fmt.Printf("Messages Out: %d\n", s.messageOut)
fmt.Printf("Total Time: %s\n", time.Since(s.start))
}