-
Notifications
You must be signed in to change notification settings - Fork 11
/
juliapingplot.jl
82 lines (68 loc) · 2.04 KB
/
juliapingplot.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using Pkg
Pkg.activate(".")
#Pkg.add(["DataFrames","StatsPlots","CSV"])
using DataFrames, StatsPlots, CSV
gr()
site = "www.google.com" # site to traceroute to
nsec = 120 # number of seconds to ping for
function gethops(dname)
trin = Pipe()
trout = Pipe()
trerr = Pipe()
trproc = run(pipeline(`traceroute -n -w 0.5 $dname`; stdin=trin,stdout=trout,stderr=trerr),wait=false)
hops = DataFrame()
@async (wait(trproc);close(trout));
readline(trout) ## throw away the first line
while true
if(!eof(trout))
line = lstrip(readline(trout));
if match(r"[0-9.]+ ms",line) === nothing
continue
end
s = split(line,r"[ *]+")
push!(hops,(n=s[1],addr=s[2],ms=s[3]))
#@show hops
else
break;
end
end
return hops
end
function pinghops(hops,dur)
pids = [];
pipes = [];
data = DataFrame();
endplot = false
@sync begin
for (i,r) in Iterators.enumerate(eachrow(hops))
push!(pipes,Pipe())
push!(pids,run(pipeline(`ping -n -D -w $(dur) $(r.addr)`,pipes[end]),wait=false))
@async begin
while !eof(pipes[$i])
l = readline(pipes[$i])
m = match(r"\[(.*)] .* icmp_seq=([0-9]*) .* time=([0-9.]*) ms",l)
m === nothing || push!(data,(time=parse(Float64,m[1]),dest=$(r.addr),seq=m[2],ms=parse(Float64,m[3])))
end
end
end
plottask =
@async begin
sleep(3)
while !endplot
sleep(2)
p = plot(data.time .- minimum(data.time),data.ms,group=data.dest)
display(p)
end
end
for i in pids
wait(i)
end
endplot = true
for i in pipes
close(i)
end
end
data
end
pingdata = pinghops(gethops(site),nsec)
#@df pingdata plot((:time - minimum(:time)), :ms,group=:dest)