mirror of
https://github.com/bluenviron/mediamtx.git
synced 2026-01-26 13:29:15 -08:00
api, metrics: add number of bytes received and sent from/to all entities (#1235)
* API: number of bytes received/sent from/to RTSP connections * API: number of bytes received/sent from/to RTSP sessions * API: number of bytes received/sent from/to RTMP connections * API: number of bytes sent to HLS connections * API: number of bytes received from paths * metrics of all the above
This commit is contained in:
parent
71ef9b47ab
commit
8bee4af86a
25 changed files with 338 additions and 277 deletions
|
|
@ -1,42 +1,36 @@
|
|||
package bytecounter
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
type readerInner struct {
|
||||
r io.Reader
|
||||
count uint32
|
||||
}
|
||||
|
||||
func (r *readerInner) Read(p []byte) (int, error) {
|
||||
n, err := r.r.Read(p)
|
||||
r.count += uint32(n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Reader allows to count read bytes.
|
||||
type Reader struct {
|
||||
ri *readerInner
|
||||
*bufio.Reader
|
||||
r io.Reader
|
||||
count uint64
|
||||
}
|
||||
|
||||
// NewReader allocates a Reader.
|
||||
func NewReader(r io.Reader) *Reader {
|
||||
ri := &readerInner{r: r}
|
||||
return &Reader{
|
||||
ri: ri,
|
||||
Reader: bufio.NewReader(ri),
|
||||
r: r,
|
||||
}
|
||||
}
|
||||
|
||||
// Count returns read bytes.
|
||||
func (r Reader) Count() uint32 {
|
||||
return r.ri.count
|
||||
// Read implements io.Reader.
|
||||
func (r *Reader) Read(p []byte) (int, error) {
|
||||
n, err := r.r.Read(p)
|
||||
atomic.AddUint64(&r.count, uint64(n))
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Count returns received bytes.
|
||||
func (r *Reader) Count() uint64 {
|
||||
return atomic.LoadUint64(&r.count)
|
||||
}
|
||||
|
||||
// SetCount sets read bytes.
|
||||
func (r *Reader) SetCount(v uint32) {
|
||||
r.ri.count = v
|
||||
func (r *Reader) SetCount(v uint64) {
|
||||
atomic.StoreUint64(&r.count, v)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue