Beispiel #1
0
    def send_database_status(self, event_mgr):
        status = CassandraStatusData()
        status.cassandra_compaction_task = CassandraCompactionTask()
        # Get compactionstats
        base_cmd = "nodetool -p {}".format(self.db_jmx_port)
        try:
            res = self.exec_cmd(base_cmd + " compactionstats")
            status.cassandra_compaction_task.pending_compaction_tasks = \
                self.get_pending_compaction_count(res)
        except Exception as e:
            msg = "Failed to get nodetool compactionstats: {}".format(e)
            event_mgr.msg_log(msg, level=SandeshLevel.SYS_ERR)
            return

        # Get the tpstats value
        try:
            res = self.exec_cmd(base_cmd + " tpstats")
            status.thread_pool_stats = self.get_tp_status(res)
        except Exception as e:
            msg = "Failed to get nodetool tpstats {}".format(e)
            event_mgr.msg_log(msg, level=SandeshLevel.SYS_ERR)
            return

        status.name = self.hostname
        status_uve = CassandraStatusUVE(data=status)
        if self.has_cassandra_status_changed(status, self.status_old):
            # Assign status to status_old
            self.status_old.thread_pool_stats = status.thread_pool_stats
            self.status_old.cassandra_compaction_task.\
                pending_compaction_tasks = status.\
                cassandra_compaction_task.pending_compaction_tasks
            msg = 'Sending UVE: ' + str(status_uve)
            event_mgr.msg_log(msg, level=SandeshLevel.SYS_DEBUG)
            status_uve.send()
 def send_database_status(self):
     cassandra_status_uve = CassandraStatusUVE()
     cassandra_status = CassandraStatusData()
     cassandra_status.cassandra_compaction_task = CassandraCompactionTask()
     # Get compactionstats
     compaction_count = subprocess.Popen("nodetool compactionstats|grep 'pending tasks:'",
         shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     op, err = compaction_count.communicate()
     if compaction_count.returncode != 0:
         msg = "Failed to get nodetool compactionstats " + err
         self.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.cassandra_compaction_task.pending_compaction_tasks = \
         self.get_pending_compaction_count(op)
     # Get the tpstats value
     tpstats_op = subprocess.Popen(["nodetool", "tpstats"], stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
     op, err = tpstats_op.communicate()
     if tpstats_op.returncode != 0:
         msg = "Failed to get nodetool tpstats " + err
         self.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.thread_pool_stats = self.get_tp_status(op)
     cassandra_status.name = socket.gethostname()
     cassandra_status_uve = CassandraStatusUVE(data=cassandra_status)
     msg = 'Sending UVE: ' + str(cassandra_status_uve)
     self.sandesh_global.logger().log(SandeshLogger.get_py_logger_level(
                         SandeshLevel.SYS_DEBUG), msg)
     cassandra_status_uve.send()
 def send_database_status(self):
     cassandra_status_uve = CassandraStatusUVE()
     cassandra_status = CassandraStatusData()
     cassandra_status.cassandra_compaction_task = CassandraCompactionTask()
     # Get compactionstats
     compaction_count = subprocess.Popen(
         "nodetool compactionstats|grep 'pending tasks:'",
         shell=True,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE)
     op, err = compaction_count.communicate()
     if compaction_count.returncode != 0:
         msg = "Failed to get nodetool compactionstats " + err
         self.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.cassandra_compaction_task.pending_compaction_tasks = \
         self.get_pending_compaction_count(op)
     # Get the tpstats value
     tpstats_op = subprocess.Popen(["nodetool", "tpstats"],
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
     op, err = tpstats_op.communicate()
     if tpstats_op.returncode != 0:
         msg = "Failed to get nodetool tpstats " + err
         self.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.thread_pool_stats = self.get_tp_status(op)
     cassandra_status.name = socket.gethostname()
     cassandra_status_uve = CassandraStatusUVE(data=cassandra_status)
     msg = 'Sending UVE: ' + str(cassandra_status_uve)
     self.sandesh_global.logger().log(
         SandeshLogger.get_py_logger_level(SandeshLevel.SYS_DEBUG), msg)
     cassandra_status_uve.send()
    def runforever(self, test=False):
        self.prev_current_time = int(time.time())
        # Initialize tpstat structures
        self.cassandra_status_old = CassandraStatusData()
        self.cassandra_status_old.cassandra_compaction_task = CassandraCompactionTask()
        self.cassandra_status_old.thread_pool_stats = []
        while 1:
            # we explicitly use self.stdin, self.stdout, and self.stderr
            # instead of sys.* so we can unit test this code
            headers, payload = self.listener_nodemgr.wait(
                self.stdin, self.stdout)

            # self.stderr.write("headers:\n" + str(headers) + '\n')
            # self.stderr.write("payload:\n" + str(payload) + '\n')

            pheaders, pdata = childutils.eventdata(payload + '\n')
            # self.stderr.write("pheaders:\n" + str(pheaders)+'\n')
            # self.stderr.write("pdata:\n" + str(pdata))

            # check for process state change events
            if headers['eventname'].startswith("PROCESS_STATE"):
                self.event_process_state(pheaders, headers)
            # check for flag value change events
            if headers['eventname'].startswith("PROCESS_COMMUNICATION"):
                self.event_process_communication(pdata)
            # do periodic events
            if headers['eventname'].startswith("TICK_60"):
                self.cassandra_mgr.database_periodic(self)
                self.event_tick_60()
            self.listener_nodemgr.ok(self.stdout)
 def __init__(self,
              cassandra_repair_logdir,
              db_owner,
              table,
              hostip,
              minimum_diskgb,
              db_port,
              db_jmx_port,
              db_use_ssl,
              db_user,
              db_password,
              process_info_manager,
              hostname=None):
     self.cassandra_repair_logdir = cassandra_repair_logdir
     self._db_owner = db_owner
     self.table = table
     self.hostip = hostip
     self.hostname = socket.getfqdn(self.hostip) if hostname is None \
         else hostname
     self.minimum_diskgb = minimum_diskgb
     self.db_port = db_port
     self.db_jmx_port = db_jmx_port
     self.db_use_ssl = db_use_ssl
     self.db_user = db_user
     self.db_password = db_password
     self.process_info_manager = process_info_manager
     # Initialize tpstat structures
     self.status_old = CassandraStatusData()
     self.status_old.cassandra_compaction_task = CassandraCompactionTask()
     self.status_old.thread_pool_stats = []
    def __init__(self, rule_file, unit_names, collector_addr, sandesh_config,
                 hostip, minimum_diskgb, contrail_databases,
                 cassandra_repair_interval, cassandra_repair_logdir):

        if os.path.exists('/tmp/supervisord_database.sock'):
            supervisor_serverurl = "unix:///tmp/supervisord_database.sock"
        else:
            supervisor_serverurl = "unix:///var/run/supervisord_database.sock"
        type_info = EventManagerTypeInfo(
            package_name='contrail-database-common',
            object_table="ObjectDatabaseInfo",
            module_type=Module.DATABASE_NODE_MGR,
            supervisor_serverurl=supervisor_serverurl,
            third_party_processes={
                "cassandra": "Dcassandra-pidfile=.*cassandra\.pid",
                "zookeeper":
                "org.apache.zookeeper.server.quorum.QuorumPeerMain"
            },
            sandesh_packages=['database.sandesh'],
            unit_names=unit_names)
        EventManager.__init__(self, type_info, rule_file, collector_addr,
                              sandesh_global, sandesh_config)
        self.hostip = hostip
        self.minimum_diskgb = minimum_diskgb
        self.contrail_databases = contrail_databases
        self.cassandra_repair_interval = cassandra_repair_interval
        self.cassandra_repair_logdir = cassandra_repair_logdir
        self.cassandra_mgr = CassandraManager(cassandra_repair_logdir)
        # Initialize tpstat structures
        self.cassandra_status_old = CassandraStatusData()
        self.cassandra_status_old.cassandra_compaction_task = CassandraCompactionTask(
        )
        self.cassandra_status_old.thread_pool_stats = []
Beispiel #7
0
 def send_database_status(self, event_mgr):
     cassandra_status_uve = CassandraStatusUVE()
     cassandra_status = CassandraStatusData()
     cassandra_status.cassandra_compaction_task = CassandraCompactionTask()
     # Get compactionstats
     cpt_cmd = "nodetool -h " + self.nodetool_ip + " compactionstats|grep 'pending tasks:'"
     compaction_count = subprocess.Popen(cpt_cmd,
                                         shell=True,
                                         stdout=subprocess.PIPE,
                                         stderr=subprocess.PIPE,
                                         close_fds=True)
     op, err = compaction_count.communicate()
     if compaction_count.returncode != 0:
         msg = "Failed to get nodetool compactionstats " + err
         event_mgr.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.cassandra_compaction_task.pending_compaction_tasks = \
         self.get_pending_compaction_count(op)
     # Get the tpstats value
     tpstats_op = subprocess.Popen(
         ["nodetool", "-h", self.nodetool_ip, "tpstats"],
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE,
         close_fds=True)
     op, err = tpstats_op.communicate()
     if tpstats_op.returncode != 0:
         msg = "Failed to get nodetool tpstats " + err
         event_mgr.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.thread_pool_stats = self.get_tp_status(op)
     cassandra_status.name = socket.gethostname()
     cassandra_status_uve = CassandraStatusUVE(data=cassandra_status)
     if self.has_cassandra_status_changed(cassandra_status,
                                          self.cassandra_status_old):
         # Assign cassandra_status to cassandra_status_old
         self.cassandra_status_old.thread_pool_stats = \
             cassandra_status.thread_pool_stats
         self.cassandra_status_old.cassandra_compaction_task.\
             pending_compaction_tasks = cassandra_status.\
             cassandra_compaction_task.pending_compaction_tasks
         msg = 'Sending UVE: ' + str(cassandra_status_uve)
         event_mgr.msg_log(msg, level=SandeshLevel.SYS_DEBUG)
         cassandra_status_uve.send()
Beispiel #8
0
 def __init__(self, cassandra_repair_logdir, db_name, contrail_databases,
              hostip, minimum_diskgb):
     self.cassandra_repair_logdir = cassandra_repair_logdir
     self._db_name = db_name
     self.contrail_databases = contrail_databases
     self.hostip = hostip
     self.minimum_diskgb = minimum_diskgb
     # Initialize tpstat structures
     self.cassandra_status_old = CassandraStatusData()
     self.cassandra_status_old.cassandra_compaction_task = CassandraCompactionTask(
     )
     self.cassandra_status_old.thread_pool_stats = []
 def send_database_status(self):
     cassandra_status_uve = CassandraStatusUVE()
     cassandra_status = CassandraStatusData()
     cassandra_status.cassandra_compaction_task = CassandraCompactionTask()
     # Get compactionstats
     compaction_count = subprocess.Popen("nodetool compactionstats|grep 'pending tasks:'",
         shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
         close_fds=True)
     op, err = compaction_count.communicate()
     if compaction_count.returncode != 0:
         msg = "Failed to get nodetool compactionstats " + err
         self.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.cassandra_compaction_task.pending_compaction_tasks = \
         self.get_pending_compaction_count(op)
     # Get the tpstats value
     tpstats_op = subprocess.Popen(["nodetool", "tpstats"], stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE, close_fds=True)
     op, err = tpstats_op.communicate()
     if tpstats_op.returncode != 0:
         msg = "Failed to get nodetool tpstats " + err
         self.msg_log(msg, level=SandeshLevel.SYS_ERR)
         return
     cassandra_status.thread_pool_stats = self.get_tp_status(op)
     cassandra_status.name = socket.gethostname()
     cassandra_status_uve = CassandraStatusUVE(data=cassandra_status)
     if self.has_cassandra_status_changed(cassandra_status, self.cassandra_status_old):
         # Assign cassandra_status to cassandra_status_old
         self.cassandra_status_old.thread_pool_stats = \
             cassandra_status.thread_pool_stats
         self.cassandra_status_old.cassandra_compaction_task.\
             pending_compaction_tasks = cassandra_status.\
             cassandra_compaction_task.pending_compaction_tasks
         msg = 'Sending UVE: ' + str(cassandra_status_uve)
         self.msg_log(msg, level=SandeshLevel.SYS_DEBUG)
         cassandra_status_uve.send()
 def __init__(self, cassandra_repair_logdir, db_owner, contrail_databases,
              hostip, minimum_diskgb, db_port, db_jmx_port,
              process_info_manager):
     self.cassandra_repair_logdir = cassandra_repair_logdir
     self._db_owner = db_owner
     self.contrail_databases = contrail_databases
     self.hostip = hostip
     self.hostname = socket.gethostname()
     self.minimum_diskgb = minimum_diskgb
     self.db_port = db_port
     self.db_jmx_port = db_jmx_port
     self.process_info_manager = process_info_manager
     # Initialize tpstat structures
     self.status_old = CassandraStatusData()
     self.status_old.cassandra_compaction_task = CassandraCompactionTask()
     self.status_old.thread_pool_stats = []
Beispiel #11
0
 def __init__(self, cassandra_repair_logdir, db_name, contrail_databases,
              hostip, minimum_diskgb, db_port):
     self.cassandra_repair_logdir = cassandra_repair_logdir
     self._db_name = db_name
     self.contrail_databases = contrail_databases
     self.hostip = hostip
     self.minimum_diskgb = minimum_diskgb
     self.db_port = db_port
     # Initialize tpstat structures
     self.cassandra_status_old = CassandraStatusData()
     self.cassandra_status_old.cassandra_compaction_task = CassandraCompactionTask(
     )
     self.cassandra_status_old.thread_pool_stats = []
     if IPy.IP(hostip).version() == 6:
         self.nodetool_ip = "::1"
     else:
         self.nodetool_ip = "127.0.0.1"