Splunk Search

query for percentage with count

asplunk123
New Member

I am trying to write a search, like Requests per second and its percentage based on total count. Please help me out in this. Thank you...

0 Karma
1 Solution

somesoni2
Revered Legend

Try this

 index=someindex "priceRequest" |rex "some-app/(?<methodName>[a-zA-Z]*)" | rex "processingTime: (?<RTIME>[0-9]*)" | eval RTIME_SEC=(RTIME/1000) | eval group = case(RTIME_SEC < 1, "1 sec", RTIME_SEC < 2,"2 sec", RTIME_SEC < 3,"3 sec", RTIME_SEC < 4,"4 sec",RTIME_SEC < 5,"5 sec",RTIME_SEC < 6,"6 sec",RTIME_SEC>6,"Time Out")| stats count by group,methodName| eventstats sum(count) as total by methodName | eval Perc=round(count*100/total,2) | chart values(count) values(Perc) over group by methodName | appendpipe [| stats sum(*) as *  | eval group="Total" | table group *]

View solution in original post

somesoni2
Revered Legend

Try this

 index=someindex "priceRequest" |rex "some-app/(?<methodName>[a-zA-Z]*)" | rex "processingTime: (?<RTIME>[0-9]*)" | eval RTIME_SEC=(RTIME/1000) | eval group = case(RTIME_SEC < 1, "1 sec", RTIME_SEC < 2,"2 sec", RTIME_SEC < 3,"3 sec", RTIME_SEC < 4,"4 sec",RTIME_SEC < 5,"5 sec",RTIME_SEC < 6,"6 sec",RTIME_SEC>6,"Time Out")| stats count by group,methodName| eventstats sum(count) as total by methodName | eval Perc=round(count*100/total,2) | chart values(count) values(Perc) over group by methodName | appendpipe [| stats sum(*) as *  | eval group="Total" | table group *]

asplunk123
New Member

@somesoni2, yes i mean , interchange the columns.

here having 2 requests like priceRequest & priceResponse. actually having query for 1,2 columns are percentages of both requests and 3,4 column are count of both requests respectively. But i am expecting the query as like as Count(priceRequest ) Percentage(priceRequest ) Count(priceResponse) Percentage(priceResponse) respectively...

0 Karma

asplunk123
New Member

@somesoni2, Please help me out here for interchange the location of fields

0 Karma

somesoni2
Revered Legend

Not sure if I understand what you need? What is the search that you're trying (before the appendpipe) and what is the fieldnames that you see?

0 Karma

asplunk123
New Member

how to add the Total field (row) in bottom of all adding all column values

0 Karma

somesoni2
Revered Legend

You can use addcoltotals command for that. (add to the end)

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...