コード例 #1
0
    def generate_status(self):
        """Generate the status for the copying manager to be reported.

        This is used in such features as 'scalyr-agent-2 status -v'.

        Note, this method is thread safe.  It needs to be since another thread will ask this object for its
        status.

        @return:  The status object containing the statistics for the copying manager.
        @rtype: CopyingManagerStatus
        """
        try:
            self.__lock.acquire()

            result = CopyingManagerStatus()
            result.total_bytes_uploaded = self.__total_bytes_uploaded
            result.last_success_time = self.__last_success_time
            result.last_attempt_time = self.__last_attempt_time
            result.last_attempt_size = self.__last_attempt_size
            result.last_response = self.__last_response
            result.last_response_status = self.__last_response_status
            result.total_errors = self.__total_errors

            for entry in self.__log_matchers:
                result.log_matchers.append(entry.generate_status())

        finally:
            self.__lock.release()

        return result
コード例 #2
0
    def generate_status(self):
        """Generate the status for the copying manager to be reported.

        This is used in such features as 'scalyr-agent-2 status -v'.

        Note, this method is thread safe.  It needs to be since another thread will ask this object for its
        status.

        @return:  The status object containing the statistics for the copying manager.
        @rtype: CopyingManagerStatus
        """
        try:
            self.__lock.acquire()

            result = CopyingManagerStatus()
            result.total_bytes_uploaded = self.__total_bytes_uploaded
            result.last_success_time = self.__last_success_time
            result.last_attempt_time = self.__last_attempt_time
            result.last_attempt_size = self.__last_attempt_size
            result.last_response = self.__last_response
            result.last_response_status = self.__last_response_status
            result.total_errors = self.__total_errors

            for entry in self.__log_matchers:
                result.log_matchers.append(entry.generate_status())

        finally:
            self.__lock.release()

        return result
コード例 #3
0
    def setUp(self):
        self.time = 1409958853
        self.status = AgentStatus()
        self.status.launch_time = self.time - 86400
        self.status.log_path = '/var/logs/scalyr-agent/agent.log'
        self.status.scalyr_server = 'https://agent.scalyr.com'
        self.status.server_host = 'test_machine'
        self.status.user = '******'
        self.status.version = '2.0.0.beta.7'

        config_status = ConfigStatus()
        self.status.config_status = config_status
        config_status.last_read_time = self.time - 43200
        config_status.last_check_time = self.time
        config_status.last_good_read = self.time - 43000
        config_status.path = '/etc/scalyr-agent-2/agent.json'
        config_status.status = 'Good'
        config_status.additional_paths = ['/etc/scalyr-agent-2/agent.d/server.json']

        copying_status = CopyingManagerStatus()
        self.status.copying_manager_status = copying_status
        copying_status.last_attempt_size = 10000
        copying_status.last_attempt_time = self.time - 60
        copying_status.last_response_status = 'success'
        copying_status.total_errors = 0
        copying_status.total_bytes_uploaded = 10000
        copying_status.last_success_time = self.time - 60

        # Add in one log path that isn't a glob but does not have any matches yet.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = False
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = '/var/logs/tomcat6/access.log'

        # Add in another matcher that isn't a glob but does have a match.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = False
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = '/var/logs/tomcat6/catalina.log'
        process_status = LogProcessorStatus()
        log_matcher.log_processors_status.append(process_status)
        process_status.log_path = '/var/logs/tomcat6/catalina.log'
        process_status.last_scan_time = self.time - 120
        process_status.total_bytes_copied = 2341234
        process_status.total_bytes_pending = 1243
        process_status.total_bytes_skipped = 12
        process_status.total_bytes_failed = 1432
        process_status.total_bytes_dropped_by_sampling = 0
        process_status.total_lines_copied = 214324
        process_status.total_lines_dropped_by_sampling = 0
        process_status.total_redactions = 0

        # Add in another matcher that is a glob and has two matches.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = True
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = '/var/logs/cron/*.log'
        process_status = LogProcessorStatus()
        log_matcher.log_processors_status.append(process_status)
        process_status.log_path = '/var/logs/cron/logrotate.log'
        process_status.last_scan_time = self.time - 120
        process_status.total_bytes_copied = 2341234
        process_status.total_bytes_pending = 1243
        process_status.total_bytes_skipped = 12
        process_status.total_bytes_failed = 1432
        process_status.total_bytes_dropped_by_sampling = 0
        process_status.total_lines_copied = 214324
        process_status.total_lines_dropped_by_sampling = 0
        process_status.total_redactions = 0
        process_status = LogProcessorStatus()
        log_matcher.log_processors_status.append(process_status)
        process_status.log_path = '/var/logs/cron/ohno.log'
        process_status.last_scan_time = self.time - 120
        process_status.total_bytes_copied = 23434
        process_status.total_bytes_pending = 12943
        process_status.total_bytes_skipped = 12
        process_status.total_bytes_failed = 1432
        process_status.total_bytes_dropped_by_sampling = 5
        process_status.total_lines_copied = 214324
        process_status.total_lines_dropped_by_sampling = 10
        process_status.total_redactions = 10

        # One more glob that doesn't have any matches.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = True
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = '/var/logs/silly/*.log'

        # Now for the monitors.
        monitor_manager = MonitorManagerStatus()
        self.status.monitor_manager_status = monitor_manager
        monitor_manager.total_alive_monitors = 2

        monitor_status = MonitorStatus()
        monitor_manager.monitors_status.append(monitor_status)
        monitor_status.is_alive = True
        monitor_status.monitor_name = 'linux_process_metrics(agent)'
        monitor_status.reported_lines = 50
        monitor_status.errors = 2

        monitor_status = MonitorStatus()
        monitor_manager.monitors_status.append(monitor_status)
        monitor_status.is_alive = True
        monitor_status.monitor_name = 'linux_system_metrics()'
        monitor_status.reported_lines = 20
        monitor_status.errors = 0

        monitor_status = MonitorStatus()
        monitor_manager.monitors_status.append(monitor_status)
        monitor_status.is_alive = False
        monitor_status.monitor_name = 'bad_monitor()'
        monitor_status.reported_lines = 20
        monitor_status.errors = 40
コード例 #4
0
    def setUp(self):
        super(TestReportStatus, self).setUp()
        self.saved_env = dict(
            (k, v) for k, v in six.iteritems(os_environ_unicode))
        os.environ.clear()
        self.time = 1409958853
        self.status = AgentStatus()
        self.status.launch_time = self.time - 86400
        self.status.log_path = "/var/logs/scalyr-agent/agent.log"
        self.status.scalyr_server = "https://agent.scalyr.com"
        self.status.server_host = "test_machine"
        self.status.user = "******"
        self.status.version = "2.0.0.beta.7"
        self.status.revision = "git revision"
        self.status.python_version = "3.6.8"

        config_status = ConfigStatus()
        self.status.config_status = config_status
        config_status.last_read_time = self.time - 43200
        config_status.last_check_time = self.time
        config_status.last_good_read = self.time - 43000
        config_status.path = "/etc/scalyr-agent-2/agent.json"
        config_status.status = "Good"
        config_status.additional_paths = [
            "/etc/scalyr-agent-2/agent.d/server.json"
        ]

        copying_status = CopyingManagerStatus()
        self.status.copying_manager_status = copying_status
        copying_status.last_attempt_size = 10000
        copying_status.last_attempt_time = self.time - 60
        copying_status.last_response_status = "success"
        copying_status.total_errors = 0
        copying_status.total_bytes_uploaded = 10000
        copying_status.last_success_time = self.time - 60

        # Add in one log path that isn't a glob but does not have any matches yet.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = False
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = "/var/logs/tomcat6/access.log"

        # Add in another matcher that isn't a glob but does have a match.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = False
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = "/var/logs/tomcat6/catalina.log"
        process_status = LogProcessorStatus()
        log_matcher.log_processors_status.append(process_status)
        process_status.log_path = "/var/logs/tomcat6/catalina.log"
        process_status.last_scan_time = self.time - 120
        process_status.total_bytes_copied = 2341234
        process_status.total_bytes_pending = 1243
        process_status.total_bytes_skipped = 12
        process_status.total_bytes_failed = 1432
        process_status.total_bytes_dropped_by_sampling = 0
        process_status.total_lines_copied = 214324
        process_status.total_lines_dropped_by_sampling = 0
        process_status.total_redactions = 0

        # Add in another matcher that is a glob and has two matches.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = True
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = "/var/logs/cron/*.log"
        process_status = LogProcessorStatus()
        log_matcher.log_processors_status.append(process_status)
        process_status.log_path = "/var/logs/cron/logrotate.log"
        process_status.last_scan_time = self.time - 120
        process_status.total_bytes_copied = 2341234
        process_status.total_bytes_pending = 1243
        process_status.total_bytes_skipped = 12
        process_status.total_bytes_failed = 1432
        process_status.total_bytes_dropped_by_sampling = 0
        process_status.total_lines_copied = 214324
        process_status.total_lines_dropped_by_sampling = 0
        process_status.total_redactions = 0
        process_status = LogProcessorStatus()
        log_matcher.log_processors_status.append(process_status)
        process_status.log_path = "/var/logs/cron/ohno.log"
        process_status.last_scan_time = self.time - 120
        process_status.total_bytes_copied = 23434
        process_status.total_bytes_pending = 12943
        process_status.total_bytes_skipped = 12
        process_status.total_bytes_failed = 1432
        process_status.total_bytes_dropped_by_sampling = 5
        process_status.total_lines_copied = 214324
        process_status.total_lines_dropped_by_sampling = 10
        process_status.total_redactions = 10

        # One more glob that doesn't have any matches.
        log_matcher = LogMatcherStatus()
        copying_status.log_matchers.append(log_matcher)
        log_matcher.is_glob = True
        log_matcher.last_check_time = self.time - 10
        log_matcher.log_path = "/var/logs/silly/*.log"

        # Now for the monitors.
        monitor_manager = MonitorManagerStatus()
        self.status.monitor_manager_status = monitor_manager
        monitor_manager.total_alive_monitors = 2

        monitor_status = MonitorStatus()
        monitor_manager.monitors_status.append(monitor_status)
        monitor_status.is_alive = True
        monitor_status.monitor_name = "linux_process_metrics(agent)"
        monitor_status.reported_lines = 50
        monitor_status.errors = 2

        monitor_status = MonitorStatus()
        monitor_manager.monitors_status.append(monitor_status)
        monitor_status.is_alive = True
        monitor_status.monitor_name = "linux_system_metrics()"
        monitor_status.reported_lines = 20
        monitor_status.errors = 0

        monitor_status = MonitorStatus()
        monitor_manager.monitors_status.append(monitor_status)
        monitor_status.is_alive = False
        monitor_status.monitor_name = "bad_monitor()"
        monitor_status.reported_lines = 20
        monitor_status.errors = 40