コード例 #1
0
ファイル: test_config.py プロジェクト: CaptTofu/dd-agent
    def testBadPidFile(self):
        pid_dir = "/does-not-exist"

        p = PidFile('test', pid_dir)
        path = p.get_path()
        self.assertEquals(path, "/tmp/test.pid")

        pid = "666"
        pid_f = open(path, 'w')
        pid_f.write(pid)
        pid_f.close()

        self.assertEquals(p.get_pid(), 666)
        self.assertEquals(p.clean(), True)
        self.assertEquals(os.path.exists(path), False)
コード例 #2
0
ファイル: test_config.py プロジェクト: jboyle2001/dd-agent
    def testGoodPidFie(self):
        """Verify that the pid file succeeds and fails appropriately"""

        pid_dir = tempfile.mkdtemp()
        program = 'test'

        expected_path = os.path.join(pid_dir, '%s.pid' % program)
        pid = "666"
        pid_f = open(expected_path, 'w')
        pid_f.write(pid)
        pid_f.close()

        p = PidFile(program, pid_dir)

        self.assertEquals(p.get_pid(), 666)
        # clean up
        self.assertEquals(p.clean(), True)
        self.assertEquals(os.path.exists(expected_path), False)
コード例 #3
0
ファイル: test_config.py プロジェクト: CaptTofu/dd-agent
    def testGoodPidFie(self):
        """Verify that the pid file succeeds and fails appropriately"""

        pid_dir = tempfile.mkdtemp()
        program = 'test'

        expected_path = os.path.join(pid_dir, '%s.pid' % program)
        pid = "666"
        pid_f = open(expected_path, 'w')
        pid_f.write(pid)
        pid_f.close()

        p = PidFile(program, pid_dir)

        self.assertEquals(p.get_pid(), 666)
        # clean up
        self.assertEquals(p.clean(), True)
        self.assertEquals(os.path.exists(expected_path), False)
コード例 #4
0
def main(config_path=None):
    """ The main entry point for the unix version of dogstatsd. """
    parser = optparse.OptionParser("%prog [start|stop|restart|status]")
    parser.add_option('-u', '--use-local-forwarder', action='store_true',
                        dest="use_forwarder", default=False)
    opts, args = parser.parse_args()

    reporter, server = init(config_path, use_watchdog=True, use_forwarder=opts.use_forwarder)

    # If no args were passed in, run the server in the foreground.
    if not args:
        reporter.start()
        server.start()

        # If we're here, we're done.
        logger.info("Shutting down ...")
        return 0

    # Otherwise, we're process the deamon command.
    else:
        command = args[0]
        pid_file = PidFile('dogstatsd')
        daemon = Dogstatsd(pid_file.get_path(), server, reporter)

        if command == 'start':
            daemon.start()
        elif command == 'stop':
            daemon.stop()
        elif command == 'restart':
            daemon.restart()
        elif command == 'status':
            pid = pid_file.get_pid()
            if pid:
                message = 'dogstatsd is running with pid %s' % pid
            else:
                message = 'dogstatsd is not running'
            logger.info(message)
            sys.stdout.write(message + "\n")
        else:
            sys.stderr.write("Unknown command: %s\n\n" % command)
            parser.print_help()
            return 1
        return 0
コード例 #5
0
            daemon.start()

        elif 'stop' == command:
            logging.info('Stop daemon')
            daemon.stop()

        elif 'restart' == command:
            logging.info('Restart daemon')
            daemon.restart()

        elif 'foreground' == command:
            logging.info('Running in foreground')
            daemon.run()

        elif 'status' == command:
            pid = pid_file.get_pid()
            if pid is not None:
                sys.stdout.write('dd-agent is running as pid %s.\n' % pid)
                logging.info("dd-agent is running as pid %s." % pid)
            else:
                sys.stdout.write('dd-agent is not running.\n')
                logging.info("dd-agent is not running.")

        else:
            sys.stderr.write('Unknown command: %s.\n' % sys.argv[1])
            sys.exit(2)

        sys.exit(0)

    else:
        sys.stderr.write('Usage: %s start|stop|restart|foreground|status' % sys.argv[0])
コード例 #6
0
            daemon.start()

        elif 'stop' == command:
            logging.info('Stop daemon')
            daemon.stop()

        elif 'restart' == command:
            logging.info('Restart daemon')
            daemon.restart()

        elif 'foreground' == command:
            logging.info('Running in foreground')
            daemon.run()

        elif 'status' == command:
            pid = pid_file.get_pid()
            if pid is not None:
                sys.stdout.write('dd-agent is running as pid %s.\n' % pid)
                logging.info("dd-agent is running as pid %s." % pid)
            else:
                sys.stdout.write('dd-agent is not running.\n')
                logging.info("dd-agent is not running.")

        else:
            sys.stderr.write('Unknown command: %s.\n' % sys.argv[1])
            sys.exit(2)

        sys.exit(0)

    else:
        sys.stderr.write('Usage: %s start|stop|restart|foreground|status' %
コード例 #7
0
ファイル: agent.py プロジェクト: ovesh/dd-agent
def main():
    options, args = get_parsed_args()
    agentConfig = get_config()

    # Logging
    setup_logging(agentConfig)


    COMMANDS = [
        'start',
        'stop',
        'restart',
        'foreground',
        'status',
        'info',
    ]

    if len(args) < 1:
        sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], "|".join(COMMANDS)))
        return 2

    command = args[0]

    if command not in COMMANDS:
        sys.stderr.write("Unknown command: %s\n" % command)
        return 3

    pid_file = PidFile('dd-agent')
 
    # Only initialize the Agent if we're starting or stopping it.
    if command in ['start', 'stop', 'restart', 'foreground']:

        if options.clean:
            pid_file.clean()

        agent = Agent(pid_file.get_path())

        if 'start' == command:
            logging.info('Start daemon')
            agent.start()

        elif 'stop' == command:
            logging.info('Stop daemon')
            agent.stop()

        elif 'restart' == command:
            logging.info('Restart daemon')
            agent.restart()

        elif 'foreground' == command:
            logging.info('Running in foreground')
            agent.run()

    # Commands that don't need the agent to be initialized.
    else:
        if 'status' == command:
            pid = pid_file.get_pid()
            if pid is not None:
                sys.stdout.write('dd-agent is running as pid %s.\n' % pid)
            else:
                sys.stdout.write('dd-agent is not running.\n')

        elif 'info' == command:
            return CollectorStatus.print_latest_status()

    return 0
コード例 #8
0
ファイル: agent.py プロジェクト: CaptTofu/dd-agent
def main():
    options, args = get_parsed_args()
    agentConfig = get_config(options=options)
    autorestart = agentConfig.get('autorestart', False)

    COMMANDS = [
        'start',
        'stop',
        'restart',
        'foreground',
        'status',
        'info',
    ]

    if len(args) < 1:
        sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], "|".join(COMMANDS)))
        return 2

    command = args[0]
    if command not in COMMANDS:
        sys.stderr.write("Unknown command: %s\n" % command)
        return 3

    pid_file = PidFile('dd-agent')

    # Only initialize the Agent if we're starting or stopping it.
    if command in ['start', 'stop', 'restart', 'foreground']:

        if options.clean:
            pid_file.clean()

        agent = Agent(pid_file.get_path(), autorestart)

        if 'start' == command:
            log.info('Start daemon')
            agent.start()

        elif 'stop' == command:
            log.info('Stop daemon')
            agent.stop()

        elif 'restart' == command:
            log.info('Restart daemon')
            agent.restart()

        elif 'foreground' == command:
            logging.info('Running in foreground')

            if autorestart:
                # Set-up the supervisor callbacks and fork it.
                logging.info('Running Agent with auto-restart ON')
                def child_func(): agent.run()
                def parent_func(): agent.start_event = False
                AgentSupervisor.start(parent_func, child_func)
            else:
                # Run in the standard foreground.
                agent.run(config=agentConfig)

    # Commands that don't need the agent to be initialized.
    else:
        if 'status' == command:
            pid = pid_file.get_pid()
            if pid is not None:
                sys.stdout.write('dd-agent is running as pid %s.\n' % pid)
                log.info("dd-agent is running as pid %s." % pid)
            else:
                sys.stdout.write('dd-agent is not running.\n')
                log.info("dd-agent is not running.")

        elif 'info' == command:
            logging.getLogger().setLevel(logging.ERROR)
            return CollectorStatus.print_latest_status(verbose=options.verbose)

    return 0
コード例 #9
0
ファイル: agent.py プロジェクト: dwradcliffe/dd-agent
def main():
    options, args = get_parsed_args()
    agentConfig = get_config(options=options)
    autorestart = agentConfig.get('autorestart', False)

    COMMANDS = [
        'start',
        'stop',
        'restart',
        'foreground',
        'status',
        'info',
        'check',
    ]

    if len(args) < 1:
        sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], "|".join(COMMANDS)))
        return 2

    command = args[0]
    if command not in COMMANDS:
        sys.stderr.write("Unknown command: %s\n" % command)
        return 3

    pid_file = PidFile('dd-agent')

    # Only initialize the Agent if we're starting or stopping it.
    if command in ['start', 'stop', 'restart', 'foreground', 'check']:

        if options.clean:
            pid_file.clean()

        agent = Agent(pid_file.get_path(), autorestart)

        if 'start' == command:
            log.info('Start daemon')
            agent.start()

        elif 'stop' == command:
            log.info('Stop daemon')
            agent.stop()

        elif 'restart' == command:
            log.info('Restart daemon')
            agent.restart()

        elif 'foreground' == command:
            logging.info('Running in foreground')

            if autorestart:
                # Set-up the supervisor callbacks and fork it.
                logging.info('Running Agent with auto-restart ON')
                def child_func(): agent.run()
                def parent_func(): agent.start_event = False
                AgentSupervisor.start(parent_func, child_func)
            else:
                # Run in the standard foreground.
                agent.run(config=agentConfig)

        elif 'check' == command:
            check_name = args[1]
            try:
                import checks.collector
                # Try the old-style check first
                print getattr(checks.collector, check_name)(log).check(agentConfig)
            except Exception:
                # If not an old-style check, try checks.d
                checks = load_check_directory(agentConfig)
                for check in checks:
                    if check.name == check_name:
                        check.run()
                        print check.get_metrics()
                        print check.get_events()
                        if len(args) == 3 and args[2] == 'check_rate':
                            print "Running 2nd iteration to capture rate metrics"
                            time.sleep(1)
                            check.run()
                        print check.get_metrics()
                        print check.get_events()


    # Commands that don't need the agent to be initialized.
    else:
        if 'status' == command:
            pid = pid_file.get_pid()
            if pid is not None:
                sys.stdout.write('dd-agent is running as pid %s.\n' % pid)
                log.info("dd-agent is running as pid %s." % pid)
            else:
                sys.stdout.write('dd-agent is not running.\n')
                log.info("dd-agent is not running.")

        elif 'info' == command:
            logging.getLogger().setLevel(logging.ERROR)
            return CollectorStatus.print_latest_status(verbose=options.verbose)

    return 0
コード例 #10
0
ファイル: agent.py プロジェクト: jkoppe/dd-agent
def main():
    options, args = get_parsed_args()
    agentConfig = get_config()

    # Logging
    setup_logging(agentConfig)

    COMMANDS = [
        'start',
        'stop',
        'restart',
        'foreground',
        'status',
        'info',
    ]

    if len(args) < 1:
        sys.stderr.write("Usage: %s %s\n" % (sys.argv[0], "|".join(COMMANDS)))
        return 2

    command = args[0]

    if command not in COMMANDS:
        sys.stderr.write("Unknown command: %s\n" % command)
        return 3

    pid_file = PidFile('dd-agent')

    # Only initialize the Agent if we're starting or stopping it.
    if command in ['start', 'stop', 'restart', 'foreground']:

        if options.clean:
            pid_file.clean()

        agent = Agent(pid_file.get_path())

        if 'start' == command:
            logging.info('Start daemon')
            agent.start()

        elif 'stop' == command:
            logging.info('Stop daemon')
            agent.stop()

        elif 'restart' == command:
            logging.info('Restart daemon')
            agent.restart()

        elif 'foreground' == command:
            logging.info('Running in foreground')
            agent.run()

    # Commands that don't need the agent to be initialized.
    else:
        if 'status' == command:
            pid = pid_file.get_pid()
            if pid is not None:
                sys.stdout.write('dd-agent is running as pid %s.\n' % pid)
            else:
                sys.stdout.write('dd-agent is not running.\n')

        elif 'info' == command:
            CollectorStatus.print_latest_status()

    return 0