How to change number format in ValueString?

ValueString has float numbers with very long precision.

How to define the number of decimal numbers?

The only way to manipulate it is with Regular Expressions?

Hi @giovannitirloni

Is ValueString the same as a value coming from your alerting query? For example, if I had this:

I could trim the 1.2104705741732575 shown above using {{ printf "%.2f" $values.D.Value }} For example, in annotation Summary, we could write the following:

{{ $values.D.Labels.Source }} at the {{ $values.D.Labels.Location }} has generated {{ printf "%.2f" $values.D.Value }} jigowatts.

which would display as:

Thanks for the advice, really appreciate it.

So I need to tweak the notification in the notification template and in each alert’s annotation?

It seems a regression from the legacy alerting days.

If you are able to use the a multidimensional alerting rule (one “generic” alert rule that can cover many similar situations) then I think you could write one notification template for such an alert and have it properly display the correct number of digits.

We are using that and it works. The metrics retrieved from Prometheus contain these labels… for example, in the page you linked, it has cpu=N … that’s useful metadata from the metric.

I could use alert annotations and templates to surface that information using $labels, on a per-alert basis.

But that information is exposed in the notification template as .ValueString already… but in string format. I can’t easily manipulate those metric’s labels in a notification… so right now I’m opting to show the full .ValueString content… sometimes that has a lot of information I don’t want (ideally, I only want the label that I’m grouping by… in the doc that would be cpu but I have other queries where I group by 2-4 labels… and I want to surface that information).

So if I had, say, the contents of ValueString as a proper list of maps, I could easily iterate over them and format as I wished. Of course, I’m only interested in the label that I grouped by in the alert query… ValueString has many other stuff I’m not interested in (e.g. if I’m not grouping by job_name … I don’t want to show that).

Thanks again for the help and ideas, it’s being a long journey for me.