Sunday, 8 June 2025

How to Sort Metrics in Prometheus (Ascending or Descending)?

When you work with metrics in Prometheus, it’s often useful to organize them based on their values. For example, if you want to know which instance handled the most HTTP requests, or which handled the least, sorting helps you quickly spot the top or bottom performers.

Prometheus provides two functions for this:

·      sort(): Sorts metrics in ascending order (smallest to largest).

·      sort_desc(): Sorts metrics in descending order (largest to smallest).

 

Let’s take a common metric, node_cpu_seconds_total  that tell the seconds the CPUs spent in each mode.  


 

Sorting in Ascending Order

sort(node_cpu_seconds_total) 


 

Sorting in Descending Order

sort_desc(node_cpu_seconds_total)


 

Previous                                                    Next                                                    Home

No comments:

Post a Comment