Beispiel #1
0
 def leastUtilizedNode(self, serverAddress):
     min = float("-inf")
     dummy = []
     for ip, channel in self.activeIpList.items():
         if ip == serverAddress:
             continue
         stub = heartbeat_pb2_grpc.HearBeatStub(channel)
         response = stub.isAlive(heartbeat_pb2.NodeInfo())
         dummy.append(
             (float(response.cpu_usage), float(response.disk_space),
              float(response.used_mem), ip, channel))
     if len(dummy) == 0:
         return 9999
     print("dummy", dummy)
     a = sorted(dummy, key=lambda x: (x[1]))
     heartbeat_pb2_grpc.HearBeatStub(a[0][4]).isAlive(
         heartbeat_pb2.NodeInfo())
     return a[0][3]
Beispiel #2
0
 def getAvg(self):
     count, cpu_usage, disk_space, used_mem = 0, 0, 0, 0
     for ip, channel in self.activeIpList.items():
         stub = heartbeat_pb2_grpc.HearBeatStub(channel)
         response = stub.isAlive(heartbeat_pb2.NodeInfo())
         disk_space += float(response.disk_space)
         used_mem += float(response.used_mem)
         cpu_usage += float(response.cpu_usage)
         count += 1
     if count == 0:
         return (0, 0, 0)
     return (disk_space / count, used_mem / count, cpu_usage / count)
Beispiel #3
0
 def run(self):
     while True:
         channel = grpc.insecure_channel(self.target + ':' +
                                         str(server_config.get('port')))
         stub = heartbeat_pb2_grpc.HearBeatStub(channel)
         response = stub.getStatus(
             heartbeat_pb2.HeartBeatRequest(ip=self.ip, leader=False))
         self.response['cpu_usage'] = response.cpu_usage
         self.response['mem_usage'] = response.used_mem
         self.stat[self.index] = self.response
         print(
             "Status from server received. Server's response is: {}".format(
                 response))
         time.sleep(2)
    def leastUtilizedNode(self):
        min = float("-inf")
        self.dummy = []
        for ip, channel in self.activeIpList.items():
            stub = heartbeat_pb2_grpc.HearBeatStub(channel)
            response = stub.isAlive(heartbeat_pb2.NodeInfo())
            self.dummy.append((response.disk_space, response.used_mem,
                               response.cpu_usage, ip))

        if len(self.dummy) == 0:
            return 9999

        a = sorted(self.dummy, key=lambda x: (x[0], x[1]))
        #self.dummy.sort(key=lambda x: (x[0], x[1]))
        return a[0][3]
Beispiel #5
0
    def leastUtilizedNodeHelper(self):
        minVal, minVal2 = 301.00, 301.00
        leastLoadedNode, leastLoadedNode2 = "", ""
        for ip, channel in self.active_ip_channel_dict.items():
            if (self.isChannelAlive(channel)):
                stub = heartbeat_pb2_grpc.HearBeatStub(channel)
                stats = stub.isAlive(heartbeat_pb2.NodeInfo(ip="", port=""))
                total = float(stats.cpu_usage) + float(
                    stats.disk_space) + float(stats.used_mem)
                if ((total / 3) < minVal):
                    minVal2 = minVal
                    minVal = total / 3
                    leastLoadedNode2 = leastLoadedNode
                    leastLoadedNode = ip
                elif ((total / 3) < minVal2):
                    minVal2 = total / 3
                    leastLoadedNode2 = ip

        if (leastLoadedNode == ""):
            return -1
        return leastLoadedNode, leastLoadedNode2
Beispiel #6
0
    def getClusterStats(self, request, context):
        print("Inside getClusterStats")
        active_ip_channel_dict = self.activeNodesChecker.getActiveChannels()
        total_cpu_usage, total_disk_space, total_used_mem = 0.0, 0.0, 0.0
        total_nodes = 0
        for ip, channel in active_ip_channel_dict.items():
            if (self.isChannelAlive(channel)):
                stub = heartbeat_pb2_grpc.HearBeatStub(channel)
                stats = stub.isAlive(heartbeat_pb2.NodeInfo(ip="", port=""))
                total_cpu_usage = float(stats.cpu_usage)
                total_disk_space = float(stats.disk_space)
                total_used_mem = float(stats.used_mem)
                total_nodes += 1

        if (total_nodes == 0):
            return fileService_pb2.ClusterStats(cpu_usage=str(100.00),
                                                disk_space=str(100.00),
                                                used_mem=str(100.00))

        return fileService_pb2.ClusterStats(
            cpu_usage=str(total_cpu_usage / total_nodes),
            disk_space=str(total_disk_space / total_nodes),
            used_mem=str(total_used_mem / total_nodes))
Beispiel #7
0
def client():
	with grpc.insecure_channel('localhost:3000') as channel:
		stub = heartbeat_pb2_grpc.HearBeatStub(channel)
		response = stub.isAlive(heartbeat_pb2.NodeInfo())
		print("Greeter client received: " + response.used_mem)