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!

[Puzzles] Solve, Learn, Repeat: Dynamic formatting from XML events

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

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Stronger Security with Federated Search for S3, GCP SQL & Australian Threat ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...