One thing that's important to understand here is that OctoPrint doesn't know exactly when a layer has actually finished.
The thing is that the firmware does have buffers. So when OctoPrint sends a
G1 Z... (and fires the z change event), that doesn't mean that the printer/printer's firmware has actually already executed the layer change. Depending on the planner buffer size and the length of the enqueued moves, it might actually take a couple of seconds until that happens.
Additionally it is not trivial to parse out individual layers from a GCODE file (as visible with some of the problems the GCODE viewer implementation suffers from), thanks to z-hop, spiral mode and stuff like priming routines at odd z positions.
So - in order to answer your question - what exactly do you want? And does that need an accurate layer count or would the last sent z-height be enough?
PS: Moved this into the Plugins category, since it sounds more like a "is there a plugin or could one be written" question than a "I want to implement X" question. Correct me if I understood that wrong though please!