Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
92be49be
Commit
92be49be
authored
9 years ago
by
ale
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into jessie
parents
1c01bf6c
799a263b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
api.go
+7
-0
7 additions, 0 deletions
api.go
cmd/radioctl/radioctl.go
+1
-6
1 addition, 6 deletions
cmd/radioctl/radioctl.go
debug.go
+73
-0
73 additions, 0 deletions
debug.go
fe/http.go
+2
-63
2 additions, 63 deletions
fe/http.go
node/bwmonitor/bwmonitor.go
+1
-2
1 addition, 2 deletions
node/bwmonitor/bwmonitor.go
with
84 additions
and
71 deletions
api.go
+
7
−
0
View file @
92be49be
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"encoding/json"
"encoding/json"
"errors"
"errors"
"fmt"
"fmt"
"hash/crc32"
"net"
"net"
"strings"
"strings"
"time"
"time"
...
@@ -403,3 +404,9 @@ func GeneratePassword() string {
...
@@ -403,3 +404,9 @@ func GeneratePassword() string {
rand
.
Read
(
b
)
rand
.
Read
(
b
)
return
base64
.
StdEncoding
.
EncodeToString
(
b
)
return
base64
.
StdEncoding
.
EncodeToString
(
b
)
}
}
// GenerateUsername returns a username somehow related to the name of
// the mount, possibly unique (but not actually guaranteed to be so).
func
GenerateUsername
(
path
string
)
string
{
return
fmt
.
Sprintf
(
"source%d"
,
crc32
.
ChecksumIEEE
([]
byte
(
path
)))
}
This diff is collapsed.
Click to expand it.
cmd/radioctl/radioctl.go
+
1
−
6
View file @
92be49be
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"encoding/json"
"encoding/json"
"flag"
"flag"
"fmt"
"fmt"
"hash/crc32"
"log"
"log"
"net/url"
"net/url"
"os"
"os"
...
@@ -140,14 +139,10 @@ func getClient() *autoradio.Client {
...
@@ -140,14 +139,10 @@ func getClient() *autoradio.Client {
return
autoradio
.
NewClient
(
autoradio
.
NewEtcdClient
(
false
))
return
autoradio
.
NewClient
(
autoradio
.
NewEtcdClient
(
false
))
}
}
func
generateUsername
(
path
string
)
string
{
return
fmt
.
Sprintf
(
"source%d"
,
crc32
.
ChecksumIEEE
([]
byte
(
path
)))
}
func
setRelay
(
m
*
autoradio
.
Mount
,
relayUrl
string
)
{
func
setRelay
(
m
*
autoradio
.
Mount
,
relayUrl
string
)
{
if
relayUrl
==
""
{
if
relayUrl
==
""
{
// Randomly generate source credentials.
// Randomly generate source credentials.
m
.
Username
=
g
enerateUsername
(
m
.
Name
)
m
.
Username
=
autoradio
.
G
enerateUsername
(
m
.
Name
)
m
.
Password
=
autoradio
.
GeneratePassword
()
m
.
Password
=
autoradio
.
GeneratePassword
()
}
else
{
}
else
{
// Validate the given relay URL.
// Validate the given relay URL.
...
...
This diff is collapsed.
Click to expand it.
debug.go
0 → 100644
+
73
−
0
View file @
92be49be
package
autoradio
import
"sort"
// MountStatus reports the configuration and status of a mount,
// including eventual transcoded mounts that source it.
type
MountStatus
struct
{
Mount
*
Mount
Listeners
int
TransMounts
[]
*
MountStatus
}
func
newMountStatus
(
m
*
Mount
,
nodes
[]
*
NodeStatus
)
*
MountStatus
{
var
listeners
int
for
_
,
n
:=
range
nodes
{
for
_
,
ims
:=
range
n
.
Mounts
{
if
ims
.
Name
==
m
.
Name
{
listeners
+=
ims
.
Listeners
break
}
}
}
return
&
MountStatus
{
Mount
:
m
,
Listeners
:
listeners
,
}
}
type
mountStatusList
[]
*
MountStatus
func
(
l
mountStatusList
)
Len
()
int
{
return
len
(
l
)
}
func
(
l
mountStatusList
)
Swap
(
i
,
j
int
)
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
func
(
l
mountStatusList
)
Less
(
i
,
j
int
)
bool
{
return
l
[
i
]
.
Mount
.
Name
<
l
[
j
]
.
Mount
.
Name
}
// MountsToStatus converts a list of mounts (and eventually the
// current list of nodes) to a nicely sorted and tree-aggregated list
// of MountStatus objects. The list of nodes can be nil, in which case
// listener statistics will be omitted.
func
MountsToStatus
(
mounts
[]
*
Mount
,
nodes
[]
*
NodeStatus
)
[]
*
MountStatus
{
// Aggregate stats, and create a tree of transcoding mounts.
ms
:=
make
(
map
[
string
]
*
MountStatus
)
for
_
,
m
:=
range
mounts
{
if
m
.
HasTranscoder
()
{
continue
}
ms
[
m
.
Name
]
=
newMountStatus
(
m
,
nodes
)
}
for
_
,
m
:=
range
mounts
{
if
!
m
.
HasTranscoder
()
{
continue
}
src
:=
ms
[
m
.
Transcoding
.
SourceName
]
if
src
==
nil
{
continue
}
src
.
TransMounts
=
append
(
src
.
TransMounts
,
newMountStatus
(
m
,
nodes
))
}
msl
:=
make
([]
*
MountStatus
,
0
,
len
(
ms
))
for
_
,
m
:=
range
ms
{
msl
=
append
(
msl
,
m
)
}
// Sort everything (including transcoded mounts).
sort
.
Sort
(
mountStatusList
(
msl
))
for
_
,
s
:=
range
msl
{
if
s
.
TransMounts
!=
nil
{
sort
.
Sort
(
mountStatusList
(
s
.
TransMounts
))
}
}
return
msl
}
This diff is collapsed.
Click to expand it.
fe/http.go
+
2
−
63
View file @
92be49be
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"net/http"
"net/http"
"net/url"
"net/url"
"path/filepath"
"path/filepath"
"sort"
"strconv"
"strconv"
"strings"
"strings"
"time"
"time"
...
@@ -266,76 +265,16 @@ func (h *HTTPRedirector) serveSource(mount *autoradio.Mount, w http.ResponseWrit
...
@@ -266,76 +265,16 @@ func (h *HTTPRedirector) serveSource(mount *autoradio.Mount, w http.ResponseWrit
proxy
.
ServeHTTP
(
w
,
r
)
proxy
.
ServeHTTP
(
w
,
r
)
}
}
type
mountStatus
struct
{
Mount
*
autoradio
.
Mount
Listeners
int
TransMounts
[]
*
mountStatus
}
func
newMountStatus
(
m
*
autoradio
.
Mount
,
nodes
[]
*
autoradio
.
NodeStatus
)
*
mountStatus
{
var
listeners
int
for
_
,
n
:=
range
nodes
{
for
_
,
ims
:=
range
n
.
Mounts
{
if
ims
.
Name
==
m
.
Name
{
listeners
+=
ims
.
Listeners
break
}
}
}
return
&
mountStatus
{
Mount
:
m
,
Listeners
:
listeners
,
}
}
type
mountStatusList
[]
*
mountStatus
func
(
l
mountStatusList
)
Len
()
int
{
return
len
(
l
)
}
func
(
l
mountStatusList
)
Swap
(
i
,
j
int
)
{
l
[
i
],
l
[
j
]
=
l
[
j
],
l
[
i
]
}
func
(
l
mountStatusList
)
Less
(
i
,
j
int
)
bool
{
return
l
[
i
]
.
Mount
.
Name
<
l
[
j
]
.
Mount
.
Name
}
// Serve our cluster status page.
// Serve our cluster status page.
func
(
h
*
HTTPRedirector
)
serveStatusPage
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
h
*
HTTPRedirector
)
serveStatusPage
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
nodes
,
_
:=
h
.
client
.
GetNodes
()
nodes
,
_
:=
h
.
client
.
GetNodes
()
mounts
,
_
:=
h
.
client
.
ListMounts
()
mounts
,
_
:=
h
.
client
.
ListMounts
()
// Aggregate stats, and create a tree of transcoding mounts.
msl
:=
autoradio
.
MountsToStatus
(
mounts
,
nodes
)
ms
:=
make
(
map
[
string
]
*
mountStatus
)
for
_
,
m
:=
range
mounts
{
if
m
.
HasTranscoder
()
{
continue
}
ms
[
m
.
Name
]
=
newMountStatus
(
m
,
nodes
)
}
for
_
,
m
:=
range
mounts
{
if
!
m
.
HasTranscoder
()
{
continue
}
src
:=
ms
[
m
.
Transcoding
.
SourceName
]
if
src
==
nil
{
continue
}
src
.
TransMounts
=
append
(
src
.
TransMounts
,
newMountStatus
(
m
,
nodes
))
}
msl
:=
make
([]
*
mountStatus
,
0
,
len
(
ms
))
for
_
,
m
:=
range
ms
{
msl
=
append
(
msl
,
m
)
}
// Sort everything.
sort
.
Sort
(
mountStatusList
(
msl
))
for
_
,
s
:=
range
msl
{
if
s
.
TransMounts
!=
nil
{
sort
.
Sort
(
mountStatusList
(
s
.
TransMounts
))
}
}
ctx
:=
struct
{
ctx
:=
struct
{
Domain
string
Domain
string
Nodes
[]
*
autoradio
.
NodeStatus
Nodes
[]
*
autoradio
.
NodeStatus
Mounts
[]
*
m
ountStatus
Mounts
[]
*
autoradio
.
M
ountStatus
}{
h
.
domain
,
nodes
,
msl
}
}{
h
.
domain
,
nodes
,
msl
}
var
buf
bytes
.
Buffer
var
buf
bytes
.
Buffer
...
...
This diff is collapsed.
Click to expand it.
node/bwmonitor/bwmonitor.go
+
1
−
2
View file @
92be49be
...
@@ -68,9 +68,8 @@ func (bw *BandwidthMonitor) Run(stop chan bool) {
...
@@ -68,9 +68,8 @@ func (bw *BandwidthMonitor) Run(stop chan bool) {
t
:=
time
.
NewTicker
(
bw
.
period
)
t
:=
time
.
NewTicker
(
bw
.
period
)
for
{
for
{
select
{
select
{
case
<-
t
.
C
:
case
now
:=
<-
t
.
C
:
if
c
,
err
:=
getBytesSentForDevice
(
bw
.
device
);
err
==
nil
{
if
c
,
err
:=
getBytesSentForDevice
(
bw
.
device
);
err
==
nil
{
now
:=
time
.
Now
()
bw
.
lock
.
Lock
()
bw
.
lock
.
Lock
()
bw
.
rate
=
float64
(
c
-
bw
.
counter
)
/
now
.
Sub
(
bw
.
stamp
)
.
Seconds
()
bw
.
rate
=
float64
(
c
-
bw
.
counter
)
/
now
.
Sub
(
bw
.
stamp
)
.
Seconds
()
bw
.
counter
=
c
bw
.
counter
=
c
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment