Hi everyone,
Problem:
Unfortunately, you cannot display data more than 10K on the dashboard using ES queries.
So the only way to do it is from the API.
Objective:
We want automation to find the last 24h visits every day just by running a script and sending an email with the results daily using Cronjob
Solution:
I made a script to get the total number of Nusuk website visits using AppDynamics API as it’s the only way to get the number.
Challenges:
1- I had to find a way to automate the script to find the current date and time in UNIX format
2- Then, call the API with the right parameters to get the scrollID.
3- Lastly, call the API again to get the Visits number.
Script tasks:
Script:
#!/bin/bash
today=$(date +"%s.%3N" | awk '{printf "%d%03d\n", $1, substr($2,1,3)}')
yesterday=$(date -d "yesterday" +"%s.%3N" | awk '{printf "%d%03d\n", $1, substr($2,1,3)}')
scrollid=$(curl -s -X POST "<ES-IP>:9080/events/query?start=${yesterday}&end=${today}" -H"X-Events-API-Key:<your-Key>" -H"X-Events-API-AccountName:<customer-ID>" -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:<your-key>" \
-H "X-Events-API-AccountName:<customer-ID>" \
-d "[{ \"query\": <ES_IP>\"SELECT count(*) FROM web_session_records\", \"mode\": \"scroll\", \"scrollid\":\"$scrollid\"}]" \
-X POST "http://<ES_IP>:9080/events/query?start=${yesterday}&end=${today}")
echo "$curlout" | grep -o '"results":\[\[[0-9]*\]\]' | cut -d "[" -f3 | cut -d "]" -f1
You can get the variables from:
1- Account name
From the license page on the Contoller UI