Dealing with Time
Dealing with Time:
- Its extremely important to have a proper timestamp.
- It helps to have all the events organized.
- _time is a default field and is present in all the events.
- In cases where an event doesn't contain a timestamp, Splunk automatically assign a timestamp value to the event when the event was indexed.
- Refrain from using "All Time", reason being it will really be a very heavy task for Splunk to have all the data in place and then to apply your SPL over it.
Time conversion and its usage:
- There is a function called now(), which takes no arguments and returns the time when the search was started.
- Another add-on in Splunk is, we have an ability to convert and use time based on our requirements.
- For doing so we can use eval function followed by few functions:
- strftime(X, Y)
- This will convert an epoch timestamp (X) into a string format described by Y (Example: To showcase time based on our requirements).
- strptime(X, Y)
- This will convert a string X, e.g. "2019-04-09 11:00:00", into epoch, with the string format described by Y (Example: To calculate the difference between two timestamps).
Important variables:
- %c: Displays day, date and time defined by operating system.
- %+: Displays day, date, time along with the timezone as defined by operating system.
- %H: Displays hours based on 24 hours clock (00-23).
- %M: Displays minutes (00-59).
- %S: Displays seconds (00-59).
- %I: Displays hours based on 12 hours clock (01-12).
- %k: Similar to %H but leading 0's are replaced by blank spaces.
- %N: Number of subsecond digits, %3N for milliseconds %6N for microseconds %9N for nanoseconds.
- %s: Gives you unix timestamps in seconds.
- %T: Includes hours, minutes, seconds and gives time based on 24 hours clock.
- %Z: Gives the timezone as well.
- %z: Gives the timezone offset from UTC.
- %F: Gives the date in YYYY-MM-DD format.
- %x: Gives the date in MM/DD/YY format.
Comments
Post a Comment