Adding a Label to a special Metric from the node exporter.

645 views
Skip to first unread message

Thomas Berger

unread,
Dec 25, 2021, 2:03:30 PM12/25/21
to Prometheus Users
Hi, everyone.

Sorry, I'm new to Prometheus.
I would like to add a status label only to the node metric: node_boot_time_seconds.

Ground:
Exporters generally only deliver measured values.
I would like to evaluate a measured value in just one place (Prometheus / Grafana).

Idea:
After querying the measured value, determine the status and save it in the 'State' Label.

Logic:
t = time () - node_boot_time_seconds {instance = "<Host>: 9100", job = "node"}
t < 50d: state = Ok (0)
t < 75d: state = Warning (1)
t > 75d: state = Critical (2)
t == null: state = Unknown (3)

What would be best practice in this case?

Thanks and regards,
Thomas

Brian Candler

unread,
Dec 26, 2021, 5:51:57 AM12/26/21
to Prometheus Users
Best practice would be to use your dashboard to interpret the value from the expression "time() - node_boot_time_seconds" and convert this to a display value.  Grafana can already do this: you can set thresholds and colours/labels to display for the different values.

> I would like to add a status label only to the node metric: node_boot_time_seconds.

If you are forced to add the label in the way you want (which I don't recommend), then you can use recording rules to create new timeseries.

Thomas Berger

unread,
Dec 26, 2021, 7:31:29 AM12/26/21
to Prometheus Users
Hello Brian,

thanks for your recommendation.
No, I am not forced to add a status label.
But I would be very interested in why that is not optimal??

I wanted to use Prometheus' Alertmanager for the alert.
So I would have double the work, because I would have to determine the alerts in Prometheus and then again for the display in Grafana.

The problem with this:
A change in 2 places quickly leads to errors.

Therefore, the threshold values would like to be determined only at a central point. Is that possible?

Stuart Clark

unread,
Dec 26, 2021, 7:58:19 AM12/26/21
to Thomas Berger, Prometheus Users
On 26/12/2021 12:31, Thomas Berger wrote:
> Hello Brian,
>
> thanks for your recommendation.
> No, I am not forced to add a status label.
> But I would be very interested in why that is not optimal??
>
> I wanted to use Prometheus' Alertmanager for the alert.
> So I would have double the work, because I would have to determine the
> alerts in Prometheus and then again for the display in Grafana.
>
> The problem with this:
> A change in 2 places quickly leads to errors.
>
> Therefore, the threshold values would like to be determined only at a
> central point. Is that possible?

To do that you could use a recording rule as suggested.

--
Stuart Clark

Reply all
Reply to author
Forward
0 new messages