Splunk Search

|metadata - Need results for Custom time range

splunker12er
Motivator
|metadata type=hosts earliest=-1d latest=now

This displays the overall eventcounts for the available hosts but not specific to the time range mentioned.
Is there a way to specify the time range for metadata results ?

somesoni2
Revered Legend

If you're on version 6.x, the you can use tstats command to generate metadata stats, which is time bound and much faster (then regular search). Following is the equivalent to metadata search

metadata search | metadata type=hosts index=*
tstats search | tstats count as totalCount min(_time) as firstTime max(_time) as lastTime WHERE index=* by host | eval recentTime=lastTime | eval type="hosts"

Ayn
Legend

No, not really. Time range for metadata only affects which entries that will be returned based on recentTime and lastTime.

May I suggest another option - use metasearch instead. As a bonus this also enables you to split your stats by multiple fields if you want (so for instance you could do stats count by host,sourcetype). This query should give you something similar to what you get with metadata:

| metasearch earliest=-1d | stats latest(_time) as lastTime,count by host

mendesjo
Path Finder

That doesn't seem to work for me anyway. If I put that in, not matter what it's ignored. Rather, whatever I select from the time picker is the time actually queried. Any idea why?

Get Updates on the Splunk Community!

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer at Splunk .conf24 ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...

Combine Multiline Logs into a Single Event with SOCK: a Step-by-Step Guide for ...

Combine multiline logs into a single event with SOCK - a step-by-step guide for newbies Olga Malita The ...