rails stats:controllers # Show basic controller usage stats
rails stats:models # Show basic model usage stats
rails stats:trends # show frequency trends for a date column; MODEL=x COLUMN=y
rails stats:unroutable # Find routes that will raise a routing error when requested
rails stats:users # Show basic details of users
parses the logs, so you need a log/production.log file.
+------------------------------+----------+------------+---------------------------+------------+
| Action | Requests | Earliest | Latest | Latest_rel |
+------------------------------+----------+------------+---------------------------+------------+
| MyController#create | 2 | 2023-11-28 | 2024-01-29 11:34:58 -0500 | 3 days |
| MyController#destroy | No Log | | | |
| MyController#edit | 20 | 2023-07-12 | 2024-01-29 11:57:35 -0500 | 3 days |
| MyController#generate | 13 | 2023-09-06 | 2024-01-29 11:34:53 -0500 | 3 days |
Model Stats:
+-------------------------------+--------+------------+------------+----------------+
| Model | Count | Earliest | Latest | Latest_rel |
+-------------------------------+--------+------------+------------+----------------+
| MyModelA | 688 | 2021-08-26 | 2024-01-31 | 1 day |
| MyModelB | 9835 | 2019-12-03 | 2024-02-01 | about 4 hours |
...
Life Stats: over 6 years (2017-2024)
Latest record (MyModelC): 2024-02-01 - 1 minute ago
This one especially would go poorly for a huge database.
❯ bin/rails stats:trends MODEL=CayuseUsername COLUMN=created_at
+---------------------------+---+---+---+---+---+---+---+------+------+------+----+------+----+-------+-------+----+----+------+------+----+----+----+----+----+
| hour | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
+---------------------------+---+---+---+---+---+---+---+------+------+------+----+------+----+-------+-------+----+----+------+------+----+----+----+----+----+
| hour | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
+---------------------------+---+---+---+---+---+---+---+------+------+------+----+------+----+-------+-------+----+----+------+------+----+----+----+----+----+
| counts | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 3 | 61 | 1 | 0 | 69 | 0 | 1439 | 1315 | 0 | 0 | 106 | 105 | 0 | 0 | 0 | 0 | 0 |
| pct (total=3099) | - | - | - | - | - | - | - | 0.10 | 1.97 | 0.03 | - | 2.23 | - | 46.43 | 42.43 | - | - | 3.42 | 3.39 | - | - | - | - | - |
| pct (total_with_nil=3099) | - | - | - | - | - | - | - | 0.10 | 1.97 | 0.03 | - | 2.23 | - | 46.43 | 42.43 | - | - | 3.42 | 3.39 | - | - | - | - | - |
+---------------------------+---+---+---+---+---+---+---+------+------+------+----+------+----+-------+-------+----+----+------+------+----+----+----+----+----+
+---------------------------+---+---+---+---+---+---+---+---+---+----+----+----+----+----+-------+----+----+----+----+----+----+----+----+----+------+------+------+----+----+----+----+
| day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------------------------+---+---+---+---+---+---+---+---+---+----+----+----+----+----+-------+----+----+----+----+----+----+----+----+----+------+------+------+----+----+----+----+
| day | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
+---------------------------+---+---+---+---+---+---+---+---+---+----+----+----+----+----+-------+----+----+----+----+----+----+----+----+----+------+------+------+----+----+----+----+
| counts | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2965 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 2 | 63 | 69 | 0 | 0 | 0 | 0 |
| pct (total=3099) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | 95.68 | - | - | - | - | - | - | - | - | - | 0.06 | 2.03 | 2.23 | - | - | - | - |
| pct (total_with_nil=3099) | - | - | - | - | - | - | - | - | - | - | - | - | - | - | 95.68 | - | - | - | - | - | - | - | - | - | 0.06 | 2.03 | 2.23 | - | - | - | - |
+---------------------------+---+---+---+---+---+---+---+---+---+----+----+----+----+----+-------+----+----+----+----+----+----+----+----+----+------+------+------+----+----+----+----+
+---------------------------+---+---+---+---+-------+------+---+---+---+------+----+----+
| month | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
+---------------------------+---+---+---+---+-------+------+---+---+---+------+----+----+
| month | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
+---------------------------+---+---+---+---+-------+------+---+---+---+------+----+----+
| counts | 0 | 0 | 0 | 0 | 2965 | 132 | 0 | 0 | 0 | 2 | 0 | 0 |
| pct (total=3099) | - | - | - | - | 95.68 | 4.26 | - | - | - | 0.06 | - | - |
| pct (total_with_nil=3099) | - | - | - | - | 95.68 | 4.26 | - | - | - | 0.06 | - | - |
+---------------------------+---+---+---+---+-------+------+---+---+---+------+----+----+
+---------------------------+-------+------+
| year | 2022 | 2023 |
+---------------------------+-------+------+
| year | 2022 | 2023 |
+---------------------------+-------+------+
| counts | 2967 | 132 |
| pct (total=3099) | 95.74 | 4.26 |
| pct (total_with_nil=3099) | 95.74 | 4.26 |
+---------------------------+-------+------+
❯ bin/rails stats:unroutable
Prefix Verb URI Pattern Controller#Action
new_auth_users GET /auth/admin/auth_users/new(.:format) auth_users#new
edit_auth_users GET /auth/admin/auth_users/edit(.:format) auth_users#edit
PATCH /auth/admin/auth_users(.:format) auth_users#update
PUT /auth/admin/auth_users(.:format) auth_users#update
username GET /usernames/:id(.:format) usernames#show
5 unroutable routes
Our user records usually have either a User#role or User#roles. We're also using auth_logic, so have some last-login-time audit columns. This could be easily tweaked for devise.
This example output lacks the terminal color coding in the activity section.
User count: 2
Role method: role
Roles: user
Roles => Users
user: bill, ted
Users by Activity: Request in within week, month, year, beyond, unknown (these are terminal color coded)
year: bill, ted