简体   繁体   English

如何在 Grafana 中可视化 Kafka 主题消息?

[英]How to visualize Kafka topic messages in Grafana?

Edited:编辑:

I've successfully configured the Kafka data source into Grafana, but how do I display the messages of my 'temp-sensor' topic in a dashboard?我已成功将 Kafka 数据源配置到 Grafana 中,但如何在仪表板中显示我的“温度传感器”主题的消息? Those are temperature value output from the ds18x20 sensor as shown in the figure below from the Kafka console consumer.这些是来自 ds18x20 传感器的温度值 output,如下图所示,来自 Kafka 控制台消费者。

Kafka console consumer Kafka 控制台消费者

The topic is able to consume all the temperature values when the sensor is running, however, when I try to visualize the temperature data in Grafana, the time-series chart is not showing any value accordingly when I've already done the Kafka configuration.该主题能够在传感器运行时消耗所有温度值,但是,当我尝试在 Grafana 中可视化温度数据时,当我已经完成 Kafka 配置时,时间序列图表没有相应地显示任何值。

Kafka dashboard卡夫卡仪表板

This is what I did -这就是我所做的 -

Kafka data source / Kafka topics describe Kafka数据源/ Kafka主题描述

Kafka-python lib in python3 - python3 中的 Kafka-python 库 -

import socket
import json
from kafka import KafkaProducer
producer = KafkaProducer(value_serializer=lambda m: json.dumps(m).encode('ascii'), bootstrap_servers='kafka.develop.com.my:9092')
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 1024))
s.listen(5)
while True:
    clt, adr=s.accept()
    print(f"Connection to {adr} established")
    while True:
        data = clt.recv(1024)
        f = float(data)
        print('Received', data)
        temp = {"temp":f}
        producer.send('temp-sensor', value=temp)
    clt.close()

Also, I've added Prometheus data source and imported Kafka Overview dashboard into Grafana.此外,我还添加了 Prometheus 数据源并将Kafka 概览仪表板导入到 Grafana 中。 The dashboard shows that there are messages/bytes received from the 'temp-sensor' topic when I run to code.当我运行代码时,仪表板显示从“temp-sensor”主题接收到消息/字节。

Kafka Overview - Prometheus Kafka 概览——普罗米修斯

So, I'm wondering what I have missed out or done wrong that my Kafka data source isn't displaying messages in the chart.所以,我想知道我错过了什么或做错了什么,因为我的 Kafka 数据源没有在图表中显示消息。

Unclear what DataSource you are using, but this one under Known Limitations says it only accepts JSON, not single floating point values, so update your Python code to use value=json.dumps({"value1": data})不清楚您使用的是什么数据源,但是已知限制下的这个数据源说它只接受 JSON,而不是单个浮点值,因此请更新您的 Python 代码以使用value=json.dumps({"value1": data})

They even have their own Python producer example .他们甚至有自己的Python producer example

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM