Example #1
0
    def metrics(self):
        self.connect()
        metrics = dict()

        topic = f',topic={self.topic_name}' if self.topic_name else ''

        query = [
            jmxquery.JMXQuery(
                f"kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec{topic}"
            )
        ]
        res = self.jmx_conn.query(query)
        metrics['bytes_in'] = round(
            [_.value for _ in res if _.attribute == 'OneMinuteRate'][0], 4)

        query = [
            jmxquery.JMXQuery(
                f"kafka.server:type=BrokerTopicMetrics,name=BytesOutPerSec{topic}"
            )
        ]
        res = self.jmx_conn.query(query)
        metrics['bytes_out'] = round(
            [_.value for _ in res if _.attribute == 'OneMinuteRate'][0], 4)

        query = [
            jmxquery.JMXQuery(
                f"kafka.server:type=BrokerTopicMetrics,name=MessagesInPerSec{topic}"
            )
        ]
        res = self.jmx_conn.query(query)
        metrics['messages_in'] = round(
            [_.value for _ in res if _.attribute == 'OneMinuteRate'][0], 4)

        return metrics
Example #2
0
 def connect(self):
     try:
         self.jmx_conn = jmxquery.JMXConnection(
             f"service:jmx:rmi:///jndi/rmi://{self.host}:{self.port}/jmxrmi",
             jmx_username=self.user,
             jmx_password=self.password)
         if self.user:
             query = [
                 jmxquery.JMXQuery(
                     "kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec"
                 )
             ]
             self.jmx_conn.query(query)
         else:
             self.jmx_conn = jmxquery.JMXConnection(
                 f"service:jmx:rmi:///jndi/rmi://{self.host}:{self.port}/jmxrmi"
             )
             query = [
                 jmxquery.JMXQuery(
                     "kafka.server:type=BrokerTopicMetrics,name=BytesInPerSec"
                 )
             ]
             self.jmx_conn.query(query)
     except Exception:
         raise ConnectionError
Example #3
0
 def connect(self):
     try:
         self.jmx_conn = jmxquery.JMXConnection(f"service:jmx:rmi:///jndi/rmi://{self.host}:{self.port}/jmxrmi",
                                                jmx_username=self.user, jmx_password=self.password)
         if self.user:
             query = [jmxquery.JMXQuery("org.apache.cassandra.metrics:type=Keyspace")]
             self.jmx_conn.query(query)
         else:
             self.jmx_conn = jmxquery.JMXConnection(f"service:jmx:rmi:///jndi/rmi://{self.host}:{self.port}/jmxrmi")
             query = [jmxquery.JMXQuery("org.apache.cassandra.metrics:type=Keyspace")]
             self.jmx_conn.query(query)
     except Exception:
         raise ConnectionError
Example #4
0
    def status(self):
        self.connect()
        status = dict()

        query = [jmxquery.JMXQuery("java.lang:type=Memory/HeapMemoryUsage")]
        res = self.jmx_conn.query(query)
        status['heap_memory_usage'] = [_.value for _ in res if _.attributeKey == 'used'][0]

        query = [jmxquery.JMXQuery("java.lang:type=Threading/ThreadCount")]
        res = self.jmx_conn.query(query)
        status['thread_count'] = res[0].value

        query = [jmxquery.JMXQuery("java.lang:type=ClassLoading/LoadedClassCount")]
        res = self.jmx_conn.query(query)
        status['loaded_class_count'] = res[0].value

        query = [jmxquery.JMXQuery("java.lang:type=OperatingSystem/ProcessCpuLoad")]
        res = self.jmx_conn.query(query)
        status['process_cpu_load'] = round(res[0].value, 4)

        return status
Example #5
0
    def metrics(self):
        self.connect()
        metrics = dict()

        query = [jmxquery.JMXQuery("org.apache.cassandra.metrics:type=ClientRequest,scope=Read,name=Latency")]
        res = self.jmx_conn.query(query)
        metrics['read_one_minute_rate'] = round([_.value for _ in res if _.attribute == 'OneMinuteRate'][0], 6)
        metrics['read_75th_percentile'] = round([_.value for _ in res if _.attribute == '75thPercentile'][0], 6)
        metrics['read_99th_percentile'] = round([_.value for _ in res if _.attribute == '99thPercentile'][0], 6)

        query = [jmxquery.JMXQuery("org.apache.cassandra.metrics:type=ClientRequest,scope=Write,name=Latency")]
        res = self.jmx_conn.query(query)
        metrics['write_one_minute_rate'] = round([_.value for _ in res if _.attribute == 'OneMinuteRate'][0], 6)
        metrics['write_75th_percentile'] = round([_.value for _ in res if _.attribute == '75thPercentile'][0], 6)
        metrics['write_99th_percentile'] = round([_.value for _ in res if _.attribute == '99thPercentile'][0], 6)

        query = [jmxquery.JMXQuery("org.apache.cassandra.metrics:type=DroppedMessage,scope=READ,name=Dropped/Count")]
        res = self.jmx_conn.query(query)
        metrics['dropped_count'] = res[0].value

        metrics['timestamp'] = time()

        return metrics