Send CPU load to ZK

This commit is contained in:
Joshua Boniface 2018-09-24 15:09:51 -04:00
parent efc8cf3cef
commit 40f36271cc
1 changed files with 4 additions and 2 deletions

View File

@ -133,10 +133,12 @@ class RouterInstance():
self.daemon_state = 'run' self.daemon_state = 'run'
# Set our information in zookeeper # Set our information in zookeeper
cpuload = os.getloadavg()[0]
keepalive_time = int(time.time()) keepalive_time = int(time.time())
try: try:
zkhandler.writedata(self.zk_conn, { zkhandler.writedata(self.zk_conn, {
'/routers/{}/keepalive'.format(self.name): str(keepalive_time) '/routers/{}/keepalive'.format(self.name): str(keepalive_time),
'/routers/{}/cpuload'.format(self.name): str(cpuload),
}) })
except: except:
ansiiprint.echo('Failed to set keepalive data', '', 'e') ansiiprint.echo('Failed to set keepalive data', '', 'e')
@ -144,7 +146,7 @@ class RouterInstance():
# Display router information to the terminal # Display router information to the terminal
ansiiprint.echo('{}{} keepalive{}'.format(ansiiprint.purple(), self.name, ansiiprint.end()), '', 't') ansiiprint.echo('{}{} keepalive{}'.format(ansiiprint.purple(), self.name, ansiiprint.end()), '', 't')
ansiiprint.echo('{0}Network list:{1} {2}'.format(ansiiprint.bold(), ansiiprint.end(), self.network_list), '', 'c') ansiiprint.echo('{0}Networks count:{1} {2} {0}Load average:{1} {3}'.format(ansiiprint.bold(), ansiiprint.end(), len(self.network_list), cpuload), '', 'c')
# Update our local router lists # Update our local router lists
for router_name in self.t_router: for router_name in self.t_router: