无法在flink 1.3.2中添加计数器

lkaoscv7  于 2021-06-25  发布在  Flink
关注(0)|答案(1)|浏览(334)

我试图在flink中添加一个计数器,正如这里提到的,但问题是counter.inc()返回的是void而不是integer。我的指标代码如下

private  static class myMetric extends RichMapFunction<String,Integer> {
       private Counter counter ;

        @Override
        public void open(Configuration parameters) throws Exception {
            super.open(parameters);
            this.getRuntimeContext().
                    getMetricGroup().
                    counter("countit");
        }

        @Override
        public Integer map(String s) throws Exception {

            return this.counter.inc();

        }
    }
xxhby3vn

xxhby3vn1#

如果您为计数器指定一个值,它应该工作得更好:

this.counter = getRuntimeContext()
      .getMetricGroup()
      .counter("countit");

您可能会发现这些文档很有用。

相关问题