cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Last minute active/concurrent sessions using ES EUM API

Mohamed.Mohamed
Creator

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

MohamedMohamed_1-1710586327199.png

Do you guys have a better way to do it?

 

Best regards,
Mohamed Ashraf

MohamedMohamed_2-1710589347469.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

 

MohamedMohamed_3-1710589347474.png

 

MohamedMohamed_4-1710589347474.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



0 REPLIES 0