Getting Data In

 


Configure timestamp recognition

Configure timestamp recognition

Most events don't require any special timestamp handling. Splunk automatically recognizes and extracts their timestamps. However, for some sources and distributed deployments, you might need to configure how Splunk extracts timestamps, so that they format properly.

There are two ways to configure timestamp extraction:

Splunk's timestamp processor

Splunk's timestamp processor is located by default in $SPLUNK_HOME/etc/datetime.xml. You ordinarily do not need to touch this file, unless you're dealing with unusual, custom timestamps. If you need to configure timestamp recognition in some way, you can usually make the necessary changes by setting props.conf timestamp attributes, as described below.

If you have a custom timestamp that can't be handled by configuring props.conf, you can substitute your own timestamp processor with the DATETIME_CONFIG attribute, described in the next section. This attribute specifies the file Splunk should use for timestamp processing.

Edit timestamp properties in props.conf

To configure how Splunk recognizes timestamps, edit props.conf. There are a number of attributes that pertain to timestamps. In particular, you can determine how Splunk recognizes a timestamp by using the TIME_FORMAT attribute to specify a strptime() format for the timestamp. You can also set other attributes pertaining to timestamps; for example, to specify where a timestamp is located in an event, what time zone to use, or how to deal with timestamps of varying currency.

Edit the props.conf file in $SPLUNK_HOME/etc/system/local/ or in your own custom application directory in $SPLUNK_HOME/etc/apps/. For information on configuration files in general, see "About configuration files" in the Admin manual.

To set Splunk's timestamp recognition, configure one or more of the timestamp attributes in props.conf. Refer to the props.conf specification file for detailed information regarding these and other attributes.

Syntax overview

Here's an overview of the syntax for the timestamp attributes:

[<spec>]
DATETIME_CONFIG = <filename relative to $SPLUNK_HOME>
TIME_PREFIX = <regular expression>
MAX_TIMESTAMP_LOOKAHEAD = <integer>
TIME_FORMAT = <strptime-style format>
TZ = <posix time zone string>
MAX_DAYS_AGO = <integer>
MAX_DAYS_HENCE = <integer>
MAX_DIFF_SECS_AGO = <integer>
MAX_DIFF_SECS_HENCE = <integer>

In this syntax, <spec> can be:

If an event contains data that matches the value of <spec>, then the timestamp rules specified in the stanza apply to that event. You can have multiple stanzas, to handle different <spec> values.

Timestamp attributes

These are the timestamp attributes settable through props.conf:

DATETIME_CONFIG = <filename relative to $SPLUNK_HOME>

TIME_PREFIX = <regular expression>

MAX_TIMESTAMP_LOOKAHEAD = <integer>

TIME_FORMAT = <strptime-style format>

TZ = <time zone identifier>

MAX_DAYS_AGO = <integer>

MAX_DAYS_HENCE = <integer>

MAX_DIFF_SECS_AGO = <integer>

MAX_DIFF_SECS_HENCE = <integer>

Enhanced strptime() support

Use the TIME_FORMAT attribute in props.conf to configure timestamp parsing. This attribute takes a strptime() format string, which it uses to extract the timestamp.

Splunk implements an enhanced version of Unix strptime() that supports additional formats, allowing for microsecond, millisecond, any time width format, and some additional time formats for compatibility. The additional formats are listed in this table:

 %N For GNU date-time nanoseconds. Specify any sub-second parsing by providing the width: %3N = milliseconds, %6N = microseconds, %9N = nanoseconds.
%Q,%q For milliseconds, microseconds for Apache Tomcat. %Q and %q can format any time resolution if the width is specified.
%I For hours on a 12-hour clock format. If %I appears after %S or %s (like "%H:%M:%S.%l"), it takes on the log4cpp meaning of milliseconds.
%+ For standard Unix date format timestamps.
 %v For BSD and OSX standard date format.
%Z, %z, %::z, %:::zGNU libc support.
%o For AIX timestamp support (%o used as an alias for %Y).
%p The locale's equivalent of AM or PM. (Note: there may be none.)

strptime() format expression examples

Here are some sample date formats, with the strptime() expressions that handle them:

1998-12-31  %Y-%m-%d
98-12-31  %y-%m-%d
1998 years, 312 days  %Y years, %j days
Jan 24, 2003  %b %d, %Y
January 24, 2003  %B %d, %Y
q|25 Feb '03 = 2003-02-25| q|%d %b '%y = %Y-%m-%d|

Note: Splunk does not currently recognize non-English month names in timestamps. If you have an app that's writing non-English month names to log files, reconfigure the app to use numerical months, if possible.

Examples

Your data might contain an easily recognizable timestamp, such as:

...FOR: 04/24/07 PAGE 01...

To extract that timestamp, add this stanza in props.conf:

[host::foo]
TIME_PREFIX = FOR: 
TIME_FORMAT = %m/%d/%y

Your data might contain other information that Splunk parses as timestamps, for example:

...1989/12/31 16:00:00 ed May 23 15:40:21 2007...

Splunk extracts the date as Dec 31, 1989, which is not useful. In this case, configure props.conf to extract the correct timestamp from events from host::foo:

[host::foo]
TIME_PREFIX = \d{4}/\d{2}/\d{2} \d{2}:\d{2}:\d{2} \w+\s
TIME_FORMAT = %b %d %H:%M:%S %Y

This configuration assumes that all timestamps from host::foo are in the same format. Configure your props.conf stanza to be as granular as possible to avoid potential timestamping errors.

For detailed information on extracting the correct timestamp from events containing multiple timestamps, see "Configure timestamp assignment for events with multiple timestamps".

Configure timestamps for specific needs

You can use the attributes described in this topic to configure Splunk's timestamp extraction processor for some specialized purposes, such as:

Configure how timestamps appear in search results

You can use your browser's locale setting to configure how the browser formats Splunk timestamps in search results. For information on setting the browser locale, see "User language and locale".

Reconfigure how timestamps appear in raw data

Even though Splunk uses the browser locale to configure how timestamps appear in search results, the data still remains in its original format in the raw data. You might want to change this, so that the data format is standardized in both raw data and search results. You can do this by means of props.conf and transforms.conf. Here's an example:

Assume the timestamp data in the raw event looks like this:

06/07/2011 10:26:11 PM

but you want it to look like this (to correspond with how it appears in search results):

07/06/2011 10:26:11 PM

This example shows briefly how you can use props.conf and transforms.conf to transform the timestamp in the raw event.

In transforms.conf, add this stanza:

[resortdate]
REGEX = ^(\d{2})\/(\d{2})\/(\d{4})\s([^/]+)
FORMAT = $2/$1/$3 $4
DEST_KEY = _raw 

In props.conf, add this stanza, where <spec> qualifies your data:

[<spec>]
TRANSFORMS-sortdate = resortdate

Answers

Have questions? Visit Splunk Answers and see what questions and answers the Splunk community has around timestamp recognition and configuration.

This documentation applies to the following versions of Splunk: 4.3 , 4.3.1 , 4.3.2 View the Article History for its revisions.


You must be logged into splunk.com in order to post comments. Log in now.

Was this documentation topic helpful?

If you'd like to hear back from us, please provide your email address:

We'd love to hear what you think about this topic or the documentation as a whole. Feedback you enter here will be delivered to the documentation team.

Feedback submitted, thanks!