Пример #1
0
 def disk_used_size(self):
     """
     Obtaining the system disk used size
     :return: current disk used size of the GaussDb
     """
     proc_pid = Common.get_proc_pid(self.ip, self.port)
     get_data_path = "ps -ux | awk '{if ($2==\"%s\")print}'" % proc_pid
     std, _ = Common.execute_cmd(get_data_path)
     if not std:
         self.logger.warn("There is no process of: %s." % proc_pid)
         return "0.0M"
     std = std.decode()
     data_dir = std.split()[std.split().index("-D") + 1]
     if not os.path.isdir(data_dir):
         self.logger.warn("The data dir does not exist: %s." % data_dir)
         return "0.0M"
     disk_info, _ = Common.execute_cmd("du -sh %s" % data_dir.strip())
     usage = Common.unify_byte_unit(disk_info.decode("utf-8").split()[0])
     return usage
Пример #2
0
 def io_wait():
     """
     Obtaining the system io_wait
     :return: io_wait info
     """
     std, _ = Common.execute_cmd("iostat")
     if not std:
         return "0.0"
     usage = std.decode("utf-8").split("\n")[3].split()[3]
     return usage
Пример #3
0
 def io_read(self):
     """
     Obtaining the io_read info of the GaussDB
     :return: io_read info
     """
     proc_pid = Common.get_proc_pid(self.ip, self.port)
     cmd = "pidstat -d | awk '{if ($4==\"%s\")print}' | awk '{print $5}'" % proc_pid
     std, _ = Common.execute_cmd(cmd)
     if not std:
         return "0.0"
     return std.decode("utf-8").strip()
Пример #4
0
 def memory_usage(self):
     """
     Obtaining the memory Usage of the GaussDB
     :return: current memory usage of the GaussDb
     """
     proc_pid = Common.get_proc_pid(self.ip, self.port)
     cmd = "ps -ux | awk '{if ($2==\"%s\")print}' |awk '{print $4}'" % proc_pid
     std, _ = Common.execute_cmd(cmd)
     if not std:
         return "0.0"
     return std.decode("utf-8").strip()
Пример #5
0
 def stop_agent(self):
     try:
         if not os.path.exists(self.pid_file):
             self.logger.warn("The pid file does not exists.")
             std = Common.check_proc_exist("role agent")
             if not std:
                 raise Exception("ERROR: Process not running.")
             else:
                 kill_proc = "kill -9 %s" % std
                 Common.execute_cmd(kill_proc)
         else:
             with open(self.pid_file, mode='r') as f:
                 pid = int(f.read())
                 os.kill(pid, signal.SIGTERM)
                 os.remove(self.pid_file)
         self.logger.info("Successfully stopped agent.")
     except Exception as e:
         self.logger.error("Failed to stop agent, Error: %s" % str(e))
         sys.stdout.write("Error: " + str(e) + "\n")
         if os.path.exists(self.pid_file):
             os.remove(self.pid_file)
Пример #6
0
 def stop_service(self):
     try:
         if not os.path.isfile(self.pid_file):
             std = Common.check_proc_exist("role server")
             if not std:
                 raise Exception("ERROR: Process not running.")
             else:
                 kill_proc = "kill -9 %s" % std
                 Common.execute_cmd(kill_proc)
         else:
             with open(self.pid_file, mode='r') as f:
                 pid = int(f.read())
                 os.kill(pid, signal.SIGTERM)
                 os.remove(self.pid_file)
         self.logger.info("Successfully stopped server.")
     except Exception as err_msg:
         self.logger.error("Failed to stop service, Error: %s" %
                           str(err_msg))
         sys.stdout.write("Error: " + str(err_msg) + "\n")
         if os.path.isfile(self.pid_file):
             os.remove(self.pid_file)
Пример #7
0
def manage_service(args):
    server_pid_file = os.path.join(current_dirname, './tmp/server.pid')
    agent_pid_file = os.path.join(current_dirname, './tmp/agent.pid')
    if args.role == 'server':
        from service.my_app import MyApp
        if args.mode == 'start':
            MyApp(server_pid_file, LOGGER).start_service(CONFIG_PATH)
        else:
            MyApp(server_pid_file, LOGGER).stop_service()
    elif args.role == 'agent':
        from agent.manage_agent import Agent
        if args.mode == 'start':
            get_data_path = "ps -ux | grep -v grep | grep gaussdb"
            std, _ = Common.execute_cmd(get_data_path)
            if not std:
                raise Exception(
                    "The GaussDb process does not exists, please check it.")
            Agent(agent_pid_file, LOGGER).start_agent(CONFIG_PATH)
        else:
            Agent(agent_pid_file, LOGGER).stop_agent()
    else:
        print('FATAL: incorrect parameter.')
        print(usage())
        return -1