def _save_logs_path(self): prefix = '' if Platform.is_windows(): prefix = 'windows_' config = get_logging_config() self._collector_log = config.get('{0}collector_log_file'.format(prefix)) self._forwarder_log = config.get('{0}forwarder_log_file'.format(prefix)) self._dogstatsd_log = config.get('{0}dogstatsd_log_file'.format(prefix)) self._jmxfetch_log = config.get('jmxfetch_log_file')
def _save_logs_path(self): prefix = "" if Platform.is_windows(): prefix = "windows_" config = get_logging_config() self._collector_log = config.get("{0}collector_log_file".format(prefix)) self._forwarder_log = config.get("{0}forwarder_log_file".format(prefix)) self._dogstatsd_log = config.get("{0}dogstatsd_log_file".format(prefix)) self._jmxfetch_log = config.get("jmxfetch_log_file")
def _supervisor_status(self): if Platform.is_windows(): print "Windows - status not implemented" else: agent_exec = self._get_path_agent_exec() print "{0} status".format(agent_exec) self._print_output_command([agent_exec, "status"]) supervisor_exec = self._get_path_supervisor_exec() print "{0} status".format(supervisor_exec) self._print_output_command([supervisor_exec, "-c", self._get_path_supervisor_conf(), "status"])
def _supervisor_status(self): if Platform.is_windows(): print 'Windows - status not implemented' else: agent_exec = self._get_path_agent_exec() print '{0} status'.format(agent_exec) self._print_output_command([agent_exec, 'status']) supervisor_exec = self._get_path_supervisor_exec() print '{0} status'.format(supervisor_exec) self._print_output_command([supervisor_exec, '-c', self._get_path_supervisor_conf(), 'status'])
def _add_conf_tar(self): conf_path = get_config_path() log.info(" * {0}".format(conf_path)) self._tar.add(self._strip_comment(conf_path), os.path.join(self._prefix, "etc", "datadog.conf")) if not Platform.is_windows(): supervisor_path = os.path.join(os.path.dirname(get_config_path()), "supervisor.conf") log.info(" * {0}".format(supervisor_path)) self._tar.add(self._strip_comment(supervisor_path), os.path.join(self._prefix, "etc", "supervisor.conf")) for file_path in glob.glob(os.path.join(get_confd_path(), "*.yaml")) + glob.glob( os.path.join(get_confd_path(), "*.yaml.default") ): self._add_clean_confd(file_path)
def _add_conf_tar(self): conf_path = get_config_path() log.info(" * {0}".format(conf_path)) self._tar.add(self._strip_comment(conf_path), os.path.join(self._prefix, 'etc', 'datadog.conf')) if not Platform.is_windows(): supervisor_path = os.path.join(os.path.dirname(get_config_path()), 'supervisor.conf') log.info(" * {0}".format(supervisor_path)) self._tar.add(self._strip_comment(supervisor_path), os.path.join(self._prefix, 'etc', 'supervisor.conf')) for file_path in glob.glob(os.path.join(get_confd_path(), '*.yaml')): self._add_clean_confd(file_path)
def pid_exists(pid): """ Check if a pid exists. Lighter than psutil.pid_exists """ if psutil: return psutil.pid_exists(pid) if Platform.is_windows(): import ctypes # Available from python2.5 kernel32 = ctypes.windll.kernel32 synchronize = 0x100000 process = kernel32.OpenProcess(synchronize, 0, pid) if process != 0: kernel32.CloseHandle(process) return True else: return False # Code from psutil._psposix.pid_exists # See https://github.com/giampaolo/psutil/blob/master/psutil/_psposix.py if pid == 0: # According to "man 2 kill" PID 0 has a special meaning: # it refers to <<every process in the process group of the # calling process>> so we don't want to go any further. # If we get here it means this UNIX platform *does* have # a process with id 0. return True try: os.kill(pid, 0) except OSError as err: if err.errno == errno.ESRCH: # ESRCH == No such process return False elif err.errno == errno.EPERM: # EPERM clearly means there's a process to deny access to return True else: # According to "man 2 kill" possible error values are # (EINVAL, EPERM, ESRCH) therefore we should never get # here. If we do let's be explicit in considering this # an error. raise err else: return True
def _add_conf_tar(self): conf_path = get_config_path() if self._can_read(conf_path): self._tar.add(self._strip_comment(conf_path), os.path.join(self._prefix, 'etc', 'datadog.conf')) if not Platform.is_windows(): supervisor_path = os.path.join(os.path.dirname(get_config_path()), 'supervisor.conf') if self._can_read(supervisor_path): self._tar.add( self._strip_comment(supervisor_path), os.path.join(self._prefix, 'etc', 'supervisor.conf')) for file_path in glob.glob(os.path.join(get_confd_path(), '*.yaml')) +\ glob.glob(os.path.join(get_confd_path(), '*.yaml.default')): if self._can_read(file_path, output=False): self._add_clean_confd(file_path)