Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
CPUnetLOG
TCPlivePLOT
Commits
4a7aadbf
Commit
4a7aadbf
authored
Sep 24, 2016
by
Michael König
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use user's default backend + reconn. to logserver
parent
7219255e
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
83 additions
and
38 deletions
+83
-38
matplotlibrc.example
matplotlibrc.example
+3
-0
setup.py
setup.py
+2
-2
tcpliveplot/backends/gui/live.py
tcpliveplot/backends/gui/live.py
+7
-7
tcpliveplot/backends/input/socket.py
tcpliveplot/backends/input/socket.py
+59
-28
tcpliveplot/main.py
tcpliveplot/main.py
+12
-1
No files found.
matplotlibrc.example
0 → 100644
View file @
4a7aadbf
# LOCATION: ~/.config/matplotlib/matplotlibrc
#backend : qt5agg
backend : qt4agg
setup.py
View file @
4a7aadbf
...
...
@@ -4,7 +4,7 @@
from
setuptools
import
setup
# keep in sync with main.py (!)
version
=
"0.2.
0
"
version
=
"0.2.
1
"
desc
=
"Realtime-visualization of TCP flows logged by TCPlog."
setup
(
...
...
@@ -37,7 +37,7 @@ setup(
platforms
=
"Linux"
,
zip_safe
=
False
,
install_requires
=
[
'matplotlib==1.4.
0
'
,
'matplotlib==1.4.
2
'
,
'tcplog>=0.2'
],
keywords
=
[
'tcp'
,
'flow'
,
'plot'
,
'visualize'
,
'graph'
,
'live'
,
'analyze'
,
'network'
,
'traffic'
],
...
...
tcpliveplot/backends/gui/live.py
View file @
4a7aadbf
...
...
@@ -6,12 +6,6 @@
# * fix socket-input
# * dynamic value detection
import
matplotlib
matplotlib
.
use
(
'Qt4Agg'
)
import
matplotlib.pyplot
as
plt
plt
.
style
.
use
(
'fivethirtyeight'
)
import
matplotlib.animation
as
animation
from
matplotlib.widgets
import
Button
,
RadioButtons
import
numpy
as
np
import
math
...
...
@@ -19,7 +13,6 @@ import sys
import
time
import
threading
from
collections
import
deque
from
.gui_base
import
GuiBase
VALUES_TO_PLOT
=
[
'cwnd'
,
'sst'
,
'rtt'
,
'smoothedThroughput'
]
# (only values for Y-axis)
...
...
@@ -31,6 +24,12 @@ PLOT_TITLE = "Data from"
PAUSE
=
"Pause"
QUIT
=
"Quit"
import
matplotlib
import
matplotlib.pyplot
as
plt
plt
.
style
.
use
(
'fivethirtyeight'
)
import
matplotlib.animation
as
animation
from
matplotlib.widgets
import
Button
,
RadioButtons
# constants
CLEAR_GAP
=
0.2
# gap in s
INFINITY_THRESHOLD
=
1e8
...
...
@@ -41,6 +40,7 @@ class LiveGui(GuiBase):
self
.
infoRegistry
=
infoRegistry
self
.
__stopped
=
threading
.
Event
()
self
.
timestampOfLastGuiRefresh
=
0
if
(
self
.
options
.
debug
):
print
(
"matplotlib-version: "
+
matplotlib
.
__version__
)
print
(
"available matplotlib-styles:"
+
str
(
plt
.
style
.
available
))
...
...
tcpliveplot/backends/input/socket.py
View file @
4a7aadbf
...
...
@@ -14,14 +14,17 @@ LOG_FORMAT = ['time', 'srcIp', 'srcPort', 'dstIp', 'dstPort', 'cwnd', 'rwnd', 's
#at least time & dstPort required
NUMBER_OF_VALUES
=
len
(
LOG_FORMAT
)
LOGSERVER_CONNECT_RETRY_TIME
=
3
#in s
LOGSERVER_CONNECT_RETRY_TIME
=
1
#in s
LOGSERVER_ERROR_TIMEOUT
=
0.5
#in s
class
SocketInput
(
InputBase
):
def
__init__
(
self
,
options
,
infoRegistry
):
self
.
options
=
options
self
.
infoRegistry
=
infoRegistry
self
.
__incomeBuffer
=
deque
();
self
.
incomeBuffer
=
deque
();
self
.
__incomeBuffer
=
deque
()
self
.
incomeBuffer
=
deque
()
self
.
connectionUp
=
False
self
.
socketUp
=
False
ip
,
separator
,
port
=
self
.
options
.
logServer
.
rpartition
(
':'
)
if
(
':'
not
in
self
.
options
.
logServer
or
port
is
''
):
...
...
@@ -37,23 +40,42 @@ class SocketInput(InputBase):
def
startUp
(
self
):
#TODO: eprint + debug..
self
.
createSocket
()
while
not
self
.
connectToServer
():
pass
def
createSocket
(
self
):
try
:
self
.
socket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
except
socket
.
error
:
print
(
"Failed to create socket"
)
else
:
print
(
"Socket created."
)
self
.
socketUp
=
True
if
(
self
.
options
.
debug
):
print
(
"Socket created."
)
while
True
:
try
:
self
.
socket
.
connect
((
str
(
self
.
logServerIp
),
self
.
logServerPort
))
print
(
"Successfully connected to "
+
self
.
dst
+
""
)
return
except
socket
.
error
:
print
(
"Error: Could not connect to "
+
self
.
dst
+
". Retrying in "
+
str
(
LOGSERVER_CONNECT_RETRY_TIME
)
+
"s ..."
)
time
.
sleep
(
LOGSERVER_CONNECT_RETRY_TIME
)
else
:
pass
def
connectToServer
(
self
):
try
:
self
.
socket
.
connect
((
str
(
self
.
logServerIp
),
self
.
logServerPort
))
self
.
connectionUp
=
True
print
(
"Successfully connected to "
+
self
.
dst
+
""
)
return
True
except
socket
.
error
:
print
(
"Error: Could not connect to "
+
self
.
dst
+
". Retrying in "
+
str
(
LOGSERVER_CONNECT_RETRY_TIME
)
+
"s ..."
)
time
.
sleep
(
LOGSERVER_CONNECT_RETRY_TIME
)
return
False
else
:
time
.
sleep
(
LOGSERVER_CONNECT_RETRY_TIME
)
return
False
def
reconnectToServer
(
self
):
if
not
self
.
socketUp
:
self
.
socket
.
close
()
self
.
createSocket
()
while
not
self
.
connectToServer
():
pass
def
tearDown
(
self
):
self
.
socket
.
close
()
...
...
@@ -78,22 +100,31 @@ class SocketInput(InputBase):
def
retrieveDataFromSocket
(
self
):
try
:
data
=
self
.
socket
.
recv
(
4096
)
except
socket
.
timeout
:
print
(
"Connection timeout."
)
self
.
socket
.
close
()
return
""
except
IOError
:
print
(
"Error: Could not retrieve data from "
+
self
.
dst
)
self
.
socket
.
close
()
return
""
else
:
if
(
len
(
data
)
==
0
):
print
(
"Connection closed by foreign host."
)
if
(
self
.
connectionUp
):
try
:
data
=
self
.
socket
.
recv
(
4096
)
except
socket
.
timeout
:
print
(
"Connection timeout."
)
self
.
socket
.
close
()
self
.
socketUp
=
False
self
.
connectionUp
=
False
return
""
except
IOError
:
print
(
"Error: Could not retrieve data from "
+
self
.
dst
)
self
.
socket
.
close
()
self
.
socketUp
=
False
self
.
connectionUp
=
False
return
""
else
:
self
.
__incomeBuffer
.
append
(
data
)
if
(
len
(
data
)
==
0
):
print
(
"Connection closed by foreign host."
)
self
.
socket
.
close
()
self
.
socketUp
=
False
self
.
connectionUp
=
False
else
:
self
.
__incomeBuffer
.
append
(
data
)
else
:
self
.
reconnectToServer
()
def
processDataFromSocket
(
self
):
...
...
tcpliveplot/main.py
View file @
4a7aadbf
...
...
@@ -11,7 +11,7 @@ from .info_registry import InfoRegistry
# constants
TCP_PLOT_VERSION
=
"0.2.
0
"
TCP_PLOT_VERSION
=
"0.2.
1
"
TCP_LOG_FORMAT_VERSION_MIN
=
"2"
DEFAULT_LOGFILE_PATH
=
"/tmp/tcplog.log"
...
...
@@ -103,6 +103,7 @@ def parse_options():
dest
=
"inputBackend"
,
default
=
DEFAULT_INPUT_BACKEND
)
# TODO: remove
parser
.
add_argument
(
"-b"
,
"--buffer"
,
help
=
"Length of preload buffer (in seconds, default: 1, 0 to deactivate preload buffer)"
,
...
...
@@ -110,6 +111,7 @@ def parse_options():
dest
=
"preloadBuffer"
,
default
=
1
)
# TODO: remove
parser
.
add_argument
(
"-ib"
,
"--interimbuffer"
,
help
=
"Activate interim buffering."
,
...
...
@@ -117,12 +119,15 @@ def parse_options():
dest
=
"interimBuffering"
,
default
=
False
)
# TODO: remove
parser
.
add_argument
(
"-ps"
,
"--playback-speed"
,
help
=
"Playback speed (factor, default: 1)"
,
type
=
float
,
dest
=
"playbackSpeed"
,
default
=
1
)
# TODO: remove
parser
.
add_argument
(
"-aps"
,
"--adaptive-playback-speed"
,
help
=
"Enable adaptive playback speed (default: false)"
,
...
...
@@ -136,6 +141,12 @@ def parse_options():
dest
=
"bufferLength"
,
default
=
5000
)
parser
.
add_argument
(
"-4"
,
"--useQt4"
,
help
=
"Use Qt-4 instead of Qt-5 (default) as matplotlib-backend (default: False)"
,
action
=
"store_true"
,
dest
=
"useQt4"
,
default
=
False
)
parser
.
add_argument
(
"-z"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment