def __get_replica_info(self): cmd = "redis-cli -h %s -p %s info replication" % (self.hostname, self.port) res = exec_shell(cmd, p=False, need_return=True) d = _str2dict(res[0]) return d
def get_process(self, t): def get_diff(new, old): diff = {} for k, v in new.items(): diff[k] = v - old[k] diff['latency'] = new['latency'] return diff cmd = "%s --type %s" % (self.config.sdfs_mon, t) try: out, err = exec_shell(cmd, p=False, need_return=True) except: return d = _str2dict(out, col=' ') #print (d) newdata = {} diff = {} for k, v in d.items(): #print (k, v) tmp = _str2dict(v, row=';', col=':') for k1, v1 in tmp.items(): tmp[k1] = int(v1) newdata[k] = tmp try: olddata = self.rawdata[t][k] diff[k] = get_diff(tmp, olddata) #print ("got old--------------") except: #not exists diff[k] = tmp #print ("no old---------------%s %s---" % (t, k)) #print (self.rawdata) #print ("no old---------------%s %s---" % (t, k)) self.rawdata[t] = newdata self.instence[t] = diff
def __get_replica_info(self): cmd = "redis-cli -h %s -p %s info replication" % (self.hostname, self.port) while (1): try: res = exec_shell(cmd, p=False, need_return=True) except Exp as e: derror("get info replication error: " + str(Exp)) time.sleep(1) continue; break; d = _str2dict(res[0]) return d
def __get_used_percent(self, lst=None): #lst = ['node4/0', 'node4/1', 'node4/2', 'node4/3', 'node5/0'] used_percent = [] res = _exec_pipe([self.lich_admin, '--listnode'], 3, False)[:-1] if lst: list = [x.strip() for x in res.splitlines() if x.strip() in lst] else: list = [x.strip() for x in res.splitlines()] if len(list) == 0: _derror("node is not exists") exit(errno.EINVAL) for node in list: res = _exec_pipe([self.lich_admin, '--stat', node], 3, False)[:-1] if (len(res) != 0): d = _str2dict(res) used = d['used'] capacity = d['capacity'] percent = float(used) / float(capacity) * 100 used_percent.append((node, percent, used, capacity)) return sorted(used_percent, key=lambda d: d[1], reverse=False)
def read_dict(filename): with open(filename) as f: res = f.read() return _str2dict(res)