You need to sign in or sign up before continuing.
Commit 7344f9f9 authored by Nilesh Jagdish's avatar Nilesh Jagdish

Added client and monitor files

parent 060dad00
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
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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment