Getting Data In

How search the latest timestamp of each event type in our data?

MikeBertelsen
Communicator

We run a query that produces a count of each event type, but we also want to know when was the last time the event ran.
Here is the query:
index=lisa_vse| top limit=100 serviceName | fields serviceName count serviceTimeStamp

The results are:


serviceNamecountserviceTimeStamp
trn_RiskReportsService32208
trn_ProductPortfolioService16501
engr_RiskReportsService12790
RatingSymbolService_PC10751
trn_GeoCoderService9856
trn_RatingService8777
RiskReportsService_GUnit7308
AutoRateInfoService_PC6851
trn_AutoRateInfoService6315
trn_PolicyTransitionService4532

Tags (2)
1 Solution

aweitzman
Motivator

I think you want to structure the search a little differently:

index=lisa_vse | stats count, first(_time) as serviceTimeStamp by serviceName | sort -count | head 100 | fieldformat serviceTimeStamp = strftime('serviceTimeStamp', "%c")

(edited to correct typo)

You can keep track of the latest time and the count simultaneously by using the stats command instead of top. Then sort by the count descending, and just take the first 100.

View solution in original post

aweitzman
Motivator

I think you want to structure the search a little differently:

index=lisa_vse | stats count, first(_time) as serviceTimeStamp by serviceName | sort -count | head 100 | fieldformat serviceTimeStamp = strftime('serviceTimeStamp', "%c")

(edited to correct typo)

You can keep track of the latest time and the count simultaneously by using the stats command instead of top. Then sort by the count descending, and just take the first 100.

MikeBertelsen
Communicator

My partner figured it out. Here is what he came up with:
index=lisa_vse source=/opt/lisavse/VSEMetrics/Logs/VSE_CallsMade.* | stats count, first(serviceTimeStamp) as lastExecution by serviceName | sort -count
It works but I like the format of aweitzman's query better. Thanks for the help.

aweitzman
Motivator

Oh, I see the second typo in my answer, the extra space in the field name taken by strftime! If you take that out, it ought to work.

0 Karma

aweitzman
Motivator

I'm confused.

Except for the typo in my answer (index-lisa_vse should be index=lisa_vse, which you seem to have figured out), your search is exactly the same as my suggestion, except for the final clause.

Where does maxTimeStamp come from? serviceTimeStamp already contains the epoch time value you want - the fieldformat clause just makes it easier to read. If you want to create a new field maxTimeStamp for that instead of overwriting the existing serviceTimeStamp, you need to write your final clause like this:

fieldformat maxTimeStamp=strftime('serviceTimeStamp',"%c")

0 Karma

MikeBertelsen
Communicator

Which provided the following output:





serviceNamecountserviceTimeStampmaxTimeStamp
RatingSymbolService_PC 73291410212566
RiskReportsService_GUnit73081410212831
trn_RiskReportsService 66771410212851
AutoRateInfoService_PC51521410212857
engr_RiskReportsService37841409937368
RatingService_PC 25801410212832
closer but not there

0 Karma

MikeBertelsen
Communicator

It made no difference in the output.

I should have included the following info.
There are two Field Extractions defined:

1. VSE_CallsMade : EXTRACT-serviceName Inline (?i)^(?P[^,]+)

2. VSE_CallsMade : EXTRACT-serviceTimeStamp Inline (?i)^(?:[^,]*,){2}(?P.+)



So I made a few changes to the offered solution:
index=lisa_vse | stats count, first(_time) as serviceTimeStamp by serviceName | sort -count | head 100 | fieldformat maxTimeStamp =strftime('maxTimeStamp ', "%c")

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...