Last active
July 23, 2021 13:49
-
-
Save nwstephens/c8a7199118e97d12727ee5f6d5ddb572 to your computer and use it in GitHub Desktop.
This script will output the AWS account ID, AWS region, and other user metrics for single node installations of RStudio Workbench running in AWS.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| METADATA=$(curl --silent http://169.254.169.254/latest/dynamic/instance-identity/document) | |
| REGION=$(echo "$METADATA" | grep 'region' | cut -d : -f2 | awk -F\" '{print $2}') | |
| ACCOUNTID=$(echo "$METADATA" | grep 'accountId' | cut -d : -f2 | awk -F\" '{print $2}') | |
| METRICS=$(sqlite3 /var/lib/rstudio-server/rstudio.sqlite <<EOF | |
| select \ | |
| total(CASE WHEN locked=0 and last_sign_in >= datetime('now', '-1 days') then 1 else 0 end) as DAU0, | |
| total(CASE WHEN locked=0 and last_sign_in >= datetime('now', '-7 days') then 1 else 0 end) as WAU0, | |
| total(CASE WHEN locked=0 and last_sign_in >= datetime('now', '-30 days') then 1 else 0 end) as MAU0, | |
| total(CASE WHEN locked=0 and last_sign_in >= datetime('now', '-365 days') then 1 else 0 end) as YAU0, | |
| total(CASE WHEN locked=1 and last_sign_in >= datetime('now', '-1 days') then 1 else 0 end) as DAU1, | |
| total(CASE WHEN locked=1 and last_sign_in >= datetime('now', '-7 days') then 1 else 0 end) as WAU1, | |
| total(CASE WHEN locked=1 and last_sign_in >= datetime('now', '-30 days') then 1 else 0 end) as MAU1, | |
| total(CASE WHEN locked=1 and last_sign_in >= datetime('now', '-365 days') then 1 else 0 end) as YAU1 | |
| from licensed_users; | |
| EOF | |
| ) | |
| printf "ACCOUNTID|REGION|METRICS|DAU0|WAU0|MAU0|YAU0|DAU1|WAU1|MAU1|YAU1\n$ACCOUNTID|$REGION|$METRICS\n" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Alternatively, you can simplify the bash script by calling the SQLite query from a file (e.g.
query.sql).For example:
query.sql
rstudio-user-report.sh