Splunk Search

How to change chart count to a percent value?

nikkkc
Path Finder

I do not know how to change count values to a percentage value and I couldn't find an answer by searching this forum, so maybe someone could help me please? thanks in advance

This is my search:

index=* 
| fields eventDateTime,computerName,name,agentGuid,ID 
| eval _timeepoch = strptime(eventDateTime,"%Y-%m-%d %H:%M")     
| eval myDay = strftime(_timeepoch,"%A")    
| eval myYear = strftime(_timeepoch,"%Y") 
| eval myMonth = strftime(_timeepoch,"%m") 
| where (myDay != "Saturday" AND myDay != "Sunday")  
| lookup Workdays myYear myMonth OUTPUT Days 
| chart count  over computerName by name  
| eval count=round(count*100/(Days*10),4) 
| eval count=if(Servicetime>100,100.0000,Servicetime)

The last two evals were my idea to change the count values, but this does NOT work!Maybe also the lookup value isn't available after the chart function right? How can I do this? 🙂

0 Karma
1 Solution

fdi01
Motivator

try like :

 index=* 
 | fields eventDateTime,computerName,name,agentGuid,ID 
 | eval _timeepoch = strptime(eventDateTime,"%Y-%m-%d %H:%M")     
 | eval myDay = strftime(_timeepoch,"%A")    
 | eval myYear = strftime(_timeepoch,"%Y") 
 | eval myMonth = strftime(_timeepoch,"%m") 
 | where (myDay != "Saturday" AND myDay != "Sunday")  
 | lookup Workdays myYear myMonth OUTPUT Days 
 | chart count  over computerName by name  | eventstats sum(count) as Total by Days 
 | eval Percent=round(count*100/Total,4) 
 | eval count=if(Servicetime>100,100.0000,Servicetime)

or

your base search  | stats  count by computerName  name | eventstats sum(count) as Total by Days  | eval Percent=round(count*100/Total,4) | ....

View solution in original post

fdi01
Motivator

try like :

 index=* 
 | fields eventDateTime,computerName,name,agentGuid,ID 
 | eval _timeepoch = strptime(eventDateTime,"%Y-%m-%d %H:%M")     
 | eval myDay = strftime(_timeepoch,"%A")    
 | eval myYear = strftime(_timeepoch,"%Y") 
 | eval myMonth = strftime(_timeepoch,"%m") 
 | where (myDay != "Saturday" AND myDay != "Sunday")  
 | lookup Workdays myYear myMonth OUTPUT Days 
 | chart count  over computerName by name  | eventstats sum(count) as Total by Days 
 | eval Percent=round(count*100/Total,4) 
 | eval count=if(Servicetime>100,100.0000,Servicetime)

or

your base search  | stats  count by computerName  name | eventstats sum(count) as Total by Days  | eval Percent=round(count*100/Total,4) | ....

nikkkc
Path Finder

Thank you, now you brought me to this final and great result:

my base search | stats count by computerName name,atage
| eval Servicetime=round(count*100/(Days*11),4)
| eval Servicetime=if(Servicetime>100,100.0000,Servicetime)
| fields - Days,count
| chart sum(Servicetime) over computerName by name

0 Karma

aholzer
Motivator

You are correct that the lookup fields would not be available after the stats. The only fields available to you after the stats are count, computerName and name.

If you use the "top" command, you should get a percent field automatically

Hope this helps

0 Karma

nikkkc
Path Finder

ok thanks, but i cant use the top command because splunk can not know my definition for 100 percent. it depends on the lookup result. is there no way to do this?

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...