简体   繁体   English

Prometheus 没有显示 flink 指标

[英]Prometheus not showing flink metrics

I have following code in my flink job;我的 flink 工作中有以下代码;

    @Override
    public void open(Configuration config) {
          this.counter = getRuntimeContext()
                        .getMetricGroup()
                        .counter("myCounter");
    }

    @Override
    public Tuple2<String, String> map(String s) throws Exception {
            this.counter.inc();
            Thread.sleep(5000);
            return new Tuple2<String, String>(s, s.toUpperCase());
    }

In prometheus.yml inside prometheus distribution, I have following:在 prometheus 发行版中的 prometheus.yml 中,我有以下内容:

- job_name: 'flink-prometheus'
    scrape_interval: 5s
    static_configs:
      - targets: ['localhost:9999']
    metrics_path: /

And in flink-conf.yaml inside flink distribution:而在 flink-conf.yaml 里面的 flink 分布:

metrics.reporters: prom
  metrics.reporter.prom.class: org.apache.flink.metrics.prometheus.PrometheusReporter
  metrics.reporter.prom.host: 127.0.0.1
  metrics.reporter.prom.port: 9999

On prometheus board, I can see localhost:9999 as target, and also various metric logs.在 prometheus 板上,我可以看到 localhost:9999 作为目标,以及各种指标日志。 But there is no log for the counter I have added in the code.但是我在代码中添加的计数器没有日志。 I searched for string "myCounter" as well as "flink-prometheus", but zero results.我搜索了字符串“myCounter”以及“flink-prometheus”,但结果为零。

What else I need to do for my metrics to show up?我还需要做什么才能显示我的指标?

The main difference I see between the example in https://github.com/mbode/flink-prometheus-example and your own config is that the example is scraping the job manager as well as the task manager(s):我在https://github.com/mbode/flink-prometheus-example中的示例和您自己的配置之间看到的主要区别是该示例正在抓取作业管理器以及任务管理器:

scrape_configs:
- job_name: 'flink'
  static_configs:
  - targets: ['job-cluster:9249', 'taskmanager1:9249', 'taskmanager2:9249']

In my own example -- see Flink Timing Explorer -- I found it necessary to do this as well.在我自己的示例中——参见Flink Timing Explorer——我发现也有必要这样做。 Here's what worked for me:这对我有用:

flink-conf.yaml flink-conf.yaml

metrics.reporters: prom
metrics.reporter.prom.class: org.apache.flink.metrics.prometheus.PrometheusReporter
metrics.reporter.prom.port: 9250-9260

prometheus.yaml普罗米修斯.yaml

global:
  scrape_interval: 5s
  evaluation_interval: 5s

scrape_configs:
  - job_name: 'flink'
    static_configs:
      - targets: ['host.docker.internal:9250', 'host.docker.internal:9251']

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

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