Splunk Quick Reference Guide
Splunk Quick Reference Guide
This guide describes key concepts and features, common source types are HTTP web server logs and
as well as commonly used commands and Windows event logs.
functions for Splunk Cloud and Splunk Enterprise.
Events with the same source types can come from
different sources. For example, events from the file
Metric data points and events can be searched and source on a host and is classified into a source type.
correlated together, but are stored in separate types Timestamps are extracted, and the data is parsed into
2
QUICK REFERENCE GUIDE
System Components values are columns. Each search command redefines the
shape of that table. For example, search commands that
Forwarders
filter events will remove rows, search commands that
A Splunk instance that forwards data to another Splunk
extract fields will add columns.
instance is referred to as a forwarder.
Time Modifiers
Indexer
You can specify a time range to retrieve events inline
An indexer is the Splunk instance that indexes data. The
with your search by using the latest and earliest search
indexer transforms the raw data into events and stores
modifiers. The relative times are specified with a string
the events into an index. The indexer also searches the
of characters to indicate the amount of time (integer and
indexed data in response to search requests. The search
unit) and an optional “snap to” time unit. The syntax is:
peers are indexers that fulfill search requests from the
search head. [+|-]<integer><unit>@<snap_time_unit>
3
QUICK REFERENCE GUIDE
Command Description
Explore our full suite of products, or investigate the table below to find the specific starting point for your journey.
Or dive right in: Download the free trial and see for yourself what the Splunk platform can do for your data strategy.
4
QUICK REFERENCE GUIDE
The eval command calculates an expression and puts the resulting value into a field (e.g. “...| eval force = mass *
acceleration”). The following table lists some of the functions used with the eval command. You can also use basic
arithmetic operators (+ - * / %), string concatenation (e.g., “...| eval name = last . “,” . first”), and Boolean operations (AND
OR NOT XOR < > <= >= != = == LIKE).
case(X,"Y",...) Takes pairs of arguments X and Y, where case(error == 404, "Not found", error ==
X arguments are Boolean expressions. 500,"Internal Server Error", error == 200,
When evaluated to TRUE, the arguments "OK")
return the corresponding Y argument.
ceil(X) Ceiling of a number X. ceil(1.9)
5
QUICK REFERENCE GUIDE
ltrim(X,Y) Returns X with the characters in Y ltrim(" ZZZabcZZ ", " Z")
trimmed from the left side. Y defaults to
spaces and tabs.
match(X,Y) Returns if X matches the regex pattern Y. match(field, "^\d{1,3}\.\d$")
6
QUICK REFERENCE GUIDE
7
QUICK REFERENCE GUIDE
Common statistical functions used with the chart, stats, and timechart commands. Field names can be wildcarded, so
avg(*delay) might calculate the average of the delay and xdelay fields.
8
QUICK REFERENCE GUIDE
Search Examples
Filter Results
Given pairs of arguments, Boolean expressions X and validate(isint(port), "ERROR: Port is not an
strings Y, returns the string Y corresponding to the first integer",
expression X that evaluates to False and defaults to NULL port >= 1 AND port <= 65535, "ERROR: Port is out
if all are True. of range")
Group Results
Cluster results together, sort by their “cluster_count” ... | cluster t=0.9 showcount=true | sort limit=20
values, and then return the 20 largest clusters (in -cluster_count
data size).
Group results that have the same “host” and “cookie,” ... | transaction host cookie maxspan=30s
occur within 30 seconds of each other, and do not have maxpause=5s
a pause greater than 5 seconds between each event into
a transaction.
Group results with the same IP address (clientip) and ... | transaction clientip startswith="signon"
where the first result contains “signon,” and the last result endswith="purchase"
contains “purchase.”
Order Results
9
QUICK REFERENCE GUIDE
Reporting
Return the average and count using a 30 second | mstats avg(_value), count(_value) WHERE metric_
span of all metrics ending in cpu.percent split by each name="*.cpu.percent" by metric_name span=30s
metric name.
Return max(delay) for each value of foo split by the value ... | chart max(delay) over foo by bar
of bar.
Return max(delay) for each value of foo. ... | chart max(delay) over foo
Create a table showing the count of events and a small ... | stats sparkline count by host
line chart.
Create a timechart of the count of from “web” sources
... | timechart count by host
by “host.”
Calculate the average value of “CPU” each minute for
... | timechart span=1m avg(CPU) by host
each “host.”
Return the average for each hour, of any unique field that
... | stats avg(*lay) by date_hour
ends with the string “lay” (e.g., delay, xdelay, relay, etc).
Return the 20 most common values of the “url” field. ... | top limit=20 url
Return the least common values of the “url” field. ... | rare url
Advanced Reporting
Find anomalies in the field ‘Close_Price’ during the last sourcetype=nasdaq earliest=-10y | anomalydetection
10 years. Close_Price
10
QUICK REFERENCE GUIDE
Metrics
List all of the metric names in the “_metrics” metric index. | mcatalog values(metric_name) WHERE index=_metrics
See examples of the metric data points stored in the | mpreview index=_metrics target_per_timeseries=5
“_metrics” metric index.
Return the average value of a metric in the “_metrics” | mstats avg(aws.ec2.CPUUtilization) WHERE index=_
metric index. Bucket the results into 30 second metrics span=30s
time spans.
Add Fields
Filter Fields
Keep only the “host” and “ip” fields, and display them in
... | fields + host, ip
that order.
Remove the “host” and “ip” fields from the results. ... | fields - host, ip
For each event, use the lookup table usertogroup to locate ... | lookup usertogroup user output group
the matching “user” value from the event. Output the
group field value to the event.
Read in the usertogroup lookup table that is defined in the ... | inputlookup usertogroup
transforms.conf file.
Write the search results to the lookup file “users.csv.” ... | outputlookup users.csv
Modify Fields
11
QUICK REFERENCE GUIDE
Regular Expressions are useful in multiple areas: search commands regex and rex; eval functions match() and
replace(); and in field extraction.
Multi-Valued Fields
Combine the multiple values of the recipients field into ... | nomv recipients
a single value.
Separate the values of the “recipients” field into ... | makemv delim="," recipients | top recipients
multiple field values, displaying the top recipients.
Create new results for each value of the multivalue ... | mvexpand recipients
field “recipients.”
Find the number of recipient values. ... | eval to_count = mvcount(recipients)
Find the first email address in the recipient field. ... | eval recipient_first = mvindex(recipient,0)
Find all recipient values that end in .net or .org. ... | eval netorg_recipients = mvfilter
match(recipient,"\.net$") OR match(recipient,"\.org$"))
Find the index of the first recipient value match ... | eval orgindex = mvfind(recipient, "\.org$")
“\.org$”
12
QUICK REFERENCE GUIDE
Use these values for eval functions strftime() and strptime(), and for timestamping event data.
Splunk, Splunk> and Turn Data Into Doing are trademarks and registered trademarks of Splunk LLC. in the United States and other countries.
All other brand names, product names or trademarks belong to their respective owners. © 2024 Splunk LLC. All rights reserved. 24_CMP_guide_general-quick-reference-guide_v2