Hi, I'm currently implementing custom metrics and ...
# troubleshooting
a
Hi, I'm currently implementing custom metrics and could use some help. What I am trying to achieve is having a simple metric reported to Prometheus that also has a custom label.
Copy code
class MyCustomMetric extends RichMapFunction[String, String] {
  @transient private var valueToExpose = 0

  override def open(parameters: Configuration): Unit = {
    getRuntimeContext()
      .getMetricGroup()
      .addGroup("MyMetricKey", "MyMetricValue")
      .gauge[Int, ScalaGauge[Int]]("MyGauge", ScalaGauge[Int]( () => valueToExpose ) )
  }

  override def map(value: String): String = {
    valueToExpose += 1
    return value
  }
}
First of all, from my understanding, the
addGroup(key, value)
will define a User-Variable and this will be exported to Prometheus as a label, is that correct? I configured the necessary settings for exporting metrics to Prometheus and it's working for the default Flink system metrics. However, I have some problems with my custom metric: 1. When using the code above as it is, the metric is not accessible at all, neither from the Flink Web UI nor from Prometheus 2. Without using the
addGroup(key, value)
part the metric is accessible from the Flink Web UI and Prometheus but, of course, with any additional custom label Can anyone help me understand what I'm doing wrong or what's missing here?
✅ 1
Never mind, an implementation detail caused the problem that the metric was not accessible... Actually, the example code should work as intended.