[英]Why I cannot view the Flink metrics on the Prometheus dashboard?
我將Apache Flink配置為通過conf/flink-conf.yaml
文件向Prometheus發送指標:
metrics.reporter.prom.class: org.apache.flink.metrics.prometheus.PrometheusReporter
metrics.reporter.prom.host: 192.168.56.1
metrics.reporter.prom.port: 9250-9260
然后我在文件/etc/prometheus/prometheus.yml
上配置了Prometheus:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100']
- job_name: 'flink'
scrape_interval: 5s
static_configs:
- targets: ['jobmanager:9250', 'taskmanager1:9251', 'taskmanager2:9252']
第一個任務管理器的日志表明Prometheus已配置:
2019-03-29 17:04:57,347 INFO org.apache.flink.configuration.GlobalConfiguration - Loading configuration property: metrics.reporter.prom.class, org.apache.flink.metrics.prometheus.PrometheusReporter
2019-03-29 17:04:57,348 INFO org.apache.flink.configuration.GlobalConfiguration - Loading configuration property: metrics.reporter.prom.host, 192.168.56.1
2019-03-29 17:04:57,349 INFO org.apache.flink.configuration.GlobalConfiguration - Loading configuration property: metrics.reporter.prom.port, 9250-9260
...
2019-03-29 17:04:59,463 INFO org.apache.flink.runtime.metrics.MetricRegistryImpl - Configuring prom with {port=9250-9260, host=192.168.56.1, class=org.apache.flink.metrics.prometheus.PrometheusReporter}.
2019-03-29 17:04:59,479 INFO org.apache.flink.metrics.prometheus.PrometheusReporter - Started PrometheusReporter HTTP server on port 9251.
2019-03-29 17:04:59,479 INFO org.apache.flink.runtime.metrics.MetricRegistryImpl - Reporting metrics for reporter prom of type org.apache.flink.metrics.prometheus.PrometheusReporter.
O將jar文件flink-metrics-prometheus_2.11-1.7.2.jar
復制到我的FLink實例的兩個節點的lib
目錄中。 我有一個RichMapper類,它暴露了一個Counter和一個Meter。 為什么我在Prometheus儀表板上看不到指標?
我使用這個命令來./bin/flink run -c org.sense.flink.App ../../../felipe/eclipse-workspace/explore-flink/target/explore-flink.jar 14 192.168.56.20 &
我的應用程序./bin/flink run -c org.sense.flink.App ../../../felipe/eclipse-workspace/explore-flink/target/explore-flink.jar 14 192.168.56.20 &
我可以看到其中一個任務管理器日志的輸出。
public static class SensorTypeMapper
extends RichMapFunction<MqttSensor, Tuple2<CompositeKeySensorType, MqttSensor>> {
private static final long serialVersionUID = -4080196110995184486L;
private transient Counter counter;
private transient Meter meter;
@Override
public void open(Configuration config) {
this.counter = getRuntimeContext().getMetricGroup().counter("counterSensorTypeMapper");
com.codahale.metrics.Meter dropwizardMeter = new com.codahale.metrics.Meter();
this.meter = getRuntimeContext().getMetricGroup().meter("meterSensorTypeMapper",
new DropwizardMeterWrapper(dropwizardMeter));
}
@Override
public Tuple2<CompositeKeySensorType, MqttSensor> map(MqttSensor value) throws Exception {
this.meter.markEvent();
this.counter.inc();
// every sensor key: sensorId, sensorType, platformId, platformType, stationId
// Integer sensorId = value.getKey().f0;
String sensorType = value.getKey().f1;
Integer platformId = value.getKey().f2;
// String platformType = value.getKey().f3;
Integer stationId = value.getKey().f4;
CompositeKeySensorType compositeKey = new CompositeKeySensorType(stationId, platformId, sensorType);
return Tuple2.of(compositeKey, value);
}
}
我解決了 我只需要在文件/etc/prometheus/prometheus.yml
的targets
屬性上配置正確的主機名
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
- job_name: 'node_exporter'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9100']
- job_name: 'flink'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9250', 'localhost:9251', '192.168.56.20:9250']
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.