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.
  • %A: Name of the day (Full).
  • %a: Name of the day (Abbreviated form).
  • %d/%e: Day of the month.
  • %j: Day of the year.
  • %V: Week of the year.
  • %b: Abbreviated name of the month.
  • %B: Full name of the month.
  • %m: Month as a decimal number.

  • %y: Year as a decimal number in YY format.
  • %Y: Year as a decimal number in YYYY format.


Comments

Popular posts from this blog

#3 Splunk sub(Commands) [eval, round, trim, stats, ceil, exact, floor, tostring]

#6 Splunk sub(Commands) [fields, rename, replace, table, transaction]

#2 Splunk sub(Commands) [eval, trim, chart, showperc, stats, avg]