It's available on the web page as a client application that is downloading the gcode file and keeping track of position internally to that client. That exact positional data is not available from the API or socket really. There is an option in Marlin to auto report position similar to temperature, but there's still nothing built-in to OctoPrint to utilize that. A plugin could be developed to process the positional data being reported though.
I went through the page source, read through the JavaScript, tried to follow the logic paths, and there is a call I cannot find which has the information. It probably is an Ajax call.
The API is on GitHub, and I find it difficult to winkle out contact information. Besides it would require a change to the plugin.
My last resort is to use WireShark to capture the packets.
I mean the information is getting there somehow, it's just not publicly available, ie published.
Sigh. I was hoping someone had information about a plugin which would send back JSON with the information. I can get everything else I want, just not the layer progress.
Yes a plugin could be developed. However I do not do Python. Plus, I think, the information about layer progress probably requires extensive gcode parsing.
Someone has already gone through that process. I was hoping to just piggyback on the results.
The only thing that works out the current layer progress in OctoPrint is the gcode viewer. As @jneilliii mentioned, this is all done client side. Yes you're right that it requires parsing and analysing the whole gcode file. OctoPrint reports "printed bytes" over the socket, which you can match up to your analysed copy of the gcode file to work out where the current position is.
Well it appears that the Dashboard which has the required information shown is using WebSocket for data transfer.
Plus, the data is coded. Bleah.
So, since a layer is pretty much the same size as a previous layer, I will use the previous layer's duration as the MAX, then count seconds, thus giving me a completion percentage.
It's only an approximation, but better than nothing