How to use the amplify.agent.common.context.context.log function in amplify

To help you get started, we’ve selected a few amplify examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nginxinc / nginx-amplify-agent / amplify / ext / mysql / util.py View on Github external
raw_stdout, _ = subp.call(VERSION_CMD % bin_path)

        # also trying to get the first line of output
        # here's the line that we are interested in::
        # mysqld  Ver 5.5.55-0ubuntu0.14.04.1 for debian-linux-gnu on x86_64 ((Ubuntu))
        raw_line = raw_stdout[0]
    except Exception as e:
        exc_name = e.__class__.__name__
        # this is being logged as debug only since we will rely on bin_path
        # collection error to tip off support as to what is going wrong with
        # version detection
        context.log.debug(
            'failed to get version info from "%s" due to %s' %
            (bin_path, exc_name)
        )
        context.log.debug('additional info:', exc_info=True)
    else:
        raw_version = raw_line.split()[2]  # 5.5.55-0ubuntu0.14.04.1

        version = []
        for char in raw_version:
            if char.isdigit() or char == '.':
                version.append(char)
            else:
                break

        return ''.join(version), raw_line
github nginxinc / nginx-amplify-agent / amplify / agent / pipelines / syslog.py View on Github external
self.address = address  # This stores the address that we were passed
        self.listener = None
        self.listener_setup_attempts = 0
        self.thread = None

        # Try to start listener right away, handle the exception
        try:
            self._setup_listener(**self.kwargs)
        except AmplifyAddresssAlreadyInUse as e:
            context.log.warning(
                'failed to start listener during syslog tail init due to "%s", will try later (attempts: %s)' % (
                    e.__class__.__name__,
                    self.listener_setup_attempts
                )
            )
            context.log.debug('additional info:', exc_info=True)

        self.running = True
github nginxinc / nginx-amplify-agent / amplify / agent / collectors / nginx / metrics.py View on Github external
def handle_zombie(self, pid):
        """
        removes pid from workers list
        :param pid: zombie pid
        """
        context.log.warning('zombie process %s found' % pid)
        self.zombies.add(pid)
github nginxinc / nginx-amplify-agent / amplify / agent / objects / nginx / config / config.py View on Github external
def full_parse(self, include_ssl_certs=True):
        context.log.debug('parsing full tree of %s' % self.filename)

        # parse raw data
        try:
            self._setup_parser()
            self.parser.parse(include_ssl_certs=include_ssl_certs)
            self._handle_parse()
        except Exception as e:
            context.log.error('failed to parse config at %s (due to %s)' % (self.filename, e.__class__.__name__))
            context.log.debug('additional info:', exc_info=True)
            self._setup_parser()  # Re-init parser to discard partial data (if any)

        # Post-handling
        # try to add logs from nginx -V configure options
        self.add_configured_variable_logs()

        # try to locate and use default logs (PREFIX/logs/*)
github nginxinc / nginx-amplify-agent / amplify / agent / supervisor.py View on Github external
# reset the cloud talk counter to avoid sending new requests every 5.0 seconds
            self.last_cloud_talk_time = int(time.time())

            cloud_response = CloudResponse(
                context.http_client.post('agent/', data=root_object)
            )

            if self.cloud_talk_delay:
                self.cloud_talk_fails = 0
                self.cloud_talk_delay = 0
                context.log.debug('successful cloud connect, reset cloud talk delay')
        except Exception as e:
            if isinstance(e, HTTPError) and e.response.status_code == 503:
                backpressure_error = HTTP503Error(e)
                context.backpressure_time = int(time.time() + backpressure_error.delay)
                context.log.debug(
                    'back pressure delay %s added (next talk: %s)' % (
                        backpressure_error.delay,
                        context.backpressure_time
                    )
                )
            else:
                self.cloud_talk_fails += 1
                self.cloud_talk_delay = exponential_delay(self.cloud_talk_fails)
                context.log.debug(
                    'cloud talk delay set to %s (fails: %s)' % (self.cloud_talk_delay, self.cloud_talk_fails)
                )

            context.log.error('could not connect to cloud', exc_info=True)
            raise AmplifyCriticalException()

        # check agent version status