UniFi Client Reporting: How to monitor and analyze network activity
Published onby Iron (edited on )
For MSPs and IT businesses, it's crucal to understand the behavior of the clients connected to your network. This goes beyond just monitoring the performance of your UniFi devices.
Detailed client reporting allows you to analyze network usage, track connected devices, and identify potential issues or security risks.
In this blog post, we'll explore how to set up and use UniFi client reporting to get a comprehensive view of your network activity.
Let's get it!
Table of Contents
- Why client reporting matters
- Setting up UniFi client reporting
- Generating client reports
- Using the UniFi API for advanced reporting
- Scheduling regular reports
- Final Thoughts
Why client reporting matters
Client reporting provides several key benefits:
- Usage insights: Understand how different clients use your network, helping you optimize performance and bandwidth allocation.
- Security: Identify unauthorized devices and potential security threats.
- Troubleshooting: Diagnose connectivity issues and ensure a seamless experience for all users.
- Compliance: Maintain logs and reports for regulatory compliance or internal audits.
Setting up UniFi client reporting
To set up client reporting in UniFi, you'll need to access your UniFi Controller. The Controller provides built-in tools for generating client reports and offers API access for more advanced reporting capabilities.
Step 1: Access the UniFi Controller
Log in to your UniFi Controller via your web browser. The Controller's dashboard provides an overview of your network, including connected devices and clients.
Step 2: Navigate to the 'Clients' section
In the UniFi Controller dashboard, navigate to the "Clients" section. Here, you can see a list of all clients currently connected to your network, along with detailed information such as IP address, MAC address, device type, and data usage.
Generating client reports
The UniFi Controller allows you to generate various client reports directly from the interface. Here's how you can create and customize these reports:
-
Access client statistics: In the "Clients" section, click on a client to view detailed statistics, including connection history, data usage, and signal strength.
-
Create custom reports: Use the "Insights" and "Statistics" tabs to generate custom reports based on specific time frames and data points. You can filter by device type, connection status, and data usage.
-
Export reports: Export the reports to CSV or PDF format for further analysis or sharing. This is useful for keeping records or integrating with other reporting tools.
Using the UniFi API for advanced reporting
For more advanced client reporting, you can leverage the UniFi API to automate data extraction and report generation.
Here’s how to get started:
Step 1: Install required libraries
You’ll need the requests
library in Python to interact with the UniFi API. Install it using pip:
pip install requests
Step 2: Authenticate with the UniFi Controller
Use the UniFi API to authenticate and extract data. Below is a Python script example for authentication and data extraction:
import requests
# UniFi Controller details
controller_url = "https://your-controller-url:8443"
username = "your-username"
password = "your-password"
site = "default"
# Login to the UniFi Controller
login_data = {
"username": username,
"password": password
}
session = requests.Session()
response = session.post(f"{controller_url}/api/login", json=login_data, verify=False)
if response.status_code != 200:
raise Exception("Failed to log in to UniFi Controller")
print("Successfully logged in!")
# Function to get data from an endpoint
def get_data(endpoint):
response = session.get(f"{controller_url}/api/s/{site}/{endpoint}", verify=False)
return response.json()['data']
# Retrieve client statistics
clients = get_data("stat/sta")
# Print client statistics
for client in clients:
print(f"MAC: {client['mac']}, IP: {client['ip']}, Download: {client['tx_bytes']/1e6:.2f} MB, Upload: {client['rx_bytes']/1e6:.2f} MB")
# Logout from the UniFi Controller
session.post(f"{controller_url}/api/logout", verify=False)
print("Successfully logged out!")
Step 3: Create automated reports
You can extend the above script to generate automated reports. Here’s an example of how to save the data to a CSV file:
import csv
# Write client statistics to a CSV file
with open('client_report.csv', mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['MAC Address', 'IP Address', 'Download (MB)', 'Upload (MB)'])
for client in clients:
writer.writerow([
client['mac'],
client['ip'],
client['tx_bytes'] / 1e6,
client['rx_bytes'] / 1e6
])
print("Client report saved to client_report.csv")
Scheduling regular reports
To ensure you always have up-to-date client reports, you can schedule your Python script to run at regular intervals using a scheduling tool like cron
on Unix-based systems or Task Scheduler on Windows.
Example cron job
Here’s an example cron
job that runs the script daily at midnight:
0 0 * * * /usr/bin/python3 /path/to/your_script.py
Final Thoughts
UniFi client reporting is an essential aspect of network management that provides valuable insights into network usage, security, and performance.
By using the UniFi Controller’s built-in tools and leveraging the API for advanced reporting, you can effectively monitor and analyze client activity on your network.
At UniHosted, we do this for you. We provide fully managed UniFi Controllers with automatic backups, worry-free SSL setup, and with client reporting.
Feel free to give it a spin. Additionally, if you would like me to personally walk you through, you can schedule a meeting using my link.If you would like me to personally walk you through UniHosted, you can schedule a call with me here.
We host UniFi Controllers in the Cloud
Are you ready to take your UniFi Network to the next level? Deploy a UniFi Cloud Controller in minutes and manage your network from anywhere.
Free tier available
Get the best support
Join 1660+ customers
No credit card required