Splunk Search

Unable to draw timechart

mayank101
New Member

I have a query that accumulates the total count for host over a 6 period of month. Now when I am trying to draw time chart for it ,I am unable to do so.It shows no result .
| savedsearch "r1"
| top 10 event by host | sort-count | eventstats sum(count) as TotalNumber| eval PercentOfTotal = round(100 * count / TotalNumber,2). "%"
| stats list(entity) as "Entity" list(count) as "Count", sum(count) as "Total" by event
| sort-Total

| addinfo
| eval rank=1 | accum rank | sort +num(rank) | head (rank <=10) | fields rank, host,event, Entity, Count,Total | eval Entity=mvindex(Entity,0,9)
| eval Count=mvindex(Count,0,9) | eval Percent=mvindex(Percent,0,9)
|timechart span=1d useother=f count by host
Can you please help in drawing timechart

Tags (1)
0 Karma
1 Solution

jlemley
Path Finder

Timechart requires _time in order to function, but your "stats" commands don't pass _time through. Assuming your saved search includes _time, try this:

| savedsearch "r1" 
| bin _time span=1d
| top 10 event by host, _time
| sort-count 
| eventstats sum(count) as TotalNumber 
| eval PercentOfTotal = round(100 * count / TotalNumber,2). "%" 
| stats list(entity) as "Entity" list(count) as "Count", sum(count) as "Total" by event, _time
| sort-Total 
| addinfo 
| eval rank=1 
| accum rank 
| sort +num(rank) 
| head (rank <=10) 
| fields rank, host,event, Entity, Count,Total 
| eval Entity=mvindex(Entity,0,9) 
| eval Count=mvindex(Count,0,9) 
| eval Percent=mvindex(Percent,0,9) 
| timechart span=1d useother=f count by host

If your saved search has a different time field, then you may need to convert that to _time using strptime.

View solution in original post

0 Karma

mayank101
New Member

Thank you so much ,it worked

0 Karma

jlemley
Path Finder

Timechart requires _time in order to function, but your "stats" commands don't pass _time through. Assuming your saved search includes _time, try this:

| savedsearch "r1" 
| bin _time span=1d
| top 10 event by host, _time
| sort-count 
| eventstats sum(count) as TotalNumber 
| eval PercentOfTotal = round(100 * count / TotalNumber,2). "%" 
| stats list(entity) as "Entity" list(count) as "Count", sum(count) as "Total" by event, _time
| sort-Total 
| addinfo 
| eval rank=1 
| accum rank 
| sort +num(rank) 
| head (rank <=10) 
| fields rank, host,event, Entity, Count,Total 
| eval Entity=mvindex(Entity,0,9) 
| eval Count=mvindex(Count,0,9) 
| eval Percent=mvindex(Percent,0,9) 
| timechart span=1d useother=f count by host

If your saved search has a different time field, then you may need to convert that to _time using strptime.

0 Karma

mayank101
New Member

Hey jlemley...The above command is not working, its not showing top10,its just listing alphabetically.

0 Karma

mayank101
New Member

Thank you so much ,it worked

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...