Commit 118ad7a3 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Display actual rate in statistics.

parent 5dd27e50
...@@ -643,8 +643,9 @@ type connStats struct { ...@@ -643,8 +643,9 @@ type connStats struct {
} }
type trackStats struct { type trackStats struct {
bitrate uint64 bitrate uint64
loss uint8 maxBitrate uint64
loss uint8
} }
func getGroupStats() []groupStats { func getGroupStats() []groupStats {
...@@ -693,8 +694,9 @@ func getClientStats(c *client) clientStats { ...@@ -693,8 +694,9 @@ func getClientStats(c *client) clientStats {
expected = 1 expected = 1
} }
conns.tracks = append(conns.tracks, trackStats{ conns.tracks = append(conns.tracks, trackStats{
bitrate: atomic.LoadUint64(&t.maxBitrate), bitrate: uint64(t.rate.Estimate()) * 8,
loss: uint8(lost * 100 / expected), maxBitrate: atomic.LoadUint64(&t.maxBitrate),
loss: uint8(lost * 100 / expected),
}) })
} }
cs.up = append(cs.up, conns) cs.up = append(cs.up, conns)
...@@ -708,8 +710,9 @@ func getClientStats(c *client) clientStats { ...@@ -708,8 +710,9 @@ func getClientStats(c *client) clientStats {
for _, t := range down.tracks { for _, t := range down.tracks {
loss := atomic.LoadUint32(&t.loss) loss := atomic.LoadUint32(&t.loss)
conns.tracks = append(conns.tracks, trackStats{ conns.tracks = append(conns.tracks, trackStats{
bitrate: atomic.LoadUint64(&t.maxBitrate.bitrate), bitrate: uint64(t.rate.Estimate()) * 8,
loss: uint8((loss * 100) / 256), maxBitrate: atomic.LoadUint64(&t.maxBitrate.bitrate),
loss: uint8((loss * 100) / 256),
}) })
} }
cs.down = append(cs.down, conns) cs.down = append(cs.down, conns)
......
...@@ -156,9 +156,11 @@ func statsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -156,9 +156,11 @@ func statsHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "<title>Stats</title>\n") fmt.Fprintf(w, "<title>Stats</title>\n")
fmt.Fprintf(w, "<head><body>\n") fmt.Fprintf(w, "<head><body>\n")
printBitrate := func(w io.Writer, rate uint64) error { printBitrate := func(w io.Writer, rate, maxRate uint64) error {
var err error var err error
if rate != 0 && rate != ^uint64(0) { if maxRate != 0 && maxRate != ^uint64(0) {
_, err = fmt.Fprintf(w, "%v/%v", rate, maxRate)
} else {
_, err = fmt.Fprintf(w, "%v", rate) _, err = fmt.Fprintf(w, "%v", rate)
} }
return err return err
...@@ -167,7 +169,7 @@ func statsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -167,7 +169,7 @@ func statsHandler(w http.ResponseWriter, r *http.Request) {
printTrack := func(w io.Writer, t trackStats) { printTrack := func(w io.Writer, t trackStats) {
fmt.Fprintf(w, "<tr><td></td><td></td><td></td>") fmt.Fprintf(w, "<tr><td></td><td></td><td></td>")
fmt.Fprintf(w, "<td>") fmt.Fprintf(w, "<td>")
printBitrate(w, t.bitrate) printBitrate(w, t.bitrate, t.maxBitrate)
fmt.Fprintf(w, "</td>") fmt.Fprintf(w, "</td>")
fmt.Fprintf(w, "<td>%d%%</td></tr>\n", fmt.Fprintf(w, "<td>%d%%</td></tr>\n",
t.loss, t.loss,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment