Splunk Search

How do I get an accurate count for a field that has values in different formats?

vinay4444
Explorer

Hi

We have field that has data in different formats (having values in [] but other simply name) e.g.

itemkey = ms.db.cpu_usage_percent[WL_DBA]
itemkey = ms.db.locks_count

I use the search below to get distinct metrics name stripping out workload [WL_DBA] but it does not count metrics without [] like ms.db.locks_count how do I get counts of both together?

index=xxxx sourcetype="xxx" value >= 0.000 | rex field=itemKey (?<metric>.)[(?<space>.)] | dedup metric | stats count(metric)
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try something like this

index=xxxx sourcetype="xxx" value >= 0.000 | rex field=itemKey "(?<metric>[^\[]*)" | dedup metric | stats count(metric)

OR

  index=xxxx sourcetype="xxx" value >= 0.000 | eval metric=replace(itemKey,"(.*)\[.*\]","\1") | stats dc(metric)

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try something like this

index=xxxx sourcetype="xxx" value >= 0.000 | rex field=itemKey "(?<metric>[^\[]*)" | dedup metric | stats count(metric)

OR

  index=xxxx sourcetype="xxx" value >= 0.000 | eval metric=replace(itemKey,"(.*)\[.*\]","\1") | stats dc(metric)
Get Updates on the Splunk Community!

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

Splunk is officially part of Cisco

Revolutionizing how our customers build resilience across their entire digital footprint.   Splunk ...

Splunk APM & RUM | Planned Maintenance March 26 - March 28, 2024

There will be planned maintenance for Splunk APM and RUM between March 26, 2024 and March 28, 2024 as ...