Splunk Search

Why is this query malformed after adding in a simple division statement?

michaelhaedt
Explorer

Good afternoon Guru's,

I just was put into a position to teach myself how to splunk. I don't have experience with this kind of query type language and it's bringing me to my knees. Here's my query...there is a selected index and everything works perfectly except when I add in a simple division statement...then it says the query is malformed but pretty sure that's not the case at all: I'm trying to get the percentage of events that the response_time is greater than 2 standard deviations:

 

index="myIndex"

| eventstats avg(response_time) as Average_Response_Time stdev(response_time) as Standard_Deviation count(response_time) as Total_Count

| eval calc = Average_Response_Time+(2*Standard_Deviation)

| eval 2xStd = if(response_time>calc, 1, 0)

| eventstats sum(2xStd) as 2times

| eval percent = 2times/Total_Count

| table response_time Average_Response_Time Standard_Deviation

Labels (1)
0 Karma
1 Solution

SanjayReddy
SplunkTrust
SplunkTrust

Hi @michaelhaedt 

for division statments instead of using 2times filed, can you use times2 or any name which doesnot start with number, 

| eval percent = 2times/Total_Count


index="myIndex"
| eventstats avg(response_time) as Average_Response_Time stdev(response_time) as Standard_Deviation count(response_time) as Total_Count
| eval calc = Average_Response_Time+(2*Standard_Deviation)
| eval 2xStd = if(response_time>calc, 1, 0)
| eventstats sum(2xStd) as times2
| eval percent = times2/Total_Count
| table response_time Average_Response_Time Standard_Deviation



View solution in original post

0 Karma

michaelhaedt
Explorer

Thank you folks, this really had me bent. I'm sure I'll have many more questions 🙂

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You could try enclosing the field name in single quotes (not double quotes) when referring to the field

index="myIndex"

| eventstats avg(response_time) as Average_Response_Time stdev(response_time) as Standard_Deviation count(response_time) as Total_Count

| eval calc = Average_Response_Time+(2*Standard_Deviation)

| eval 2xStd = if(response_time>calc, 1, 0)

| eventstats sum('2xStd') as 2times

| eval percent = '2times'/Total_Count

| table response_time Average_Response_Time Standard_Deviation
0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Hi @michaelhaedt 

for division statments instead of using 2times filed, can you use times2 or any name which doesnot start with number, 

| eval percent = 2times/Total_Count


index="myIndex"
| eventstats avg(response_time) as Average_Response_Time stdev(response_time) as Standard_Deviation count(response_time) as Total_Count
| eval calc = Average_Response_Time+(2*Standard_Deviation)
| eval 2xStd = if(response_time>calc, 1, 0)
| eventstats sum(2xStd) as times2
| eval percent = times2/Total_Count
| table response_time Average_Response_Time Standard_Deviation



0 Karma
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!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...