コード例 #1
0
ファイル: test_mongo.py プロジェクト: jkoppe/dd-agent
 def setUp(self):
     self.c = MongoDb(logging.getLogger(__file__))
     # Start 2 instances of Mongo in a replica set
     dir1 = mkdtemp()
     dir2 = mkdtemp()
     try:
         self.p1 = subprocess.Popen([
             "mongod", "--dbpath", dir1, "--port",
             str(PORT1), "--replSet",
             "testset/%s:%d" % (socket.gethostname(), PORT2), "--rest"
         ],
                                    executable="mongod",
                                    stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE)
         # Sleep until mongo comes online
         self.wait4mongo(self.p1, PORT1)
         if self.p1:
             # Set up replication
             c1 = pymongo.Connection('localhost:%s' % PORT1,
                                     slave_okay=True)
             self.p2 = subprocess.Popen([
                 "mongod", "--dbpath", dir2, "--port",
                 str(PORT2), "--replSet",
                 "testset/%s:%d" % (socket.gethostname(), PORT1), "--rest"
             ],
                                        executable="mongod",
                                        stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE)
             self.wait4mongo(self.p2, PORT2)
             # Waiting before all members are online
             time.sleep(15)
             c1.admin.command("replSetInitiate")
             # Sleep for 15s until replication is stable
             time.sleep(30)
             x = c1.admin.command("replSetGetStatus")
             assert pymongo.Connection('localhost:%s' % PORT2)
     except:
         logging.getLogger().exception("Cannot instantiate mongod properly")
コード例 #2
0
    def __init__(self, agentConfig, emitters, systemStats):
        self.agentConfig = agentConfig
        # system stats is generated by config.get_system_stats
        self.agentConfig['system_stats'] = systemStats
        # agent config is used during checks, system_stats can be accessed through the config
        self.os = getOS()
        self.plugins = None
        self.emitters = emitters
        self.metadata_interval = int(
            agentConfig.get('metadata_interval', 10 * 60))
        self.metadata_start = time.time()
        socket.setdefaulttimeout(15)
        self.run_count = 0
        self.continue_running = True

        # Unix System Checks
        self._unix_system_checks = {
            'disk': u.Disk(checks_logger),
            'io': u.IO(),
            'load': u.Load(checks_logger),
            'memory': u.Memory(checks_logger),
            'network': u.Network(checks_logger),
            'processes': u.Processes(),
            'cpu': u.Cpu(checks_logger)
        }

        # Win32 System `Checks
        self._win32_system_checks = {
            'disk': w32.Disk(checks_logger),
            'io': w32.IO(checks_logger),
            'proc': w32.Processes(checks_logger),
            'memory': w32.Memory(checks_logger),
            'network': w32.Network(checks_logger),
            'cpu': w32.Cpu(checks_logger)
        }

        # Old-style metric checks
        self._couchdb = CouchDb(checks_logger)
        self._mongodb = MongoDb(checks_logger)
        self._mysql = MySql(checks_logger)
        self._rabbitmq = RabbitMq()
        self._ganglia = Ganglia(checks_logger)
        self._cassandra = Cassandra()
        self._dogstream = Dogstreams.init(checks_logger, self.agentConfig)
        self._ddforwarder = DdForwarder(checks_logger, self.agentConfig)
        self._ec2 = EC2(checks_logger)

        # Metric Checks
        self._metrics_checks = [
            ElasticSearch(checks_logger),
            Jvm(checks_logger),
            Tomcat(checks_logger),
            ActiveMQ(checks_logger),
            Solr(checks_logger),
            WMICheck(checks_logger),
            Memcache(checks_logger),
        ]

        # Custom metric checks
        for module_spec in [
                s.strip()
                for s in self.agentConfig.get('custom_checks', '').split(',')
        ]:
            if len(module_spec) == 0: continue
            try:
                self._metrics_checks.append(
                    modules.load(module_spec, 'Check')(checks_logger))
                logger.info("Registered custom check %s" % module_spec)
            except Exception, e:
                logger.exception('Unable to load custom check module %s' %
                                 module_spec)