Splunk Search

Help on chart from subsearch- How to display a bar chart with the site field in x axis

jip31
Motivator

hello

I need to display a bar chart with the site field in x axis

For each site, I need to display 2 bar

The first bar is the avg of retrans_bytes per site and the second bar is the avg of retrans_bytes per user (it means the user corresponding to the site)

Thats' why I use a subsearch for doing this

But I dont succedd to cross the results between the 2 search

could you help please?

 

 

`index` sourcetype="netp_tcp""  
| chart avg(retrans_bytes) as retrans_bytes by site user
| append 
    [| search `index` sourcetype="netp_tcp""  
| chart avg(retrans_bytes) as retrans_bytes by site ]

 

 

 

Tags (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

Ouch. You already have the data, don't search for it twice!

One obvious approach would be to use eventstats instead of stats so you wouldn't lose the origina, events. But that would mean running the eventstats twice and since eventstats is a dataset processing command, it doesn't scale well.

<your search>
| eventstats avg(retrans_bytes) as avgretr_per_site_user by site user
| eventstats avg(retrans_bytes) as avgretr_per_site by site

Then you can pipe it to stats values() or something.

But that's - I think - kinda ineffective.

I'd try to approach it from a bit more "manual" side so I'd simply calculate number and sum of entries for each site and user. Then you can use those values to calculate the stats on your own. Something like

<your search>
| stats count(retrans_bytes) as count sum(retrans_bytes) as sum by site user
| streamstats sum(count) as sitecount sum(sum) as sitesum by site
| eval avg=sum/count
| eval siteavg=sitesum/sitecount

I suppose that's more effective that's the eventstats-based since stats is prone to map/reduce.

View solution in original post

0 Karma

PickleRick
SplunkTrust
SplunkTrust

Ouch. You already have the data, don't search for it twice!

One obvious approach would be to use eventstats instead of stats so you wouldn't lose the origina, events. But that would mean running the eventstats twice and since eventstats is a dataset processing command, it doesn't scale well.

<your search>
| eventstats avg(retrans_bytes) as avgretr_per_site_user by site user
| eventstats avg(retrans_bytes) as avgretr_per_site by site

Then you can pipe it to stats values() or something.

But that's - I think - kinda ineffective.

I'd try to approach it from a bit more "manual" side so I'd simply calculate number and sum of entries for each site and user. Then you can use those values to calculate the stats on your own. Something like

<your search>
| stats count(retrans_bytes) as count sum(retrans_bytes) as sum by site user
| streamstats sum(count) as sitecount sum(sum) as sitesum by site
| eval avg=sum/count
| eval siteavg=sitesum/sitecount

I suppose that's more effective that's the eventstats-based since stats is prone to map/reduce.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...