bugfix
This commit is contained in:
@@ -8,7 +8,7 @@ copy: main.go
|
|||||||
scp ./main.go root@las1stor1:/tmp/x
|
scp ./main.go root@las1stor1:/tmp/x
|
||||||
|
|
||||||
run: copy
|
run: copy
|
||||||
ssh root@las1stor1 -v "cd /tmp/x && go run ."
|
ssh -t root@las1stor1 -v "cd /tmp/x && go run ."
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm main.go
|
rm main.go
|
||||||
|
|||||||
@@ -373,22 +373,42 @@ func reachLoop(ctx context.Context, st *InterfaceStatus, hosts []string) {
|
|||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(host string) {
|
go func(host string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
st.mu.Lock(); st.TotalICMPReq++; st.mu.Unlock()
|
st.mu.Lock()
|
||||||
|
st.TotalICMPReq++
|
||||||
|
st.mu.Unlock()
|
||||||
|
|
||||||
ok := pingOnce(st.Name, host)
|
ok := pingOnce(st.Name, host)
|
||||||
mu.Lock(); res[host] = ok; mu.Unlock()
|
mu.Lock()
|
||||||
|
res[host] = ok
|
||||||
|
mu.Unlock()
|
||||||
|
|
||||||
st.mu.Lock()
|
st.mu.Lock()
|
||||||
if ok {
|
if ok {
|
||||||
st.TotalICMPRep++; st.spin()
|
st.TotalICMPRep++
|
||||||
|
st.spin()
|
||||||
} else {
|
} else {
|
||||||
st.DroppedCount++; st.LastDrop = time.Now()
|
st.DroppedCount++
|
||||||
|
st.LastDrop = time.Now()
|
||||||
}
|
}
|
||||||
st.mu.Unlock()
|
st.mu.Unlock()
|
||||||
}(h)
|
}(h)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
st.mu.Lock(); st.Reachable = res; st.LastPing = time.Now(); st.mu.Unlock()
|
st.mu.Lock()
|
||||||
|
st.Reachable = res
|
||||||
|
st.LastPing = time.Now()
|
||||||
|
// Reset DroppedCount if all hosts are reachable
|
||||||
|
allReachable := true
|
||||||
|
for _, ok := range res {
|
||||||
|
if !ok {
|
||||||
|
allReachable = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if allReachable {
|
||||||
|
st.DroppedCount = 0
|
||||||
|
}
|
||||||
|
st.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -408,11 +428,20 @@ func lossLoop(ctx context.Context, st *InterfaceStatus, hosts []string) {
|
|||||||
go func(host string) {
|
go func(host string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
lp := lossPercent(st.Name, host)
|
lp := lossPercent(st.Name, host)
|
||||||
mu.Lock(); res[host] = lp; if lp == 0 { st.spin() }; mu.Unlock()
|
mu.Lock()
|
||||||
|
res[host] = lp
|
||||||
|
if lp == 0 {
|
||||||
|
st.spin()
|
||||||
|
}
|
||||||
|
mu.Unlock()
|
||||||
}(h)
|
}(h)
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
st.mu.Lock(); for k, v := range res { st.Loss[k] = v }; st.mu.Unlock()
|
st.mu.Lock()
|
||||||
|
for k, v := range res {
|
||||||
|
st.Loss[k] = v
|
||||||
|
}
|
||||||
|
st.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -427,9 +456,15 @@ func tcpLoop(ctx context.Context, st *InterfaceStatus, hosts []string) {
|
|||||||
for _, hp := range hosts {
|
for _, hp := range hosts {
|
||||||
ms := float64(tcpDuration(st.Name, hp).Milliseconds())
|
ms := float64(tcpDuration(st.Name, hp).Milliseconds())
|
||||||
st.mu.Lock()
|
st.mu.Lock()
|
||||||
if ms < float64(tcpTimeout.Milliseconds()) { st.spin() }
|
if ms < float64(tcpTimeout.Milliseconds()) {
|
||||||
hist := st.TCP[hp]; if len(hist) >= statsHistory { hist = hist[1:] }
|
st.spin()
|
||||||
st.TCP[hp] = append(hist, ms); st.mu.Unlock()
|
}
|
||||||
|
hist := st.TCP[hp]
|
||||||
|
if len(hist) >= statsHistory {
|
||||||
|
hist = hist[1:]
|
||||||
|
}
|
||||||
|
st.TCP[hp] = append(hist, ms)
|
||||||
|
st.mu.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -489,8 +524,13 @@ func main() {
|
|||||||
}
|
}
|
||||||
a, b := newStatus(*ifaceA, *labelA), newStatus(*ifaceB, *labelB)
|
a, b := newStatus(*ifaceA, *labelA), newStatus(*ifaceB, *labelB)
|
||||||
|
|
||||||
scr, err := tcell.NewScreen(); if err != nil { panic(err) }
|
scr, err := tcell.NewScreen()
|
||||||
if err = scr.Init(); err != nil { panic(err) }
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err = scr.Init(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
@@ -504,7 +544,8 @@ func main() {
|
|||||||
if ev := scr.PollEvent(); ev != nil {
|
if ev := scr.PollEvent(); ev != nil {
|
||||||
if ke, ok := ev.(*tcell.EventKey); ok {
|
if ke, ok := ev.(*tcell.EventKey); ok {
|
||||||
if ke.Key() == tcell.KeyCtrlC || ke.Rune() == 'q' {
|
if ke.Key() == tcell.KeyCtrlC || ke.Rune() == 'q' {
|
||||||
cancel(); return
|
cancel()
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user