Kafka通过JMX进行监控

时间:2017-09-29 00:31:05

标签: apache-kafka kafka-producer-api prometheus

我使用Prometheus JMX Exporter来监控Kafka。我在JMX配置文件中定义了以下模式规则:

- pattern : kafka.server<type=(.+), name=(.+)PerSec\w*, topic=(.+)><>Count
      name: kafka_server_$1_$2_total
      labels:
        topic: "$3"
    - pattern: kafka.server<type=(.+), name=(.+)PerSec\w*><>Count
      name: kafka_server_$1_$2_total
      type: COUNTER
    - pattern: kafka.server<type=(.+), name=(.+), clientId=(.+), topic=(.+), partition=(.*)><>(Count|Value)
      name: kafka_server_$1_$2
      labels:
        clientId: "$3"
        topic: "$4"
        partition: "$5"
    - pattern: kafka.server<type=(.+), name=(.+), topic=(.+), partition=(.*)><>(Count|Value)
      name: kafka_server_$1_$2
      labels:
        topic: "$3"
        partition: "$4"
    - pattern: kafka.server<type=(.+), name=(.+), topic=(.+)><>(Count|Value)
      name: kafka_server_$1_$2
      labels:
        topic: "$3"
      type: COUNTER
    - pattern: kafka.server<type=(.+), name=(.+), clientId=(.+), brokerHost=(.+), brokerPort=(.+)><>(Count|Value)
      name: kafka_server_$1_$2
      labels:
        clientId: "$3"
        broker: "$4:$5"
    - pattern: kafka.server<type=(.+), name=(.+), clientId=(.+)><>(Count|Value)
      name: kafka_server_$1_$2
      labels:
        clientId: "$3"
    - pattern: kafka.server<type=(.+), name=(.+)><>(Count|Value)
      name: kafka_server_$1_$2

现在我遇到了以下问题。当我以这种方式向主题发送数据时:

/bin/kafka-console-producer.sh --broker-list kafka-hostname:9092 --topic test1

指标kafka_server_brokertopicmetrics_bytesin_total的计数器正确增加。

当我尝试使用以下代码发送数据时:

"use strict";

const envs = process.env;

const options = {
  "metadata.broker.list": "kafka-hostname:9092",
  "group.id": "kafka1",
  topic: "test1",
  key: "testKey"
};

const kafkesque = require("untubo")(options);

let count = 0;
const interval = setInterval(function() {
  kafkesque.push({ hello: "world", count });
  console.log("sent", count);
  count++;
}, 500);

process.once("SIGINT", function() {
  clearInterval(interval);
  console.log("closing");
  kafkesque.stop(() => {
    console.log("closed");
  });
});

在这种情况下,指标根本没有变化,但我可以在消费者中收到消息。我认为模式中没有正确配置的东西。你有什么想法吗?

0 个答案:

没有答案