示例#1
0
    def handle_shutdown_signal(signum, frame):
        print >>sys.stdout, 'Signal received, stopping monitor...'
        monitor.stop()

    for sig in (signal.SIGTERM, signal.SIGINT):
        signal.signal(sig, handle_shutdown_signal)

    try:
        if global_config_path is not None:
            controller = PlatformController.new_platform()
            paths = controller.default_paths
            global_config = Configuration( global_config_path, paths )
            global_config.parse(logger=log)
        else:
            global_config = None
        monitor = MonitorsManager.build_monitor(parsed_config, monitor_python_path, float(monitor_sample_interval),
                                                global_config )
        log.log(scalyr_logging.DEBUG_LEVEL_1, 'Constructed monitor')
        monitor.open_metric_log()
        log.log(scalyr_logging.DEBUG_LEVEL_1, 'Starting monitor')
        monitor.start()

        while monitor.isAlive():
            time.sleep(0.1)
    except BadMonitorConfiguration, e:
        print >>sys.stderr, 'Invalid monitor configuration: %s' % str(e)

    return 0

if __name__ == '__main__':
    parser = OptionParser(usage='Usage: python -m scalyr_agent.scalyr_monitor [options] monitor_module')
    parser.add_option("-p", "--monitor-python-path", dest="monitor_python_path",
        return 1

    parsed_config['module'] = monitor_module
    if 'id' not in parsed_config:
        parsed_config['id'] = ''

    # noinspection PyUnusedLocal
    def handle_shutdown_signal(signum, frame):
        print >>sys.stdout, 'Signal received, stopping monitor...'
        monitor.stop()

    for sig in (signal.SIGTERM, signal.SIGINT):
        signal.signal(sig, handle_shutdown_signal)

    try:
        monitor = MonitorsManager.build_monitor(parsed_config, monitor_python_path)
        monitor.set_sample_interval(float(monitor_sample_interval))
        monitor.open_metric_log()
        monitor.start()

        while monitor.is_alive():
            time.sleep(0.1)
    except BadMonitorConfiguration, e:
        print >>sys.stderr, 'Invalid monitor configuration: %s' % str(e)

    return 0

if __name__ == '__main__':
    parser = OptionParser(usage='Usage: python -m scalyr_agent.scalyr_monitor [options] monitor_module')
    parser.add_option("-p", "--monitor-python-path", dest="monitor_python_path",
                      help="Add PATH to the paths searched to find the python module for the monitor.", metavar="PATH",
示例#3
0
def run_standalone_monitor(
    monitor_module,
    monitor_python_path,
    monitor_config,
    monitor_sample_interval,
    monitor_debug_level,
    global_config_path,
):
    """Runs a single plugin monitor instance.

    @param monitor_module: The name of the python module implementing the monitor.
    @param monitor_python_path: The python path to search to find the module.
    @param monitor_config: The monitor configuration object.
    @param monitor_sample_interval: The default to use for the sample interval.
    @param monitor_debug_level: The debug level to use for logging.
    @param global_config_path:  The path to the agent.json global configuration file to use, or None if none was
        supplied.
    """
    scalyr_logging.set_log_destination(use_stdout=True)
    scalyr_logging.set_log_level(monitor_debug_level)

    log.log(scalyr_logging.DEBUG_LEVEL_1, "Attempting to run module %s",
            monitor_module)

    try:
        # Needs to be json_lib.parse because it is parsing configuration
        parsed_config = scalyr_util.json_scalyr_config_decode(monitor_config)
        log.log(scalyr_logging.DEBUG_LEVEL_1,
                "Parsed configuration successfully")
    except JsonParseException as e:
        print(
            "Failed to parse the monitor configuration as valid JSON: %s",
            six.text_type(e),
            file=sys.stderr,
        )
        return 1

    parsed_config["module"] = monitor_module
    if "id" not in parsed_config:
        parsed_config["id"] = ""

    # noinspection PyUnusedLocal
    def handle_shutdown_signal(signum, frame):
        print("Signal received, stopping monitor...", file=sys.stdout)
        monitor.stop()

    for sig in (signal.SIGTERM, signal.SIGINT):
        signal.signal(sig, handle_shutdown_signal)

    try:
        if global_config_path is not None:
            controller = PlatformController.new_platform()
            paths = controller.default_paths
            global_config = Configuration(global_config_path, paths, log)
            global_config.parse()
        else:
            global_config = None
        monitor = MonitorsManager.build_monitor(
            parsed_config,
            monitor_python_path,
            float(monitor_sample_interval),
            global_config,
        )
        log.log(scalyr_logging.DEBUG_LEVEL_1, "Constructed monitor")
        monitor.open_metric_log()
        log.log(scalyr_logging.DEBUG_LEVEL_1, "Starting monitor")
        monitor.start()

        while monitor.isAlive():
            time.sleep(0.1)
    except BadMonitorConfiguration as e:
        print("Invalid monitor configuration: %s" % six.text_type(e),
              file=sys.stderr)

    return 0
示例#4
0
        return 1

    parsed_config['module'] = monitor_module
    if 'id' not in parsed_config:
        parsed_config['id'] = ''

    # noinspection PyUnusedLocal
    def handle_shutdown_signal(signum, frame):
        print >> sys.stdout, 'Signal received, stopping monitor...'
        monitor.stop()

    for sig in (signal.SIGTERM, signal.SIGINT):
        signal.signal(sig, handle_shutdown_signal)

    try:
        monitor = MonitorsManager.build_monitor(parsed_config,
                                                monitor_python_path)
        log.log(scalyr_logging.DEBUG_LEVEL_1, 'Constructed monitor')
        monitor.set_sample_interval(float(monitor_sample_interval))
        monitor.open_metric_log()
        log.log(scalyr_logging.DEBUG_LEVEL_1, 'Starting monitor')
        monitor.start()

        while monitor.is_alive():
            time.sleep(0.1)
    except BadMonitorConfiguration, e:
        print >> sys.stderr, 'Invalid monitor configuration: %s' % str(e)

    return 0


if __name__ == '__main__':