Variable Inconsistencies

Hi there. I’m trying to report on DHCP activity on one of our routers.

In order to do this I have created a simple script (dhcp-count) which is as follows:

:global monDHCPCounter;
:set monDHCPCounter ($monDHCPCounter + 1);

I have made this script the lease-script for the DHCP server placing its name in the relevant box on the DHCP server config. The console shows as follows:

name=“site” interface=hotspot lease-time=4h address-pool=larger hotspot bootp-support=static authoritative=yes use-radius=no lease-script=dhcp-count

So far so good. However when I reboot the box and zero everything, I eventually see that the run-count of the script exceeds the value of the variable “monDHCPCounter”

This seems unexpected as Id expect them to follow each other in lock step. Can anybody explain how the script run count can contain run events where the variable was not incremented?

perhaps a race condition?

Also, I believe dhcp-script will run on both activation of a lease and release.

I would add some logging to the script, then you can manually look at the logs to see DHCP being allocated the the log item in the script being called.

Maybe it is easier and better to enable logging to an external syslog server (that is a good idea anyway) and then analyze the logs using one of the many available tools or your own scripts (on the syslog server machine).
This syslog server can be as simple as a Raspberry Pi.
You can also make it poll some info using SNMP e.g. the number of active leases.