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
Get Updates on the Splunk Community!

Accelerating Observability as Code with the Splunk AI Assistant

We’ve seen in previous posts what Observability as Code (OaC) is and how it’s now essential for managing ...

Integrating Splunk Search API and Quarto to Create Reproducible Investigation ...

 Splunk is More Than Just the Web Console For Digital Forensics and Incident Response (DFIR) practitioners, ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...