简体   繁体   English

如何在Flink中增加SinkFunction的numRecordsOutPut指标?

[英]How to increment numRecordsOutPut metrics of SinkFunction in Flink?

I'm using flink to consume kafka and write to redis. 我正在使用flink消耗kafka并写入redis。

Here is my sink function to redis: 这是我的接收器函数以重做:

            .addSink(new RichSinkFunction<MobilePageEvent>() {

                @Override
                public void invoke(MobilePageEvent event, Context context) {

                    JEDIS_CLUSTER.zadd(..);
                }
            })
            .name("redis sink");

Though I can get the data from redis command line, but the metrics shows the output of sink function is zero: 虽然我可以从redis命令行获取数据,但是指标显示接收器功能的输出为零:

在此处输入图片说明

How can I increment this metrics? 如何增加此指标?

The numRecordsIn and numRecordsOut metrics count only the stream records that flow within the Flink job itself, and don't include communication to external systems. numRecordsIn和numRecordsOut指标仅计算Flink作业本身中流动的流记录,不包括与外部系统的通信。 So in other words, sources don't report any records coming in, and sinks don't report any records going out. 因此,换句话说,源不报告任何进来的记录,接收器不报告任何进出的记录。

As I see it you have a couple of options: 在我看来,您有两种选择:

  1. use the numRecordsIn metric on the sink as an approximation to what you want to know 使用接收器上的numRecordsIn指标作为您要了解的近似值
  2. fork or extend the RedisSink and add the metric you want 分叉或扩展RedisSink并添加所需的指标

The pattern for adding a Counter metric is shown here . 此处显示了添加计数器指标的模式。

In the case of the redis sink you could initialize a Counter in the open() method, and increment it in the invoke(). 如果是redis接收器,则可以在open()方法中初始化一个Counter,然后在invoke()中将其递增。 But that seems rather pointless, since this will simply mirror the numRecordsIn metric. 但这似乎毫无意义,因为这将简单地反映numRecordsIn指标。 If your redis sink is doing buffered bulk writes, then it might be more meaningful to wait to increment the metric until the data is actually sent to redis -- and in that case you might rather use a Meter than a Counter. 如果您的Redis接收器正在执行缓冲的批量写操作,那么等待增量度量直到数据实际发送到Redis可能更有意义-在这种情况下,您宁愿使用仪表而不是计数器。

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

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