Long term network traffic statistics from ntopng, viewed in grafana via influxdb.
ntopng provides some transparency into the goings-on in your network. However, the available data is limited to active flows and access to historical data is paywalled. ntopng does support exporting timeseries data to InfluxDB, in essence, making it possible to view historical data through a visualization tool such as Grafana.
If you choose to use this repository, it is your responsibility to evaluate and accept any risk involved.
If your target platform is OpenWRT, follow the instructions here and then jump to the Configuration section below.
- Command line access on the target device (SSH or keyboard and display)
- Internet access from the target device
- Familiarity with the linux command line, SSH and docker
- The following command line tools pre-installed:
git
wget
unzip
docker
anddocker compose
sqlite3
Log in to the target device via SSH or connect a keyboard and display and clone this repository
git clone https://github.com/singhaxn/ntopng-grafana.git
Henceforth, let's refer to the repository directory as <ntopng-grafana>
. Please substitute it with the actual path, where ever it is used.
cd <ntopng-grafana>
chmod +x scripts/*.sh
scripts/install-deps.sh
install-deps.sh
internally calls update-luts.sh
which pulls Autonomous System Number (ASN) and Organizationally Unique Identifier (OUI) mappings and creates look-up tables in an sqlite3 database.
For simplicity, let's create a docker-compose.yml
link to the appropriate compose file:
ln -s docker-compose.default.yml docker-compose.yml
In docker-compose.yml
under services > ntopng > command
, make sure, the specified interfaces (-i
), are the ones you want to monitor. You can add more interfaces if you want, for example:
command: [..., "-i", "br-lan", "-i", "eth0", "-i", "eth1",...]
For arm64
(untested), under services > ntopng
, choose the ntop/ntopng_arm64.dev:latest
image instead of ntop/ntopng:stable
:
services:
...
ntopng:
# image: ntop/ntopng:stable
image: ntop/ntopng_arm64.dev:latest
...
The exposed TCP ports are:
service | port | location |
---|---|---|
redis |
6379 | services > redis > ports |
influxdb |
8086 | services > influxdb > ports |
grafana |
3003 | services > grafana > ports |
ntopng |
3002 | services > ntopng > command |
Please choose unused TCP ports, as appropriate for your environment, and substitute accordingly, in the configuration instructions.
In the repository base folder (<ntopng-grafana>
), run:
docker compose pull
docker compose up -d
Please be patient, this may take a little time.
Access the ntopng web UI (version 6.2
at the time of writing) by going to http://<device_IP_address>:3002
in your browser. The default username/password combination is admin
/admin
. Change the password and then you should be redirected to the ntopng dashboard.
- Within the ntopng web interface, navigate to Settings > Preferences > Timeseries. Make the following changes to collect data for the included Grafana dashboard.
- Timeseries Database
- Timeseries Driver:
InfluxDB 1.x/2.x
- InfluxDB URL:
http://localhost:8086
- Timeseries/Stats Data Retention (optional):
60
- Timeseries Driver:
- Interfaces Timeseries
- Layer-7 Applications:
None
- Layer-7 Applications:
- Local Hosts Timeseries
- Host Timeseries (one of):
Light
- defaultFull
- only if you want to monitor DNS request statistics
- Host Timeseries (one of):
- Devices Timeseries
- Traffic:
On
- Traffic:
- Other Timeseries
- Autonomous Systems:
On
- Countries:
On
- Autonomous Systems:
- Timeseries Database
- Click Save
Access the grafana web UI (version 11.2.0
at the time of writing) by going to http://<device_IP_address>:3003
in your browser. The default username/password combination is admin
/admin
. Change the password and then you should be redirected to the grafana home page.
- Navigate to Connections > Add new connection and select InfluxDB.
- Click Add new datasource
- Change the following properties
- Name:
ntopng
- HTTP
- URL (one of):
http://localhost:8086/
- OpenWRThttp://influxdb:8086/
- other platforms
- URL (one of):
- InfluxDB Details
- Database:
ntopng
- Database:
- Name:
- Click Save & test
- Verify that your datasource has been added under Connections > Datasources in the left navigation panel.
- Navigate to Connections > Add new connection and select SQLite.
- Click Add new datasource
- Change the following properties
- Name:
ntopng-luts
- Path:
/custom/lut.sqlite3
- Name:
- Click Save & test
- Verify that your datasource has been added under Connections > Datasources in the left navigation panel.
- Navigate to Dashboards, click New > Import
- Upload the
grafana-dashboard/ntopng - Long Term - xxxxxxxxxxxxx.json
file from this repository- Note: If your browser is not running on the same host, where you cloned this repository, you will have to acquire this single file, separately, in order to upload it to grafana
- Choose the InfluxDB (
ntopng
) and SQLite (ntopng-luts
) datasources you created earlier - Click Import
- Navigate to Dashboards and choose ntopng - Long Term
- Navigate to Dashboard settings by clicking the cog icon (⚙)
- Go to Variables > iface_name. This variable corresponds to the Interface Name dropdown on the dashboard.
- Under Custom Options enter the
name : index
pairs for the interfaces you're monitoring. The order must match the specification underservices > ntopng > command
indocker-compose.yml
. The format must be:Please follow this formatting precisely. Grafana doesn't tolerate missing or extra spaces. The names are purely for your reference. However, the numbers after the colon (:) must be sequential, starting with 0.<interface_name_1> : 0,<interface_name_2> : 1,<interface_name_3> : 2,...
- Verify that the Preview of values section only shows the interface names.
- Click Apply and then Save Dashboard
You should now have a functional Grafana dashboard for long-term ntopng data.
-
If you want to update the LUTs periodically, you can use
cron
to callscripts/update-luts.sh
, say, once a month by adding the following line to yourcrontab
(commandcrontab -e
)0 0 1 * * <ntopng-grafana>/scripts/update-luts.sh
-
Since docker doesn't guarantee the start order of containers on boot, at times, ntopng may fail to discover influxdb at start-up. Therefore, it makes sense restart the
ntopng
stack on boot. Thescripts/on-boot.sh
script can be used to do this.Normally, this can be achieved by adding an
@reboot
instruction to our crontab:@reboot <ntopng-grafana>/scripts/on-boot.sh
OpenWRT, however, doesn't support time shortcuts out-of-the-box. As an alternative, edit
/etc/rc.local
and add the following line beforeexit 0
/opt/ntopng-grafana/scripts/on-boot.sh &
- ASN mappings from https://github.com/sapics/ip-location-db
- OUI mappings from https://standards-oui.ieee.org