The correction is integrated into the TP (See the green boxes)
What you will learn in this TP
- Aggregate and compare with stats and timechart
- Categorize with eval and case
- Compare each event with its group (eventstats)
- Extract a field with rex
- Enrich with a lookup
- Count without reading events using tstats
All steps and instructions are shown. Recommended for this lab: semi-guided
Introduction #
Context. Customers have been complaining about payment failures since yesterday. The manager wants to know which pages are affected, since when, which users, and whether a browser is involved.
Prerequisites: a machine with Docker (4 GB free memory), curl, jq and Python 3, Lab 1 completed · Estimated time: 45 min
Six searches answering the incident questions, one enriched with a lookup table and one usingtstats.Setup #
Guided steps, with their solution.
1. Locate errors
Why? Starting wide then narrowing avoids missing an affected page.
Count server errors (5xx) per URL, then show their trend per 30-minute slot for the two most affected URLs.See the correction
index=web status>=500 earliest=-24h | stats count BY uri | sort -count index=web status>=500 earliest=-24h uri IN ("/api/paiement", "/panier") | timechart span=30m count BY uri2. Compute an error rate
Why? The error count depends on traffic; the rate lets you compare pages with each other.
For each URL, compute requests, 5xx errors, error rate in % and p95 ofduration_ms, with a readable category usingcase().See the correction
index=web earliest=-24h | eval error = if(status>=500, 1, 0) | stats count AS requests, sum(error) AS errors, perc95(duration_ms) AS p95 BY uri | eval rate = round(100*errors/requests, 1), state = case(rate>=10, "critical", rate>=2, "degraded", true(), "normal") | sort -rate3. Find abnormal requests
Why? A fixed threshold does not suit every page: compare each request with its own URL's average.
Witheventstats, keep requests more than three times slower than their URL's average, and count them per URL and code.See the correction
index=web earliest=-24h | eventstats avg(duration_ms) AS moyenne BY uri | where duration_ms > 3*moyenne | stats count BY uri, status # /api/paiement en 500 domine : les échecs de paiement sont aussi les plus lents (≈ +1,5 s)4. Extract the browser
Why? Useful data is often buried in a text field: rex makes it usable without touching ingestion.
Extract the browser name and version fromuseragent, then check whether payment errors concern a particular browser.See the correction
index=web uri="/api/paiement" earliest=-24h | rex field=useragent "(?<navigateur>Firefox|Chrome|Safari|curl)/(?<version>[\d.]+)" | stats count AS requetes, count(eval(status>=500)) AS erreurs BY navigateur | eval taux = round(100*erreurs/requetes, 1) # taux comparable pour tous les navigateurs : la cause est côté serveur5. Enrich with a lookup
Why? A lookup table turns codes into labels everyone understands, without storing them in each event.
Copyhttp_status.csvinto the search app, then count requests per category and label usinglookup.See the correction
cat > http_status.csv <<'EOF' status,category,label 200,success,OK 302,redirection,Found 404,client error,Not Found 500,server error,Internal Server Error 503,server error,Service Unavailable EOF docker cp http_status.csv splunk:/opt/splunk/etc/apps/search/lookups/http_status.csv docker exec -u root splunk chown splunk:splunk /opt/splunk/etc/apps/search/lookups/http_status.csv # Then in Splunk: | inputlookup http_status.csv index=web earliest=-24h | lookup http_status.csv status OUTPUT category label | stats count BY category, label6. Count with tstats
Why? tstats reads index files: the right habit for dashboards and large volumes.
Countwebindex events per hour and per host withtstats, then compare execution time with the equivalentstatssearch in the Job Inspector.See the correction
| tstats count WHERE index=web earliest=-24h BY _time span=1h, host index=web earliest=-24h | bin _time span=1h | stats count BY _time, host # Même résultat ; tstats ne lit pas les événements bruts, il est nettement plus rapide sur de gros volumes
Validate your work
Check that each goal above is reached and that you get the result described in the introduction.
Difficulty level : ●●●○○ (3/5)
My progress
Sign in to track your progress and take notes. Sign in
💬 Questions about this lesson
No questions yet: be the first to ask for help or share your configuration.
Recommended Articles
SPL: Splunk search fundamentals
Learning the SPL language: search structure, time range and time modifiers, search modes, filteri...
Advanced SPL and knowledge objects
Going further with Splunk: CSV and KV store lookups, eventstats and streamstats, transaction vers...
Splunk: the machine data platform at a glance
Discover Splunk: the platform's role, components (forwarders, indexers, search heads), ports, eve...
Observability, SRE and incident management for DevOps teams
Operate what you ship: metrics, logs and traces, golden signals, SLIs, SLOs and error budgets, ac...
Pipelines and functions: parse, enrich, mask
Building Cribl Stream pipelines: pre-processing, processing and post-processing, the function cat...
Installing Splunk and ingesting data
Installing Splunk Enterprise (package or Docker), understanding $SPLUNK_HOME and configuration fi...
Dashboards, reports and alerts in Splunk
Making the most of Splunk searches: reports and scheduling, Dashboard Studio dashboards (data sou...
Administering distributed Splunk
Designing and administering a production Splunk platform: reference architectures, indexer cluste...
Security and observability with Splunk
Splunk solutions beyond search: Enterprise Security (detections, findings, risk-based alerting, a...