Skip to content

Commit 51555f4

Browse files
committed
Add a few more metrics
1 parent d76fb58 commit 51555f4

File tree

5 files changed

+160
-5
lines changed

5 files changed

+160
-5
lines changed

seagl-scripts/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/node_modules

seagl-scripts/get-metrics.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
set -euo pipefail
44

@@ -10,17 +10,29 @@ function prompt_continue() {
1010
}
1111

1212
function remote_psql() {
13-
ssh -t $(date +%Y)-ephemeral.host.seagl.org sudo docker exec -it matrix-postgres psql ${2-} -c \""$1"\" synapse
13+
# LogLevel suppresses disconnection messages - https://superuser.com/a/1172143/121259
14+
# See also https://serverfault.com/a/981481/167999 for pager=off
15+
ssh -o LogLevel=QUIET -t $(date +%Y)-ephemeral.host.seagl.org sudo docker exec -it matrix-postgres psql -P pager=off ${2-} -c \""$1"\" synapse
1416
}
1517

1618
echo You will need to review the users database to make sure we\'re eliminating all staff/test users.
1719
prompt_continue
1820

19-
eliminators="name NOT SIMILAR TO '@room-[[:digit:]]+:$(date +%Y).seagl.org' AND admin = 0 AND name NOT IN $elimination_set"
20-
remote_psql "SELECT name, admin, user_type, deactivated, approved, locked, suspended FROM users WHERE $eliminators;"
21+
with_nonstaff_clause="WITH non_staff_users AS (SELECT "'*'" FROM users WHERE name NOT SIMILAR TO '@room-[[:digit:]]+:$(date +%Y).seagl.org' AND admin = 0 AND name NOT IN $elimination_set)"
22+
remote_psql "$with_nonstaff_clause SELECT name, admin, user_type, deactivated, approved, locked, suspended FROM non_staff_users;"
2123

2224
echo 'If there are staff users still present in the listing, ^C to abort this script, edit it, and then try again.'
2325
prompt_continue
2426

2527
printf 'Number of non-staff/test accounts registered on ephemeral homeserver: '
26-
remote_psql "SELECT COUNT("'*'") FROM users WHERE $eliminators;" -t | tr -d ' '
28+
remote_psql "$with_nonstaff_clause SELECT COUNT("'*'") FROM non_staff_users;" -t | tr -d ' '
29+
30+
echo 'Ephemeral homeserver device registrations, excluding staff:'
31+
echo '(suppressed due to suspected attend portal bugginess - device names did not correspond to UAs)'
32+
echo
33+
#remote_psql "$with_nonstaff_clause SELECT display_name AS \\\"Device display name\\\", COUNT(display_name) AS \\\"Registered devices\\\" FROM devices INNER JOIN non_staff_users ON non_staff_users.name = devices.user_id WHERE display_name != 'master signing key' AND display_name != 'self_signing signing key' AND display_name != 'user_signing signing key' GROUP BY display_name;"
34+
35+
echo 'Ephemeral homeserver device registration count, excluding staff:'
36+
remote_psql "$with_nonstaff_clause SELECT count AS \\\"Number of devices registered\\\", COUNT(count) AS \\\"Users in population\\\" FROM (SELECT user_id, COUNT(user_id) FROM devices INNER JOIN non_staff_users ON non_staff_users.name = devices.user_id WHERE display_name != 'master signing key' AND display_name != 'self_signing signing key' AND display_name != 'user_signing signing key' GROUP BY user_id) GROUP BY count;"
37+
38+
remote_psql "$with_nonstaff_clause SELECT user_agent FROM devices INNER JOIN non_staff_users ON non_staff_users.name = devices.user_id WHERE display_name != 'master signing key' AND display_name != 'self_signing signing key' AND display_name != 'user_signing signing key';" -t | grep -Ev '\([[:digit:]]+ rows\)' | node $(dirname $BASH_SOURCE)/process-uas.js | sort | uniq -c | sort -rh | sed 's/^[[:space:]]*//' | column -t -s' ' --table-columns-limit 2 -o ' | '

seagl-scripts/package-lock.json

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

seagl-scripts/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "seagl-scripts",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "AJ Jordan <alex@strugee.net>",
10+
"license": "LGPL-3.0+",
11+
"private": true,
12+
"dependencies": {
13+
"ua-parser-js": "^2.0.6"
14+
}
15+
}

seagl-scripts/process-uas.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env node
2+
3+
var UAParser = require('ua-parser-js');
4+
var readline = require('readline');
5+
6+
var rl = readline.createInterface({
7+
input: process.stdin,
8+
output: process.stdout,
9+
terminal: false
10+
});
11+
12+
rl.on('line', function(line) {
13+
line = line.trim();
14+
if (!line) return;
15+
if (line.includes(' rows)')) process.exit(0);
16+
17+
var parser = new UAParser(line);
18+
var result = parser.getResult();
19+
console.log(`${result.browser.name || 'unknown'}:${result.os.name.replaceAll(' ', '_') || 'unknown'}`);
20+
});

0 commit comments

Comments
 (0)