def report_check_glusterd_op_version(ctx): cmd1 = "gluster v get all cluster.op-version" cmd2 = "gluster v get all cluster.max-op-version" try: out1 = command_output(cmd1) out2 = command_output(cmd2) version1 = out1.split("\n")[-1].split(" ")[-1].strip() version2 = out1.split("\n")[-1].split(" ")[-1].strip() if version1 != version2: ctx.warning("op-version is not up to date") else: ctx.ok("Glusterd is running", uptime_sec=out.strip()) except CommandError as e: ctx.notok("Failed to check op-version") logging.warn( ctx.lf("Failed to check op-version", error_code=e[0], error=e[1]))
def report_gluster_memory_usage(ctx): cmd = ['pgrep','gluster'] try: out = command_output(cmd) for pid in out.strip().split("\n"): mem_cmd = "ps -p {} -o %mem".format(pid) mem_out = command_output(mem_cmd) mem_percent = mem_out.split('\n')[1].split('.')[0].strip() if int(mem_percent) >= gluster_mem_limit: proc_cmd = "ps -p {} -o comm=".format(pid) proc_out = command_output(proc_cmd) ctx.notok("Memory used by gluster process is at alarming level", process_name=proc_out.strip(), percentage=mem_percent) except CommandError as e: ctx.notok("Failed to get memory usage of gluster processes") logging.warn(ctx.lf("pgrep/ps command failed", error_code=e[0], error=e[1]))
def test_command_output(self): """ Run a linux command without sudo: seq - prints numeric sequences """ input_command = ['seq', '5'] seq_result = utils.command_output(input_command) seq_expected = "1\n2\n3\n4\n5\n" self.assertEqual(seq_result, seq_expected)
def report_gfid__mismatch_dht(ctx): cmd = "grep 'gfid differs' " + logfile + " | grep -v grep | wc -l" try: out = command_output(cmd) if int(out.strip()) > 0: ctx.error("gfid mismatch found", no_of_mismatches=out.strip()) else: ctx.ok("no gfid mismatch") except CommandError as e: ctx.notok("Command failure") logging.warn(ctx.lf("Command Failure", error_code=e[0], error=e[1]))
def report_check_glusterd_uptime(ctx): cmd = "ps -C glusterd --no-header -o etimes" try: out = command_output(cmd) if out.strip() < "86400": ctx.warning("Glusterd uptime is less than 24 hours", uptime_sec=out.strip()) else: ctx.ok("Glusterd is running", uptime_sec=out.strip()) except CommandError as e: ctx.notok("Glusterd is not running") logging.warn( ctx.lf("Glusterd is not running", error_code=e[0], error=e[1]))
def report_coredump(ctx): cmd = "ulimit -c" try: out = command_output(cmd) if out.strip() == "unlimited": ctx.ok("The maximum size of core files created is set to unlimted.") else: ctx.notok("The maximum size of core files created is NOT set to unlimited.") except CommandError as e: ctx.notok("ulimit check failed") logging.warn(ctx.lf("ulimit check failed", error_code=e[0], error=e[1]))
def report_peer_disconnect(ctx): cmd = "gluster peer status" try: out = command_output(cmd) peer_count = out.split("\n")[0].split(":")[1].strip() peer_conn_count = out.count("(Connected)") dis_count = int(peer_count) - int(peer_conn_count) if 0 < dis_count: ctx.notok("One or more peer/s in disconnected/rejected state", total_peer_count=int(peer_count), disconnected_rejected_count=dis_count) logging.warning("Peer status: \n" + out) else: ctx.ok("All peers are in connected state", total_peer_count=int(peer_count), connected_count=int(peer_conn_count)) except CommandError as e: ctx.notok("Failed to check peer status") logging.warn( ctx.lf("peer status command failed", error_code=e[0], error=e[1]))
def report_system_memory_usage(ctx): cmd = "free -m" try: out = command_output(cmd) for line in out.split("\n"): if "Mem" in line: memtype, total, used, free, shared, cache, available = \ line.split() elif "Swap" in line: memtype, total, used, free = line.split() else: continue percent = int(100 * float(used)/float(total)) if percent >= mem_used_limit: ctx.notok("Memory used percentage on system is at alarming level", memtype=memtype.strip(':'), percentage=str(percent)) except CommandError as e: ctx.notok("Failed to get memory usage") logging.warn(ctx.lf("free command failed", error_code=e[0], error=e[1]))