fac6e285bd
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.
36 lines
589 B
Go
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))
|
|
}
|