def report_app_metadata():
    CoreAgentSocket.instance().send(
        ApplicationEvent(
            event_type="scout.metadata",
            event_value=get_metadata(),
            source="Pid: " + str(getpid()),
            timestamp=dt.datetime.utcnow(),
        ))
Example #2
0
def test_socket_instance_is_recreated_if_not_running(running_agent):
    socket1 = CoreAgentSocket.instance()
    socket1.stop()
    socket1.join()
    socket2 = CoreAgentSocket.instance()
    try:
        assert socket2 is not socket1
    finally:
        socket2.stop()
        socket2.join()
Example #3
0
def test_socket_instance_is_a_singleton(running_agent):
    socket1 = CoreAgentSocket.instance()
    socket2 = CoreAgentSocket.instance()
    try:
        assert socket2 is socket1
    finally:
        socket1.stop()
        socket1.join()
        socket2.stop()
        socket2.join()
    def finish(self):
        logger.debug("Stopping request: %s", self.request_id)
        if self.end_time is None:
            self.end_time = dt.datetime.utcnow()
        if self.is_real_request:
            self.tag("mem_delta", self._get_mem_delta())
            if not self.is_ignored():
                batch_command = BatchCommand.from_tracked_request(self)
                CoreAgentSocket.instance().send(batch_command)
            SamplersThread.ensure_started()

        from scout_apm.core.context import context

        context.clear_tracked_request(self)
Example #5
0
def socket(running_agent):
    socket = CoreAgentSocket.instance()
    try:
        time.sleep(0.01)  # wait for socket to connect and register
        yield socket
    finally:
        socket.stop()
        socket.join()
Example #6
0
    def run(self):
        logger.debug("Starting Samplers.")
        instances = [Cpu(), Memory()]

        while True:
            for instance in instances:
                event_value = instance.run()
                if event_value is not None:
                    event_type = instance.metric_type + "/" + instance.metric_name
                    event = ApplicationEvent(
                        event_value=event_value,
                        event_type=event_type,
                        timestamp=dt.datetime.utcnow(),
                        source="Pid: " + str(os.getpid()),
                    )
                    CoreAgentSocket.instance().send(event)

            should_stop = self._stop_event.wait(timeout=60)
            if should_stop:
                logger.debug("Stopping Samplers.")
                break
Example #7
0
 def socket(cls):
     return CoreAgentSocket.instance(scout_config=ScoutConfig())