Skip to content

Commit

Permalink
fixed blank data
Browse files Browse the repository at this point in the history
  • Loading branch information
sagostin committed Sep 7, 2022
1 parent e7ff6e9 commit 493eeeb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
17 changes: 9 additions & 8 deletions icmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,24 @@ func CheckICMP(t *agent_models.IcmpTarget) (agent_models.IcmpData, error) {
func TestIcmpTargets(t []*agent_models.IcmpTarget, count int, interval int) {
var wg sync.WaitGroup

for n := range t {
log.Infof("len %v", len(t))
for _, tn := range t {
log.Infof("starting icmp for %s", tn.Address)
wg.Add(1)
go func() {
go func(tn1 *agent_models.IcmpTarget) {
defer wg.Done()
for i := 0; i < count; i++ {
icmp, err := CheckICMP(t[n])
icmp, err := CheckICMP(tn1)
if err != nil {
// read ip 0.0.0.0: raw-read ip4 0.0.0.0: i/o timeout
log.Errorf("%s", err)
}

t[n].Result.Data = append(t[n].Result.Data, icmp)
t[n].Result.StopTimestamp = time.Now()
tn1.Result.Data = append(tn1.Result.Data, icmp)
tn1.Result.StopTimestamp = time.Now()
time.Sleep(time.Duration(int(time.Second) * interval))
}
}()
log.Infof("ending icmp for %s", tn1.Address)
}(tn)
}
wg.Wait()
wg.Add(1)
Expand Down Expand Up @@ -153,6 +155,5 @@ func calculateMetrics(t []*agent_models.IcmpTarget) {
}()
// TODO jitter max, and jitter 95 percentile
}

wg.Wait()
}
20 changes: 10 additions & 10 deletions mtr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@ import (
func TestMtrTargets(t []*agent_models.MtrTarget, triggered bool) {
var wg sync.WaitGroup

wg.Add(1)
go func() {
defer wg.Done()
for n := range t {
res, err := CheckMTR(t[n], 5)
for _, tn := range t {
wg.Add(1)
go func(tn1 *agent_models.MtrTarget) {
defer wg.Done()
res, err := CheckMTR(tn1, 5)
if err != nil {
log.Fatal(err)
}

t[n].Result.Mtr = mtr.MTR{
tn1.Result.Mtr = mtr.MTR{
SrcAddress: res.SrcAddress,
Address: res.Address,
Statistic: res.Statistic,
}
t[n].Result.StopTimestamp = time.Now()
t[n].Result.Triggered = triggered
}
}()
tn1.Result.StopTimestamp = time.Now()
tn1.Result.Triggered = triggered
}(tn)
}

wg.Wait()
}
Expand Down
10 changes: 5 additions & 5 deletions scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func StartScheduler(agentConfig *agent_models.AgentConfig) {
wg.Add(1)
go func() {
defer wg.Done()
runIcmpCheck(agentConfig, 2)
runIcmpCheck(agentConfig, 30)
}()
wg.Add(1)
go func() {
Expand Down Expand Up @@ -186,12 +186,11 @@ func runIcmpCheck(t *agent_models.AgentConfig, count int) {
for true {
var pingTargets []*agent_models.IcmpTarget

for n := range t.PingTargets {
for i, n := range t.PingTargets {
pingTargets = append(pingTargets, &agent_models.IcmpTarget{
Address: t.PingTargets[n],
Address: n,
})

pingTargets[n].Result.StartTimestamp = time.Now()
pingTargets[i].Result.StartTimestamp = time.Now()
}
wg.Add(1)
go func() {
Expand Down Expand Up @@ -227,5 +226,6 @@ func runIcmpCheck(t *agent_models.AgentConfig, count int) {

/*j, _ := json.Marshal(resp)
log.Infof("%s", j)*/
time.Sleep(time.Second * 2)
}
}

0 comments on commit 493eeeb

Please sign in to comment.