Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pa2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nilesh Jagdish
pa2
Commits
7344f9f9
Commit
7344f9f9
authored
Mar 13, 2021
by
Nilesh Jagdish
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added client and monitor files
parent
060dad00
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
0 deletions
+96
-0
client.py
client.py
+32
-0
lookup.py
lookup.py
+31
-0
monitor.py
monitor.py
+33
-0
No files found.
client.py
0 → 100644
View file @
7344f9f9
import
socket
import
concurrent.futures
import
urllib.request
import
random
import
time
TCP_IP
=
'192.168.123.174'
TCP_PORT
=
9001
BUFFER_SIZE
=
1024
server_conns
=
[[
'192.168.123.174'
,
9001
]]
def
send_request
(
request
,
server_index
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
((
server_conns
[
server_index
][
0
],
server_conns
[
server_index
][
1
]))
s
.
send
(
request
.
encode
(
'ascii'
))
data
=
s
.
recv
(
BUFFER_SIZE
)
s
.
close
()
return
data
request
=
'3,50'
server_index
=
0
while
(
True
)
:
l
=
[
request
]
*
50
server_index
=
(
server_index
+
1
)
%
len
(
server_conns
)
with
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
2
)
as
executor
:
req_sender
=
[
executor
.
submit
(
send_request
,
request
,
server_index
)
for
request
in
l
]
for
future
in
concurrent
.
futures
.
as_completed
(
req_sender
):
data
=
future
.
result
()
print
(
data
)
time
.
sleep
(
0.5
)
\ No newline at end of file
lookup.py
0 → 100644
View file @
7344f9f9
from
__future__
import
print_function
import
sys
import
libvirt
conn
=
libvirt
.
open
(
'qemu:///system'
)
if
conn
==
None
:
print
(
'Failed to open connection to qemu:///system'
,
file
=
sys
.
stderr
)
exit
(
1
)
# import libvirt
for
lease
in
conn
.
networkLookupByName
(
"default"
)
.
DHCPLeases
():
print
(
lease
)
# domainName = 'server1'
# dom = conn.lookupByName(domainName)
# if dom == None:
# print('Failed to get the domain object', file=sys.stderr)
# ifaces = dom.interfaceAddresses(libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT, 0)
# print("The interface IP addresses:")
# for (name, val) in ifaces.iteritems():
# if val['addrs']:
# for ipaddr in val['addrs']:
# if ipaddr['type'] == libvirt.VIR_IP_ADDR_TYPE_IPV4:
# print(ipaddr['addr'] + " VIR_IP_ADDR_TYPE_IPV4")
# elif ipaddr['type'] == libvirt.VIR_IP_ADDR_TYPE_IPV6:
# print(ipaddr['addr'] + " VIR_IP_ADDR_TYPE_IPV6")
# conn.close()
# exit(0)
\ No newline at end of file
monitor.py
0 → 100644
View file @
7344f9f9
import
sys
import
libvirt
import
time
conn
=
libvirt
.
open
(
'qemu:///system'
)
if
conn
==
None
:
print
(
'Failed to open connection to qemu:///system'
,
file
=
sys
.
stderr
)
exit
(
1
)
domainName
=
'server1'
dom
=
conn
.
lookupByName
(
domainName
)
if
dom
==
None
:
print
(
'Failed to get the domain object'
,
file
=
sys
.
stderr
)
N
=
10
cpu_stats
=
dom
.
getCPUStats
(
True
)
cpu_time1
=
0
cpu_time2
=
0
for
(
i
,
cpu
)
in
enumerate
(
cpu_stats
):
cpu_time1
=
cpu
[
'cpu_time'
]
/
1000000000.
print
(
'CPU '
+
str
(
i
)
+
' Time: '
+
str
(
cpu
[
'cpu_time'
]
/
1000000000.
))
time
.
sleep
(
N
)
cpu_stats
=
dom
.
getCPUStats
(
True
)
for
(
i
,
cpu
)
in
enumerate
(
cpu_stats
):
cpu_time2
=
cpu
[
'cpu_time'
]
/
1000000000.
print
(
'CPU '
+
str
(
i
)
+
' Time: '
+
str
(
cpu
[
'cpu_time'
]
/
1000000000.
))
print
(
100
*
(
cpu_time2
-
cpu_time1
)
/
N
)
conn
.
close
()
exit
(
0
)
\ No newline at end of file
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