Splunk Search

result in single row

roopeshetty
Path Finder

Hi Guys

 

I have a query like this

 

<query>| stats avg(CurrentConnections) as CC by host 

 

And the output is as below with multiple rows

roopeshetty_0-1642822724701.png

 

 

But we have a requirement to get all the results in a single row (all outputs are required but in a single row instead of multiple rows one after one) some thing like this;

 

host

 

CC

server01

server02

server03

server04

server05

server06

368.333333333333

365.333333333333

345.333333333333

379.666666666666

356.333333333333

381.666666666666

 

Can someone please guide us how to do this?

 

Labels (1)
0 Karma
1 Solution

johnhuang
Motivator

<query>
| stats avg(CurrentConnections) as CC by host 
| stats list(host) AS host list(CC) AS CC

View solution in original post

0 Karma

johnhuang
Motivator

<query>
| stats avg(CurrentConnections) as CC by host 
| stats list(host) AS host list(CC) AS CC

0 Karma

PickleRick
SplunkTrust
SplunkTrust

One big caveat though. Remember that list() doesn't care about "continuity" of entries before merging them. So if you have empty results (in your example - hosts without connections), you'll get "wrong" results.

Compare results of

| makeresults annotate=f count=100 
| streamstats count
| table count
| eval value=if(count%10!=3,count,null())
| stats avg(value) as avg by count

with

| makeresults annotate=f count=100 
| streamstats count
| table count
| eval value=if(count%10!=3,count,null())
| stats avg(value) as avg by count
| stats list(avg) list(count)

You could use fillnull to fill the "gaps"

| makeresults annotate=f count=100 
| streamstats count
| table count
| eval value=if(count%10!=3,count,null())
| stats avg(value) as avg by count
| fillnull value="N/A"
| stats list(avg) list(count)

But in general - it's best to avoid operating on such formed multivalue fields and don't rely on the order of values of those fields.

0 Karma

roopeshetty
Path Finder

thanks @johnhuang  it worked.

0 Karma
Get Updates on the Splunk Community!

Observability | How to Think About Instrumentation Overhead (White Paper)

Novice observability practitioners are often overly obsessed with performance. They might approach ...

Cloud Platform | Get Resiliency in the Cloud Event (Register Now!)

IDC Report: Enterprises Gain Higher Efficiency and Resiliency With Migration to Cloud  Today many enterprises ...

The Great Resilience Quest: 10th Leaderboard Update

The tenth leaderboard update (11.23-12.05) for The Great Resilience Quest is out &gt;&gt; As our brave ...