Discourse Stats Helper (Bash Script)

This is a small helper script built for anyone running, managing, or using a Discourse forum. It provides an interactive menu for quickly retrieving live forum statistics from the site/statistics.json endpoint using curl and jq.

The script is useful for administrators who want a simple way to check metrics without browsing the admin panel.

The tool supports both interactive and one-off direct queries. It automatically detects all numeric fields returned by the Discourse API, provides short descriptions for common metrics, and gracefully handles fields that may not exist on every forum.

Who this is for

  • System administrators
  • Self-hosted Discourse operators
  • Moderators who occasionally work with analytics
  • Anyone who wants a fast command-line way to view Discourse stats

What it does

• Fetches all numeric statistics from /site/statistics.json
• Supports single metric lookup (topics, posts, likes, users, etc.)
• Provides an interactive menu for browsing metrics
• Works on any Discourse instance (self-hosted or hosted)
• Handles missing fields cleanly
• Requires only bash, curl, and jq: apt install curl jq


How to use

Download the script

curl -O https://raw.githubusercontent.com/haydenjames/discourse-stats-helper/main/discourse_stats.sh
chmod +x discourse_stats.sh

Run it against any Discourse forum

./discourse_stats.sh your.discourse.site

You will be presented with an interactive list of statistics to choose from.
Select a number to view one metric, a to list all metrics, h for help, or q to exit.

Example

./discourse_stats.sh linuxcommunity.io

This will connect to your forum and display its available statistics.


Repository

The full source and documentation are available here:
https://github.com/haydenjames/discourse-stats-helper

Here’s a clean, forum-ready section you can paste directly beneath your post.
No mention of abuse, no mention of rate limiting, just a simple explanation of how the script works behind the scenes.


How the script works

This script retrieves the forum statistics once at the start. Here is the basic flow:

1. You run the script
You call it with the base URL of any Discourse site.
Example:

./discourse_stats.sh your.discourse.site

2. It makes a single request
The script fetches all available numeric metrics from:

/site/statistics.json

This response includes everything the menu will show you.

3. The JSON is stored locally
All metrics are loaded into a variable in memory.

4. Menu selections read from that stored data
Each time you pick a number from the menu, the script simply uses jq to extract that value from the already-loaded JSON.

5. The interactive menu continues until you quit
You can check as many stats as you like, instantly, all from the same initial data pull.