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
48b96fc2
Commit
48b96fc2
authored
5 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Reconnect prober streams every two minutes
parent
90feac95
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
prober/analysis.go
+3
-1
3 additions, 1 deletion
prober/analysis.go
prober/prober.go
+16
-3
16 additions, 3 deletions
prober/prober.go
with
19 additions
and
4 deletions
prober/analysis.go
+
3
−
1
View file @
48b96fc2
...
...
@@ -7,10 +7,12 @@ type stats struct {
rms
float64
}
const
noSignal
=
-
120
// Convert a float64 sample value to dB (0 is peak amplitude).
func
toDB
(
value
float64
)
float64
{
if
value
<
1e-6
{
return
-
120
return
noSignal
}
return
20
*
math
.
Log10
(
value
)
}
...
...
This diff is collapsed.
Click to expand it.
prober/prober.go
+
16
−
3
View file @
48b96fc2
...
...
@@ -12,6 +12,7 @@ import (
var
(
reconnectDelay
=
3
*
time
.
Second
streamTimeout
=
2
*
time
.
Minute
// Exported metrics.
connections
=
prometheus
.
NewCounterVec
(
...
...
@@ -42,6 +43,13 @@ var (
},
[]
string
{
"stream"
},
)
streamErrors
=
prometheus
.
NewCounterVec
(
prometheus
.
CounterOpts
{
Name
:
"stream_errors"
,
Help
:
"Number of times the connection was broken."
,
},
[]
string
{
"stream"
},
)
streamRMS
=
prometheus
.
NewGaugeVec
(
prometheus
.
GaugeOpts
{
Name
:
"stream_rms"
,
...
...
@@ -95,7 +103,7 @@ func New(streamURL string) (*Prober, error) {
// Receive a stream content over HTTP. We're using the standard Go
// client as it can handle this case, no need to hijack the connection.
func
(
p
*
Prober
)
stream
()
{
func
(
p
*
Prober
)
stream
(
deadline
time
.
Time
)
{
resp
,
err
:=
http
.
Get
(
p
.
streamURL
)
if
err
!=
nil
{
log
.
Printf
(
"connection error: %v"
,
err
)
...
...
@@ -126,8 +134,9 @@ func (p *Prober) stream() {
// second of audio), compute some metrics and export them.
fr
:=
&
floatReader
{
dec
}
buf
:=
make
([]
float64
,
bufSize
)
for
{
for
time
.
Now
()
.
Before
(
deadline
)
{
if
err
:=
fr
.
ReadFloats
(
buf
);
err
!=
nil
{
streamErrors
.
WithLabelValues
(
p
.
streamName
)
.
Inc
()
break
}
...
...
@@ -140,13 +149,17 @@ func (p *Prober) stream() {
log
.
Printf
(
"decode error: %v"
,
err
)
}
// Reset stream analysis values for convenience, so we don't
// have to join with 'stream_connected' every time.
connected
.
WithLabelValues
(
p
.
streamName
)
.
Set
(
0
)
streamRMS
.
WithLabelValues
(
p
.
streamName
)
.
Set
(
noSignal
)
streamPeak
.
WithLabelValues
(
p
.
streamName
)
.
Set
(
noSignal
)
}
// Run the Prober forever.
func
(
p
*
Prober
)
Run
()
{
for
{
p
.
stream
()
p
.
stream
(
time
.
Now
()
.
Add
(
streamTimeout
)
)
// Limit the number of outgoing connections by
// sleeping a bit before retrying.
...
...
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