This will show you how to monitor the traffic of your TTN gateway. This guide works for the single channel gateway by Jaab Braam and for the most Raspberry Pi based DIY gateways.
The traffic problem should be solved now, so please check for the now flow on GitHub.
To Do: monitoring of outbound traffic - accurate order by time, some measurements are stacked together.
To monitor your gateways you need an instance running:
- InfluxDB with a database
- Grafana with the InfluxDB database as datasource
- tcpdump installed on the gateway
The single channel gateway by Jaap Braam is pretty easy to monitor. You only have to open a telnet session and you will get all info needed. Node-RED will generate the payload out of this stream. All interesting data will be saved into an InfluxDB and visualized by Grafana.
I uploaded the flow to GitHub. You only have to change the IP of your gateway and your InfluxDB settings.
You can find the Grafana dashboard also on GitHub. You only change the DB query according to your setup.
One thing to keep in mind. If you restart your gateway, the connection will get lost. You have to restart Node-RED or you double change the IP address of your Gateway in the Node-RED flow.
The idea behind this is to establish a SSH connection to our gateway and perform a tcpdump on port 1700.
To establish the connection I use the node big-ssh, which has to be installed with manage palette. Now you can copy the flow from GitHub and edit your InfluxDB preferences.
big-ssh need a private RSA key to work so we have to generate one. Before that you can look if you do not already have one:
root@raspberrypi:/# ls ~/.ssh/ id_rsa id_rsa.pub known_hosts
Otherwise we will make a new one with a password:
ssh-keygen -t rsa -b 1024
Now we have to check which user is running node-red. If it is not root, we have to copy the key to a location readable by this user. In my example node-red runs under the user pi.
root@raspberrypi:/# ps -ef |grep node-red pi 405 1 0 Oct27 ? 01:05:30 node-red cp ~/.ssh/id_rsa /home/pi chmod 644 /home/pi/id_rsa
Now we have to copy to our gateway's authorized keys.
ssh-copy-id -i ~/.ssh/id_rsa.pub gw-user@gw-ip
Now we can edit the big-ssh preferences. We have to edit the host ip, the directory of the private key and the password.
Once you inject the time into the flow, all should be running fine. Now you can build a fancy dashbaird with Grafana.
One thing to keep in mind: big-ssh is not able to disconnect the ssh session, so it will remain open until your gateway or your node-red restarts. Every time you inject into the flow, it will open another ssh session, which will not be terminated. So big-ssh is only suitable for permanent connections.