Splunk Search

Why does this newly created field (via eval) not produce any values?

johnnydunlop
Engager

Hi,

I have written the below search query based on some prometheus metrics being onboarded:

 

index=lab_openshift_prometheus sourcetype=openshift_prometheus metric_name=ceph_cluster_total_bytes | eval ceph_cluster_total_bytes_decimal = round(v,0)
| append [ search  index=lab_openshift_prometheus sourcetype=openshift_prometheus metric_name=ceph_cluster_total_used_bytes | eval ceph_cluster_total_used_bytes_decimal = round(v,0) ]
| eval aaa = ceph_cluster_total_bytes_decimal - ceph_cluster_total_used_bytes_decimal / ceph_cluster_total_bytes_decimal
| table aaa

 

 

Basically what I want to do is:
convert each metric's V field (value) from scientific notation to decimal (rounding to 2 decimal places)
Do some arithmetic on the new decimal values and create a new field based on the result

I am able to create the new decimal value fields but when I do the arithmetic on them, the new aaa field does not contain any data:

johnnydunlop_0-1631881117604.png

Can anyone help me with what I am doing wrong?

Thanks in advance!


 

Labels (4)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

When the result of an eval is null it's usually because at least one of the fields in the eval is null.  In the screen shot, there are two separate events, each with one field used in the eval therefore, the eval does not have enough information to calculate aaa.

Use the stats command to combine the events then compute aaa.

index=lab_openshift_prometheus sourcetype=openshift_prometheus metric_name=ceph_cluster_total_bytes | eval ceph_cluster_total_bytes_decimal = round(v,0)
| append [ search  index=lab_openshift_prometheus sourcetype=openshift_prometheus metric_name=ceph_cluster_total_used_bytes | eval ceph_cluster_total_used_bytes_decimal = round(v,0) ]
| stats sum(*) as * 
| eval aaa = ceph_cluster_total_bytes_decimal - ceph_cluster_total_used_bytes_decimal / ceph_cluster_total_bytes_decimal
| table aaa

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

When the result of an eval is null it's usually because at least one of the fields in the eval is null.  In the screen shot, there are two separate events, each with one field used in the eval therefore, the eval does not have enough information to calculate aaa.

Use the stats command to combine the events then compute aaa.

index=lab_openshift_prometheus sourcetype=openshift_prometheus metric_name=ceph_cluster_total_bytes | eval ceph_cluster_total_bytes_decimal = round(v,0)
| append [ search  index=lab_openshift_prometheus sourcetype=openshift_prometheus metric_name=ceph_cluster_total_used_bytes | eval ceph_cluster_total_used_bytes_decimal = round(v,0) ]
| stats sum(*) as * 
| eval aaa = ceph_cluster_total_bytes_decimal - ceph_cluster_total_used_bytes_decimal / ceph_cluster_total_bytes_decimal
| table aaa

 

---
If this reply helps you, Karma would be appreciated.

johnnydunlop
Engager

Beautiful! Thank you very much!

johnnydunlop_0-1631886525426.png

 

0 Karma
Get Updates on the Splunk Community!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...

[Puzzles] Solve, Learn, Repeat: Dereferencing XML to Fixed-length events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...