All Apps and Add-ons

CPU by Search: *NIX

Ron_Naken
Splunk Employee
Splunk Employee

On a *NIX monolithic search-head/indexer, what is the best method to determine Splunk's CPU load by search at a point in time (no need to calculate avg, etc.)? We are looking to build a report to display something like this:

search index=os sourcetype=ps | multikv     8%     
search index=netapp_perf object=system | ...     5%

Cheers,
Ron

0 Karma
1 Solution

Ron_Naken
Splunk Employee
Splunk Employee

Thanks, here's the solution:

index=os sourcetype=ps | multikv | search COMMAND=splunkd | rex field=_raw "search_--id=(?<srid>[^-]+)(?=_)" | search srid=* | join srid [search index=_audit search_id=* search=* | rex field=search_id "'?(?<srid>[^']+)" | fields srid search] | table _time user search pctCPU

Cheers,
Ron

View solution in original post

Ron_Naken
Splunk Employee
Splunk Employee

Thanks, here's the solution:

index=os sourcetype=ps | multikv | search COMMAND=splunkd | rex field=_raw "search_--id=(?<srid>[^-]+)(?=_)" | search srid=* | join srid [search index=_audit search_id=* search=* | rex field=search_id "'?(?<srid>[^']+)" | fields srid search] | table _time user search pctCPU

Cheers,
Ron

sloshburch
Splunk Employee
Splunk Employee

If you are using SOS, you can do this search on the SOS rather than the OS index.

I think I may have optimized the performance of this search by moving the 'search srid=*' into a 'search_--id' string in the initial search (thereby reducing the number of events to operate on in the remaining search.

index=os sourcetype=ps search_--id | multikv | search COMMAND=splunkd | rex field=raw "search--id=(?[^-]+)(?=_)" | join srid [search index=_audit search_id=* search=* | rex field=search_id "'?(?[^']+)" | fields srid search] | table _time user search pctCPU

0 Karma

lguinn2
Legend

Nice answer!

0 Karma

lguinn2
Legend

If you really wanted to see CPU usage at a point in time, you could collect the data via the *NIX ps command.
Each search in Splunk runs as a separate process. You could even correlate the CPU usage back to the specific search using the search id, which appears in the process information.

The *NIX app has a script that runs the ps command and indexes its output. You just need to enable it - and then write the searches to analyze the data.

Another approach, if you want to look at CPU usage over time: Splunk keeps information about each search that it runs in the _audit index. You can see some of the statistics that can be computed, if you are logged into Splunk as an admin. From the Search app, choose the Status menu (between Search and Views in the menu bar). Then choose "Search Activity" and "Search Details." This dashboard will show the most common and the most expensive searches.

Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

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