Ubiquiti Unifi Gateway WAN Statistics

This is a nice little application for those of you that run a Ubiquiti Unifi Gateway/router.

Today I discuss UGatewayStats which is a web application to display Unifi Gateway WAN bandwidth statistics pulled from the Unifi Controller with direct API calls.

The Github project site for UGatewayStats is here.

This is an easy to install application and we are going to install it in an Incus container. If you don’t know what Incus is all about, watch my “Incus Containers Step by Step” tutorial.

Create a container for the project:

incus launch images:ubuntu/22.04 WAN-Usage --profile default --profile bridgeprofile -c boot.autostart=true

Connect to the container shell root account and take the latest updates:

incus shell WAN-Usage
apt update && apt upgrade -y

Create a user account and put it in the sudo group and move over to that account.

adduser scott
usermod -aG sudo scott
su - scott

Install the dependencies into the container:

sudo apt install apache2 php php-json php-curl git nano openssh-server -y

Move over to the folder where the website application code will be stored.

cd /var/www/html

Clone the project from Github:

sudo git clone https://github.com/stevesinchak/UGatewayStats.git

Now move into the folder for the application:

cd UGatewayStats

Edit the configuration file:

sudo nano config.php

The file should appear as follows in the nano editor.

Change the controller URL to be the address of your controller which will be the address of your gateway or the address of your cloud key if that is where your controller is running. Typically this will look like:

https://192.168.1.1

You will want to sign on to your unifi controller and create a local account with READONLY privilege since that is all that is needed. Specify the username and the password of the Unifi OS account that you created in the config file pictured above.

Then SAVE the file with a CTRL O and enter and then CTRL X to exit the nano editor.

Next move to the Apache web server configuration folder.

cd /etc/apache2/sites-available

Edit the default configuration file:

sudo nano 000-default.conf

In this file, change the document root as follows:

image

Then SAVE the file with a CTRL O and enter and then CTRL X to exit the nano editor.

Reload the Apache Web Server configuration.

sudo service apache2 reload

You may need to enable PHP, but the installation of PHP as described should have done that. So, optionally you may need:

sudo a2enmod php8.1

Find out the address of our container.

ip -br -4 a

You should get an output something like the one below and make a note of the IP address of eth0:

Go to your favorite web browser and visit the IP address you just found and you will be at the “Unifi Gateway Stats” application web page.

Enjoy your new app!