Reporting: Compare hourly sums between multiple days
Reporting: Compare hourly sums between multiple days
While the timechart is great for creating charts that show trends over time, it has strict boundaries limiting what it can do. There are times when you're better off with the chart command, which can provide more flexibility.
This is an example of how you might want to use chart to compare values collected over several days. This is something you can't do with timechart
Scenario
You have two searches that are nearly identical. They both show the hourly sum of the P field over a 24-hour period. The only difference is that one search covers a period ten days in the past, while the other covers a period nine days into the past:
Search 1:
earliest=-10d latest=-9d | timechart span="1h" sum(P)Search 2:
earliest=-9d latest=-8d | timechart span="1h" sum(P)What you'd like to do is create a column chart that combines the results of these two searches, so you can see the sum of P for 3pm, ten days ago side-by-side with the sum of P for 3pm, nine days ago.
Solution
You can't pull this off with the timechart command. But you can do it with the chart command, and it's pretty simple. Set up a search that covers both days, and then have it create a "sum of P" column for each distinct date_hour and date_day combination found in the search events.
The finished search looks like this:
earliest=-10d latest=-8d | chart sum(P) by date_hour date_dayThis produces a single chart with 24 slots, one for each hour of the day. Each slot contains two columns that enable you to compare hourly sums between the two days covered by the time range of the report.
For a primer on reporting searches and how they're constructed, see "Use reporting commands" in the User Manual.
For more information about chart> and timechart functions, see "Functions for stats, chart, and timechart" in the Search Reference Manual.
This documentation applies to the following versions of Splunk: 4.1 , 4.1.1 , 4.1.2 , 4.1.3 , 4.1.4 , 4.1.5 , 4.1.6 , 4.1.7 , 4.1.8 , 4.2 , 4.2.1 , 4.2.2 , 4.2.3 , 4.2.4 , 4.2.5 , 4.3 , 4.3.1 , 4.3.2 View the Article History for its revisions.