Splunk Search

When using the rangemap command, how do I determine the order in which ranges display in tables and charts?

mattness
Splunk Employee
Splunk Employee

When you have a set of events that share a field with a numeric value, you can group those events together according to various ranges of that value. For example, you could have a set of fields with that share SRTime, a field that measures service response time, and which has values ranging between 0 and 1200 ms. Assuming you've already extracted the SRTime field, you can use the rangemap command to break the potential ranges down into groups like so:

    sourcetype=ApplicationLog SRTime="*" 
    | rangemap field=SRTime Great=1-200 Good=201-400 Acceptable 401-600 default=Slow 
    | stats count by range 

This adds a new field to your events called "range" and then gives it a value according to the numeric value of "SRTime". The stats command then breaks your events up into groups according to the value of range that they have.

One of the problems that you'll find, however, is that the finished table/chart orders the counts of the "range" field alphabetically. So if you create a column chart from this, you'll see the columns in this order: Acceptable, Good, Great, Slow.

How do you adjust the search so that the columns are ordered according to their range (Great, Good, Acceptable, Slow)?

1 Solution

mattness
Splunk Employee
Splunk Employee

To do this, you extend the search by:

  • Adding an eval command that introduces a temporary (this search only) order field that is mapped to the range values.
  • Sorting on this order field in an ascending order.
  • Removing the order field from the resulting table/chart (while keeping the sorting order).

Here's what the amended search looks like after this sorting functionality is included:

   sourcetype=ApplicationLog SRTime="*" 
   | rangemap field=SRTime Great=1-200 Good=201-400 Acceptable 401-600 default=Slow 
   | stats count by range 
   | eval order = if(range="Great",0,if(range="Good",1,if(range="Acceptable",2,3))) 
   | sort + order 
   | fields - order

With this, you can create a column chart with columns labeled "Great," "Good," "Acceptable," and "Slow," in that order from left to right.

For a more detailed version of this rangemap command demonstration, see this topic in the Splunk User Manual.

View solution in original post

mattness
Splunk Employee
Splunk Employee

To do this, you extend the search by:

  • Adding an eval command that introduces a temporary (this search only) order field that is mapped to the range values.
  • Sorting on this order field in an ascending order.
  • Removing the order field from the resulting table/chart (while keeping the sorting order).

Here's what the amended search looks like after this sorting functionality is included:

   sourcetype=ApplicationLog SRTime="*" 
   | rangemap field=SRTime Great=1-200 Good=201-400 Acceptable 401-600 default=Slow 
   | stats count by range 
   | eval order = if(range="Great",0,if(range="Good",1,if(range="Acceptable",2,3))) 
   | sort + order 
   | fields - order

With this, you can create a column chart with columns labeled "Great," "Good," "Acceptable," and "Slow," in that order from left to right.

For a more detailed version of this rangemap command demonstration, see this topic in the Splunk User Manual.

aryamehr360
New Member

Thank you.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...