Share a Tip

Last minute active/concurrent sessions using ES EUM API

Mohamed_Mohamed
New Member

Hi everyone,
As you know from the dashboard the least standard timeframe is the last 5 minutes, we wanted to know the last 1 minute, so I used the same script as I did before when I wanted to get the visits per day (Check the article). And just changed the time frame

I now made a new script that checks the concurrent visits for the last minute.

The script is below:

#!/bin/bash

now=$(date +"%s.%3N" | awk '{printf "%d%03d\n", $1, substr($2,1,3)}')
lastmin=$(date -d "now - 1 minute" +"%s.%3N" | awk '{printf "%d%03d\n", $1, substr($2,1,3)}')


scrollid=$(curl -s -X POST "<ES_IP>:9080/events/query?start=${lastmin}&end=${now}" -H"X-Events-API-Key:<API-KEY>" -H"X-Events-API-AccountName:<Your-Account-Global-Name>" -H"Content-Type:application/vnd.appd.events+text;v=2" -H"Accept:application/vnd.appd.events+json;v=2" -d"[{  \"query\": \"SELECT * FROM web_session_records\",  \"mode\": \"scroll\"}]" | grep -oP '(?<="scrollid":").*?(?=",)')

curlout=$(curl -s -i \
-H "Accept: application/vnd.appd.events+json;v=2" \
-H "Content-Type:application/vnd.appd.events+text;v=2" \
-H "X-Events-API-Key:<API-KEY>" \
-H "X-Events-API-AccountName:<Your-Account-Global-Name>" \
-d "[{  \"query\": \"SELECT count(*) FROM web_session_records\",  \"mode\": \"scroll\", \"scrollid\":\"$scrollid\"}]" \
-X POST "http://<ES_IP>:9080/events/query?start=${lastmin}&end=${now}")

echo "$curlout" | grep -o '"results":\[\[[0-9]*\]\]' | cut -d "[" -f3 | cut -d "]" -f1

Also, I made a small webserver on port 8000 that returns the output of this script:

https://<Contoller_IP>:8000

image.png

Do you guys have a better way to do it?

Best regards,
Mohamed Ashraf

image.png

Mohamed Ashraf

Application Operations Engineer

Platform & IT Solution Ops team

Saudi Company for Visa and Travel Solutions (SVTS)

Phone: +966549574746

Email: mmahmoud.c@saudivts.com 

Riyadh, Saudi Arabia

image.pngimage.png
0 Karma
Get Updates on the Splunk Community!

Why You Can't Miss .conf25: Unleashing the Power of Agentic AI with Splunk & Cisco

The Defining Technology Movement of Our Lifetime The advent of agentic AI is arguably the defining technology ...

Deep Dive into Federated Analytics: Unlocking the Full Power of Your Security Data

In today’s complex digital landscape, security teams face increasing pressure to protect sprawling data across ...

Your summer travels continue with new course releases

Summer in the Northern hemisphere is in full swing, and is often a time to travel and explore. If your summer ...