Splunk Search

How to sort by field?

jackpal
Path Finder

I am trying to get the highest used process percentage by user, however, I am unable to sort by the field I want to.

index=os sourcetype=top host=hostname
| chart sum(pctCPU) as CPU_USAGE by USER,COMMAND
| sort sum(pctCPU) desc 
| head 5

This produces a table but I'd like the chart to only show the top 5 users and the commands they are running sorted by their CPU_USAGE

0 Karma
1 Solution

cpetterborg
SplunkTrust
SplunkTrust

Does this do it for you?:

index=os sourcetype=top host=hostname
| stats sum(pctCPU) as CPU_USAGE by USER,COMMAND
| sort - CPU_USAGE
| head 5

View solution in original post

0 Karma

jackpal
Path Finder

Thanks to all who responded.

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

Does this do it for you?:

index=os sourcetype=top host=hostname
| stats sum(pctCPU) as CPU_USAGE by USER,COMMAND
| sort - CPU_USAGE
| head 5
0 Karma

renjith_nair
Legend

Hi @jackpal,

Try

index=os sourcetype=top host=hostname |fields USER,pctCPU,COMMAND|sort pctCPU desc|head 5| chart sum(pctCPU) as CPU_USAGE by USER,COMMAND

This will sort based on cpu usage not on the sum . If you need to sort on sum of cpu usage of a user then , try

    index=os sourcetype=top host=hostname |stats sum(pctCPU) as CPU_USAGE by USER,COMMAND
    |sort CPU_USAGE desc|head 5
Happy Splunking!
0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...