Search code examples
splunksplunk-query

Using dedup to find unique hosts. How can I find an average for the selected time frame?


The goal is to provide percent availability. I would like to check every 15 minutes if the unique count for server1, server2, and server3 is equal to 3 for each interval (indicating the system is fully healthy). From this count I want to check on the average for whatever time period is selected in splunk to output an average and convert to percent.

index="os" sourcetype=ps host="server1" OR host="server2" OR host="server3"
| search "/logs/temp/random/path" OR "application_listener"
| dedup host
| timechart span=30m count

The count should be 3 for each interval.


Solution

  • It's not clear how much of your requirements the example SPL solves, so I'll assume it does nothing.

    Having dedup followed by timechart means the timechart command will only see 3 events - one for each host. That doesn't make for a helpful chart. I suggest using dc(host), instead to get a count of hosts for each interval.

    The appendpipe command can be used to add average and percentage values on the end.

    index="os" sourcetype=ps host="server1" OR host="server2" OR host="server3" 
    | search "/logs/temp/random/path" OR "application_listener"
    | timechart span=30m dc(host) as count
    | appendpipe [ stats avg(count) as Avg | eval Pct=round(Avg*100/3,2) ]