Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alain Takoudjou
sfu
Commits
7ce61a11
Commit
7ce61a11
authored
Sep 18, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move stats code into its own module.
Move RTP-specific code into its own file.
parent
813d89b6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
171 additions
and
23 deletions
+171
-23
rtpstats.go
rtpstats.go
+74
-0
stats/stats.go
stats/stats.go
+73
-0
webserver.go
webserver.go
+24
-23
No files found.
stats.go
→
rtp
stats.go
View file @
7ce61a11
...
...
@@ -5,78 +5,21 @@ import (
"sync/atomic"
"time"
"sfu/group"
"sfu/rtptime"
"sfu/stats"
)
type
groupStats
struct
{
name
string
clients
[]
clientStats
}
type
clientStats
struct
{
id
string
up
,
down
[]
connStats
}
type
connStats
struct
{
id
string
maxBitrate
uint64
tracks
[]
trackStats
}
type
trackStats
struct
{
bitrate
uint64
maxBitrate
uint64
loss
uint8
rtt
time
.
Duration
jitter
time
.
Duration
}
func
getGroupStats
()
[]
groupStats
{
names
:=
group
.
GetNames
()
gs
:=
make
([]
groupStats
,
0
,
len
(
names
))
for
_
,
name
:=
range
names
{
g
:=
group
.
Get
(
name
)
if
g
==
nil
{
continue
}
clients
:=
g
.
GetClients
(
nil
)
stats
:=
groupStats
{
name
:
name
,
clients
:
make
([]
clientStats
,
0
,
len
(
clients
)),
}
for
_
,
c
:=
range
clients
{
c
,
ok
:=
c
.
(
*
webClient
)
if
ok
{
cs
:=
getClientStats
(
c
)
stats
.
clients
=
append
(
stats
.
clients
,
cs
)
}
}
sort
.
Slice
(
stats
.
clients
,
func
(
i
,
j
int
)
bool
{
return
stats
.
clients
[
i
]
.
id
<
stats
.
clients
[
j
]
.
id
})
gs
=
append
(
gs
,
stats
)
}
sort
.
Slice
(
gs
,
func
(
i
,
j
int
)
bool
{
return
gs
[
i
]
.
name
<
gs
[
j
]
.
name
})
return
gs
}
func
getClientStats
(
c
*
webClient
)
clientStats
{
func
(
c
*
webClient
)
GetStats
()
*
stats
.
Client
{
c
.
mu
.
Lock
()
defer
c
.
mu
.
Unlock
()
cs
:=
clientStats
{
i
d
:
c
.
id
,
cs
:=
stats
.
Client
{
I
d
:
c
.
id
,
}
for
_
,
up
:=
range
c
.
up
{
conns
:=
connStats
{
i
d
:
up
.
id
,
conns
:=
stats
.
Conn
{
I
d
:
up
.
id
,
}
tracks
:=
up
.
getTracks
()
for
_
,
t
:=
range
tracks
{
...
...
@@ -88,23 +31,23 @@ func getClientStats(c *webClient) clientStats {
jitter
:=
time
.
Duration
(
t
.
jitter
.
Jitter
())
*
(
time
.
Second
/
time
.
Duration
(
t
.
jitter
.
HZ
()))
rate
,
_
:=
t
.
rate
.
Estimate
()
conns
.
tracks
=
append
(
conns
.
tracks
,
trackStats
{
b
itrate
:
uint64
(
rate
)
*
8
,
l
oss
:
loss
,
j
itter
:
jitter
,
conns
.
Tracks
=
append
(
conns
.
Tracks
,
stats
.
Track
{
B
itrate
:
uint64
(
rate
)
*
8
,
L
oss
:
loss
,
J
itter
:
jitter
,
})
}
cs
.
up
=
append
(
cs
.
u
p
,
conns
)
cs
.
Up
=
append
(
cs
.
U
p
,
conns
)
}
sort
.
Slice
(
cs
.
u
p
,
func
(
i
,
j
int
)
bool
{
return
cs
.
up
[
i
]
.
id
<
cs
.
up
[
j
]
.
i
d
sort
.
Slice
(
cs
.
U
p
,
func
(
i
,
j
int
)
bool
{
return
cs
.
Up
[
i
]
.
Id
<
cs
.
Up
[
j
]
.
I
d
})
jiffies
:=
rtptime
.
Jiffies
()
for
_
,
down
:=
range
c
.
down
{
conns
:=
connStats
{
i
d
:
down
.
id
,
m
axBitrate
:
down
.
GetMaxBitrate
(
jiffies
),
conns
:=
stats
.
Conn
{
I
d
:
down
.
id
,
M
axBitrate
:
down
.
GetMaxBitrate
(
jiffies
),
}
for
_
,
t
:=
range
down
.
tracks
{
rate
,
_
:=
t
.
rate
.
Estimate
()
...
...
@@ -113,19 +56,19 @@ func getClientStats(c *webClient) clientStats {
loss
,
jitter
:=
t
.
stats
.
Get
(
jiffies
)
j
:=
time
.
Duration
(
jitter
)
*
time
.
Second
/
time
.
Duration
(
t
.
track
.
Codec
()
.
ClockRate
)
conns
.
tracks
=
append
(
conns
.
tracks
,
trackStats
{
b
itrate
:
uint64
(
rate
)
*
8
,
m
axBitrate
:
t
.
maxBitrate
.
Get
(
jiffies
),
l
oss
:
uint8
(
uint32
(
loss
)
*
100
/
256
),
r
tt
:
rtt
,
j
itter
:
j
,
conns
.
Tracks
=
append
(
conns
.
Tracks
,
stats
.
Track
{
B
itrate
:
uint64
(
rate
)
*
8
,
M
axBitrate
:
t
.
maxBitrate
.
Get
(
jiffies
),
L
oss
:
uint8
(
uint32
(
loss
)
*
100
/
256
),
R
tt
:
rtt
,
J
itter
:
j
,
})
}
cs
.
down
=
append
(
cs
.
d
own
,
conns
)
cs
.
Down
=
append
(
cs
.
D
own
,
conns
)
}
sort
.
Slice
(
cs
.
d
own
,
func
(
i
,
j
int
)
bool
{
return
cs
.
down
[
i
]
.
id
<
cs
.
down
[
j
]
.
i
d
sort
.
Slice
(
cs
.
D
own
,
func
(
i
,
j
int
)
bool
{
return
cs
.
Down
[
i
]
.
Id
<
cs
.
Down
[
j
]
.
I
d
})
return
cs
return
&
cs
}
stats/stats.go
0 → 100644
View file @
7ce61a11
package
stats
import
(
"sort"
"time"
"sfu/group"
)
type
GroupStats
struct
{
Name
string
Clients
[]
*
Client
}
type
Client
struct
{
Id
string
Up
,
Down
[]
Conn
}
type
Statable
interface
{
GetStats
()
*
Client
}
type
Conn
struct
{
Id
string
MaxBitrate
uint64
Tracks
[]
Track
}
type
Track
struct
{
Bitrate
uint64
MaxBitrate
uint64
Loss
uint8
Rtt
time
.
Duration
Jitter
time
.
Duration
}
func
GetGroups
()
[]
GroupStats
{
names
:=
group
.
GetNames
()
gs
:=
make
([]
GroupStats
,
0
,
len
(
names
))
for
_
,
name
:=
range
names
{
g
:=
group
.
Get
(
name
)
if
g
==
nil
{
continue
}
clients
:=
g
.
GetClients
(
nil
)
stats
:=
GroupStats
{
Name
:
name
,
Clients
:
make
([]
*
Client
,
0
,
len
(
clients
)),
}
for
_
,
c
:=
range
clients
{
s
,
ok
:=
c
.
(
Statable
)
if
ok
{
cs
:=
s
.
GetStats
()
stats
.
Clients
=
append
(
stats
.
Clients
,
cs
)
}
else
{
stats
.
Clients
=
append
(
stats
.
Clients
,
&
Client
{
Id
:
c
.
Id
()},
)
}
}
sort
.
Slice
(
stats
.
Clients
,
func
(
i
,
j
int
)
bool
{
return
stats
.
Clients
[
i
]
.
Id
<
stats
.
Clients
[
j
]
.
Id
})
gs
=
append
(
gs
,
stats
)
}
sort
.
Slice
(
gs
,
func
(
i
,
j
int
)
bool
{
return
gs
[
i
]
.
Name
<
gs
[
j
]
.
Name
})
return
gs
}
webserver.go
View file @
7ce61a11
...
...
@@ -21,6 +21,7 @@ import (
"sfu/disk"
"sfu/group"
"sfu/stats"
)
var
server
*
http
.
Server
...
...
@@ -50,7 +51,7 @@ func webserver() {
IdleTimeout
:
120
*
time
.
Second
,
}
server
.
RegisterOnShutdown
(
func
()
{
group
.
Range
(
func
(
g
*
group
.
Group
)
bool
{
group
.
Range
(
func
(
g
*
group
.
Group
)
bool
{
go
g
.
Shutdown
(
"server is shutting down"
)
return
true
})
...
...
@@ -225,7 +226,7 @@ func statsHandler(w http.ResponseWriter, r *http.Request) {
return
}
s
tats
:=
getGroupStat
s
()
s
s
:=
stats
.
GetGroup
s
()
fmt
.
Fprintf
(
w
,
"<!DOCTYPE html>
\n
<html><head>
\n
"
)
fmt
.
Fprintf
(
w
,
"<title>Stats</title>
\n
"
)
...
...
@@ -242,51 +243,51 @@ func statsHandler(w http.ResponseWriter, r *http.Request) {
return
err
}
printTrack
:=
func
(
w
io
.
Writer
,
t
trackStats
)
{
printTrack
:=
func
(
w
io
.
Writer
,
t
stats
.
Track
)
{
fmt
.
Fprintf
(
w
,
"<tr><td></td><td></td><td></td>"
)
fmt
.
Fprintf
(
w
,
"<td>"
)
printBitrate
(
w
,
t
.
bitrate
,
t
.
m
axBitrate
)
printBitrate
(
w
,
t
.
Bitrate
,
t
.
M
axBitrate
)
fmt
.
Fprintf
(
w
,
"</td>"
)
fmt
.
Fprintf
(
w
,
"<td>%d%%</td>"
,
t
.
l
oss
,
t
.
L
oss
,
)
fmt
.
Fprintf
(
w
,
"<td>"
)
if
t
.
r
tt
>
0
{
fmt
.
Fprintf
(
w
,
"%v"
,
t
.
r
tt
)
if
t
.
R
tt
>
0
{
fmt
.
Fprintf
(
w
,
"%v"
,
t
.
R
tt
)
}
if
t
.
j
itter
>
0
{
fmt
.
Fprintf
(
w
,
"±%v"
,
t
.
j
itter
)
if
t
.
J
itter
>
0
{
fmt
.
Fprintf
(
w
,
"±%v"
,
t
.
J
itter
)
}
fmt
.
Fprintf
(
w
,
"</td>"
)
fmt
.
Fprintf
(
w
,
"</tr>"
)
}
for
_
,
gs
:=
range
s
tat
s
{
fmt
.
Fprintf
(
w
,
"<p>%v</p>
\n
"
,
html
.
EscapeString
(
gs
.
n
ame
))
for
_
,
gs
:=
range
ss
{
fmt
.
Fprintf
(
w
,
"<p>%v</p>
\n
"
,
html
.
EscapeString
(
gs
.
N
ame
))
fmt
.
Fprintf
(
w
,
"<table>"
)
for
_
,
cs
:=
range
gs
.
c
lients
{
fmt
.
Fprintf
(
w
,
"<tr><td>%v</td></tr>
\n
"
,
cs
.
i
d
)
for
_
,
up
:=
range
cs
.
u
p
{
for
_
,
cs
:=
range
gs
.
C
lients
{
fmt
.
Fprintf
(
w
,
"<tr><td>%v</td></tr>
\n
"
,
cs
.
I
d
)
for
_
,
up
:=
range
cs
.
U
p
{
fmt
.
Fprintf
(
w
,
"<tr><td></td><td>Up</td><td>%v</td>"
,
up
.
i
d
)
if
up
.
m
axBitrate
>
0
{
up
.
I
d
)
if
up
.
M
axBitrate
>
0
{
fmt
.
Fprintf
(
w
,
"<td>%v</td>"
,
up
.
m
axBitrate
)
up
.
M
axBitrate
)
}
fmt
.
Fprintf
(
w
,
"</tr>
\n
"
)
for
_
,
t
:=
range
up
.
t
racks
{
for
_
,
t
:=
range
up
.
T
racks
{
printTrack
(
w
,
t
)
}
}
for
_
,
down
:=
range
cs
.
d
own
{
for
_
,
down
:=
range
cs
.
D
own
{
fmt
.
Fprintf
(
w
,
"<tr><td></td><td>Down</td><td> %v</td>"
,
down
.
i
d
)
if
down
.
m
axBitrate
>
0
{
down
.
I
d
)
if
down
.
M
axBitrate
>
0
{
fmt
.
Fprintf
(
w
,
"<td>%v</td>"
,
down
.
m
axBitrate
)
down
.
M
axBitrate
)
}
fmt
.
Fprintf
(
w
,
"</tr>
\n
"
)
for
_
,
t
:=
range
down
.
t
racks
{
for
_
,
t
:=
range
down
.
T
racks
{
printTrack
(
w
,
t
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment