【问题标题】:Different jobName per Job when reporting Flink metrics to PushGateway向 PushGateway 报告 Flink 指标时,每个 Job 的 jobName 不同
【发布时间】:2019-12-17 14:48:06
【问题描述】:

我正在使用 Flink 1.9.1 和 PrometheusPushGateway 来报告我的指标。 报告指标的作业名称在 flink-conf.yaml 文件中定义,这使得集群上运行的所有作业的作业名称相同,但我希望为每个正在运行的作业报告不同的作业名称。 为此,我尝试在执行 Stream 之前覆盖作业中的配置值:

Configuration conf = GlobalConfiguration.loadConfiguration();
    conf.setString(
            "metrics.reporter.promgateway.jobName",
            conf.getString("metrics.reporter.promgateway.jobName", "") + "-" + pipeline
    );
    final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.getConfig().setGlobalJobParameters(conf);

pipeline 是字符串变量时。

在本地运行作业时,它可以工作。但是现在我在高可用性模式下运行 flink,它不再工作了 :( 我在代码中覆盖的配置被忽略,只使用集群的 flink-conf.yaml 文件中的值。

那么如何更改每个作业的作业名称?如果我不能,有没有办法在报告指标时设置额外的标签?因为我也没有看到这样的选择。

谢谢:)

【问题讨论】:

    标签: java apache-flink prometheus metrics


    【解决方案1】:

    您可以使用以下步骤来实现:

    1. jobName 作为命令参数传递,例如:--jobName MyJobName

    2. 设置全局参数:

    public static void main(String[] args) throws Exception {
        final ParameterTool command = ParameterTool.fromArgs(args);
        String jobName = command.getRequired("jobName");
    
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        Configuration globalConfiguration = new Configuration();
        globalConfiguration.setString("jobName", jobName);
        env.getConfig().setGlobalJobParameters(globalConfiguration);
    
    }
    
    1. 使用它:
    ParameterTool parameters = (ParameterTool) getRuntimeContext().getExecutionConfig().getGlobalJobParameters();
    parameters.getRequired("jobName");
    

    以下链接也可能对您有所帮助: https://ci.apache.org/projects/flink/flink-docs-stable/dev/best_practices.html#parsing-command-line-arguments-and-passing-them-around-in-your-flink-application

    【讨论】:

    • 这和我做的有什么不同?而且我不是使用参数metrics.reporter.promgateway.jobName 的人。就是写的PrometheusPushGatewayReporter的open函数。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多