benisai / Openwrt-Monitoring

Openwrt Monitoring via Grafana
109 stars 16 forks source link

Intro



* Here are some features of this project
  * Internet monitoring via pings to google/quad9/Cloudflare
  * Packetloss monitoring via shell script, pinging google 40 times
  * Speedtest monitoring via shell script -- (kind of broken, hit/miss, I'll explain below)
  * DNS Stats via AdguardHome Container in Docker
  * GeoIP Map for Destnation (provided by Netify logs, Check out the netify-log.sh script in the Docker folder https://github.com/benisai/Openwrt-Monitoring/blob/main/Docker/netify-log.sh)
  * Device Traffic Panel via netify-log.sh (provided by Netify logs). Src + Dst + Port + GeoInfo 
  * Device Status (Hostname + IP + Status Online or Offline)
  * System Resources monitoring (CPU/MEM/Load/Etc) via prometheus on Router
  * Monthly Bandwidth monitoring via VNState2 (Will clear monthly on 1st via crontab)
  * 12hr Traffic usage (calucated by itpmon results from prometheus)
  * WAN Speeds via prometheus
  * Live traffic per device (iptmon)
  * Traffic per client usage for 2hr (calucated by itpmon results from prometheus)
  * Ping Stats via CollectD
  * Hourly traffic usage (calucated by itpmon results from prometheus)
  * 7 Day traffic usage (calucated by itpmon results from prometheus)
  * New Devices Connected to Network via shell script
  * Destnation IP count (calucated by nat_traffic results from prometheus)
  * Destnation Port count (calucated by nat_traffic results from prometheus)
  * NAT Traffic (calucated by nat_traffic results from prometheus)
* We need to install a few pieces of software + custom shell scripts on the router to collect this data  



Software Used to Monitor Traffic

Home Server (Ubuntu)

Router



Grafana Dashboard Grafana Dashboard Grafana Dashboard Grafana Dashboard Grafana Dashboard Grafana Dashboard Grafana Dashboard Grafana Dashboard Grafana Dashboard



Home Server Installation (Linux)


Router Installation (Openwrt 21.x)

The routersetup.sh script will do the following:
* Install Nano, netperf (needed for speedtest.sh), openssh-sftp-server,vnstat
* Install Prometheus and CollectD
* Install iptmon, wrtbwmon and luci-wrtbwmon
* Copy custom scripts from this git to /usr/bin/ on the router
* Copy custom LUA files from this git to /usr/lib/lua/prometheus-collectors on the router.
* Adding new_device.sh script to dhcp dnsmasq
* Adding scripts to Crontab
* Update prometheus config to 'lan'
* Update Collectd Export IP to home server ip address
* Add iptmon to your dhcp file under dnsmasq section
* Set your lan interface to assign out DNS IP of your home server
* restarts services




Extra Configuration for OpenWRT




Troubleshooting:

firewall configuration

echo '/usr/sbin/iptmon init' >> /etc/firewall.user

luci_statistics/collectd configuration.

uci set luci_statistics.collectd.Include='/etc/collectd/conf.d'

Commit changes.

uci commit

Restart services.

/etc/init.d/dnsmasq restart /etc/init.d/firewall restart /etc/init.d/luci_statistics restart

rm -rf /tmp/luci-modulecache/



--------

Credit: I have to give credit to Matthew Helmke, I used his blog and grafana dashboard and I added some stuff. I cant say I'm an expert in Grafana or Prometheus (first time using Prom) https://grafana.com/blog/2021/02/09/how-i-monitor-my-openwrt-router-with-grafana-cloud-and-prometheus/