我猜你是想要将 table name 作为一个标签方便后期分组查询过滤?
wangl...@geekplus.com.cn <wangl...@geekplus.com.cn> 于2020年7月3日周五 上午10:24写道: > public void invoke(ObjectNode node, Context context) throws Exception { > > String tableName = node.get("metadata").get("topic").asText(); > Meter meter = getRuntimeContext().getMetricGroup().meter(tableName, > new MeterView(10)); > meter.markEvent(); > log.info("### counter: " + meter.toString() + "\t" + > meter.getCount()); > > 如上面代码所示,在 invoke 方法中解析得到 tableName, 以 tableName 名字作为 metrics. > 但这样写每一消息下来了后相当于重新定义了 这个 metrics , 又从 0 开始计数了。 > > 谢谢, > 王磊 > > > wangl...@geekplus.com.cn > > > Sender: kcz > Send Time: 2020-07-03 09:13 > Receiver: wanglei2 > Subject: 回复:在一个 flink operator 中怎样根据消息内容动态生成多个监控指标? > 按照你的描述 你就是少了tablename,那么你解析log 得到了tablename又做metric就好了吧 > > > > ------------------ 原始邮件 ------------------ > 发件人: 王磊2 <wangl...@geekplus.com.cn> > 发送时间: 2020年7月2日 21:46 > 收件人: user-zh <user-zh@flink.apache.org>, 17610775726 <17610775...@163.com> > 主题: 回复:在一个 flink operator 中怎样根据消息内容动态生成多个监控指标? > > > 没有明白你说的实现方式。 > > 我最终要得到类似的 Metrics: myCounter_table1, myCounter_table2, ..., > myCounter_tableX > 但我看代码中 Metrics 的初始化都是在 open 方法中的,在这个方法中我没法得到 tableName 是什么。 > > 谢谢, > 王磊 > > > > ------------------------------------------------------------------ > 发件人:JasonLee <17610775...@163.com> > 发送时间:2020年7月2日(星期四) 21:12 > 收件人:user-zh <user-zh@flink.apache.org> > 主 题:回复:在一个 flink operator 中怎样根据消息内容动态生成多个监控指标? > > 你把tablename传到下面metric里不就行了吗 > > > | | > JasonLee > | > | > 邮箱:17610775...@163.com > | > > Signature is customized by Netease Mail Master > > 在2020年07月02日 16:39,wangl...@geekplus.com.cn 写道: > > 全都是同一种类型的 metrics. > 比如消息中是 mysql binlog 解析结果,我想要根据消息内容拿到 tableName, 按 tableName 生成不同名称的 > metrics(但都是 meter 类型) > > 谢谢, > 王磊 > > > > > wangl...@geekplus.com.cn > > > 发件人: JasonLee > 发送时间: 2020-07-02 16:16 > 收件人: user-zh > 主题: 回复:在一个 flink operator 中怎样根据消息内容动态生成多个监控指标? > 是要生成不同类型的metric吗 比如counter meter ? > > > | | > JasonLee > | > | > 邮箱:17610775...@163.com > | > > Signature is customized by Netease Mail Master > > 在2020年07月02日 15:34,wangl...@geekplus.com.cn 写道: > > 官网上的例子: > > public class MyMapper extends RichMapFunction<String, String> { > private transient Counter counter; > @Override > public void open(Configuration config) { > this.counter = getRuntimeContext() > .getMetricGroup() > .counter("myCounter"); > } > @Override > public String map(String value) throws Exception { > this.counter.inc(); > return value; > } > } > > 我想要根据 map 方法中传入的参数生成不同的 监控指标,怎样可以实现呢? > > 谢谢, > 王磊 > > > > wangl...@geekplus.com.cn > > >