I built a network monitoring solution following this guides :
Truly, a great job.
But I has build the solution at home for another network, I would like that my raspberry start and monitor at boot. And I missed in the comments or text a few thing.
I created services as described in the comment for prometheus, add another for the tcpdump. Don't forget prometheus working directory in this configuration (no specific user for prometheus).
[Unit] Description=Prometheus After=tcpdump.service [Service] User=pi Group=pi Type=simple WorkingDirectory=/home/pi/prometheus/prometheus-2.23.0.linux-armv7 ExecStart=/home/pi/prometheus/prometheus-2.23.0.linux-armv7/prometheus \ --config.file /home/pi/prometheus/prometheus.yml [Install] WantedBy=multi-user.target
/etc/systemd/system/tcpdump.service [Unit] Description=TCPDump service for traffic monitoring After=network-online.target [Service] Type=idle ExecStart=python3 /home/pi/network-traffic-metrics/network-traffic-metrics.py "(src net 192.168.10.0/24 and not dst net 192.168.10.0/24) or (dst net 192.168.10.0/24 and not src net 192.168.10.0/24)" [Install] WantedBy=default.target
But I had some network issues :
First, disable dhcpcd and install isc-dhcp-server
In my case, I keep dhcpcd as it mount the network interfaces eth0 & eth1. I also put a no gateway on eth0 (my lan part)
My dhcpcd.conf configuration for interfaces :
interface eth1 static ip_address=192.168.1.10 static routers=192.168.1.1 static domain_name_servers=126.96.36.199 static domain_search=188.8.131.52 interface eth0 static ip_address=192.168.10.1 static routers=192.168.10.1 static domain_name_servers=184.108.40.206 static domain_search=220.127.116.11 nogateway
But with this configuration, at boot :
- isc-dhcp-server and tcpdump
were not started because eth0 was not up or plugged. In my case, I could plug eth0 later.
So I took a while, but I found the network hook that works (forget all /etc/network thing, dhcpcd do not use it).
Create a file (not a directory...) called /etc/dhcpcd.exit-hook with
#!/bin/bash if [ "$interface" = "eth0" & "$reason" = "STATIC" & "$if_up" = "true" ] then systemctl start tcpdump systemctl start isc-dhcp-server.service fi
And all is starting when eth0 is going up.