File tree 2 files changed +11
-6
lines changed
2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -64,8 +64,7 @@ func main() {
64
64
}
65
65
66
66
func collectMetrics () {
67
- for {
68
- rand .Seed (time .Now ().UnixNano ())
67
+ iteration := func () {
69
68
if result , err := runSpeedTest (); err != nil {
70
69
atomic .AddUint64 (& errorCount , 1 )
71
70
if errorCount > fatalErrorCountThreshold {
@@ -78,12 +77,14 @@ func collectMetrics() {
78
77
jitter .WithLabelValues (hostname ).Set (result .Jitter )
79
78
latency .WithLabelValues (hostname ).Set (result .Latency )
80
79
81
- if len (strings .TrimSpace (args .CallbackUrl )) > 0 {
82
- if err := pkg .Callback (args .CallbackUrl , result ); err != nil {
83
- log .Printf ("Got error while callback %s\n " , err .Error ())
84
- }
80
+ if err := pkg .Callback (args .CallbackUrl , result ); err != nil {
81
+ log .Printf ("Got error while callback %s\n " , err .Error ())
85
82
}
86
83
}
84
+ }
85
+ for {
86
+ iteration ()
87
+ rand .Seed (time .Now ().UnixNano ())
87
88
time .Sleep (time .Duration (args .Interval )* time .Minute + time .Duration (rand .Intn (120 ))* time .Second )
88
89
}
89
90
}
Original file line number Diff line number Diff line change @@ -2,12 +2,16 @@ package pkg
2
2
3
3
import (
4
4
"encoding/json"
5
+ "strings"
5
6
"time"
6
7
7
8
"github.com/valyala/fasthttp"
8
9
)
9
10
10
11
func Callback (url string , result * Result ) error {
12
+ if len (strings .TrimSpace (url )) == 0 {
13
+ return nil
14
+ }
11
15
req := fasthttp .AcquireRequest ()
12
16
defer fasthttp .ReleaseRequest (req )
13
17
resp := fasthttp .AcquireResponse ()
You can’t perform that action at this time.
0 commit comments