Splunk Search

Timechart with Failurepercentage and appendcols

yuvrajsharma_13
Explorer

I am using below query to get search result and calculate the failure percentage but not getting the expected result.

 

index=dl* ("Error_MongoDB") | timechart span 1d count as Failure | appendcols [search index=dl* ("inserted Record") | timechart span=1d count as Success | eval (FailurePercentage = Failure/Sucess)*100 | field _time,Failure,Sucess,FailurePercentage

 

I am getting all the values except FailurePercentage. What could be the reason ?

 

Labels (2)
Tags (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

So, try the suggestion - you only need the single search as I posted earlier, but with your updated search it should be like this

index=dl* ("Error_MongoDB") OR ("Record_Inserted") 
| eval Status=if(match(_raw, "Error_MongoDB"), "Failure", "Success")
| rename msg.attribute.ticketId as ticketId
| timechart span=1d dc(ticketId) by Status 
| eval FailurePercentage = (Failure/Success)*100 
| fillnull FailurePercentage

You don't need to use all the fields/table commands - the timechart will remove all the unnecessary fields anyway

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

There are lots of errors in that query if cut/pasted to a Splunk search, but if you are not getting FailurePercentage, that's because the statement

| eval (FailurePercentage = Failure/Sucess)*100

is not a valid Splunk eval statement and Sucess is also spelt incorrectly compared to the calculation in your stats command

Note that your approach to appendcols if not a good way to approach this problem and can be done more efficiently like this

index=dl* ("Error_MongoDB") OR ("inserted Record") 
| eval Status=if(match(_raw, "Error_MongoDB"), "Failure", "Success")
| timechart span=1d count as Total by Status 
| eval FailurePercentage = (Failure/Success)*100 
| fillnull FailurePercentage

so you don't need a subsearch and can do it in one timechart and the fillnull will take care if the value of Success is 0

Note that the eval Status line may be improved if you have a field that can indicate success/failure better than by matching _raw

0 Karma

yuvrajsharma_13
Explorer

Thank you @bowesmana for quick response. I am writing down the exact query here.

I have to combine both the queries to get Failure %  using timechart.

 

Query 1 ( Success ) :

index=dl* ("Record_Inserted")  | fields msg.attribute.ticketId

| rename msg.attribute.ticketId as ticketId

| table ticketId,_time

| timechart span=1d dc(ticketId)

 

Query 2 ( Failure ) :

index=dl* ("Error_MongoDB")  | fields msg.attribute.ticketId | rename msg.attribute.ticketId as ticketId

| table ticketId,_time

| timechart span=1d dc(ticketId)

 

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

So, try the suggestion - you only need the single search as I posted earlier, but with your updated search it should be like this

index=dl* ("Error_MongoDB") OR ("Record_Inserted") 
| eval Status=if(match(_raw, "Error_MongoDB"), "Failure", "Success")
| rename msg.attribute.ticketId as ticketId
| timechart span=1d dc(ticketId) by Status 
| eval FailurePercentage = (Failure/Success)*100 
| fillnull FailurePercentage

You don't need to use all the fields/table commands - the timechart will remove all the unnecessary fields anyway

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!

Agentic SOC Triage: Investigating Splunk ES Notables with MCP Server and a Local LLM

The Problem: Too Many Alerts, Too Little Context Security operations teams running Splunk Enterprise Security ...

All Work and No Play? Not at .conf26! Unwind at These Evening Events

Between hands-on technical sessions, keynote reveals, and diving into live architectures, .conf26 is packed ...

Join the Hackathon at .conf26 and build a No-Code AI agent

Join us for the AI Agent Buildathon, an in-person, three-hour hands-on Hackathon where you’ll use Splunk Agent ...