Monitoring Splunk

How to find difference of date in same table as another column?

nikhil29
Loves-to-Learn Everything

I have 1 table having current date when in maintenance and another is last date when it started and looking new value with difference of 2 date without Join.

2022-12-26_18h49_56.png

Labels (1)
0 Karma

PickleRick
SplunkTrust
SplunkTrust

There is surely more than one approach to this. I'd probably firstly split the date between two different fields

<your search>
| eval maintenance_date=if(role_status="MAINTENANCE_MODE",date,null())
| eval start_date=if(role_status="STARTED",date,null())

Then you can join several rows (depending on your use case it might be with transaction or some stats) and have separate fields on which you can easily calculate difference.

0 Karma

pstout2
Loves-to-Learn

You want to use the delta search command. First, invert the sort order otherwise your maintenance mode entry will have nothing against which it can compare.

This assumes the dates in epoch time as your example suggests.

Then,  use the delta command a=on the date field. Remember, because you inverted the order these numbers will now be negative.

Finally, search for anything older than 2 days (86400s * 2) and not 0. 

Here's a straw man search:

| index=<your_index> sourcetype=<your_sourcetype>
| sort - date
| delta date AS date_diff
| search date_diff < 172800 AND date_diff != 0

 

0 Karma

nikhil29
Loves-to-Learn Everything

I tried your work around but i want services is in maintenance mode from how many days when it was STARTED and then it went to MAINTENANCE_MODE that time difference.

But here first column reflecting blank and days calculating wrong as well

It would be really appreciate if someone can help me please

2023-01-02_18h32_13.png

0 Karma

nikhil29
Loves-to-Learn Everything

I have one more doubt how splunk will and  calculate the date difference if it will sort properly like Maintenance Started alternative.

please see the blow screenshot and help me.

2023-01-02_14h49_41.png

0 Karma

nikhil29
Loves-to-Learn Everything

will not sort alternative*

0 Karma

nikhil29
Loves-to-Learn Everything

Actually I want to know from how long role is in maintenance mode like from last 2 days or more than that.

0 Karma

nikhil29
Loves-to-Learn Everything

Would someone please help me ?

0 Karma
Get Updates on the Splunk Community!

New in Observability - Improvements to Custom Metrics SLOs, Log Observer Connect & ...

The latest enhancements to the Splunk observability portfolio deliver improved SLO management accuracy, better ...

Improve Data Pipelines Using Splunk Data Management

  Register Now   This Tech Talk will explore the pipeline management offerings Edge Processor and Ingest ...

3-2-1 Go! How Fast Can You Debug Microservices with Observability Cloud?

Register Join this Tech Talk to learn how unique features like Service Centric Views, Tag Spotlight, and ...