This commit is contained in:
Joshua Boniface 2018-06-01 01:00:55 -04:00
parent 985977dafc
commit 0a8faac2aa
2 changed files with 29 additions and 22 deletions

View File

@ -9,7 +9,7 @@ class NodeInstance(threading.Thread):
self.zkey = '/nodes/%s' % name self.zkey = '/nodes/%s' % name
self.zk = zk self.zk = zk
self.name = name self.name = name
#self.state = 'stop' self.state = 'stop'
self.stop_thread = threading.Event() self.stop_thread = threading.Event()
self.node_list = node_list self.node_list = node_list
self.domainlist = [] self.domainlist = []
@ -53,25 +53,9 @@ class NodeInstance(threading.Thread):
def run(self): def run(self):
if self.name == socket.gethostname(): if self.name == socket.gethostname():
conn = self.setup_local_node() self.setup_local_node()
else:
while True: self.setup_remote_node()
if self.name == socket.gethostname():
self.memfree = conn.getFreeMemory()
self.cpuload = os.getloadavg()[0]
try:
self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii'))
self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii'))
except:
if self.stop_thread.is_set():
return
print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload ))
print("Active domains: %s" % self.domainlist)
for x in range(0,100):
time.sleep(0.1)
if self.stop_thread.is_set():
return
@zk.DataWatch(self.zkey + '/state') @zk.DataWatch(self.zkey + '/state')
def watch_state(data, stat): def watch_state(data, stat):
@ -111,4 +95,28 @@ class NodeInstance(threading.Thread):
print("Node hostname: %s" % self.name) print("Node hostname: %s" % self.name)
print("CPUs: %s" % self.cpucount) print("CPUs: %s" % self.cpucount)
return conn while True:
self.memfree = conn.getFreeMemory()
self.cpuload = os.getloadavg()[0]
try:
self.zk.set(self.zkey + '/memfree', str(self.memfree).encode('ascii'))
self.zk.set(self.zkey + '/cpuload', str(self.cpuload).encode('ascii'))
except:
if self.stop_thread.is_set():
return
print("Free memory: %s | Load: %s" % ( self.memfree, self.cpuload ))
print("Active domains: %s" % self.domainlist)
for x in range(0,100):
time.sleep(0.1)
if self.stop_thread.is_set():
return
def setup_remote_node(self):
while True:
for x in range(0,100):
time.sleep(0.1)
if self.stop_thread.is_set():
return

View File

@ -79,7 +79,6 @@ def updatenodes(new_node_list):
else: else:
t_node[node] = NodeInstance.NodeInstance(node, node_list, zk); t_node[node] = NodeInstance.NodeInstance(node, node_list, zk);
t_node[node].start() t_node[node].start()
time.sleep(0.1)
node_state = t_node[node].getstate() node_state = t_node[node].getstate()
print(node_state) print(node_state)