I have a data source in splunk that queries a database for metrics; the query runs once an hour, and returns JSON that looks something like this:
{"counts": {
"visible":19608,"invisible":22360,"total":41968,
"breakdown_list":{
"sub_1":{ "name":"First Sub Topic" ,"total":247 ,"visible":238 ,"invisible":9 },
"sub_2":{ "name":"Second Sub Topic" ,"total":16 ,"visible":0 ,"invisible":16 },
...}
}
}
The story I'm working on now says that Splunk should raise an alert when the top-level visible count drops 10% from the value 24 hours ago.
I can get the current value like this:
index="my_index" source="My_Dev_Stats" | head 1 | spath path=counts.visible output=vis_now
And I can get the 24-hour old value like this:
index="my_index" source="My_Dev_Stats" latest=-1d | head 1 | spath path=counts.visible output=vis_yesterday
But I'm drawing a blank on how to get the results of the two queries on the same page so I can alert when
(vis_yesterday - vis_now)/vis_yesterday > 0.10
As I'm very new to splunk, I'd also appreciate any pointers on how to write queries efficiently and idiomatically.