Splunk Search

Which is faster, appendcols with second search or replacing values?

gcharles
Explorer

I would like to understand which of the following is the fastest and why or if there are any more faster ways to achieve the same thing...

Method 1 - appendcols with second search

index="index1" (app="outbound-service" message="Outbound Successful*") 
|  rex field=message "Amount=(?[0-9]+)"
| eval outboundAmount=outboundAmount/100 
| timechart span=1d sum(outboundAmount) as "Outbound ($)"
|  appendcols 
    [search index="index1" (app="inbound-service" message="Inbound Successful*") 
|  rex field=message "Amount=(?[0-9]+)"
| eval inboundAmount=inboundAmount/100 
| timechart span=1d sum(inboundAmount) as "Inbound ($)"]

Method 2 - replacing values and timechart 'by'

index="index1" (app="outbound-service" message="Outbound Successful*") OR (app="inbound-service" message="Inbound Successful*")
|  rex field=message "Amount=(?[0-9]+)"
| eval amount=amount/100 
|  replace "outbound-service" with "Outbound ($)" in app
|  replace "inbound-service" with "Inbound ($)" in app
| timechart span=1d sum(amount) by app

... or further alternatives...

I know for method two I could not worry about the replacements which would save time but I would like the timehchart to have nicer labels.

0 Karma
1 Solution

niketn
Legend

@gcharles appendcols will have sub search limitation, so option 2 would definitely be better than option 1. Have you tried running the two query with bulk data and use Search Job Inspector to compare their performance?
You should however use

Option 3 using rename to format column name after timechart
Instead of replacing the values in the data you can perform timechart with actual app name and then use rename command in the end to format the column name.

 index="index1" (app="outbound-service" message="Outbound Successful*") OR (app="inbound-service" message="Inbound Successful*")
 |  rex field=message "Amount=(?[0-9]+)"
 | eval amount=amount/100 
 | timechart span=1d sum(amount) by app
 |  rename "outbound-service" as "Outbound ($)",
                    "inbound-service" as "Inbound ($)"

Following is a run anywhere example based on Splunk's _internal index

index=_internal sourcetype=splunkd log_level!=INFO
| timechart count by log_level
| rename "ERROR" as "Splunkd Errors", "WARN" as "Splnkd Warnings"
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@gcharles appendcols will have sub search limitation, so option 2 would definitely be better than option 1. Have you tried running the two query with bulk data and use Search Job Inspector to compare their performance?
You should however use

Option 3 using rename to format column name after timechart
Instead of replacing the values in the data you can perform timechart with actual app name and then use rename command in the end to format the column name.

 index="index1" (app="outbound-service" message="Outbound Successful*") OR (app="inbound-service" message="Inbound Successful*")
 |  rex field=message "Amount=(?[0-9]+)"
 | eval amount=amount/100 
 | timechart span=1d sum(amount) by app
 |  rename "outbound-service" as "Outbound ($)",
                    "inbound-service" as "Inbound ($)"

Following is a run anywhere example based on Splunk's _internal index

index=_internal sourcetype=splunkd log_level!=INFO
| timechart count by log_level
| rename "ERROR" as "Splunkd Errors", "WARN" as "Splnkd Warnings"
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

gcharles
Explorer

Thanks. That was really what I was after, renaming the labels after the timechart process. Thanks again.

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!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...