dynamic metric

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

dynamic metric

aldu29
Hi,

I want to create one metric related to the number of errors but in fact I would like to add some contextual labels ?
What is the best way to do that ? gauge ?
How to create this kind of metric dynamically during the run of the task (because open method is not possible because too early) ?
Thanks in advance

David
Reply | Threaded
Open this post in threaded view
|

Re: dynamic metric

Till Rohrmann
Hi David,

I think it is not strictly required that you register the metric in the open method. It is just convenient because otherwise you have to make sure that you register the metric only once (e.g. when doing it in the map function).

What you need in order to register a metric is the runtime context which you get if you implement a RichFunction:

getRuntimeContext().getMetricGroup().gauge("MyGauge", new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return valueToExpose;
    }
  });

Cheers,
Till

On Fri, Jun 21, 2019 at 12:36 AM David Morin <[hidden email]> wrote:
Hi,

I want to create one metric related to the number of errors but in fact I would like to add some contextual labels ?
What is the best way to do that ? gauge ?
How to create this kind of metric dynamically during the run of the task (because open method is not possible because too early) ?
Thanks in advance

David
Reply | Threaded
Open this post in threaded view
|

Re: dynamic metric

aldu29
Thanks Till.
Ok, I've got it.
So, to prevent from register the metric twice I have to keep an index (Hasmap for example) to check if the metric already exists ?

Le ven. 21 juin 2019 à 01:27, Till Rohrmann <[hidden email]> a écrit :
Hi David,

I think it is not strictly required that you register the metric in the open method. It is just convenient because otherwise you have to make sure that you register the metric only once (e.g. when doing it in the map function).

What you need in order to register a metric is the runtime context which you get if you implement a RichFunction:

getRuntimeContext().getMetricGroup().gauge("MyGauge", new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return valueToExpose;
    }
  });

Cheers,
Till

On Fri, Jun 21, 2019 at 12:36 AM David Morin <[hidden email]> wrote:
Hi,

I want to create one metric related to the number of errors but in fact I would like to add some contextual labels ?
What is the best way to do that ? gauge ?
How to create this kind of metric dynamically during the run of the task (because open method is not possible because too early) ?
Thanks in advance

David
Reply | Threaded
Open this post in threaded view
|

Re: dynamic metric

Till Rohrmann
Yes, this could be an option. Or you simply have a flag for it.

On Fri, Jun 21, 2019, 01:47 David Morin <[hidden email]> wrote:
Thanks Till.
Ok, I've got it.
So, to prevent from register the metric twice I have to keep an index (Hasmap for example) to check if the metric already exists ?

Le ven. 21 juin 2019 à 01:27, Till Rohrmann <[hidden email]> a écrit :
Hi David,

I think it is not strictly required that you register the metric in the open method. It is just convenient because otherwise you have to make sure that you register the metric only once (e.g. when doing it in the map function).

What you need in order to register a metric is the runtime context which you get if you implement a RichFunction:

getRuntimeContext().getMetricGroup().gauge("MyGauge", new Gauge<Integer>() {
    @Override
    public Integer getValue() {
      return valueToExpose;
    }
  });

Cheers,
Till

On Fri, Jun 21, 2019 at 12:36 AM David Morin <[hidden email]> wrote:
Hi,

I want to create one metric related to the number of errors but in fact I would like to add some contextual labels ?
What is the best way to do that ? gauge ?
How to create this kind of metric dynamically during the run of the task (because open method is not possible because too early) ?
Thanks in advance

David