Splunk Search

Can you help me with my eval statement question?

Kendo213
Communicator

My results look like this:

ServerName count
ServerFarmA-1 47
ServerFarmA-2 49
ServerFarmB-1 16
ServerFarmB-2 15

Each server farm has two servers that should be load balanced. I basically want to take the count per server in a farm, divide it by the other number, and if it is relatively similar, (i.e. 47/49 = 95%) in the eval I will give it a status of 'Good', or 'Needs Attention' if it is at, as an example, 75%.

How can I go about doing this given the matching field names?

Thanks

Tags (1)
0 Karma
1 Solution

KailA
Contributor

Hello,

What do you think about that

| makeresults 
| eval ServerName = "ServerFarmA-1", count=47 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmA-2", count=49] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-1", count=16] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-2", count=15]
| table ServerName,count
| rex field=ServerName "^(?<Farm>[^-]+")
| stats values(count) as count by Farm
| eval FirstServer = mvindex(count,0),
       SecondServer = mvindex(count,1),
       Percentage = (FirstServer / SecondServer)*100,
       State = case(Percentage>=0.95,"Good",
                    Percentage >=0.75,"Needs Attention",
                    true(),"Bad")

That give you the percentage by ServerFarm and after you ca you a case to assign the value you want to a percentage range 🙂

Let me know

Kail


Edit

If the count is equal between two server of the same farm

| makeresults 
| eval ServerName = "ServerFarmA-1", count=57 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmA-2", count=47] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-1", count=16] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-2", count=16] 
| table ServerName,count 
| rex field=ServerName "^(?<Farm>[^-]+") 
| stats list(count) as count by Farm 
| eval FirstServer = mvindex(count,0),
    SecondServer = mvindex(count,1),
    First = case(FirstServer > SecondServer,SecondServer,
    FirstServer < SecondServer, FirstServer,
    FirstServer = SecondServer, FirstServer),
    Second = case(SecondServer > FirstServer,SecondServer,
    SecondServer < FirstServer, FirstServer,
    FirstServer = SecondServer, SecondServer),
    Percentage = (First / Second)*100,
    State = case(Percentage>=0.95,"Good",
    Percentage >=0.75,"Needs Attention",
    true(),"Bad")

View solution in original post

0 Karma

KailA
Contributor

Hello,

What do you think about that

| makeresults 
| eval ServerName = "ServerFarmA-1", count=47 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmA-2", count=49] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-1", count=16] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-2", count=15]
| table ServerName,count
| rex field=ServerName "^(?<Farm>[^-]+")
| stats values(count) as count by Farm
| eval FirstServer = mvindex(count,0),
       SecondServer = mvindex(count,1),
       Percentage = (FirstServer / SecondServer)*100,
       State = case(Percentage>=0.95,"Good",
                    Percentage >=0.75,"Needs Attention",
                    true(),"Bad")

That give you the percentage by ServerFarm and after you ca you a case to assign the value you want to a percentage range 🙂

Let me know

Kail


Edit

If the count is equal between two server of the same farm

| makeresults 
| eval ServerName = "ServerFarmA-1", count=57 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmA-2", count=47] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-1", count=16] 
| append 
    [| makeresults 
    | eval ServerName = "ServerFarmB-2", count=16] 
| table ServerName,count 
| rex field=ServerName "^(?<Farm>[^-]+") 
| stats list(count) as count by Farm 
| eval FirstServer = mvindex(count,0),
    SecondServer = mvindex(count,1),
    First = case(FirstServer > SecondServer,SecondServer,
    FirstServer < SecondServer, FirstServer,
    FirstServer = SecondServer, FirstServer),
    Second = case(SecondServer > FirstServer,SecondServer,
    SecondServer < FirstServer, FirstServer,
    FirstServer = SecondServer, SecondServer),
    Percentage = (First / Second)*100,
    State = case(Percentage>=0.95,"Good",
    Percentage >=0.75,"Needs Attention",
    true(),"Bad")
0 Karma

Kendo213
Communicator

So one thing I've noticed is that if both servers have the same value, it's only passing the number of one of them (i.e. 15 is only listed once so it goes critical). Any ideas?

0 Karma

KailA
Contributor

I edited my answer 🙂

0 Karma

Kendo213
Communicator

Great! Thanks again

0 Karma

KailA
Contributor

I edited it a second time, take the second search now, should be good 🙂

0 Karma

Kendo213
Communicator

That's...exactly what I wanted. Thanks a ton.

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 ...