Exemple #1
0
    def generate_status(self):
        """Creates and returns a status object that reports the monitor status.

        @return:  The status for all the monitors.
        @rtype: MonitorManagerStatus
        """
        try:
            self.__lock.acquire()
            result = MonitorManagerStatus()

            for monitor in self.__monitors:
                if monitor.isAlive():
                    result.total_alive_monitors += 1

                status = MonitorStatus()
                status.monitor_name = monitor.monitor_name
                status.reported_lines = monitor.reported_lines()
                status.errors = monitor.errors()
                status.is_alive = monitor.isAlive()

                result.monitors_status.append(status)

            return result
        finally:
            self.__lock.release()
    def generate_status(self):
        """Creates and returns a status object that reports the monitor status.

        @return:  The status for all the monitors.
        @rtype: MonitorManagerStatus
        """
        try:
            self.__lock.acquire()
            result = MonitorManagerStatus()

            for monitor in self.__monitors:
                if monitor.isAlive():
                    result.total_alive_monitors += 1

                status = MonitorStatus()
                status.monitor_name = monitor.monitor_name
                status.reported_lines = monitor.reported_lines()
                status.errors = monitor.errors()
                status.is_alive = monitor.isAlive()

                result.monitors_status.append(status)

            return result
        finally:
            self.__lock.release()
    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
Exemple #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